diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java index 4dafd01a5..fd9ab2a51 100755 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/ObjectPropertyDao.java @@ -33,8 +33,8 @@ public interface ObjectPropertyDao extends PropertyDao { public void deleteObjectProperty(ObjectProperty objectProperty); - public boolean skipEditForm(String predicateURI); - + public boolean skipEditForm(String predicateURI); + // List /*of ObjectProperty */ getObjectPropertiesForObjectPropertyStatements(List /*of ObjectPropertyStatement */ objectPropertyStatements); // @@ -56,5 +56,5 @@ public interface ObjectPropertyDao extends PropertyDao { public List getObjectPropertyList(String subjectUri); - public String getCustomListView(); + public String getCustomListConfigFilename(ObjectProperty objectProperty); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyDaoFiltering.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyDaoFiltering.java index 899af6871..06ce601aa 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyDaoFiltering.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/filtering/ObjectPropertyDaoFiltering.java @@ -216,7 +216,7 @@ class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectProperty } @Override - public String getCustomListView() { - return innerObjectPropertyDao.getCustomListView(); + public String getCustomListConfigFilename(ObjectProperty objectProperty) { + return innerObjectPropertyDao.getCustomListConfigFilename(objectProperty); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java index c2858bf02..523e943be 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ApplicationDaoJena.java @@ -19,6 +19,7 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao { Integer portalCount = null; List externallyLinkedNamespaces = null; + public ApplicationDaoJena(WebappDaoFactoryJena wadf) { super(wadf); 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 d8afcfb39..5da38ea58 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 @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -18,15 +19,14 @@ 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.QuerySolutionMap; 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; @@ -38,9 +38,6 @@ import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; import edu.cornell.mannlib.vitro.webapp.beans.BaseResourceBean; -import edu.cornell.mannlib.vitro.webapp.beans.DataProperty; -import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; -import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; @@ -74,6 +71,8 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp } } + Map customListViewConfigFiles = null; + public ObjectPropertyDaoJena(WebappDaoFactoryJena wadf) { super(wadf); } @@ -859,9 +858,26 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp } @Override - public String getCustomListView() { - //return getPropertyStringValue(, PROPERTY_CUSTOM_LIST_VIEW_ANNOT); - return null; + 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); + } + } + } + } + return customListViewConfigFiles.get(op); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java index 122e1c158..335fa75aa 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/web/templatemodels/individual/ObjectPropertyTemplateModel.java @@ -15,6 +15,7 @@ import org.w3c.dom.NodeList; import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty; +import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel { @@ -30,7 +31,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel // Get the config for this object property try { - config = new PropertyListConfig(op); + config = new PropertyListConfig(op, wdf); } catch (Exception e) { log.error(e, e); } @@ -69,31 +70,34 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel private String templateName; private String collationTarget; - PropertyListConfig(ObjectProperty op) throws Exception { - String filename = DEFAULT_CONFIG_FILE;; + PropertyListConfig(ObjectProperty op, WebappDaoFactory wdf) throws Exception { + + // Get the custom config filename + ObjectPropertyDao opDao = wdf.getObjectPropertyDao(); + String filename = opDao.getCustomListConfigFilename(op); + if (filename == null) { // no custom config; use default config + filename = DEFAULT_CONFIG_FILE; + } + log.debug("Using custom list view config file " + filename + " for object property " + op.getURI()); - // Get the config filename from ObjectPropertyDaoJena by looking for the custom property list view annotation. - // If there is none, use the default config filename. - // do stuff here to get the custom config filename *** - - String configFilename = getConfigFilename(filename); + String configFilePath = getConfigFilePath(filename); try { - File config = new File(configFilename); - if (configFilename != DEFAULT_CONFIG_FILE && ! config.exists()) { - log.warn("Can't find config file " + configFilename + " for object property " + op.getURI() + "\n" + + File config = new File(configFilePath); + if (configFilePath != DEFAULT_CONFIG_FILE && ! config.exists()) { + log.warn("Can't find config file " + configFilePath + " for object property " + op.getURI() + "\n" + ". Using default config file instead."); - configFilename = getConfigFilename(DEFAULT_CONFIG_FILE); + configFilePath = getConfigFilePath(DEFAULT_CONFIG_FILE); // Should we test for the existence of the default, and throw an error if it doesn't exist? } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); - Document doc = db.parse(configFilename); + Document doc = db.parse(configFilePath); queryString = getConfigValue(doc, NODE_NAME_QUERY); templateName = getConfigValue(doc, NODE_NAME_TEMPLATE); collationTarget = getConfigValue(doc, NODE_NAME_COLLATION_TARGET); } catch (Exception e) { - log.error("Error processing config file " + configFilename + " for object property " + op.getURI(), e); + log.error("Error processing config file " + configFilePath + " for object property " + op.getURI(), e); // What should we do here? } @@ -118,7 +122,7 @@ public abstract class ObjectPropertyTemplateModel extends PropertyTemplateModel return value; } - private String getConfigFilename(String filename) { + private String getConfigFilePath(String filename) { return servletContext.getRealPath(CONFIG_FILE_PATH + filename); } }