Add utility method to determine whether an individual's uri is in the default namespace.
This commit is contained in:
parent
f1ae5c6f01
commit
cd0f9f1f6d
2 changed files with 20 additions and 12 deletions
|
@ -18,6 +18,7 @@ import org.openrdf.model.impl.URIImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.filters.PortalPickerFilter;
|
import edu.cornell.mannlib.vitro.webapp.filters.PortalPickerFilter;
|
||||||
|
|
||||||
|
@ -319,6 +320,22 @@ public class UrlBuilder {
|
||||||
return profileUrl;
|
return profileUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isUriInDefaultNamespace(String individualUri, VitroRequest vreq) {
|
||||||
|
return isUriInDefaultNamespace(individualUri, vreq.getWebappDaoFactory());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isUriInDefaultNamespace(String individualUri, WebappDaoFactory wadf) {
|
||||||
|
try {
|
||||||
|
URI uri = new URIImpl(individualUri); // throws exception if individualUri is invalid
|
||||||
|
String namespace = uri.getNamespace();
|
||||||
|
String defaultNamespace = wadf.getDefaultNamespace();
|
||||||
|
return defaultNamespace.equals(namespace);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static String urlEncode(String str) {
|
public static String urlEncode(String str) {
|
||||||
String encoding = "ISO-8859-1";
|
String encoding = "ISO-8859-1";
|
||||||
String encodedUrl = null;
|
String encodedUrl = null;
|
||||||
|
|
|
@ -94,18 +94,9 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
||||||
|
|
||||||
String individualUri = getUri();
|
String individualUri = getUri();
|
||||||
String profileUrl = getProfileUrl();
|
String profileUrl = getProfileUrl();
|
||||||
|
boolean isUriInDefaultNamespace = UrlBuilder.isUriInDefaultNamespace(individualUri, vreq);
|
||||||
URI uri = new URIImpl(individualUri);
|
return isUriInDefaultNamespace ? profileUrl + "/" + getLocalName() + ".rdf"
|
||||||
String namespace = uri.getNamespace();
|
: UrlBuilder.addParams(profileUrl, "format", "rdfxml");
|
||||||
|
|
||||||
// Individuals in the default namespace
|
|
||||||
// e.g., http://vivo.cornell.edu/individual/n2345/n2345.rdf
|
|
||||||
// where default namespace = http://vivo.cornell.edu/individual/
|
|
||||||
// Other individuals: http://some.other.namespace/n2345?format=rdfxml
|
|
||||||
String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
|
|
||||||
return (defaultNamespace.equals(namespace)) ? profileUrl + "/" + getLocalName() + ".rdf"
|
|
||||||
: UrlBuilder.addParams(profileUrl, "format", "rdfxml");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEditUrl() {
|
public String getEditUrl() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue