Merge r5968, r5972 from nihvivo-rel-1.1.-maint. Externally-linked namespaces.

This commit is contained in:
rjy7 2010-09-29 18:56:36 +00:00
parent 717cbc68ce
commit 3975d9aa01
5 changed files with 64 additions and 9 deletions

View file

@ -2,10 +2,14 @@
package edu.cornell.mannlib.vitro.webapp.dao;
import java.util.List;
public interface ApplicationDao {
public boolean isFlag1Active();
public boolean isFlag2Active();
public List<String> getExternallyLinkedNamespaces();
}

View file

@ -34,6 +34,8 @@ public class VitroVocabulary {
// an OWL DL-compatible surrogate for rdf:value for use with boxing idiom
public static final String value = vitroURI + "value";
public static final String DISPLAY = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#";
// properties found on the beans

View file

@ -2,19 +2,23 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.util.Collection;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
Integer portalCount = null;
List<String> externallyLinkedNamespaces = null;
public ApplicationDaoJena(WebappDaoFactoryJena wadf) {
super(wadf);
@ -39,4 +43,22 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
return (getFlag2ValueMap().isEmpty()) ? false : true;
}
public List<String> getExternallyLinkedNamespaces() {
if (externallyLinkedNamespaces == null) {
externallyLinkedNamespaces = new ArrayList<String>();
OntModel ontModel = getOntModelSelector().getDisplayModel();
Property linkedNamespaceProp = ontModel.getProperty(VitroVocabulary.DISPLAY + "linkedNamespace");
NodeIterator nodes = ontModel.listObjectsOfProperty(linkedNamespaceProp);
while (nodes.hasNext()) {
RDFNode node = nodes.next();
if (node.isLiteral()) {
String namespace = ((Literal)node).getLexicalForm();
externallyLinkedNamespaces.add(namespace);
}
}
}
return externallyLinkedNamespaces;
}
}

View file

@ -42,4 +42,6 @@ public interface OntModelSelector {
*/
public OntModel getTBoxModel(String ontologyURI);
public OntModel getDisplayModel();
}

View file

@ -27,6 +27,7 @@ import org.openrdf.model.URI;
import org.openrdf.model.impl.URIImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
@ -152,11 +153,12 @@ public class URLRewritingHttpServletResponse implements HttpServletResponse {
NamespaceMapper nsMap = NamespaceMapperFactory.getNamespaceMapper(_context);
try {
URI uri = new URIImpl(keyAndValue[1]);
if ( (uri.getNamespace() != null) && (uri.getLocalName() != null) ) {
String prefix = nsMap.getPrefixForNamespace(uri.getNamespace());
String localName = uri.getLocalName();
String namespace = uri.getNamespace();
String localName = uri.getLocalName();
if ( (namespace != null) && (localName != null) ) {
String prefix = nsMap.getPrefixForNamespace(namespace);
if (wadf.getDefaultNamespace().
equals(uri.getNamespace())
equals(namespace)
&& prefix == null) {
// make a URI that matches the URI
// of the resource to support
@ -164,6 +166,21 @@ public class URLRewritingHttpServletResponse implements HttpServletResponse {
url.pathParts.add(localName);
// remove the ugly uri parameter
indexToRemove = qpIndex;
} else if (isExternallyLinkedNamespace(namespace)) {
namespace = removeFinalSlash(namespace);
log.debug("Found externally linked namespace " + namespace);
// Use the externally linked namespace in the url
url.pathParts = new ArrayList<String>();
url.pathParts.add(namespace);
url.pathParts.add(localName);
// remove the ugly uri parameter
indexToRemove = qpIndex;
// remove protocol, host, and port, since the external namespace
// includes these elements
url.protocol = null;
url.host = null;
url.port = null;
url.pathBeginsWithSlash = false;
} else if (prefix != null) {
// add the pretty path parts
url.pathParts.add(prefix);
@ -449,9 +466,17 @@ public class URLRewritingHttpServletResponse implements HttpServletResponse {
str = StringEscapeUtils.escapeXml(str);
}
return str;
}
}
}
private boolean isExternallyLinkedNamespace(String namespace) {
namespace = removeFinalSlash(namespace);
List<String> externallyLinkedNamespaces = wadf.getApplicationDao().getExternallyLinkedNamespaces();
return externallyLinkedNamespaces.contains(namespace);
}
private String removeFinalSlash(String str) {
return str.replaceAll("/$", "");
}
}