Moved edu.cornell.mannlib.vitro.webapp.view package to edu.cornell.mannlib.vitro.webapp.web.templatemodels
This commit is contained in:
parent
e110a0fde1
commit
75b9030cc3
22 changed files with 380 additions and 17 deletions
|
@ -17,7 +17,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
|
|||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
|
||||
import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag;
|
||||
import edu.cornell.mannlib.vitro.webapp.view.VClassGroupView;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.VClassGroupView;
|
||||
import freemarker.template.SimpleSequence;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
|
|
@ -27,11 +27,11 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
|||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.view.fileList.ScriptList;
|
||||
import edu.cornell.mannlib.vitro.webapp.view.fileList.StylesheetList;
|
||||
import edu.cornell.mannlib.vitro.webapp.view.menu.TabMenu;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.PortalWebUtil;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.filelist.ScriptList;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.filelist.StylesheetList;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.menu.TabMenu;
|
||||
import freemarker.cache.ClassTemplateLoader;
|
||||
import freemarker.cache.FileTemplateLoader;
|
||||
import freemarker.cache.MultiTemplateLoader;
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.view.ViewObject;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.ViewObject;
|
||||
import freemarker.ext.beans.BeansWrapper;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.DefaultObjectWrapper;
|
||||
|
|
|
@ -14,7 +14,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.view.IndividualView;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.IndividualView;
|
||||
|
||||
/**
|
||||
* Generates a list of individuals for display in a template
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Link;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.ViewFinder.ClassView;
|
||||
|
||||
public class IndividualView extends ViewObject {
|
||||
|
||||
private static final Log log = LogFactory.getLog(IndividualView.class.getName());
|
||||
|
||||
private static final String PATH = Route.INDIVIDUAL.path();
|
||||
|
||||
private Individual individual;
|
||||
|
||||
public IndividualView(Individual individual) {
|
||||
this.individual = individual;
|
||||
}
|
||||
|
||||
/* These methods perform some manipulation of the data returned by the Individual methods */
|
||||
public String getTagline() {
|
||||
String tagline = individual.getMoniker();
|
||||
return StringUtils.isEmpty(tagline) ? individual.getVClass().getName() : tagline;
|
||||
}
|
||||
|
||||
// Return link to individual's profile page.
|
||||
// There may be other urls associated with the individual. E.g., we might need
|
||||
// getEditUrl(), getDeleteUrl() to return the links computed by PropertyEditLinks.
|
||||
// RY **** Need to account for everything in URLRewritingHttpServlet
|
||||
// Currently this is incorrect for individuals that are not in the default namespace (e.g., geographic individuals).
|
||||
public String getProfileUrl() {
|
||||
return getUrl(PATH + "/" + individual.getLocalName());
|
||||
}
|
||||
|
||||
public String getSearchView() {
|
||||
return getView(ClassView.SEARCH);
|
||||
}
|
||||
|
||||
public String getShortView() {
|
||||
return getView(ClassView.SHORT);
|
||||
}
|
||||
|
||||
public String getDisplayView() {
|
||||
return getView(ClassView.DISPLAY);
|
||||
}
|
||||
|
||||
private String getView(ClassView view) {
|
||||
ViewFinder vf = new ViewFinder(view);
|
||||
return vf.findClassView(individual, context);
|
||||
}
|
||||
|
||||
public Link getPrimaryLink() {
|
||||
Link primaryLink = null;
|
||||
String anchor = individual.getAnchor();
|
||||
String url = individual.getUrl();
|
||||
if (anchor != null && url != null) {
|
||||
primaryLink = new Link();
|
||||
primaryLink.setAnchor(individual.getAnchor());
|
||||
primaryLink.setUrl(individual.getUrl());
|
||||
}
|
||||
return primaryLink;
|
||||
}
|
||||
|
||||
public List<Link> getLinks() {
|
||||
List<Link> additionalLinks = individual.getLinksList();
|
||||
List<Link> links = new ArrayList<Link>(additionalLinks.size()+1);
|
||||
Link primaryLink = getPrimaryLink();
|
||||
if (primaryLink != null) {
|
||||
links.add(primaryLink);
|
||||
}
|
||||
links.addAll(additionalLinks);
|
||||
return links;
|
||||
}
|
||||
|
||||
/* These methods simply forward to the Individual methods. It would be desirable to implement a scheme
|
||||
for proxying or delegation so that the methods don't need to be simply listed here.
|
||||
A Ruby-style method missing method would be ideal. */
|
||||
public String getName() {
|
||||
return individual.getName();
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return individual.getURI();
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return individual.getDescription();
|
||||
}
|
||||
|
||||
public String getBlurb() {
|
||||
return individual.getBlurb();
|
||||
}
|
||||
|
||||
public String getCitation() {
|
||||
return individual.getBlurb();
|
||||
}
|
||||
|
||||
public List<String> getKeywords() {
|
||||
return individual.getKeywords();
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return individual.getImageUrl();
|
||||
}
|
||||
|
||||
public String getThumbUrl() {
|
||||
return individual.getThumbUrl();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
|
||||
public class VClassGroupView extends ViewObject {
|
||||
|
||||
private static final Log log = LogFactory.getLog(VClassGroupView.class.getName());
|
||||
|
||||
private VClassGroup vClassGroup = null;
|
||||
private List<VClassView> classes = null;
|
||||
|
||||
public VClassGroupView(VClassGroup vClassGroup) {
|
||||
this.vClassGroup = vClassGroup;
|
||||
}
|
||||
|
||||
public int getDisplayRank() {
|
||||
return vClassGroup.getDisplayRank();
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return vClassGroup.getURI();
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return vClassGroup.getNamespace();
|
||||
}
|
||||
|
||||
public String getLocalName() {
|
||||
return vClassGroup.getLocalName();
|
||||
}
|
||||
|
||||
public String getPublicName() {
|
||||
return vClassGroup.getPublicName();
|
||||
}
|
||||
|
||||
public List<VClassView> getClasses() {
|
||||
if (classes == null) {
|
||||
List<VClass> classList = vClassGroup.getVitroClassList();
|
||||
classes = new ArrayList<VClassView>();
|
||||
for (VClass vc : classList) {
|
||||
classes.add(new VClassView(vc));
|
||||
}
|
||||
}
|
||||
|
||||
return classes;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Params;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||
|
||||
public class VClassView extends ViewObject {
|
||||
|
||||
private static final Log log = LogFactory.getLog(VClassView.class.getName());
|
||||
private static final String PATH = Route.INDIVIDUAL_LIST.path();
|
||||
|
||||
private VClass vclass;
|
||||
|
||||
public VClassView(VClass vclass) {
|
||||
this.vclass = vclass;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return vclass.getName();
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return getUrl(PATH, new Params("vclassId", vclass.getURI()));
|
||||
}
|
||||
|
||||
public int getIndividualCount() {
|
||||
return vclass.getEntityCount();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Class to find custom class views for individuals
|
||||
* @author rjy7
|
||||
*
|
||||
*/
|
||||
public class ViewFinder {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ViewFinder.class.getName());
|
||||
|
||||
public enum ClassView {
|
||||
DISPLAY("getCustomDisplayView", "/view/display"),
|
||||
// NB this is not the value currently used for custom forms - we use the value on the object property
|
||||
FORM("getCustomEntryForm", "/form"),
|
||||
SEARCH("getCustomSearchView", "/view/search"),
|
||||
SHORT("getCustomShortView", "/view/short");
|
||||
|
||||
private static String TEMPLATE_PATH = "/templates/freemarker/body/partials/class";
|
||||
|
||||
private Method method = null;
|
||||
private String path = null;
|
||||
|
||||
ClassView(String methodName, String path) {
|
||||
Class<VClass> vc = VClass.class;
|
||||
this.path = path;
|
||||
try {
|
||||
method = vc.getMethod(methodName);
|
||||
} catch (SecurityException e) {
|
||||
log.error("Access denied to method " + methodName + " or class " + vc.getName());
|
||||
} catch (NoSuchMethodException e) {
|
||||
log.error("Method " + methodName + " not defined for class " + vc.getName());
|
||||
}
|
||||
}
|
||||
|
||||
protected Method getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
protected String getPath() {
|
||||
return TEMPLATE_PATH + path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ClassView view;
|
||||
|
||||
public ViewFinder(ClassView view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
public String findClassView(Individual individual, ServletContext context) {
|
||||
String viewName = "default.ftl";
|
||||
List<VClass> vclasses = individual.getVClasses();
|
||||
Method method = view.getMethod();
|
||||
/* RY The logic here is incorrect. The vclasses are
|
||||
* returned in a random order, whereas we need to
|
||||
* traverse the class hierarchy and find the most
|
||||
* specific custom view applicable to the individual.
|
||||
* The logic is complex because individuals can belong
|
||||
* to multiple classes, and classes can subclass multiple
|
||||
* classes. If there are two competing custom views at the
|
||||
* same level of specificity, what should we do? Also, if we
|
||||
* are displaying a list of individuals belonging to a certain
|
||||
* class, we may want to use only a custom view defined for that
|
||||
* class and NOT a more specific one. See NIHVIVO-568.
|
||||
*/
|
||||
for (VClass vc : vclasses) {
|
||||
try {
|
||||
String v = (String) method.invoke(vc);
|
||||
if (!StringUtils.isEmpty(v)) {
|
||||
String pathToView = context.getRealPath(view.getPath() + "/" + v);
|
||||
File viewFile = new File(pathToView);
|
||||
if (viewFile.isFile() && viewFile.canRead()) {
|
||||
viewName = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error("Incorrect arguments passed to method " + method.getName() + " in findView().");
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error("Method " + method.getName() + " cannot be accessed in findView().");
|
||||
} catch (InvocationTargetException e) {
|
||||
log.error("Exception thrown by method " + method.getName() + " in findView().");
|
||||
}
|
||||
|
||||
}
|
||||
return viewName;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Params;
|
||||
|
||||
public abstract class ViewObject {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ViewObject.class.getName());
|
||||
|
||||
public static ServletContext context = null;
|
||||
|
||||
// Wrap UrlBuilder method so templates can call ${item.url}
|
||||
public String getUrl(String path) {
|
||||
return UrlBuilder.getUrl(path);
|
||||
}
|
||||
|
||||
// Wrap UrlBuilder method so templates can call ${item.url}
|
||||
public String getUrl(String path, Params params) {
|
||||
return UrlBuilder.getUrl(path, params);
|
||||
}
|
||||
|
||||
/*
|
||||
* public static List<?> wrapList(List<?> list, Class cl)
|
||||
* throw error if cl not a child of ViewObject
|
||||
* This block of code is going to be repeated a lot:
|
||||
List<VClassGroup> groups = // code to get the data
|
||||
List<VClassGroupView> vcgroups = new ArrayList<VClassGroupView>(groups.size());
|
||||
Iterator<VClassGroup> i = groups.iterator();
|
||||
while (i.hasNext()) {
|
||||
vcgroups.add(new VClassGroupView(i.next()));
|
||||
}
|
||||
body.put("classGroups", vcgroups);
|
||||
Can we generalize it to a generic method of ViewObject - wrapList() ?
|
||||
static method of ViewObject
|
||||
Params: groups, VClassGroupView (the name of the class) - but must be a child of ViewObject
|
||||
Return: List<viewObjectType>
|
||||
*/
|
||||
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.view.fileList;
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.fileList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.view.ViewObject;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.ViewObject;
|
||||
|
||||
public abstract class FileList extends ViewObject {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.view.fileList;
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.fileList;
|
||||
|
||||
public class ScriptList extends FileList {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.view.fileList;
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.fileList;
|
||||
|
||||
public class StylesheetList extends FileList {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.view.menu;
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.menu;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.view.menu;
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.menu;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.view.menu;
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.menu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -9,7 +9,7 @@ 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.view.ViewObject;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.ViewObject;
|
||||
|
||||
public class Menu extends ViewObject {
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.view.menu;
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.menu;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.view.ViewObject;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.ViewObject;
|
||||
|
||||
public class MenuItem extends ViewObject {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.view.menu;
|
||||
package edu.cornell.mannlib.vitro.webapp.web.templatemodels.menu;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
Loading…
Add table
Reference in a new issue