diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java index 5da38ea58..ddd04e738 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyDaoJena.java @@ -13,20 +13,21 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.hp.hpl.jena.datatypes.xsd.XSDDatatype; +import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.ontology.ConversionException; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntProperty; import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.ontology.ProfileException; import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Literal; -import com.hp.hpl.jena.rdf.model.NodeIterator; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.RDFNode; -import com.hp.hpl.jena.rdf.model.ResIterator; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.Statement; @@ -71,7 +72,22 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp } } - Map customListViewConfigFiles = null; + static protected String customListViewConfigFileQueryString = + "PREFIX display: " + + "SELECT ?property ?filename WHERE { \n" + + " ?property display:customListViewConfigurationFile ?filename . \n" + + "} LIMIT 1"; + static protected Query customListViewConfigFileQuery; + static { + try { + customListViewConfigFileQuery = QueryFactory.create(customListViewConfigFileQueryString); + } catch(Throwable th){ + log.error("could not create SPARQL query for customListViewConfigFileQueryString " + th.getMessage()); + log.error(customListViewConfigFileQueryString); + } + } + + Map customListViewConfigFileMap = null; public ObjectPropertyDaoJena(WebappDaoFactoryJena wadf) { super(wadf); @@ -848,8 +864,8 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp ResultSet results = getPropertyQueryResults(subjectUri, objectPropertyQuery); List properties = new ArrayList(); while (results.hasNext()) { - QuerySolution sol = results.next(); - Resource resource = sol.getResource("property"); + QuerySolution soln = results.next(); + Resource resource = soln.getResource("property"); String uri = resource.getURI(); ObjectProperty property = getObjectPropertyByURI(uri); properties.add(property); @@ -859,25 +875,37 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp @Override public String getCustomListConfigFilename(ObjectProperty op) { - if (customListViewConfigFiles == null) { - customListViewConfigFiles = new HashMap(); - OntModel ontModel = getOntModelSelector().getDisplayModel(); - Property listViewConfigProp = ontModel.getProperty(VitroVocabulary.DISPLAY + "customListViewConfigurationFile"); - ResIterator resources = ontModel.listResourcesWithProperty(listViewConfigProp); - while (resources.hasNext()) { - Resource resource = resources.next(); - ObjectProperty prop = getObjectPropertyByURI(resource.getURI()); - NodeIterator nodes = ontModel.listObjectsOfProperty(resource, listViewConfigProp); - if (nodes.hasNext()) { - RDFNode node = nodes.next(); // there should be at most one value; just get the first one - if (node.isLiteral()) { - String configFileName = ((Literal)node).getLexicalForm(); - customListViewConfigFiles.put(prop, configFileName); - } - } - } + if (customListViewConfigFileMap == null) { + customListViewConfigFileMap = new HashMap(); + OntModel displayModel = getOntModelSelector().getDisplayModel(); + +// Property listViewConfigProp = displayModel.getProperty(VitroVocabulary.DISPLAY + "customListViewConfigurationFile"); +// ResIterator resources = displayModel.listResourcesWithProperty(listViewConfigProp); +// while (resources.hasNext()) { +// Resource resource = resources.next(); +// ObjectProperty prop = getObjectPropertyByURI(resource.getURI()); +// NodeIterator nodes = displayModel.listObjectsOfProperty(resource, listViewConfigProp); +// if (nodes.hasNext()) { +// RDFNode node = nodes.next(); // there should be at most one value; just get the first one +// if (node.isLiteral()) { +// String configFileName = ((Literal)node).getLexicalForm(); +// customListViewConfigFiles.put(prop, configFileName); +// } +// } +// } + + QueryExecution qexec = QueryExecutionFactory.create(customListViewConfigFileQuery, displayModel); + ResultSet results = qexec.execSelect(); + while (results.hasNext()) { + QuerySolution soln = results.next(); + Resource resource = soln.getResource("property"); + String uri = resource.getURI(); + ObjectProperty prop = getObjectPropertyByURI(uri); + String filename = soln.getLiteral("filename").getLexicalForm(); + customListViewConfigFileMap.put(prop, filename); + } } - return customListViewConfigFiles.get(op); + return customListViewConfigFileMap.get(op); } - + }