Manually copy EntityController.java from branch - manual merge of 4721, 4722 and the remainder of 4719 (web.xml was already merged).
This commit is contained in:
parent
16496437c9
commit
846aad6d50
1 changed files with 45 additions and 64 deletions
|
@ -27,7 +27,11 @@ import com.hp.hpl.jena.rdf.model.Model;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||||
import com.hp.hpl.jena.rdf.model.Property;
|
import com.hp.hpl.jena.rdf.model.Property;
|
||||||
|
import com.hp.hpl.jena.rdf.model.RDFNode;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
||||||
|
@ -67,6 +71,7 @@ public class EntityController extends VitroHttpServlet {
|
||||||
VitroRequest vreq = new VitroRequest(req);
|
VitroRequest vreq = new VitroRequest(req);
|
||||||
//get URL without hostname or servlet context
|
//get URL without hostname or servlet context
|
||||||
String url = req.getRequestURI().substring(req.getContextPath().length());
|
String url = req.getRequestURI().substring(req.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, req.getHeader("accept") );
|
String redirectURL = checkForRedirect ( url, req.getHeader("accept") );
|
||||||
if( redirectURL != null ){
|
if( redirectURL != null ){
|
||||||
|
@ -76,7 +81,6 @@ public class EntityController extends VitroHttpServlet {
|
||||||
|
|
||||||
ContentType rdfFormat = checkForLinkedDataRequest(url,req.getHeader("accept"));
|
ContentType rdfFormat = checkForLinkedDataRequest(url,req.getHeader("accept"));
|
||||||
if( rdfFormat != null ){
|
if( rdfFormat != null ){
|
||||||
System.out.println("RDF Format? ");
|
|
||||||
doRdf( vreq, res, rdfFormat );
|
doRdf( vreq, res, rdfFormat );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -193,9 +197,6 @@ public class EntityController extends VitroHttpServlet {
|
||||||
vreq.setAttribute("entityDatapropsListJsp",Controllers.ENTITY_DATAPROP_LIST_JSP);
|
vreq.setAttribute("entityDatapropsListJsp",Controllers.ENTITY_DATAPROP_LIST_JSP);
|
||||||
vreq.setAttribute("entityMergedPropsListJsp",Controllers.ENTITY_MERGED_PROP_LIST_GROUPED_JSP);
|
vreq.setAttribute("entityMergedPropsListJsp",Controllers.ENTITY_MERGED_PROP_LIST_GROUPED_JSP);
|
||||||
vreq.setAttribute("entityKeywordsListJsp",Controllers.ENTITY_KEYWORDS_LIST_JSP);
|
vreq.setAttribute("entityKeywordsListJsp",Controllers.ENTITY_KEYWORDS_LIST_JSP);
|
||||||
} else if (view.equals("rdf.rdf")) {
|
|
||||||
writeRDF(indiv, vreq, res);
|
|
||||||
// BJL23 temporarily disabling this until we add filtering of hidden properties (get RDF through Vitro API with filtering DAOs)
|
|
||||||
} else {
|
} else {
|
||||||
log.debug("Found view parameter "+view+" in request for rendering "+indiv.getName());
|
log.debug("Found view parameter "+view+" in request for rendering "+indiv.getName());
|
||||||
}
|
}
|
||||||
|
@ -229,6 +230,7 @@ public class EntityController extends VitroHttpServlet {
|
||||||
|
|
||||||
vreq.setAttribute("css",css);
|
vreq.setAttribute("css",css);
|
||||||
vreq.setAttribute("scripts", "/templates/entity/entity_inject_head.jsp");
|
vreq.setAttribute("scripts", "/templates/entity/entity_inject_head.jsp");
|
||||||
|
|
||||||
RequestDispatcher rd = vreq.getRequestDispatcher( view );
|
RequestDispatcher rd = vreq.getRequestDispatcher( view );
|
||||||
rd.forward(vreq,res);
|
rd.forward(vreq,res);
|
||||||
}
|
}
|
||||||
|
@ -242,14 +244,15 @@ public class EntityController extends VitroHttpServlet {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Model ontModel = null;
|
OntModel ontModel = null;
|
||||||
HttpSession session = vreq.getSession(false);
|
HttpSession session = vreq.getSession(false);
|
||||||
if( session != null )
|
if( session != null )
|
||||||
ontModel =(Model)session.getAttribute("jenaOntModel");
|
ontModel =(OntModel)session.getAttribute("jenaOntModel");
|
||||||
if( ontModel == null)
|
if( ontModel == null)
|
||||||
ontModel = (Model)getServletContext().getAttribute("jenaOntModel");
|
ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
|
||||||
|
|
||||||
Model newModel = getRDF(indiv, ontModel, ModelFactory.createDefaultModel(), 0);
|
Model newModel;
|
||||||
|
newModel = getRDF(indiv, ontModel, ModelFactory.createDefaultModel(), 0);
|
||||||
|
|
||||||
res.setContentType(rdfFormat.getMediaType());
|
res.setContentType(rdfFormat.getMediaType());
|
||||||
String format = "";
|
String format = "";
|
||||||
|
@ -402,13 +405,10 @@ public class EntityController extends VitroHttpServlet {
|
||||||
return redirectUrl + ".n3";
|
return redirectUrl + ".n3";
|
||||||
}else if( TTL_MIMETYPE.equals( c.getMediaType() )){
|
}else if( TTL_MIMETYPE.equals( c.getMediaType() )){
|
||||||
return redirectUrl + ".ttl";
|
return redirectUrl + ".ttl";
|
||||||
}else{ //this case shouldn't happen
|
}//else send them to html
|
||||||
return redirectUrl + ".rdf";
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
//redirect to HTML representation
|
|
||||||
return "/individual/" + m.group(1) + "/" + m.group(1) + ".html";
|
|
||||||
}
|
}
|
||||||
|
//else redirect to HTML representation
|
||||||
|
return "/display/" + m.group(1) ;
|
||||||
}else{
|
}else{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,7 @@ public class EntityController extends VitroHttpServlet {
|
||||||
private static Pattern RDF_REQUEST = Pattern.compile("^/individual/([^/]*)/\\1.rdf$");
|
private static Pattern RDF_REQUEST = Pattern.compile("^/individual/([^/]*)/\\1.rdf$");
|
||||||
private static Pattern N3_REQUEST = Pattern.compile("^/individual/([^/]*)/\\1.n3$");
|
private static Pattern N3_REQUEST = Pattern.compile("^/individual/([^/]*)/\\1.n3$");
|
||||||
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("^/individual/([^/]*)/\\1.html$");
|
private static Pattern HTML_REQUEST = Pattern.compile("^/display/([^/]*)$");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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
|
||||||
|
@ -477,58 +477,21 @@ public class EntityController extends VitroHttpServlet {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeRDF(Individual entity, HttpServletRequest req, HttpServletResponse res) {
|
private Model getRDF(Individual entity, OntModel contextModel, Model newModel, int recurseDepth ) {
|
||||||
OntModel ontModel = (OntModel) getServletContext().getAttribute("jenaOntModel");
|
Resource subj = newModel.getResource(entity.getURI());
|
||||||
|
|
||||||
Resource i = ontModel.getResource(entity.getURI());
|
|
||||||
ModelMaker modelMaker = ontModel.getImportModelMaker();
|
|
||||||
Model newModel = modelMaker.createModel(entity.getURI(), false);
|
|
||||||
newModel = getRDF(entity, ontModel, newModel, 0);
|
|
||||||
try {
|
|
||||||
ServletOutputStream outstream = res.getOutputStream();
|
|
||||||
/*
|
|
||||||
newModel.remove(newModel.listStatements());
|
|
||||||
newModel.add(aboutEntity);
|
|
||||||
aboutEntity.close();
|
|
||||||
StmtIterator aboutEntity2 = ontModel.listStatements(i , null, (RDFNode)null);
|
|
||||||
while(aboutEntity2.hasNext()) {
|
|
||||||
Statement st = aboutEntity2.nextStatement();
|
|
||||||
Resource o = null;
|
|
||||||
Property p = st.getPredicate();
|
|
||||||
RDFNode obj = st.getObject();
|
|
||||||
if(!(obj instanceof Literal)) o = (Resource)obj;
|
|
||||||
if(!p.getURI().equals(RDF.type.getURI()) && o!=null) {
|
|
||||||
StmtIterator aboutObject = ontModel.listStatements(o, null, (RDFNode)null);
|
|
||||||
newModel.add(aboutObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
res.setContentType("application/rdf+xml");
|
|
||||||
newModel.write(outstream);
|
|
||||||
}
|
|
||||||
catch (Throwable e) {
|
|
||||||
log.error(e);
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds data from ontModel about entity to newModel. Go down 1 level if recurse is true
|
|
||||||
private Model getRDF(Individual entity, Model ontModel, Model newModel, int recurseDepth ) {
|
|
||||||
Resource subj = ontModel.getResource(entity.getURI());
|
|
||||||
|
|
||||||
List<DataPropertyStatement> dstates = entity.getDataPropertyStatements();
|
List<DataPropertyStatement> dstates = entity.getDataPropertyStatements();
|
||||||
//System.out.println("data: "+dstates.size());
|
//System.out.println("data: "+dstates.size());
|
||||||
TypeMapper typeMapper = TypeMapper.getInstance();
|
TypeMapper typeMapper = TypeMapper.getInstance();
|
||||||
for (DataPropertyStatement ds: dstates) {
|
for (DataPropertyStatement ds: dstates) {
|
||||||
Property dp = ontModel.getProperty(ds.getDatapropURI());
|
Property dp = newModel.getProperty(ds.getDatapropURI());
|
||||||
Literal lit = null;
|
Literal lit = null;
|
||||||
if ((ds.getLanguage()) != null && (ds.getLanguage().length()>0)) {
|
if ((ds.getLanguage()) != null && (ds.getLanguage().length()>0)) {
|
||||||
lit = ontModel.createLiteral(ds.getData(),ds.getLanguage());
|
lit = newModel.createLiteral(ds.getData(),ds.getLanguage());
|
||||||
} else if ((ds.getDatatypeURI() != null) && (ds.getDatatypeURI().length()>0)) {
|
} else if ((ds.getDatatypeURI() != null) && (ds.getDatatypeURI().length()>0)) {
|
||||||
lit = ontModel.createTypedLiteral(ds.getData(),typeMapper.getSafeTypeByName(ds.getDatatypeURI()));
|
lit = newModel.createTypedLiteral(ds.getData(),typeMapper.getSafeTypeByName(ds.getDatatypeURI()));
|
||||||
} else {
|
} else {
|
||||||
lit = ontModel.createLiteral(ds.getData());
|
lit = newModel.createLiteral(ds.getData());
|
||||||
}
|
}
|
||||||
newModel.add(newModel.createStatement(subj, dp, lit));
|
newModel.add(newModel.createStatement(subj, dp, lit));
|
||||||
}
|
}
|
||||||
|
@ -537,17 +500,35 @@ public class EntityController extends VitroHttpServlet {
|
||||||
List<ObjectPropertyStatement> ostates = entity.getObjectPropertyStatements();
|
List<ObjectPropertyStatement> ostates = entity.getObjectPropertyStatements();
|
||||||
for (ObjectPropertyStatement os: ostates) {
|
for (ObjectPropertyStatement os: ostates) {
|
||||||
ObjectProperty objProp = os.getProperty();
|
ObjectProperty objProp = os.getProperty();
|
||||||
Property op = ontModel.getProperty(os.getPropertyURI());
|
Property op = newModel.getProperty(os.getPropertyURI());
|
||||||
Resource obj = ontModel.getResource(os.getObjectURI());
|
Resource obj = newModel.getResource(os.getObjectURI());
|
||||||
newModel.add(newModel.createStatement(subj, op, obj));
|
newModel.add(newModel.createStatement(subj, op, obj));
|
||||||
if( objProp.getStubObjectRelation() )
|
if( objProp.getStubObjectRelation() )
|
||||||
newModel.add(getRDF(os.getObject(), ontModel, newModel, recurseDepth + 1));
|
newModel.add(getRDF(os.getObject(), contextModel, newModel, recurseDepth + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newModel = getLabelAndTypes(entity, contextModel, newModel );
|
||||||
return newModel;
|
return newModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the properties that are difficult to get via a filtered WebappDaoFactory. */
|
||||||
|
private Model getLabelAndTypes(Individual entity, Model ontModel, Model newModel){
|
||||||
|
for( VClass vclass : entity.getVClasses()){
|
||||||
|
newModel.add(newModel.getResource(entity.getURI()), RDF.type, newModel.getResource(vclass.getURI()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ontModel.enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
|
newModel.add(ontModel.listStatements(ontModel.getResource(entity.getURI()), RDFS.label, (RDFNode)null));
|
||||||
|
} finally {
|
||||||
|
ontModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return newModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void checkForSearch(HttpServletRequest req, Individual ent) {
|
private void checkForSearch(HttpServletRequest req, Individual ent) {
|
||||||
if (req.getSession().getAttribute("LastQuery") != null) {
|
if (req.getSession().getAttribute("LastQuery") != null) {
|
||||||
VitroQueryWrapper qWrap = (VitroQueryWrapper) req.getSession()
|
VitroQueryWrapper qWrap = (VitroQueryWrapper) req.getSession()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue