diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ApplicationDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ApplicationDao.java index 03a3db19e..6ccd29b4f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ApplicationDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ApplicationDao.java @@ -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 getExternallyLinkedNamespaces(); + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java index 50e9b33fb..4cb54fc51 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/VitroVocabulary.java @@ -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 diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java index 8b2a018f0..8ceac577d 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java @@ -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 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 getExternallyLinkedNamespaces() { + if (externallyLinkedNamespaces == null) { + externallyLinkedNamespaces = new ArrayList(); + 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; + } + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/OntModelSelector.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/OntModelSelector.java index c58aafe09..e5aa2f68b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/OntModelSelector.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/OntModelSelector.java @@ -42,4 +42,6 @@ public interface OntModelSelector { */ public OntModel getTBoxModel(String ontologyURI); + public OntModel getDisplayModel(); + } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java index 08965269d..1b5a85185 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filters/URLRewritingHttpServletResponse.java @@ -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(); + 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 externallyLinkedNamespaces = wadf.getApplicationDao().getExternallyLinkedNamespaces(); + return externallyLinkedNamespaces.contains(namespace); + } + + private String removeFinalSlash(String str) { + return str.replaceAll("/$", ""); + } }