Merge r7047-7048 from nihvivo-rel-1.2-maint
This commit is contained in:
parent
c2e69fe9e1
commit
c6afc196c8
6 changed files with 119 additions and 70 deletions
|
@ -92,7 +92,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
|
String url = vreq.getRequestURI().substring(vreq.getContextPath().length());
|
||||||
|
|
||||||
// Check to see if the request is for a non-information resource, redirect if it is.
|
// Check to see if the request is for a non-information resource, redirect if it is.
|
||||||
String redirectURL = checkForRedirect ( url, vreq.getHeader("accept") );
|
String redirectURL = checkForRedirect ( url, vreq );
|
||||||
if( redirectURL != null ){
|
if( redirectURL != null ){
|
||||||
return new RedirectResponseValues(redirectURL);
|
return new RedirectResponseValues(redirectURL);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
return doNotFound(vreq);
|
return doNotFound(vreq);
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentType rdfFormat = checkForLinkedDataRequest(url,vreq.getHeader("accept"));
|
ContentType rdfFormat = checkForLinkedDataRequest(url, vreq);
|
||||||
if( rdfFormat != null ){
|
if( rdfFormat != null ){
|
||||||
return doRdf(vreq, individual, rdfFormat);
|
return doRdf(vreq, individual, rdfFormat);
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
private String getRdfLinkTag(IndividualTemplateModel itm) {
|
private String getRdfLinkTag(IndividualTemplateModel itm) {
|
||||||
String linkTag = null;
|
String linkTag = null;
|
||||||
String linkedDataUrl = itm.getLinkedDataUrl();
|
String linkedDataUrl = itm.getRdfUrl(false);
|
||||||
if (linkedDataUrl != null) {
|
if (linkedDataUrl != null) {
|
||||||
linkTag = "<link rel=\"alternate\" type=\"application/rdf+xml\" href=\"" +
|
linkTag = "<link rel=\"alternate\" type=\"application/rdf+xml\" href=\"" +
|
||||||
linkedDataUrl + "\" /> ";
|
linkedDataUrl + "\" /> ";
|
||||||
|
@ -200,10 +200,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
individual.setKeywords(iwDao.getKeywordsForIndividualByMode(individual.getURI(),"visible"));
|
individual.setKeywords(iwDao.getKeywordsForIndividualByMode(individual.getURI(),"visible"));
|
||||||
individual.sortForDisplay();
|
individual.sortForDisplay();
|
||||||
|
|
||||||
//setup highlighter for search terms
|
return new IndividualTemplateModel(individual, vreq);
|
||||||
//checkForSearch(vreq, individual);
|
|
||||||
|
|
||||||
return new IndividualTemplateModel(individual, vreq, LoginStatusBean.getBean(vreq));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine whether the individual has a custom display template based on its class membership.
|
// Determine whether the individual has a custom display template based on its class membership.
|
||||||
|
@ -387,10 +384,10 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
//Redirect if the request is for http://hostname/individual/localname
|
//Redirect if the request is for http://hostname/individual/localname
|
||||||
// if accept is nothing or text/html redirect to ???
|
// if accept is nothing or text/html redirect to ???
|
||||||
// if accept is some RDF thing redirect to the URL for RDF
|
// if accept is some RDF thing redirect to the URL for RDF
|
||||||
private String checkForRedirect(String url, String acceptHeader) {
|
private String checkForRedirect(String url, VitroRequest vreq) {
|
||||||
Matcher m = URI_PATTERN.matcher(url);
|
Matcher m = URI_PATTERN.matcher(url);
|
||||||
if( m.matches() && m.groupCount() == 1 ){
|
if( m.matches() && m.groupCount() == 1 ){
|
||||||
ContentType c = checkForLinkedDataRequest(url, acceptHeader);
|
ContentType c = checkForLinkedDataRequest(url, vreq);
|
||||||
if( c != null ){
|
if( c != null ){
|
||||||
String redirectUrl = "/individual/" + m.group(1) + "/" + m.group(1) ;
|
String redirectUrl = "/individual/" + m.group(1) + "/" + m.group(1) ;
|
||||||
if( RDFXML_MIMETYPE.equals( c.getMediaType()) ){
|
if( RDFXML_MIMETYPE.equals( c.getMediaType()) ){
|
||||||
|
@ -413,13 +410,37 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
private static Pattern TTL_REQUEST = Pattern.compile("^/individual/([^/]*)/\\1.ttl$");
|
private static Pattern TTL_REQUEST = Pattern.compile("^/individual/([^/]*)/\\1.ttl$");
|
||||||
private static Pattern HTML_REQUEST = Pattern.compile("^/display/([^/]*)$");
|
private static Pattern HTML_REQUEST = Pattern.compile("^/display/([^/]*)$");
|
||||||
|
|
||||||
|
public static final Pattern RDFXML_FORMAT = Pattern.compile("rdfxml");
|
||||||
|
public static final Pattern N3_FORMAT = Pattern.compile("n3");
|
||||||
|
public static final Pattern TTL_FORMAT = Pattern.compile("ttl");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null if this is not a linked data request, returns content type if it is a
|
* @return null if this is not a linked data request, returns content type if it is a
|
||||||
* linked data request.
|
* linked data request.
|
||||||
*/
|
*/
|
||||||
protected ContentType checkForLinkedDataRequest(String url, String acceptHeader) {
|
protected ContentType checkForLinkedDataRequest(String url, VitroRequest vreq ) {
|
||||||
try {
|
try {
|
||||||
//check the accept header
|
ContentType contentType = null;
|
||||||
|
Matcher m;
|
||||||
|
// Check for url param specifying format
|
||||||
|
String formatParam = (String) vreq.getParameter("format");
|
||||||
|
if (formatParam != null) {
|
||||||
|
m = RDFXML_FORMAT.matcher(formatParam);
|
||||||
|
if ( m.matches() ) {
|
||||||
|
return new ContentType(RDFXML_MIMETYPE);
|
||||||
|
}
|
||||||
|
m = N3_FORMAT.matcher(formatParam);
|
||||||
|
if( m.matches() ) {
|
||||||
|
return new ContentType(N3_MIMETYPE);
|
||||||
|
}
|
||||||
|
m = TTL_FORMAT.matcher(formatParam);
|
||||||
|
if( m.matches() ) {
|
||||||
|
return new ContentType(TTL_MIMETYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//check the accept header
|
||||||
|
String acceptHeader = vreq.getHeader("accept");
|
||||||
if (acceptHeader != null) {
|
if (acceptHeader != null) {
|
||||||
List<ContentType> actualContentTypes = new ArrayList<ContentType>();
|
List<ContentType> actualContentTypes = new ArrayList<ContentType>();
|
||||||
actualContentTypes.add(new ContentType( XHTML_MIMETYPE ));
|
actualContentTypes.add(new ContentType( XHTML_MIMETYPE ));
|
||||||
|
@ -428,14 +449,13 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
actualContentTypes.add(new ContentType( RDFXML_MIMETYPE ));
|
actualContentTypes.add(new ContentType( RDFXML_MIMETYPE ));
|
||||||
actualContentTypes.add(new ContentType( N3_MIMETYPE ));
|
actualContentTypes.add(new ContentType( N3_MIMETYPE ));
|
||||||
actualContentTypes.add(new ContentType( TTL_MIMETYPE ));
|
actualContentTypes.add(new ContentType( TTL_MIMETYPE ));
|
||||||
|
|
||||||
|
contentType = ContentType.getBestContentType(acceptHeader,actualContentTypes);
|
||||||
ContentType best = ContentType.getBestContentType(acceptHeader,actualContentTypes);
|
if (contentType!=null && (
|
||||||
if (best!=null && (
|
RDFXML_MIMETYPE.equals(contentType.getMediaType()) ||
|
||||||
RDFXML_MIMETYPE.equals(best.getMediaType()) ||
|
N3_MIMETYPE.equals(contentType.getMediaType()) ||
|
||||||
N3_MIMETYPE.equals(best.getMediaType()) ||
|
TTL_MIMETYPE.equals(contentType.getMediaType()) ))
|
||||||
TTL_MIMETYPE.equals(best.getMediaType()) ))
|
return contentType;
|
||||||
return best;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -444,22 +464,30 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
http://vivo.cornell.edu/individual/n23/n23.n3
|
http://vivo.cornell.edu/individual/n23/n23.n3
|
||||||
http://vivo.cornell.edu/individual/n23/n23.ttl
|
http://vivo.cornell.edu/individual/n23/n23.ttl
|
||||||
*/
|
*/
|
||||||
|
m = RDF_REQUEST.matcher(url);
|
||||||
Matcher m = RDF_REQUEST.matcher(url);
|
if( m.matches() ) {
|
||||||
if( m.matches() )
|
return new ContentType(RDFXML_MIMETYPE);
|
||||||
return new ContentType(RDFXML_MIMETYPE);
|
}
|
||||||
m = N3_REQUEST.matcher(url);
|
m = N3_REQUEST.matcher(url);
|
||||||
if( m.matches() )
|
if( m.matches() ) {
|
||||||
return new ContentType(N3_MIMETYPE);
|
return new ContentType(N3_MIMETYPE);
|
||||||
m = TTL_REQUEST.matcher(url);
|
}
|
||||||
if( m.matches() )
|
m = TTL_REQUEST.matcher(url);
|
||||||
return new ContentType(TTL_MIMETYPE);
|
if( m.matches() ) {
|
||||||
|
return new ContentType(TTL_MIMETYPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (Throwable th) {
|
} catch (Throwable th) {
|
||||||
log.error("problem while checking accept header " , th);
|
log.error("problem while checking accept header " , th);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ContentType getContentTypeFromString(String string) {
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private boolean checkForSunset(VitroRequest vreq, Individual entity) {
|
private boolean checkForSunset(VitroRequest vreq, Individual entity) {
|
||||||
|
@ -540,27 +568,6 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
return newModel;
|
return newModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkForSearch(HttpServletRequest req, Individual ent) {
|
|
||||||
if (req.getSession().getAttribute("LastQuery") != null) {
|
|
||||||
VitroQueryWrapper qWrap = (VitroQueryWrapper) req.getSession()
|
|
||||||
.getAttribute("LastQuery");
|
|
||||||
if (qWrap.getRequestCount() > 0 && qWrap.getQuery() != null) {
|
|
||||||
VitroQuery query = qWrap.getQuery();
|
|
||||||
|
|
||||||
//set query text so we can get it in JSP
|
|
||||||
req.setAttribute("querytext", query.getTerms());
|
|
||||||
|
|
||||||
//setup highlighting for output
|
|
||||||
StringProcessorTag.putStringProcessorInRequest(req, qWrap.getHighlighter());
|
|
||||||
|
|
||||||
qWrap.setRequestCount(qWrap.getRequestCount() - 1);
|
|
||||||
} else {
|
|
||||||
req.getSession().removeAttribute("LastQuery");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Pattern badrequest= Pattern.compile(".*([&\\?=]|\\.\\.).*");
|
private Pattern badrequest= Pattern.compile(".*([&\\?=]|\\.\\.).*");
|
||||||
|
|
||||||
|
|
|
@ -234,12 +234,24 @@ public class UrlBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPath(String path, ParamMap params) {
|
public static String getPath(String path, ParamMap params) {
|
||||||
String glue = "?";
|
return addParams(path, params, "?");
|
||||||
for (String key : params.keySet()) {
|
}
|
||||||
path += glue + key + "=" + urlEncode(params.get(key));
|
|
||||||
|
private static String addParams(String url, ParamMap params, String glue) {
|
||||||
|
for (String key: params.keySet()) {
|
||||||
|
url += glue + key + "=" + urlEncode(params.get(key));
|
||||||
glue = "&";
|
glue = "&";
|
||||||
}
|
}
|
||||||
return path;
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String addParams(String url, ParamMap params) {
|
||||||
|
String glue = url.contains("?") ? "&" : "?";
|
||||||
|
return addParams(url, params, glue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String addParams(String url, String...params) {
|
||||||
|
return addParams(url, new ParamMap(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPath(Route route, ParamMap params) {
|
public static String getPath(Route route, ParamMap params) {
|
||||||
|
@ -267,8 +279,7 @@ public class UrlBuilder {
|
||||||
if (defaultNamespace.equals(namespace)) {
|
if (defaultNamespace.equals(namespace)) {
|
||||||
profileUrl = getUrl(Route.INDIVIDUAL.path() + "/" + localName);
|
profileUrl = getUrl(Route.INDIVIDUAL.path() + "/" + localName);
|
||||||
} else {
|
} else {
|
||||||
List<String> externallyLinkedNamespaces = wadf.getApplicationDao().getExternallyLinkedNamespaces();
|
if (wadf.getApplicationDao().isExternallyLinkedNamespace(namespace)) {
|
||||||
if (externallyLinkedNamespaces.contains(namespace)) {
|
|
||||||
log.debug("Found externally linked namespace " + namespace);
|
log.debug("Found externally linked namespace " + namespace);
|
||||||
profileUrl = namespace + "/" + localName;
|
profileUrl = namespace + "/" + localName;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -12,4 +12,6 @@ public interface ApplicationDao {
|
||||||
|
|
||||||
public List<String> getExternallyLinkedNamespaces();
|
public List<String> getExternallyLinkedNamespaces();
|
||||||
|
|
||||||
|
public boolean isExternallyLinkedNamespace(String namespace);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,6 +80,11 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
|
||||||
return externallyLinkedNamespaces;
|
return externallyLinkedNamespaces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isExternallyLinkedNamespace(String namespace) {
|
||||||
|
List<String> namespaces = getExternallyLinkedNamespaces();
|
||||||
|
return namespaces.contains(namespace);
|
||||||
|
}
|
||||||
|
|
||||||
private class ExternalNamespacesChangeListener extends StatementListener {
|
private class ExternalNamespacesChangeListener extends StatementListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,15 +2,16 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.openrdf.model.URI;
|
||||||
|
import org.openrdf.model.impl.URIImpl;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Link;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||||
|
@ -31,10 +32,10 @@ public class IndividualTemplateModel extends BaseTemplateModel {
|
||||||
protected LoginStatusBean loginStatusBean = null;
|
protected LoginStatusBean loginStatusBean = null;
|
||||||
private EditingPolicyHelper policyHelper = null;
|
private EditingPolicyHelper policyHelper = null;
|
||||||
|
|
||||||
public IndividualTemplateModel(Individual individual, VitroRequest vreq, LoginStatusBean loginStatusBean) {
|
public IndividualTemplateModel(Individual individual, VitroRequest vreq) {
|
||||||
this.individual = individual;
|
this.individual = individual;
|
||||||
this.vreq = vreq;
|
this.vreq = vreq;
|
||||||
this.loginStatusBean = loginStatusBean;
|
this.loginStatusBean = LoginStatusBean.getBean(vreq);
|
||||||
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
|
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
|
||||||
this.urlBuilder = new UrlBuilder(vreq.getPortal());
|
this.urlBuilder = new UrlBuilder(vreq.getPortal());
|
||||||
|
|
||||||
|
@ -80,16 +81,39 @@ public class IndividualTemplateModel extends BaseTemplateModel {
|
||||||
return thumbUrl == null ? null : getUrl(thumbUrl);
|
return thumbUrl == null ? null : getUrl(thumbUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLinkedDataUrl() {
|
public String getRdfUrl() {
|
||||||
String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
|
return getRdfUrl(true);
|
||||||
String uri = getUri();
|
|
||||||
return uri.startsWith(defaultNamespace) ? uri + "/" + getLocalName() + ".rdf" : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RY Used for the rdf link on the individual page. Is it correct that this is not the same
|
// Used to create a link to generate the individual's rdf.
|
||||||
// as getLinkedDataUrl()?
|
public String getRdfUrl(boolean checkExternalNamespaces) {
|
||||||
public String getRdfUrl() {
|
|
||||||
return getProfileUrl() + "/" + getLocalName() + ".rdf";
|
String individualUri = getUri();
|
||||||
|
String profileUrl = getProfileUrl();
|
||||||
|
|
||||||
|
URI uri = new URIImpl(individualUri);
|
||||||
|
String namespace = uri.getNamespace();
|
||||||
|
|
||||||
|
// Individuals in the default namespace
|
||||||
|
// e.g., http://vivo.cornell.edu/individual/n2345/n2345.rdf
|
||||||
|
// where default namespace = http://vivo.cornell.edu/individual/
|
||||||
|
String defaultNamespace = vreq.getWebappDaoFactory().getDefaultNamespace();
|
||||||
|
if (defaultNamespace.equals(namespace)) {
|
||||||
|
return profileUrl + "/" + getLocalName() + ".rdf";
|
||||||
|
}
|
||||||
|
|
||||||
|
// An RDF url is not defined for an externally linked namespace. The data does not reside
|
||||||
|
// in the current system, and the external system may not accept a request for rdf.
|
||||||
|
if (checkExternalNamespaces && vreq.getWebappDaoFactory()
|
||||||
|
.getApplicationDao()
|
||||||
|
.isExternallyLinkedNamespace(namespace)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// http://some.other.namespace/n2345?format=rdfxml
|
||||||
|
// ** RY Not sure it is correct to return this for the <link> element
|
||||||
|
return UrlBuilder.addParams(profileUrl, "format", "rdfxml");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEditUrl() {
|
public String getEditUrl() {
|
||||||
|
|
|
@ -141,7 +141,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel
|
||||||
try {
|
try {
|
||||||
return new CollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper);
|
return new CollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper);
|
||||||
} catch (InvalidConfigurationException e) {
|
} catch (InvalidConfigurationException e) {
|
||||||
log.warn(e);
|
log.warn(e.getMessage());
|
||||||
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper);
|
return new UncollatedObjectPropertyTemplateModel(op, subject, vreq, policyHelper);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue