updates for labels and uri method in webappdaofactory
This commit is contained in:
parent
d5c1cc49c6
commit
0ec8dcbce1
5 changed files with 101 additions and 129 deletions
|
@ -49,6 +49,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
|
||||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.URIUtils;
|
||||||
|
|
||||||
public class WebappDaoFactoryJena implements WebappDaoFactory {
|
public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
|
|
||||||
|
@ -204,40 +205,13 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
|
||||||
|
|
||||||
//Check if URI already in use or not either as resource OR as property
|
//Check if URI already in use or not either as resource OR as property
|
||||||
public boolean hasExistingURI(String uriStr) {
|
public boolean hasExistingURI(String uriStr) {
|
||||||
boolean existingURI = false;
|
|
||||||
OntModel ontModel = ontModelSelector.getFullModel();
|
OntModel ontModel = ontModelSelector.getFullModel();
|
||||||
ontModel.enterCriticalSection(Lock.READ);
|
return URIUtils.hasExistingURI(uriStr, ontModel);
|
||||||
try {
|
|
||||||
Resource newURIAsRes = ResourceFactory.createResource(uriStr);
|
|
||||||
Property newURIAsProp = ResourceFactory.createProperty(uriStr);
|
|
||||||
StmtIterator closeIt = ontModel.listStatements(
|
|
||||||
newURIAsRes, null, (RDFNode)null);
|
|
||||||
if (closeIt.hasNext()) {
|
|
||||||
existingURI = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
//if not in the subject position, check in object position
|
|
||||||
if (!existingURI) {
|
|
||||||
closeIt = ontModel.listStatements(null, null, newURIAsRes);
|
|
||||||
if (closeIt.hasNext()) {
|
|
||||||
existingURI= true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Check for property
|
|
||||||
if (!existingURI) {
|
|
||||||
closeIt = ontModel.listStatements(
|
|
||||||
null, newURIAsProp, (RDFNode)null);
|
|
||||||
if (closeIt.hasNext()) {
|
|
||||||
existingURI = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
ontModel.leaveCriticalSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
return existingURI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
|
public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
|
||||||
return new WebappDaoFactoryJena(this, userURI);
|
return new WebappDaoFactoryJena(this, userURI);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,42 +17,25 @@ import javax.servlet.http.HttpSession;
|
||||||
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 com.hp.hpl.jena.ontology.OntModel;
|
|
||||||
import com.hp.hpl.jena.query.Dataset;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecution;
|
|
||||||
import com.hp.hpl.jena.query.QueryExecutionFactory;
|
|
||||||
import com.hp.hpl.jena.query.QuerySolution;
|
import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.RDFNode;
|
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
|
||||||
import com.hp.hpl.jena.sparql.resultset.ResultSetMem;
|
|
||||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||||
import com.hp.hpl.jena.vocabulary.XSD;
|
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
import edu.cornell.mannlib.vitro.webapp.auth.policy.PolicyHelper;
|
||||||
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.ifaces.RequestActionConstants;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.ifaces.RequestActionConstants;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddDataPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddDataPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.AddObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataProperty;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||||
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.ParamMap;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.QueryUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.FoafNameToRdfsLabelPreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForIndividualPreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ManageLabelsForIndividualPreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectionDataGetter;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.i18n.selection.LocaleSelectorUtilities;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
import edu.cornell.mannlib.vitro.webapp.i18n.selection.SelectedLocale;
|
||||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel;
|
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.DataPropertyStatementTemplateModel;
|
||||||
|
|
||||||
|
@ -114,6 +97,14 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
prepare(vreq, config);
|
prepare(vreq, config);
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**With ISF Changes**/
|
||||||
|
//For addition of a label, with ISF changes, the name is now linked to a vcard which in turn is linked to a "fullname" that then has first/middle/last names
|
||||||
|
/*
|
||||||
|
private void addNewResources(EditConfigurationVTwo editConfiguration) {
|
||||||
|
conf.addNewResource("fullName", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||||
|
conf.addNewResource("individualVcard", DEFAULT_NS_FOR_NEW_RESOURCE);
|
||||||
|
}*/
|
||||||
|
|
||||||
private void setUrlToReturnTo(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
private void setUrlToReturnTo(EditConfigurationVTwo editConfiguration, VitroRequest vreq) {
|
||||||
editConfiguration.setUrlPatternToReturnTo(EditConfigurationUtils.getFormUrlWithoutContext(vreq));
|
editConfiguration.setUrlPatternToReturnTo(EditConfigurationUtils.getFormUrlWithoutContext(vreq));
|
||||||
|
@ -134,11 +125,8 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
private List<String> generateN3Optional(VitroRequest vreq) {
|
private List<String> generateN3Optional(VitroRequest vreq) {
|
||||||
List<String> n3Optional = new ArrayList<String>();
|
List<String> n3Optional = new ArrayList<String>();
|
||||||
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
String predicateUri = EditConfigurationUtils.getPredicateUri(vreq);
|
||||||
String n3 = "?subject <" + predicateUri + "> ?label ";
|
String n3 = "?subject <" + predicateUri + "> ?label ";
|
||||||
//n3 used if the subject is a person
|
|
||||||
String personN3 = this.N3_PREFIX + "?subject foaf:firstName ?firstName ; foaf:lastName ?lastName .";
|
|
||||||
n3Optional.add(n3);
|
n3Optional.add(n3);
|
||||||
n3Optional.add(personN3);
|
|
||||||
return n3Optional;
|
return n3Optional;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,41 +139,14 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
setName("label").
|
setName("label").
|
||||||
setValidators(getLabelValidators(vreq, editConfiguration)));
|
setValidators(getLabelValidators(vreq, editConfiguration)));
|
||||||
editConfiguration.addField(new FieldVTwo(
|
editConfiguration.addField(new FieldVTwo(
|
||||||
).setName("newLabelLanguage"));
|
).setName("newLabelLanguage"));
|
||||||
//no validators since all of this is optional
|
|
||||||
//there should be error-checking client side though
|
|
||||||
editConfiguration.addField(new FieldVTwo().
|
|
||||||
setName("firstName").
|
|
||||||
setValidators(getFirstNameValidators(vreq, editConfiguration)));
|
|
||||||
|
|
||||||
editConfiguration.addField(new FieldVTwo().
|
|
||||||
setName("lastName").
|
|
||||||
setValidators(getLastNameValidators(vreq, editConfiguration)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//first and last name have validators if is person is true
|
|
||||||
private List<String> getFirstNameValidators(VitroRequest vreq, EditConfigurationVTwo config) {
|
|
||||||
List<String> validators = new ArrayList<String>();
|
|
||||||
if(isPersonType(vreq, config)) {
|
|
||||||
validators.add("nonempty");
|
|
||||||
}
|
|
||||||
return validators;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> getLastNameValidators(VitroRequest vreq, EditConfigurationVTwo config) {
|
|
||||||
List<String> validators = new ArrayList<String>();
|
|
||||||
if(isPersonType(vreq, config)) {
|
|
||||||
validators.add("nonempty");
|
|
||||||
}
|
|
||||||
return validators;
|
|
||||||
}
|
|
||||||
|
|
||||||
//validate label if person is not true
|
//validate label if person is not true
|
||||||
private List<String> getLabelValidators(VitroRequest vreq, EditConfigurationVTwo config) {
|
private List<String> getLabelValidators(VitroRequest vreq, EditConfigurationVTwo config) {
|
||||||
List<String> validators = new ArrayList<String>();
|
List<String> validators = new ArrayList<String>();
|
||||||
if(!isPersonType(vreq, config)) {
|
|
||||||
validators.add("nonempty");
|
|
||||||
}
|
|
||||||
return validators;
|
return validators;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,9 +157,6 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
List<String> literalsOnForm = new ArrayList<String>();
|
List<String> literalsOnForm = new ArrayList<String>();
|
||||||
literalsOnForm.add("label");
|
literalsOnForm.add("label");
|
||||||
literalsOnForm.add("newLabelLanguage");
|
literalsOnForm.add("newLabelLanguage");
|
||||||
//optional for person
|
|
||||||
literalsOnForm.add("firstName");
|
|
||||||
literalsOnForm.add("lastName");
|
|
||||||
config.setLiteralsOnForm(literalsOnForm);
|
config.setLiteralsOnForm(literalsOnForm);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -219,19 +177,7 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
|
|
||||||
private void initExistingLabels(EditConfigurationVTwo config,
|
private void initExistingLabels(EditConfigurationVTwo config,
|
||||||
VitroRequest vreq) {
|
VitroRequest vreq) {
|
||||||
this.existingLabelLiterals = this.getExistingLabels(config.getSubjectUri(), vreq);
|
this.existingLabelLiterals = this.getExistingLabels(config.getSubjectUri(), vreq);
|
||||||
// this.labelsSortedByLanguage = this.getLabelsSortedByLanguage(config,vreq);
|
|
||||||
//language names sorted for the existing languages
|
|
||||||
// this.existingSortedLanguageNameList = getExistingSortedLanguageNamesList();
|
|
||||||
|
|
||||||
//Generate a label to language code hash map
|
|
||||||
//TODO:
|
|
||||||
|
|
||||||
//HashMap<String, String> labelToLanguageCode = new HashMap<String, String>();
|
|
||||||
|
|
||||||
//this.labels = getExistingLabels(config.getSubjectUri(), vreq);
|
|
||||||
//this.labelsSortedByLanguage = getLabelsSortedByLanguage(config.getSubjectUri(), vreq);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,16 +230,7 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
}else{
|
}else{
|
||||||
config.addFormSpecificData("subjectName", null);
|
config.addFormSpecificData("subjectName", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Put in whether or not person type
|
|
||||||
if(isPersonType(vreq, config)) {
|
|
||||||
//Doing this b/c unsure how freemarker will handle boolean value from JAVA
|
|
||||||
config.addFormSpecificData("isPersonType", "true");
|
|
||||||
} else {
|
|
||||||
config.addFormSpecificData("isPersonType", "false");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Include whether or not editable to enable edit/remove links and add to show up
|
//Include whether or not editable to enable edit/remove links and add to show up
|
||||||
config.addFormSpecificData("editable", isEditable(vreq, config));
|
config.addFormSpecificData("editable", isEditable(vreq, config));
|
||||||
}
|
}
|
||||||
|
@ -341,28 +278,7 @@ public class ManageLabelsForIndividualGenerator extends BaseEditConfigurationGen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Copied from NewIndividualFormGenerator
|
|
||||||
//TODO: Refactor so common code can be used by both generators
|
|
||||||
public String getFOAFPersonClassURI() {
|
|
||||||
return "http://xmlns.com/foaf/0.1/Person";
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPersonType(VitroRequest vreq, EditConfigurationVTwo config) {
|
|
||||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
|
||||||
Boolean isPersonType = Boolean.FALSE;
|
|
||||||
String foafPersonType = getFOAFPersonClassURI();
|
|
||||||
List<VClass> vclasses = this.getVClasses(config, vreq);
|
|
||||||
if( vclasses != null ){
|
|
||||||
for( VClass v: vclasses){
|
|
||||||
String typeUri = v.getURI();
|
|
||||||
if( foafPersonType.equals(typeUri)) {
|
|
||||||
isPersonType = Boolean.TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isPersonType;
|
|
||||||
}
|
|
||||||
|
|
||||||
//how to get the type of the individual in question
|
//how to get the type of the individual in question
|
||||||
public List<VClass> getVClasses(EditConfigurationVTwo config, VitroRequest vreq) {
|
public List<VClass> getVClasses(EditConfigurationVTwo config, VitroRequest vreq) {
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpSession;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*This generator selects the actual generator to be employed. This generator can be overwritten in applications
|
||||||
|
*that use/extend Vitro to allow for class-based label handling.
|
||||||
|
*/
|
||||||
|
public class ManageLabelsGenerator extends BaseEditConfigurationGenerator implements EditConfigurationGenerator {
|
||||||
|
public static Log log = LogFactory.getLog(ManageLabelsForIndividualGenerator.class);
|
||||||
|
@Override
|
||||||
|
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
|
||||||
|
ManageLabelsForIndividualGenerator g = new ManageLabelsForIndividualGenerator();
|
||||||
|
return g.getEditConfiguration(vreq, session);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -22,6 +22,9 @@ public class FoafNameToRdfsLabelPreprocessor implements ModelChangePreprocessor
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
Property firstNameP = additionsModel.getProperty(FOAF+"firstName");
|
Property firstNameP = additionsModel.getProperty(FOAF+"firstName");
|
||||||
Property lastNameP = additionsModel.getProperty(FOAF+"lastName");
|
Property lastNameP = additionsModel.getProperty(FOAF+"lastName");
|
||||||
|
//middle name is optional
|
||||||
|
Property middleNameP = additionsModel.getProperty(FOAF+"middleName");
|
||||||
|
|
||||||
Property rdfsLabelP = additionsModel.getProperty(VitroVocabulary.LABEL);
|
Property rdfsLabelP = additionsModel.getProperty(VitroVocabulary.LABEL);
|
||||||
|
|
||||||
ResIterator subs =
|
ResIterator subs =
|
||||||
|
@ -30,12 +33,14 @@ public class FoafNameToRdfsLabelPreprocessor implements ModelChangePreprocessor
|
||||||
Resource sub = subs.nextResource();
|
Resource sub = subs.nextResource();
|
||||||
Statement fname = sub.getProperty( firstNameP );
|
Statement fname = sub.getProperty( firstNameP );
|
||||||
Statement lname = sub.getProperty( lastNameP );
|
Statement lname = sub.getProperty( lastNameP );
|
||||||
|
Statement mname = sub.getProperty(middleNameP)l
|
||||||
if( fname != null && lname != null && fname.getString() != null && lname.getString() != null ){
|
if( fname != null && lname != null && fname.getString() != null && lname.getString() != null ){
|
||||||
//Check if there are languages associated with first name and last name and add the language
|
//Check if there are languages associated with first name and last name and add the language
|
||||||
//attribute to the label
|
//attribute to the label
|
||||||
//This preprocessor is used in multiple places, including for managing labels
|
//This preprocessor is used in multiple places, including for managing labels
|
||||||
Literal firstNameLiteral = fname.getLiteral();
|
Literal firstNameLiteral = fname.getLiteral();
|
||||||
Literal lastNameLiteral = lname.getLiteral();
|
Literal lastNameLiteral = lname.getLiteral();
|
||||||
|
|
||||||
String firstNameLanguage = firstNameLiteral.getLanguage();
|
String firstNameLanguage = firstNameLiteral.getLanguage();
|
||||||
String lastNameLanguage = lastNameLiteral.getLanguage();
|
String lastNameLanguage = lastNameLiteral.getLanguage();
|
||||||
String newLabel = lname.getString() + ", " + fname.getString();
|
String newLabel = lname.getString() + ", " + fname.getString();
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.utils.jena;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
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.ResourceFactory;
|
||||||
|
import com.hp.hpl.jena.rdf.model.StmtIterator;
|
||||||
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
|
||||||
|
public class URIUtils {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(URIUtils.class.getName());
|
||||||
|
|
||||||
|
public static boolean hasExistingURI(String uriStr, OntModel ontModel) {
|
||||||
|
boolean existingURI = false;
|
||||||
|
ontModel.enterCriticalSection(Lock.READ);
|
||||||
|
try {
|
||||||
|
Resource newURIAsRes = ResourceFactory.createResource(uriStr);
|
||||||
|
Property newURIAsProp = ResourceFactory.createProperty(uriStr);
|
||||||
|
StmtIterator closeIt = ontModel.listStatements(
|
||||||
|
newURIAsRes, null, (RDFNode)null);
|
||||||
|
if (closeIt.hasNext()) {
|
||||||
|
existingURI = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
//if not in the subject position, check in object position
|
||||||
|
if (!existingURI) {
|
||||||
|
closeIt = ontModel.listStatements(null, null, newURIAsRes);
|
||||||
|
if (closeIt.hasNext()) {
|
||||||
|
existingURI= true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Check for property
|
||||||
|
if (!existingURI) {
|
||||||
|
closeIt = ontModel.listStatements(
|
||||||
|
null, newURIAsProp, (RDFNode)null);
|
||||||
|
if (closeIt.hasNext()) {
|
||||||
|
existingURI = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
ontModel.leaveCriticalSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
return existingURI;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue