diff --git a/webapp/config/web.xml b/webapp/config/web.xml
index 9f6272fb8..bc7d5611f 100644
--- a/webapp/config/web.xml
+++ b/webapp/config/web.xml
@@ -266,22 +266,13 @@
AboutController
- edu.cornell.mannlib.vitro.webapp.controller.AboutController
+ edu.cornell.mannlib.vitro.webapp.controller.AboutControllerFM
AboutController
/about
-
- AboutControllerFM
- edu.cornell.mannlib.vitro.webapp.controller.AboutControllerFM
-
-
- AboutControllerFM
- /about-fm
-
-
FakeSelfEditController
edu.cornell.mannlib.vitro.webapp.controller.FakeSelfEditController
@@ -968,16 +959,14 @@
browsecontroller
- edu.cornell.mannlib.vitro.webapp.controller.BrowseController
- 5
-
-
-
- browsecontrollerFM
edu.cornell.mannlib.vitro.webapp.controller.BrowseControllerFM
5
-
+
+ browsecontroller
+ /browse
+
+
pubsbyorg
edu.cornell.mannlib.vitro.webapp.controller.vclass.PubsByDepartmentServlet
@@ -1090,14 +1079,6 @@
logout
/logout
-
- browsecontroller
- /browsecontroller
-
-
- browsecontrollerFM
- /browse
-
pubsbyorg
/pubsbyorg
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java
index 2d3bfc46c..cef7c595a 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/Controllers.java
@@ -15,8 +15,10 @@ import java.util.List;
*
*/
-public class Controllers {
- //servlet urls go here:
+public class Controllers {
+
+ // Servlet urls
+
public static final String ENTITY = "/entity";
public static final String ENTITY_PROP_LIST = "/entityPropList";
public static final String ENTITY_LIST = "/EntityList";
@@ -31,7 +33,12 @@ public class Controllers {
public static final String LOGIN = "/siteAdmin";
public static final String LOGOUT = "/siteAdmin";
- public static final String EXPORT_RDF = "/export";
+ public static final String EXPORT_RDF = "/export";
+
+ public static final String CONTACT_URL = "/comments";
+ public static final String TERMS_OF_USE_URL = "/termsOfUse";
+ public static final String BROWSE = "/browse";
+ public static final String INDIVIDUAL_LIST_URL = "/entitylist"; // will change to individuallist
// jsps go here:
@@ -86,9 +93,8 @@ public class Controllers {
public static final String TOGGLE_SCRIPT_ELEMENT = "";
- public static final Object SEARCH_ERROR_JSP = "/search_error.jsp";
+ public static final Object SEARCH_ERROR_JSP = "/search_error.jsp";
- public static final String CONTACT_URL = "/comments";
//public static final String TAB_ENTITIES_LIST_JSP = "templates/tab/tabEntities.jsp";
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FreeMarkerHttpServlet.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FreeMarkerHttpServlet.java
index d32b1b9f2..eefeb95bf 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FreeMarkerHttpServlet.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/FreeMarkerHttpServlet.java
@@ -6,11 +6,15 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -242,13 +246,16 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
if ( ! StringUtils.isEmpty(bannerImage)) {
root.put("bannerImage", getUrl(themeDir + "site_icons/" + bannerImage));
}
+
+ Map portalParam = new HashMap();
+ portalParam.put("home", "" + portalId);
- urls.put("about", getUrl(Controllers.ABOUT + "?home=" + portalId));
+ urls.put("about", getUrl(Controllers.ABOUT, portalParam));
if (ContactMailServlet.getSmtpHostFromProperties() != null) {
- urls.put("contact", getUrl(Controllers.CONTACT_URL + "?home=" + portalId));
+ urls.put("contact", getUrl(Controllers.CONTACT_URL, portalParam));
}
urls.put("search", getUrl(Controllers.SEARCH_URL));
- urls.put("termsOfUse", getUrl("/termsOfUse?home=" + portalId));
+ urls.put("termsOfUse", getUrl(Controllers.TERMS_OF_USE_URL, portalParam));
urls.put("login", getUrl(Controllers.LOGIN));
urls.put("logout", getUrl(Controllers.LOGOUT));
urls.put("siteAdmin", getUrl(Controllers.SITE_ADMIN));
@@ -318,14 +325,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
}
}
-
- public static String getUrl(String path) {
- if ( ! path.startsWith("/") ) {
- path = "/" + path;
- }
- return contextPath + path;
- }
-
+
private TabMenu getTabMenu(int portalId) {
return new TabMenu(vreq, portalId);
}
@@ -343,4 +343,41 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
request.setAttribute("ftl_footer", fcg.getFooter());
}
+
+ /* ******************** Utilities ******************* */
+
+ public static String getUrl(String path) {
+ if ( ! path.startsWith("/") ) {
+ path = "/" + path;
+ }
+ return contextPath + path;
+ }
+
+ public static String getUrl(String path, Map params) {
+ String url = getUrl(path);
+
+ Iterator i = params.keySet().iterator();
+ String key, value;
+ String glue = "?";
+ while (i.hasNext()) {
+ key = i.next();
+ value = params.get(key);
+ url += glue + key + "=" + urlEncode(value);
+ glue = "&";
+ }
+
+ return url;
+ }
+
+ public static String urlEncode(String url) {
+ String encoding = "ISO-8859-1";
+ String encodedUrl = null;
+ try {
+ encodedUrl = URLEncoder.encode(url, encoding);
+ } catch (UnsupportedEncodingException e) {
+ log.error("Error encoding url " + url + " with encoding " + encoding + ": Unsupported encoding.");
+ }
+ return encodedUrl;
+ }
+
}
\ No newline at end of file
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 04e47296e..f681c351a 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/IndividualView.java
@@ -35,6 +35,7 @@ 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...
public String getProfileUrl() {
return contextPath + URL + ""; // ADD IN the label from the individual's uri
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/VClassGroupView.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/VClassGroupView.java
index 7a89b7468..08b30b10a 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/VClassGroupView.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/VClassGroupView.java
@@ -12,15 +12,6 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
-/*
- * A VClassGroupDisplay object is associated with a VClassGroup for display.
- * It is an object that contains a linked list, rather than a type of linked list,
- * so that JSP EL can access properties such as publicName.
- *
- * RY We may want an abstract display class as a superclass.
- * RY We may want an interface that the superclass would implement.
- * RY We may want to nest this class in the VClassGroup class.
- */
public class VClassGroupView extends ViewObject {
private static final Log log = LogFactory.getLog(VClassGroupView.class.getName());
@@ -54,6 +45,7 @@ public class VClassGroupView extends ViewObject {
public List getClasses() {
// Do we need to store the classes as an instance member? Would we ever access this method more than once per template?
+ // Don't do this in the constructor, since we might not need it.
if (classes == null) {
List classList = vClassGroup.getVitroClassList();
classes = new ArrayList();
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/VClassView.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/VClassView.java
index 34c509e65..6d0e66a11 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/VClassView.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/VClassView.java
@@ -2,15 +2,19 @@
package edu.cornell.mannlib.vitro.webapp.view;
+import java.util.HashMap;
+import java.util.Map;
+
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.Controllers;
public class VClassView extends ViewObject {
private static final Log log = LogFactory.getLog(VClassView.class.getName());
- private static final String URL = "/individuallistFM?vclassId=";
+ private static final String URL = Controllers.INDIVIDUAL_LIST_URL;
private VClass vclass;
@@ -23,7 +27,9 @@ public class VClassView extends ViewObject {
}
public String getUrl() {
- return contextPath + URL + encodeUrl(vclass.getURI());
+ Map params = new HashMap();
+ params.put("vclassId", vclass.getURI());
+ return getUrl(URL, params);
}
public int getEntityCount() {
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 4eb535258..e4066d535 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/ViewObject.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/ViewObject.java
@@ -2,36 +2,33 @@
package edu.cornell.mannlib.vitro.webapp.view;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.net.URLEncoder;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.FreeMarkerHttpServlet;
-import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
+
+// RY We may want an interface that the superclass would implement.
+// RY Consider using FreeMarker's DisplayObjectWrapper instead, or extending it.
public abstract class ViewObject {
private static final Log log = LogFactory.getLog(ViewObject.class.getName());
+ // RY Can probably remove this, since we're using the FreeMarkerHttpServlet methods instead
public static String contextPath;
- protected static String getUrl(String path) {
+ protected String getUrl(String path) {
return FreeMarkerHttpServlet.getUrl(path);
}
- protected String encodeUrl(String url) {
- String encoding = "ISO-8859-1";
- String encodedUrl = null;
- try {
- encodedUrl = URLEncoder.encode(url, encoding);
- } catch (UnsupportedEncodingException e) {
- log.error("Error encoding url " + url + " with encoding " + encoding + ": Unsupported encoding.");
- }
- return encodedUrl;
+ protected String getUrl(String path, Map params) {
+ return FreeMarkerHttpServlet.getUrl(path, params);
+ }
+
+ protected String urlEncode(String str) {
+ return FreeMarkerHttpServlet.urlEncode(str);
}
}
diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/menu/TabMenu.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/menu/TabMenu.java
index 49e8d6e64..c028b43c3 100644
--- a/webapp/src/edu/cornell/mannlib/vitro/webapp/view/menu/TabMenu.java
+++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/view/menu/TabMenu.java
@@ -44,7 +44,7 @@ public class TabMenu extends MainMenu {
// Hard-coded tabs. It's not really a good idea to have these here, since any menu item that doesn't
// come from the db should be accessible to the template to change the text. But we need them here
// to apply the "active" mechanism.
- addItem("Index", "/browsecontroller");
+ addItem("Index", "/browse");
}
}
diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/FreeMarkerHttpServletTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/FreeMarkerHttpServletTest.java
new file mode 100644
index 000000000..fee521f4e
--- /dev/null
+++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/controller/FreeMarkerHttpServletTest.java
@@ -0,0 +1,52 @@
+/* $This file is distributed under the terms of the license in /doc/license.txt$ */
+
+package edu.cornell.mannlib.vitro.webapp.controller;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
+import freemarker.template.Configuration;
+
+public class FreeMarkerHttpServletTest extends AbstractTestClass {
+
+ static {
+ Configuration cfg = new Configuration();
+ FreeMarkerHttpServlet.config = cfg;
+ FreeMarkerHttpServlet.contextPath = "/vivo";
+ }
+
+ @Test
+ public void testGetUrl() {
+ String path1 = "/individual";
+ Assert.assertEquals("/vivo/individual", FreeMarkerHttpServlet.getUrl(path1));
+
+ int portalId = 1;
+ String path2 = "/individual?home=" + portalId;
+ Assert.assertEquals("/vivo/individual?home=1", FreeMarkerHttpServlet.getUrl(path2));
+ }
+
+ @Test
+ public void testGetUrlWithParams() {
+ String path = "/individual";
+ Map params = new HashMap();
+ int portalId = 1;
+ params.put("home", "" + portalId);
+ params.put("name", "Tom");
+ Assert.assertEquals("/vivo/individual?home=1&name=Tom", FreeMarkerHttpServlet.getUrl(path, params));
+ }
+
+ @Test
+ public void testEncodeUrl() {
+ String path = "/individuallist";
+ Map params = new HashMap();
+ String vClassUri = "http://vivoweb.org/ontology/core#FacultyMember";
+ params.put("vclassId", vClassUri);
+ Assert.assertEquals("/vivo/individuallist?vclassId=http%3A%2F%2Fvivoweb.org%2Fontology%2Fcore%23FacultyMember", FreeMarkerHttpServlet.getUrl(path, params));
+ }
+
+}