NIHVIVO-3198 - include namespace prefixes defined via VIVO admin interface in the RDF output from VIVO
This commit is contained in:
parent
1d321f6c83
commit
cc639de7f4
5 changed files with 63 additions and 5 deletions
|
@ -27,6 +27,7 @@ import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||||
|
|
||||||
public class OntologyController extends VitroHttpServlet{
|
public class OntologyController extends VitroHttpServlet{
|
||||||
|
@ -161,7 +162,8 @@ public class OntologyController extends VitroHttpServlet{
|
||||||
//respond to HTTP outside of critical section
|
//respond to HTTP outside of critical section
|
||||||
doNotFound(req,res);
|
doNotFound(req,res);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
JenaOutputUtils.setNameSpacePrefixes(newModel,vreq.getWebappDaoFactory());
|
||||||
res.setContentType(rdfFormat.getMediaType());
|
res.setContentType(rdfFormat.getMediaType());
|
||||||
String format = "";
|
String format = "";
|
||||||
if ( RDFXML_MIMETYPE.equals(rdfFormat.getMediaType()))
|
if ( RDFXML_MIMETYPE.equals(rdfFormat.getMediaType()))
|
||||||
|
|
|
@ -57,6 +57,7 @@ import edu.cornell.mannlib.vitro.webapp.reasoner.SimpleReasoner;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
|
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
|
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.ExtendedLinkedDataUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.ExtendedLinkedDataUtils;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
import edu.cornell.mannlib.vitro.webapp.web.beanswrappers.ReadOnlyBeansWrapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||||
|
@ -354,7 +355,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
||||||
|
|
||||||
String[] includes = vreq.getParameterValues("include");
|
String[] includes = vreq.getParameterValues("include");
|
||||||
Model newModel = getRDF(individual,ontModel,ModelFactory.createDefaultModel(),0,includes);
|
Model newModel = getRDF(individual,ontModel,ModelFactory.createDefaultModel(),0,includes);
|
||||||
|
JenaOutputUtils.setNameSpacePrefixes(newModel, vreq.getWebappDaoFactory());
|
||||||
return new RdfResponseValues(rdfFormat, newModel);
|
return new RdfResponseValues(rdfFormat, newModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,20 +13,19 @@ import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
import com.hp.hpl.jena.query.Dataset;
|
||||||
import com.hp.hpl.jena.query.DatasetFactory;
|
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
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.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.Actions;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseAdvancedDataToolsPages;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.EditOntology;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.EditOntology;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.usepages.UseAdvancedDataToolsPages;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils;
|
||||||
|
|
||||||
public class JenaExportController extends BaseEditController {
|
public class JenaExportController extends BaseEditController {
|
||||||
private static final Actions REQUIRED_ACTIONS = new Actions(
|
private static final Actions REQUIRED_ACTIONS = new Actions(
|
||||||
|
@ -177,6 +176,8 @@ public class JenaExportController extends BaseEditController {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JenaOutputUtils.setNameSpacePrefixes(model,vreq.getWebappDaoFactory());
|
||||||
|
|
||||||
if ( formatParam == null ) {
|
if ( formatParam == null ) {
|
||||||
formatParam = "RDF/XML-ABBREV"; // default
|
formatParam = "RDF/XML-ABBREV"; // default
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup;
|
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestWorkflowProcessor;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestWorkflowProcessor;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.WorkflowOntology;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.WorkflowOntology;
|
||||||
|
|
||||||
public class JenaIngestController extends BaseEditController {
|
public class JenaIngestController extends BaseEditController {
|
||||||
|
@ -324,6 +325,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
String modelType) {
|
String modelType) {
|
||||||
String modelNameStr = vreq.getParameter("modelName");
|
String modelNameStr = vreq.getParameter("modelName");
|
||||||
Model model = getModel(modelNameStr,vreq);
|
Model model = getModel(modelNameStr,vreq);
|
||||||
|
JenaOutputUtils.setNameSpacePrefixes(model,vreq.getWebappDaoFactory());
|
||||||
model.enterCriticalSection(Lock.READ);
|
model.enterCriticalSection(Lock.READ);
|
||||||
try {
|
try {
|
||||||
OutputStream out = response.getOutputStream();
|
OutputStream out = response.getOutputStream();
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.jena;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
|
|
||||||
|
public class JenaOutputUtils {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(JenaOutputUtils.class.getName());
|
||||||
|
|
||||||
|
public static void setNameSpacePrefixes(Model model, WebappDaoFactory wadf) {
|
||||||
|
|
||||||
|
Map<String,String> prefixes = new HashMap<String,String>();
|
||||||
|
List<Ontology> ontologies = wadf.getOntologyDao().getAllOntologies();
|
||||||
|
Iterator<Ontology> iter = ontologies.iterator();
|
||||||
|
String namespace = null;
|
||||||
|
String prefix = null;
|
||||||
|
|
||||||
|
prefixes.put("vitro", "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#");
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Ontology ontology = iter.next();
|
||||||
|
|
||||||
|
namespace = ontology.getURI(); // this method returns the namespace
|
||||||
|
if (namespace == null || namespace.isEmpty()) {
|
||||||
|
log.warn("ontology with empty namespace found");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix = ontology.getPrefix();
|
||||||
|
if (prefix == null || prefix.isEmpty()) {
|
||||||
|
log.info("no prefix found for namespace: " + namespace);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
prefixes.put(prefix,namespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
model.setNsPrefixes(prefixes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue