Reorganized FreeMarker controllers into a single package

This commit is contained in:
rjy7 2010-05-18 14:24:03 +00:00
parent fc8c9876f0
commit 269b89825f
15 changed files with 90 additions and 66 deletions

View file

@ -17,27 +17,27 @@ import java.util.List;
public class Controllers {
// Servlet urls
public static final String SITE_ADMIN = "/siteAdmin";
public static final String LOGIN = "/siteAdmin";
public static final String LOGOUT = "/siteAdmin";
// Servlet urls
public static final String ABOUT = "/about";
public static final String CONTACT_URL = "/comments";
public static final String TERMS_OF_USE_URL = "/termsOfUse";
public static final String SEARCH_URL = "/search";
public static final String BROWSE = "/browse";
public static final String INDIVIDUAL_LIST_URL = "/individuallist";
public static final String ENTITY = "/entity";
public static final String ENTITY_PROP_LIST = "/entityPropList";
public static final String ENTITY_LIST = "/EntityList";
public static final String BROWSE_CONTROLLER = "browse";
public static final String BROWSE_CONTROLLER = "browsecontroller";
public static final String RETRY_URL = "editForm";
public static final String TAB_ENTITIES = "/TabEntitiesController";
public static final String SITE_ADMIN = "/siteAdmin";
public static final String LOGIN = "/siteAdmin";
public static final String LOGOUT = "/siteAdmin";
public static final String EXPORT_RDF = "/export";
// jsps go here:
@ -74,7 +74,7 @@ public class Controllers {
public static final String ALPHA_INDEX_JSP = "/templates/alpha/alphaIndex.jsp";
public static final String SEARCH_URL = "/search";
public static final String SEARCH_BASIC_JSP = "/templates/search/searchBasic.jsp";
public static final String SEARCH_PAGED_JSP = "/templates/search/searchPaged.jsp";
public static final String SEARCH_FAILED_JSP = "/templates/search/searchFailed.jsp";

View file

@ -14,6 +14,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreeMarkerHttpServlet;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
public class VitroHttpServlet extends HttpServlet

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller;
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.util.HashMap;
import java.util.Map;
@ -8,10 +8,10 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class AboutControllerFM extends FreeMarkerHttpServlet {
public class AboutController extends FreeMarkerHttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(AboutControllerFM.class.getName());
private static final Log log = LogFactory.getLog(AboutController.class.getName());
protected String getTitle() {
return "About " + appName;

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller;
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.listeners.StatementListener;
@ -17,7 +17,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.filtering.WebappDaoFactoryFiltering;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilterUtils;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.VitroFilters;
import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag;
import edu.cornell.mannlib.vitro.webapp.controller.FreeMarkerHttpServlet;
import edu.cornell.mannlib.vitro.webapp.view.VClassGroupView;
import org.apache.commons.logging.Log;
@ -31,7 +30,7 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
public class BrowseControllerFM extends FreeMarkerHttpServlet {
public class BrowseController extends FreeMarkerHttpServlet {
static final long serialVersionUID=2006030721126L;
private transient ConcurrentHashMap<Integer, List> _groupListMap
@ -40,7 +39,7 @@ public class BrowseControllerFM extends FreeMarkerHttpServlet {
= new ConcurrentLinkedQueue<String>();
private RebuildGroupCacheThread _cacheRebuildThread;
private static final Log log = LogFactory.getLog(BrowseControllerFM.class.getName());
private static final Log log = LogFactory.getLog(BrowseController.class.getName());
public void init(javax.servlet.ServletConfig servletConfig)
throws javax.servlet.ServletException {
@ -230,8 +229,8 @@ public class BrowseControllerFM extends FreeMarkerHttpServlet {
/* ****************** Jena Model Change Listener***************************** */
private class BrowseControllerChangeListener extends StatementListener {
private BrowseControllerFM controller = null;
public BrowseControllerChangeListener(BrowseControllerFM controller){
private BrowseController controller = null;
public BrowseControllerChangeListener(BrowseController controller){
this.controller=controller;
}
@ -260,13 +259,13 @@ public class BrowseControllerFM extends FreeMarkerHttpServlet {
}
/* ******************** RebuildGroupCacheThread **************** */
protected class RebuildGroupCacheThread extends Thread {
BrowseControllerFM controller;
BrowseController controller;
boolean die = false;
boolean queueChange = false;
long queueChangeMills = 0;
private boolean awareOfQueueChange = false;
RebuildGroupCacheThread(BrowseControllerFM controller) {
RebuildGroupCacheThread(BrowseController controller) {
this.controller = controller;
}
public void run() {

View file

@ -1,8 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller;
import java.util.Map;
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -22,7 +20,7 @@ public class FreeMarkerComponentGenerator extends FreeMarkerHttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(FreeMarkerHttpServlet.class.getName());
FreeMarkerComponentGenerator(HttpServletRequest request, HttpServletResponse response) {
public FreeMarkerComponentGenerator(HttpServletRequest request, HttpServletResponse response) {
doSetup(request, response);
}

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller;
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.io.File;
import java.io.IOException;
@ -14,7 +14,6 @@ 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;
@ -30,6 +29,9 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vedit.beans.LoginFormBean;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.controller.ContactMailServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
import edu.cornell.mannlib.vitro.webapp.view.menu.TabMenu;
import edu.cornell.mannlib.vitro.webapp.web.BreadCrumbsUtil;
@ -58,7 +60,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
protected Portal portal;
protected String appName;
protected Map<String, Object> root = new HashMap<String, Object>();
// Some servlets have their own doGet() method, in which case they need to call
// doSetup(), setTitle(), setBody(), and write() themselves. Other servlets define only
// a getBody() and getTitle() method and use the parent doGet() method.
@ -66,7 +68,7 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
throws IOException, ServletException {
try {
callSuperGet(request, response); // RY Yuck...redo
callSuperGet(request, response); // ??
doSetup(request, response);
setTitle();
setBody();
@ -258,15 +260,15 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
Map<String, String> portalParam = new HashMap<String, String>();
portalParam.put("home", "" + portalId);
urls.put("about", getUrl(Controllers.ABOUT, portalParam));
urls.put("about", getUrl(Router.ABOUT, portalParam));
if (ContactMailServlet.getSmtpHostFromProperties() != null) {
urls.put("contact", getUrl(Controllers.CONTACT_URL, portalParam));
urls.put("contact", getUrl(Router.CONTACT, portalParam));
}
urls.put("search", getUrl(Controllers.SEARCH_URL));
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));
urls.put("search", getUrl(Router.SEARCH));
urls.put("termsOfUse", getUrl(Router.TERMS_OF_USE, portalParam));
urls.put("login", getUrl(Router.LOGIN));
urls.put("logout", getUrl(Router.LOGOUT));
urls.put("siteAdmin", getUrl(Router.SITE_ADMIN));
root.put("urls", urls);
}
@ -387,5 +389,6 @@ public class FreeMarkerHttpServlet extends VitroHttpServlet {
}
return encodedUrl;
}
}

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller;
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@ -39,6 +39,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyDao;
import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQuery;
@ -55,8 +57,10 @@ import edu.cornell.mannlib.vitro.webapp.web.jsptags.StringProcessorTag;
* @author bdc34
*
*/
public class IndividualControllerFM extends VitroHttpServlet {
private static final Log log = LogFactory.getLog(IndividualControllerFM.class.getName());
public class IndividualController extends FreeMarkerHttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(IndividualController.class.getName());
private String default_jsp = Controllers.BASIC_JSP;
private String default_body_jsp = Controllers.ENTITY_JSP;

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller;
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.io.IOException;
import java.util.ArrayList;
@ -22,12 +22,12 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.view.IndividualView;
public class IndividualListControllerFM extends FreeMarkerHttpServlet {
public class IndividualListController extends FreeMarkerHttpServlet {
long startTime = -1;
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(IndividualListControllerFM.class.getName());
private static final Log log = LogFactory.getLog(IndividualListController.class.getName());
private VClass vclass = null;
/**
@ -59,7 +59,7 @@ public class IndividualListControllerFM extends FreeMarkerHttpServlet {
vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(vitroClassIdStr);
if (vclass == null) {
log.error("Couldn't retrieve vclass "+vitroClassIdStr);
response.sendRedirect(Controllers.BROWSE_CONTROLLER+"-freemarker?"+vreq.getQueryString());
response.sendRedirect(Router.BROWSE + "?"+vreq.getQueryString());
}
} catch (Exception ex) {
throw new HelpException("EntityListControllerFM: request parameter 'vclassId' must be a URI string");

View file

@ -0,0 +1,23 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
// For now this class just holds constants for creating links. Could later be used to implement custom routing,
// if we go that route.
public class Router {
public static final String ABOUT = "/about";
public static final String CONTACT = "/comments";
public static final String BROWSE = "/browse";
public static final String INDIVIDUAL = "/individual";
public static final String INDIVIDUAL_LIST = "/individuallist";
public static final String SEARCH = "/search";
public static final String TERMS_OF_USE = "/termsOfUse";
// Put these under /siteAdmin/...
// Currently login, logout, and site admin are all the same page, but they don't have to be.
public static final String LOGIN = "/siteAdmin";
public static final String LOGOUT = "/siteAdmin";
public static final String SITE_ADMIN = "/siteAdmin";
}

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.controller;
package edu.cornell.mannlib.vitro.webapp.controller.freemarker;
import java.util.HashMap;
import java.util.Map;
@ -10,10 +10,10 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.utils.StringUtils;
public class TermsOfUseControllerFM extends FreeMarkerHttpServlet {
public class TermsOfUseController extends FreeMarkerHttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(TermsOfUseControllerFM.class.getName());
private static final Log log = LogFactory.getLog(TermsOfUseController.class.getName());
protected String getTitle() {
return appName + " Terms of Use";

View file

@ -2,9 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
@ -13,9 +10,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.FreeMarkerHttpServlet;
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;
@ -60,9 +56,7 @@ public class FreeMarkerSetup implements ServletContextListener {
String contextPath = sc.getContextPath();
FreeMarkerHttpServlet.contextPath = contextPath;
FreeMarkerHttpServlet.context = sc;
ViewObject.contextPath = contextPath;
// For JSP => FreeMarker transition.
// ViewObject.contextPath = contextPath;
}

View file

@ -8,12 +8,13 @@ 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.Router;
public class IndividualView extends ViewObject {
private static final Log log = LogFactory.getLog(IndividualView.class.getName());
private static final String URL = "/individual";
private static final String URL = Router.INDIVIDUAL;
private Individual individual;
@ -37,7 +38,8 @@ public class IndividualView extends ViewObject {
// 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
//return contextPath + URL + ""; // ADD IN the label from the individual's uri
return ""; // RY FIX THIS
}
public String getCustomView() {

View file

@ -9,12 +9,12 @@ 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;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.Router;
public class VClassView extends ViewObject {
private static final Log log = LogFactory.getLog(VClassView.class.getName());
private static final String URL = Controllers.INDIVIDUAL_LIST_URL;
private static final String URL = Router.INDIVIDUAL_LIST;
private VClass vclass;

View file

@ -7,7 +7,7 @@ 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.controller.freemarker.FreeMarkerHttpServlet;
// RY We may want an interface that the superclass would implement.
// RY Consider using FreeMarker's DisplayObjectWrapper instead, or extending it.
@ -17,7 +17,7 @@ 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;
// public static String contextPath;
protected String getUrl(String path) {
return FreeMarkerHttpServlet.getUrl(path);