From c4709265c40ebc9cf17113e901fb2797a6828aa5 Mon Sep 17 00:00:00 2001 From: rjy7 Date: Fri, 21 May 2010 21:49:53 +0000 Subject: [PATCH] Work on FreeMarker version of individual list page --- .../freemarker/BrowseController.java | 8 ++---- .../freemarker/CommentFormController.java | 3 ++- .../freemarker/FreeMarkerHttpServlet.java | 18 +++++++------ .../freemarker/FreeMarkerSetup.java | 1 - .../freemarker/IndividualListController.java | 15 +++++++---- .../webapp/controller/freemarker/Routes.java | 2 +- .../vitro/webapp/view/IndividualView.java | 22 ++++++++++------ .../mannlib/vitro/webapp/view/ViewObject.java | 19 ++++++++++++++ webapp/web/templates/entity/entityList.jsp | 2 +- .../freemarker/body/individualList.ftl | 25 ++++--------------- 10 files changed, 65 insertions(+), 50 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java index 5ccca87f1..77d9de805 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/BrowseController.java @@ -87,14 +87,10 @@ public class BrowseController extends FreeMarkerHttpServlet { body.put("message", message); } else { - List vcgroups = new ArrayList(); + List vcgroups = new ArrayList(groups.size()); Iterator i = groups.iterator(); - VClassGroup group; - VClassGroupView displayGroup; while (i.hasNext()) { - group = (VClassGroup) i.next(); - displayGroup = new VClassGroupView(group); - vcgroups.add(displayGroup); + vcgroups.add(new VClassGroupView(i.next())); } body.put("classGroups", vcgroups); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/CommentFormController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/CommentFormController.java index 8c1c52508..b30936530 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/CommentFormController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/CommentFormController.java @@ -55,7 +55,6 @@ public class CommentFormController extends FreeMarkerHttpServlet { else { ApplicationBean appBean = vreq.getAppBean(); - int portalId = portal.getPortalId(); String portalType = null; if ( (appBean.getMaxSharedPortalId()-appBean.getMinSharedPortalId()) > 1 @@ -71,6 +70,8 @@ public class CommentFormController extends FreeMarkerHttpServlet { portalType = "clone"; } body.put("portalType", portalType); + + body.put("portalId", portalId); // Not used in template. Is it used in processing the form? if (vreq.getHeader("Referer") == null) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java index 6e67e86f3..f0101824f 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerHttpServlet.java @@ -62,6 +62,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet { protected VitroRequest vreq; protected HttpServletResponse response; protected Portal portal; + protected int portalId; protected String appName; protected Map root = new HashMap(); @@ -178,15 +179,17 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet { // RY Can this be removed? Do templates need it? Ideally, they should not. // Only needed for some weird stuff in search box that I think is only used in old default theme. - int portalId = portal.getPortalId(); - setSharedVariable("portalId", portalId); + // Some forms need it also, in which case it should get set in the getBody() method and passed to that + // body template. + portalId = portal.getPortalId(); + root.put("portalId", portalId); appName = portal.getAppName(); setSharedVariable("siteName", appName); setTemplateLoader(); - TabMenu menu = getTabMenu(portalId); + TabMenu menu = getTabMenu(); root.put("tabMenu", menu); ApplicationBean appBean = vreq.getAppBean(); @@ -198,7 +201,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet { String themeDir = getThemeDir(); - setUrls(portalId, themeDir); + setUrls(themeDir); setLoginInfo(); setCopyrightInfo(); setThemeInfo(themeDir); @@ -214,7 +217,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet { // Define the URLs that are accessible to the templates. Note that we do not create menus here, // because we want the templates to be free to define the link text and where the links are displayed. - private final void setUrls(int portalId, String themeDir) { + private final void setUrls(String themeDir) { // The urls that are accessible to the templates. // NB We are not using our menu object mechanism to build menus here, because we want the // view to control which links go where, and the link text and title. @@ -240,8 +243,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet { urls.put("termsOfUse", getUrl(Routes.TERMS_OF_USE, portalParam)); urls.put("login", getUrl(Routes.LOGIN)); - Map logoutParams = new HashMap(); - logoutParams.put("home", "" + portalId); + Map logoutParams = new HashMap(portalParam); logoutParams.put("loginSubmitMode", "Log Out"); urls.put("logout", getUrl(Routes.LOGOUT, logoutParams)); @@ -329,7 +331,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet { } - private TabMenu getTabMenu(int portalId) { + private TabMenu getTabMenu() { return new TabMenu(vreq, portalId); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerSetup.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerSetup.java index 73621fdeb..fe87e997b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerSetup.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/FreeMarkerSetup.java @@ -11,7 +11,6 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreeMarkerHttpServlet; -import edu.cornell.mannlib.vitro.webapp.view.ViewObject; import freemarker.template.Configuration; import freemarker.template.DefaultObjectWrapper; import freemarker.template.TemplateException; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java index d1875bed1..2ba008a15 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/IndividualListController.java @@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.controller.freemarker; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -62,13 +63,13 @@ public class IndividualListController extends FreeMarkerHttpServlet { response.sendRedirect(Routes.BROWSE + "?"+vreq.getQueryString()); } } catch (Exception ex) { - throw new HelpException("EntityListControllerFM: request parameter 'vclassId' must be a URI string"); + throw new HelpException("IndividualListController: request parameter 'vclassId' must be a URI string"); } } } else if (obj instanceof VClass) { vclass = (VClass)obj; } else { - throw new HelpException("EntityListControllerFM: attribute 'vclass' must be of type " + throw new HelpException("IndividualListController: attribute 'vclass' must be of type " + VClass.class.getName() ); } if (vclass!=null){ @@ -96,12 +97,16 @@ public class IndividualListController extends FreeMarkerHttpServlet { // Create list of individuals List individualList = vreq.getWebappDaoFactory().getIndividualDao().getIndividualsByVClass(vclass); - List individuals = new ArrayList(); - + List individuals = new ArrayList(individualList.size()); + Iterator i = individualList.iterator(); + while (i.hasNext()) { + individuals.add(new IndividualView(i.next())); + } body.put("individuals", individuals); // But the JSP version includes url rewriting via URLRewritingHttpServletResponse - body.put("individualUrl", config.getSharedVariable("contextPath") + "/entity?home=" + config.getSharedVariable("portalId") + "&uri="); + // RY *** FIX - define getUrl method of IndividualView + body.put("individualUrl", getUrl("/entity?home=" + portalId + "&uri=")); if (individuals == null) { log.error("individuals list is null"); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/Routes.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/Routes.java index a8bdee43d..c2469a6ce 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/Routes.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/Routes.java @@ -11,7 +11,7 @@ public class Routes { public static final String BROWSE = "/browse"; public static final String COMMENT_FORM = "/comments"; public static final String INDIVIDUAL = "/individual"; - public static final String INDIVIDUAL_LIST = "/entitylist"; // change + public static final String INDIVIDUAL_LIST = "/entitylist"; // "/individuallist"; public static final String SEARCH = "/search"; public static final String TERMS_OF_USE = "/termsOfUse"; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java index 013bb9890..4de4264ed 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java @@ -6,9 +6,8 @@ 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.Portal; -import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.Routes; +import edu.cornell.mannlib.vitro.webapp.utils.StringUtils; public class IndividualView extends ViewObject { @@ -26,8 +25,9 @@ public class IndividualView extends ViewObject { return individual.getName(); } - public String getMoniker() { - return individual.getMoniker(); + public String getTagline() { + String tagline = individual.getMoniker(); + return StringUtils.isEmpty(tagline) ? individual.getVClass().getName() : tagline; } public String getUri() { @@ -36,10 +36,18 @@ public class IndividualView extends ViewObject { // Or maybe getProfileUrl - there might be other kinds of urls // e.g., getEditUrl, getDeleteUrl - these would return the computations of PropertyEditLinks - // Just call getUrl... + // RY **** Need to account for everything in URLRewritingHttpServlet public String getProfileUrl() { - //return contextPath + URL + ""; // ADD IN the label from the individual's uri - return ""; // RY FIX THIS + return getUrl("/individual/" + individual.getLocalName()); + } + + public String getRenderer() { + // TODO + // iterate through class hierarchy looking for a custom renderer. If none, use + // default individual renderer. template will just do an include on individual.renderer + // Use individual.getVClasses() - this is the class hierarchy + // Question: what order are they returned in ? If from specific to general, break out of the iteration as soon as we find one. + return null; } public String getCustomView() { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/ViewObject.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/ViewObject.java index 1a12e798d..1df6ef2e0 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/ViewObject.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/ViewObject.java @@ -2,6 +2,8 @@ package edu.cornell.mannlib.vitro.webapp.view; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; @@ -30,5 +32,22 @@ public abstract class ViewObject { protected String urlEncode(String str) { return FreeMarkerHttpServlet.urlEncode(str); } + + /* + * 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 + */ } diff --git a/webapp/web/templates/entity/entityList.jsp b/webapp/web/templates/entity/entityList.jsp index ef946b26b..b6ce049cc 100644 --- a/webapp/web/templates/entity/entityList.jsp +++ b/webapp/web/templates/entity/entityList.jsp @@ -31,7 +31,7 @@
-
+

${title}

${subTitle}"

diff --git a/webapp/web/templates/freemarker/body/individualList.ftl b/webapp/web/templates/freemarker/body/individualList.ftl index 5f931713f..ea2676786 100644 --- a/webapp/web/templates/freemarker/body/individualList.ftl +++ b/webapp/web/templates/freemarker/body/individualList.ftl @@ -4,34 +4,19 @@
-
+

${title}

<#if subtitle??>

${subTitle}"

+ <#-- RY NEED TO ACCOUNT FOR p:process stuff -->
    - <#list entities as entity> - <#-- Iterate through the object's class hierarchy, looking for a custom view --> - <#-- RY This should be done in a view method --> - <#list entity.VClasses as type> - <#if type.customSearchView?has_content> - <#assign altRender = type.customSearchView> - <#-- What order are these returned in? If from specific to general, we should break if we find one --> - - + <#list individuals as individual>
  • - <#-- RY Create a directive to work like c:url with c:param --> - <#-- RY The JSP version includes URL rewriting in a filter - see URLRewritingHttpServletResponse --> - ${entity.name} | <#-- add p:process to name --> - <#if entity.moniker?has_content> - ${entity.moniker} <#-- add p:process --> - <#else> - ${entity.VClass.name} - - + ${individual.name} ${individual.tagline}
-
\ No newline at end of file +