NIHVIVO-2612 Remove portal-relative url-building methods from UrlBuilder. As a consequence, all methods can become static, so add a private constructor so the class cannot be instantiated.

This commit is contained in:
ryounes 2011-07-07 18:30:10 +00:00
parent b3d4a305c6
commit d09a6640d9
7 changed files with 46 additions and 92 deletions

View file

@ -245,25 +245,25 @@ 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 Map<String, String> getUrls(String themeDir, UrlBuilder urlBuilder, VitroRequest vreq) {
private final Map<String, String> getUrls(String themeDir, VitroRequest vreq) {
Map<String, String> urls = new HashMap<String, String>();
urls.put("home", urlBuilder.getHomeUrl());
urls.put("home", UrlBuilder.getHomeUrl());
// Templates use this to construct urls.
urls.put("base", UrlBuilder.contextPath);
urls.put("about", urlBuilder.getPortalUrl(Route.ABOUT));
urls.put("about", UrlBuilder.getUrl(Route.ABOUT));
if (FreemarkerEmailFactory.isConfigured(vreq)) {
urls.put("contact", urlBuilder.getPortalUrl(Route.CONTACT));
urls.put("contact", UrlBuilder.getUrl(Route.CONTACT));
}
urls.put("search", urlBuilder.getPortalUrl(Route.SEARCH));
urls.put("termsOfUse", urlBuilder.getPortalUrl(Route.TERMS_OF_USE));
urls.put("login", urlBuilder.getLoginUrl());
urls.put("logout", urlBuilder.getLogoutUrl());
urls.put("search", UrlBuilder.getUrl(Route.SEARCH));
urls.put("termsOfUse", UrlBuilder.getUrl(Route.TERMS_OF_USE));
urls.put("login", UrlBuilder.getLoginUrl());
urls.put("logout", UrlBuilder.getLogoutUrl());
urls.put("myAccount", UrlBuilder.getUrl("/accounts/myAccount"));
urls.put("siteAdmin", urlBuilder.getPortalUrl(Route.SITE_ADMIN));
urls.put("themeImages", urlBuilder.getPortalUrl(themeDir + "/images"));
urls.put("siteAdmin", UrlBuilder.getUrl(Route.SITE_ADMIN));
urls.put("themeImages", UrlBuilder.getUrl(themeDir + "/images"));
urls.put("images", UrlBuilder.getUrl("/images"));
urls.put("theme", UrlBuilder.getUrl(themeDir));
urls.put("index", UrlBuilder.getUrl("/browse"));
@ -351,9 +351,8 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
map.put("title", getTitle(siteName, vreq));
String themeDir = getThemeDir(appBean);
UrlBuilder urlBuilder = new UrlBuilder(appBean);
map.put("urls", getUrls(themeDir, urlBuilder, vreq));
map.put("urls", getUrls(themeDir, vreq));
map.put("themeDir", themeDir);
map.put("currentTheme", themeDir.substring(themeDir.lastIndexOf('/')+1));
@ -368,7 +367,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
map.put("user", new User(vreq));
map.put("version", getRevisionInfo(urlBuilder));
map.put("version", getRevisionInfo());
map.put("copyright", getCopyrightInfo(appBean));
map.put("siteTagline", appBean.getShortHand());
@ -418,11 +417,11 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
return copyright;
}
private final Map<String, Object> getRevisionInfo(UrlBuilder urlBuilder) {
private final Map<String, Object> getRevisionInfo() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("label", RevisionInfoBean.getBean(getServletContext())
.getReleaseLabel());
map.put("moreInfoUrl", urlBuilder.getPortalUrl("/revisionInfo"));
map.put("moreInfoUrl", UrlBuilder.getUrl("/revisionInfo"));
return map;
}

View file

@ -25,6 +25,7 @@ import edu.cornell.mannlib.vitro.webapp.auth.requestedAction.propstmt.EditObjPro
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ExceptionResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ForwardResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
@ -519,7 +520,7 @@ public class ImageUploadController extends FreemarkerHttpServlet {
*/
private String formAction(String entityUri, String action,
String placeholderUrl) {
UrlBuilder.ParamMap params = new UrlBuilder.ParamMap(
ParamMap params = new ParamMap(
PARAMETER_ENTITY_URI, entityUri, PARAMETER_ACTION, action,
PARAMETER_PLACEHOLDER_URL, placeholderUrl);
return UrlBuilder.getPath(URL_HERE, params);

View file

@ -52,24 +52,22 @@ public class SiteAdminController extends FreemarkerHttpServlet {
@Override
protected ResponseValues processRequest(VitroRequest vreq) {
Map<String, Object> body = new HashMap<String, Object>();
UrlBuilder urlBuilder = new UrlBuilder(vreq.getAppBean());
if (PolicyHelper.isAuthorizedForActions(vreq, new EditIndividuals())) {
body.put("dataInput", getDataInputData(vreq));
}
body.put("siteConfig", getSiteConfigurationData(vreq, urlBuilder));
body.put("siteConfig", getSiteConfigurationData(vreq));
// rjy7 There is a risk that the login levels required to show the links will get out
// of step with the levels required by the pages themselves. We should implement a
// mechanism similar to what's used on the front end to display links to Site Admin
// and Revision Info iff the user has access to those pages.
if (PolicyHelper.isAuthorizedForActions(vreq, new EditOntology())) {
body.put("ontologyEditor", getOntologyEditorData(vreq, urlBuilder));
body.put("ontologyEditor", getOntologyEditorData(vreq));
}
if (PolicyHelper.isAuthorizedForActions(vreq, new UseAdvancedDataToolsPages())) {
body.put("dataTools", getDataToolsData(vreq, urlBuilder));
body.put("dataTools", getDataToolsData(vreq));
// Only for DataStar. Should handle without needing a DataStar-specific version of this controller.
//body.put("customReports", getCustomReportsData(vreq));
@ -114,22 +112,22 @@ public class SiteAdminController extends FreemarkerHttpServlet {
return map;
}
private Map<String, Object> getSiteConfigurationData(VitroRequest vreq, UrlBuilder urlBuilder) {
private Map<String, Object> getSiteConfigurationData(VitroRequest vreq) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, String> urls = new HashMap<String, String>();
if (PolicyHelper.isAuthorizedForActions(vreq, new ManageUserAccounts())) {
urls.put("userList", urlBuilder.getPortalUrl("/accountsAdmin"));
urls.put("userList", UrlBuilder.getUrl("/accountsAdmin"));
}
if (PolicyHelper.isAuthorizedForActions(vreq, new EditSiteInformation())) {
urls.put("siteInfo", urlBuilder.getPortalUrl("/editForm", new ParamMap("controller", "ApplicationBean")));
urls.put("siteInfo", UrlBuilder.getUrl("/editForm", new ParamMap("controller", "ApplicationBean")));
}
// TODO this goes away when Menu Management is complete - jblake
if (PolicyHelper.isAuthorizedForActions(vreq, MenuN3EditController.REQUIRED_ACTIONS)) {
urls.put("menuN3Editor", urlBuilder.getPortalUrl("/menuN3Editor"));
urls.put("menuN3Editor", UrlBuilder.getUrl("/menuN3Editor"));
}
if (PolicyHelper.isAuthorizedForActions(vreq, new ManageMenus())) {
@ -143,7 +141,7 @@ public class SiteAdminController extends FreemarkerHttpServlet {
return map;
}
private Map<String, Object> getOntologyEditorData(VitroRequest vreq, UrlBuilder urlBuilder) {
private Map<String, Object> getOntologyEditorData(VitroRequest vreq) {
Map<String, Object> map = new HashMap<String, Object>();
@ -171,25 +169,25 @@ public class SiteAdminController extends FreemarkerHttpServlet {
Map<String, String> urls = new HashMap<String, String>();
urls.put("ontologies", urlBuilder.getPortalUrl("/listOntologies"));
urls.put("classHierarchy", urlBuilder.getPortalUrl("/showClassHierarchy"));
urls.put("classGroups", urlBuilder.getPortalUrl("/listGroups"));
urls.put("dataPropertyHierarchy", urlBuilder.getPortalUrl("/showDataPropertyHierarchy"));
urls.put("propertyGroups", urlBuilder.getPortalUrl("/listPropertyGroups"));
urls.put("objectPropertyHierarchy", urlBuilder.getPortalUrl("/showObjectPropertyHierarchy", new ParamMap("iffRoot", "true")));
urls.put("ontologies", UrlBuilder.getUrl("/listOntologies"));
urls.put("classHierarchy", UrlBuilder.getUrl("/showClassHierarchy"));
urls.put("classGroups", UrlBuilder.getUrl("/listGroups"));
urls.put("dataPropertyHierarchy", UrlBuilder.getUrl("/showDataPropertyHierarchy"));
urls.put("propertyGroups", UrlBuilder.getUrl("/listPropertyGroups"));
urls.put("objectPropertyHierarchy", UrlBuilder.getUrl("/showObjectPropertyHierarchy", new ParamMap("iffRoot", "true")));
map.put("urls", urls);
return map;
}
private Map<String, Object> getDataToolsData(VitroRequest vreq, UrlBuilder urlBuilder) {
private Map<String, Object> getDataToolsData(VitroRequest vreq) {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, String> urls = new HashMap<String, String>();
urls.put("ingest", UrlBuilder.getUrl("/ingest"));
urls.put("rdfData", urlBuilder.getPortalUrl("/uploadRDFForm"));
urls.put("rdfExport", urlBuilder.getPortalUrl("/export"));
urls.put("rdfData", UrlBuilder.getUrl("/uploadRDFForm"));
urls.put("rdfExport", UrlBuilder.getUrl("/export"));
urls.put("sparqlQuery", UrlBuilder.getUrl("/admin/sparqlquery"));
urls.put("sparqlQueryBuilder", UrlBuilder.getUrl("/admin/sparqlquerybuilder"));
map.put("urls", urls);

View file

@ -9,13 +9,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openrdf.model.URI;
import org.openrdf.model.impl.URIImpl;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
@ -27,8 +25,6 @@ public class UrlBuilder {
private static final Log log = LogFactory.getLog(UrlBuilder.class.getName());
protected static String contextPath = null;
private ApplicationBean application;
public enum Route {
ABOUT("/about"),
@ -113,53 +109,23 @@ public class UrlBuilder {
}
}
public UrlBuilder(ApplicationBean application) {
this.application = application;
}
public String getHomeUrl() {
//String rootBreadCrumbUrl = application.getRootBreadCrumbURL();
//String path = StringUtils.isEmpty(rootBreadCrumbUrl) ? "" : rootBreadCrumbUrl;
//return getUrl(path);
private UrlBuilder() { }
public static String getHomeUrl() {
return getUrl("");
}
// Used by templates to build urls.
public String getBaseUrl() {
public static String getBaseUrl() {
return contextPath;
}
public String getLoginUrl() {
return getPortalUrl(Route.AUTHENTICATE, "return", "true");
public static String getLoginUrl() {
return getUrl(Route.AUTHENTICATE, "return", "true");
}
public String getLogoutUrl() {
return getPortalUrl(Route.LOGOUT);
}
public String getPortalUrl(String path) {
return getUrl(path);
}
public String getPortalUrl(String path, ParamMap params) {
return getUrl(path, params);
}
public String getPortalUrl(String path, String...params) {
ParamMap urlParams = new ParamMap(params);
return getPortalUrl(path, urlParams);
}
public String getPortalUrl(Route route) {
return getPortalUrl(route.path());
}
public String getPortalUrl(Route route, ParamMap params) {
return getPortalUrl(route.path(), params);
}
public String getPortalUrl(Route route, String...params) {
return getPortalUrl(route.path(), params);
public static String getLogoutUrl() {
return getUrl(Route.LOGOUT);
}
public static class ParamMap extends HashMap<String, String> {
@ -202,8 +168,6 @@ public class UrlBuilder {
}
/********** Static utility methods **********/
public static String getUrl(String path) {
if ( !path.isEmpty() && !path.startsWith("/") ) {

View file

@ -2,7 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@ -10,10 +9,7 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.StringUtils;
@ -28,12 +24,11 @@ import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper.TemplateProcessingException;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.ParamMap;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.RedirectResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.ResponseValues;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.responsevalues.TemplateResponseValues;
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.AdditionsAndRetractions;
@ -197,7 +192,7 @@ public class ProcessRdfFormController extends FreemarkerHttpServlet{
}
if( resourceToRedirectTo != null ){
UrlBuilder.ParamMap paramMap= new UrlBuilder.ParamMap();
ParamMap paramMap = new ParamMap();
paramMap.put("uri", resourceToRedirectTo);
paramMap.put("extra","true"); //for ie6
return new RedirectResponseValues( UrlBuilder.getUrl(urlPattern,paramMap) + predicateAnchor );

View file

@ -32,7 +32,6 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
private static final Log log = LogFactory.getLog(BaseIndividualTemplateModel.class);
protected Individual individual;
protected UrlBuilder urlBuilder;
protected GroupedPropertyList propertyList;
protected LoginStatusBean loginStatusBean;
private EditingPolicyHelper policyHelper;
@ -42,7 +41,6 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
this.individual = individual;
this.loginStatusBean = LoginStatusBean.getBean(vreq);
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
this.urlBuilder = new UrlBuilder(vreq.getAppBean());
// If editing, create a helper object to check requested actions against policies
if (isEditable()) {
@ -100,7 +98,7 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
}
public String getEditUrl() {
return urlBuilder.getPortalUrl(Route.INDIVIDUAL_EDIT, "uri", getUri());
return UrlBuilder.getUrl(Route.INDIVIDUAL_EDIT, "uri", getUri());
}
public GroupedPropertyList getPropertyList() {

View file

@ -76,9 +76,8 @@ public abstract class PropertyTemplateModel extends BaseTemplateModel {
verboseDisplay.put("localName", property.getLocalNameWithPrefix());
verboseDisplay.put("displayRank", getPropertyDisplayTier(property));
UrlBuilder urlBuilder = new UrlBuilder(vreq.getAppBean());
String editUrl = urlBuilder.getPortalUrl(getPropertyEditRoute(), "uri", property.getURI());
String editUrl = UrlBuilder.getUrl(getPropertyEditRoute(), "uri", property.getURI());
verboseDisplay.put("propertyEditUrl", editUrl);
}