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 edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||
|
||||
public class OntologyController extends VitroHttpServlet{
|
||||
|
@ -162,6 +163,7 @@ public class OntologyController extends VitroHttpServlet{
|
|||
doNotFound(req,res);
|
||||
return;
|
||||
} else {
|
||||
JenaOutputUtils.setNameSpacePrefixes(newModel,vreq.getWebappDaoFactory());
|
||||
res.setContentType(rdfFormat.getMediaType());
|
||||
String format = "";
|
||||
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.NamespaceMapperFactory;
|
||||
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.beanswrappers.ReadOnlyBeansWrapper;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||
|
@ -354,7 +355,7 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
|
||||
String[] includes = vreq.getParameterValues("include");
|
||||
Model newModel = getRDF(individual,ontModel,ModelFactory.createDefaultModel(),0,includes);
|
||||
|
||||
JenaOutputUtils.setNameSpacePrefixes(newModel, vreq.getWebappDaoFactory());
|
||||
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.query.Dataset;
|
||||
import com.hp.hpl.jena.query.DatasetFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.shared.Lock;
|
||||
|
||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||
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.UseAdvancedDataToolsPages;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||
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.ModelContext;
|
||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils;
|
||||
|
||||
public class JenaExportController extends BaseEditController {
|
||||
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 ) {
|
||||
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.utils.jena.JenaIngestUtils;
|
||||
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;
|
||||
|
||||
public class JenaIngestController extends BaseEditController {
|
||||
|
@ -324,6 +325,7 @@ public class JenaIngestController extends BaseEditController {
|
|||
String modelType) {
|
||||
String modelNameStr = vreq.getParameter("modelName");
|
||||
Model model = getModel(modelNameStr,vreq);
|
||||
JenaOutputUtils.setNameSpacePrefixes(model,vreq.getWebappDaoFactory());
|
||||
model.enterCriticalSection(Lock.READ);
|
||||
try {
|
||||
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