Work on FreeMarker version of individual list page

This commit is contained in:
rjy7 2010-05-21 21:49:53 +00:00
parent 4aa300e5a3
commit c4709265c4
10 changed files with 65 additions and 50 deletions

View file

@ -87,14 +87,10 @@ public class BrowseController extends FreeMarkerHttpServlet {
body.put("message", message);
}
else {
List<VClassGroupView> vcgroups = new ArrayList<VClassGroupView>();
List<VClassGroupView> vcgroups = new ArrayList<VClassGroupView>(groups.size());
Iterator<VClassGroup> 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);
}

View file

@ -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
@ -72,6 +71,8 @@ public class CommentFormController extends FreeMarkerHttpServlet {
}
body.put("portalType", portalType);
body.put("portalId", portalId);
// Not used in template. Is it used in processing the form?
if (vreq.getHeader("Referer") == null) {
vreq.getSession().setAttribute("commentsFormReferer","none");

View file

@ -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<String, Object> root = new HashMap<String, Object>();
@ -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<String, String> logoutParams = new HashMap<String, String>();
logoutParams.put("home", "" + portalId);
Map<String, String> logoutParams = new HashMap<String, String>(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);
}

View file

@ -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;

View file

@ -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<Individual> individualList = vreq.getWebappDaoFactory().getIndividualDao().getIndividualsByVClass(vclass);
List<IndividualView> individuals = new ArrayList<IndividualView>();
List<IndividualView> individuals = new ArrayList<IndividualView>(individualList.size());
Iterator<Individual> 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");

View file

@ -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";

View file

@ -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() {

View file

@ -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;
@ -31,4 +33,21 @@ public abstract class ViewObject {
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<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>
*/
}

View file

@ -31,7 +31,7 @@
<div id="content">
<div class="contents">
<div class="entityList">
<div class="individualList">
<h2>${title}</h2>
<c:if test="${!empty subTitle}"><h4>${subTitle}"</h4></c:if>

View file

@ -4,32 +4,17 @@
<div class="contents">
<div class="entityList">
<div class="individualList">
<h2>${title}</h2>
<#if subtitle??>
<h4>${subTitle}"</h4>
</#if>
<#-- RY NEED TO ACCOUNT FOR p:process stuff -->
<ul>
<#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 -->
</#if>
</#list>
<#list individuals as individual>
<li>
<#-- RY Create a directive to work like c:url with c:param -->
<#-- RY The JSP version includes URL rewriting in a filter - see URLRewritingHttpServletResponse -->
<a href="${entityUrl}${entity.URI?url}">${entity.name}</a> | <#-- add p:process to name -->
<#if entity.moniker?has_content>
${entity.moniker} <#-- add p:process -->
<#else>
${entity.VClass.name}
</#if>
<a href="${individual.profileUrl}">${individual.name}</a> ${individual.tagline}
</li>
</#list>
</ul>