From 9f9da3796e4528017e0bed7d733c97462ae784be Mon Sep 17 00:00:00 2001 From: rjy7 Date: Wed, 23 Jun 2010 19:04:51 +0000 Subject: [PATCH] Removing view package which had inadvertently gotten put into webapp/web --- webapp/web/view/IndividualView.java | 118 --------------------------- webapp/web/view/VClassGroupView.java | 57 ------------- webapp/web/view/VClassView.java | 35 -------- webapp/web/view/ViewFinder.java | 107 ------------------------ webapp/web/view/ViewObject.java | 46 ----------- 5 files changed, 363 deletions(-) delete mode 100644 webapp/web/view/IndividualView.java delete mode 100644 webapp/web/view/VClassGroupView.java delete mode 100644 webapp/web/view/VClassView.java delete mode 100644 webapp/web/view/ViewFinder.java delete mode 100644 webapp/web/view/ViewObject.java diff --git a/webapp/web/view/IndividualView.java b/webapp/web/view/IndividualView.java deleted file mode 100644 index 7955534f6..000000000 --- a/webapp/web/view/IndividualView.java +++ /dev/null @@ -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 getLinks() { - List additionalLinks = individual.getLinksList(); - List links = new ArrayList(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 getKeywords() { - return individual.getKeywords(); - } - - public String getImageUrl() { - return individual.getImageUrl(); - } - - public String getThumbUrl() { - return individual.getThumbUrl(); - } -} diff --git a/webapp/web/view/VClassGroupView.java b/webapp/web/view/VClassGroupView.java deleted file mode 100644 index 78c9b44a2..000000000 --- a/webapp/web/view/VClassGroupView.java +++ /dev/null @@ -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 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 getClasses() { - if (classes == null) { - List classList = vClassGroup.getVitroClassList(); - classes = new ArrayList(); - for (VClass vc : classList) { - classes.add(new VClassView(vc)); - } - } - - return classes; - } -} diff --git a/webapp/web/view/VClassView.java b/webapp/web/view/VClassView.java deleted file mode 100644 index 979149efd..000000000 --- a/webapp/web/view/VClassView.java +++ /dev/null @@ -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(); - } - -} diff --git a/webapp/web/view/ViewFinder.java b/webapp/web/view/ViewFinder.java deleted file mode 100644 index d59a0182d..000000000 --- a/webapp/web/view/ViewFinder.java +++ /dev/null @@ -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 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 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; - } - -} diff --git a/webapp/web/view/ViewObject.java b/webapp/web/view/ViewObject.java deleted file mode 100644 index 1943a8625..000000000 --- a/webapp/web/view/ViewObject.java +++ /dev/null @@ -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 groups = // code to get the data - List vcgroups = new ArrayList(groups.size()); - Iterator 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 - */ - -}