Removing view package which had inadvertently gotten put into webapp/web
This commit is contained in:
parent
5d0aebbfdc
commit
9f9da3796e
5 changed files with 0 additions and 363 deletions
|
@ -1,118 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.view;
|
|
||||||
|
|
||||||
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.view.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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.view;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.view;
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,107 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.view;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.view;
|
|
||||||
|
|
||||||
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>
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue