This commit is contained in:
parent
92566579f5
commit
e07a824bf8
9 changed files with 71 additions and 48 deletions
|
@ -56,9 +56,9 @@ import edu.cornell.mannlib.vitro.webapp.search.beans.VitroQueryWrapper;
|
|||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapperFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.ContentType;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.functions.IndividualUrlMethod;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.jsptags.StringProcessorTag;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel;
|
||||
import freemarker.ext.beans.BeansWrapper;
|
||||
|
||||
/**
|
||||
* Handles requests for entity information.
|
||||
|
@ -128,6 +128,8 @@ public class IndividualController extends FreemarkerHttpServlet {
|
|||
*/
|
||||
body.put("individual", ind); //getNonDefaultBeansWrapper(BeansWrapper.EXPOSE_SAFE).wrap(ind));
|
||||
|
||||
body.put("url", new IndividualUrlMethod());
|
||||
|
||||
String template = getIndividualTemplate(individual);
|
||||
|
||||
return new TemplateResponseValues(template, body);
|
||||
|
|
|
@ -7,15 +7,10 @@ import java.io.StringWriter;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateDirectiveModel;
|
||||
import freemarker.template.TemplateException;
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.web.functions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.TemplateMethodModel;
|
||||
import freemarker.template.TemplateModelException;
|
||||
|
||||
public class IndividualUrlMethod implements TemplateMethodModel {
|
||||
|
||||
@Override
|
||||
public String exec(List args) throws TemplateModelException {
|
||||
if (args.size() != 1) {
|
||||
throw new TemplateModelException("Wrong number of arguments");
|
||||
}
|
||||
|
||||
String uri = (String) args.get(0);
|
||||
Environment env = Environment.getCurrentEnvironment();
|
||||
HttpServletRequest request = (HttpServletRequest) env.getCustomAttribute("request");
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
return UrlBuilder.getIndividualProfileUrl(uri, vreq.getWebappDaoFactory());
|
||||
}
|
||||
|
||||
}
|
|
@ -32,20 +32,20 @@ public class BrowseWidget extends Widget {
|
|||
|
||||
@Override
|
||||
protected WidgetTemplateValues process(Environment env, Map params,
|
||||
HttpServletRequest request, ServletContext context) throws Exception
|
||||
VitroRequest vreq, ServletContext context) throws Exception
|
||||
{
|
||||
Mode mode = getMode( request, params );
|
||||
Mode mode = getMode( vreq, params );
|
||||
switch( mode ){
|
||||
case VCLASS_ALPHA:
|
||||
return doClassAlphaDisplay(env,params,request,context);
|
||||
return doClassAlphaDisplay(env,params,vreq,context);
|
||||
case CLASS_GROUP:
|
||||
return doClassGroupDisplay(env, params, request, context);
|
||||
return doClassGroupDisplay(env, params, vreq, context);
|
||||
case VCLASS:
|
||||
return doClassDisplay(env, params, request, context);
|
||||
return doClassDisplay(env, params, vreq, context);
|
||||
case ALL_CLASS_GROUPS:
|
||||
return doAllClassGroupsDisplay(env, params, request, context);
|
||||
return doAllClassGroupsDisplay(env, params, vreq, context);
|
||||
default:
|
||||
return doAllClassGroupsDisplay(env, params, request, context);
|
||||
return doAllClassGroupsDisplay(env, params, vreq, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,8 @@ public class BrowseWidget extends Widget {
|
|||
}
|
||||
|
||||
protected WidgetTemplateValues doAllClassGroupsDisplay(Environment env, Map params,
|
||||
HttpServletRequest request, ServletContext context) {
|
||||
Map<String,Object> body = getAllClassGroupData(request, params);
|
||||
VitroRequest vreq, ServletContext context) {
|
||||
Map<String,Object> body = getAllClassGroupData(vreq, params);
|
||||
try {
|
||||
body.put("urls",env.getDataModel().get("urls"));
|
||||
body.put("urlMapping",env.getDataModel().get("urlMapping"));
|
||||
|
@ -69,10 +69,9 @@ public class BrowseWidget extends Widget {
|
|||
return new WidgetTemplateValues(macroName, body);
|
||||
}
|
||||
|
||||
protected Map<String,Object> getAllClassGroupData(HttpServletRequest request, Map params){
|
||||
protected Map<String,Object> getAllClassGroupData(VitroRequest vreq, Map params){
|
||||
Map<String,Object> map = new HashMap<String,Object>();
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
List<VClassGroup> classGroups =
|
||||
vreq.getWebappDaoFactory().getVClassGroupDao().getPublicGroupsWithVClasses();
|
||||
|
||||
|
@ -85,9 +84,9 @@ public class BrowseWidget extends Widget {
|
|||
}
|
||||
|
||||
protected WidgetTemplateValues doClassDisplay(Environment env, Map params,
|
||||
HttpServletRequest request, ServletContext context) {
|
||||
VitroRequest vreq, ServletContext context) {
|
||||
|
||||
Map<String,Object> body = getClassData(request,params);
|
||||
Map<String,Object> body = getClassData(vreq,params);
|
||||
|
||||
try {
|
||||
body.put("urls",env.getDataModel().get("urls"));
|
||||
|
@ -100,13 +99,12 @@ public class BrowseWidget extends Widget {
|
|||
return new WidgetTemplateValues(macroName, body);
|
||||
}
|
||||
|
||||
private Map<String, Object> getClassData(HttpServletRequest request, Map params) {
|
||||
private Map<String, Object> getClassData(VitroRequest vreq, Map params) {
|
||||
Map<String,Object> map = new HashMap<String,Object>();
|
||||
|
||||
map.putAll(getClassGroupData(request, params));
|
||||
map.putAll(getClassGroupData(vreq, params));
|
||||
|
||||
String classUri = getParam(Mode.VCLASS, request, params);
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
String classUri = getParam(Mode.VCLASS, vreq, params);
|
||||
VClass vclass = vreq.getWebappDaoFactory().getVClassDao().getVClassByURI(classUri);
|
||||
map.put("class", new VClassTemplateModel(vclass));
|
||||
|
||||
|
@ -123,9 +121,9 @@ public class BrowseWidget extends Widget {
|
|||
}
|
||||
|
||||
protected WidgetTemplateValues doClassGroupDisplay(Environment env,
|
||||
Map params, HttpServletRequest request, ServletContext context) {
|
||||
Map params, VitroRequest vreq, ServletContext context) {
|
||||
|
||||
Map<String,Object> body = getClassGroupData(request,params);
|
||||
Map<String,Object> body = getClassGroupData(vreq,params);
|
||||
|
||||
try {
|
||||
body.put("urls",env.getDataModel().get("urls"));
|
||||
|
@ -138,11 +136,10 @@ public class BrowseWidget extends Widget {
|
|||
return new WidgetTemplateValues(macroName, body);
|
||||
}
|
||||
|
||||
protected Map<String, Object> getClassGroupData(HttpServletRequest request, Map params) {
|
||||
protected Map<String, Object> getClassGroupData(VitroRequest vreq, Map params) {
|
||||
Map<String,Object> map = new HashMap<String,Object>();
|
||||
|
||||
String vcgName = getParam(Mode.CLASS_GROUP, request, params);
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
String vcgName = getParam(Mode.CLASS_GROUP, vreq, params);
|
||||
VClassGroup vcg = vreq.getWebappDaoFactory().getVClassGroupDao().getGroupByName(vcgName);
|
||||
|
||||
vreq.getWebappDaoFactory().getVClassDao().addVClassesToGroup(vcg, false, true);
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder.Route;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.login.LoginProcessBean;
|
||||
|
@ -67,14 +68,14 @@ public class LoginWidget extends Widget {
|
|||
|
||||
@Override
|
||||
protected WidgetTemplateValues process(Environment env, Map params,
|
||||
HttpServletRequest request, ServletContext context) {
|
||||
VitroRequest vreq, ServletContext context) {
|
||||
|
||||
WidgetTemplateValues values = null;
|
||||
TemplateModel urls = null;
|
||||
|
||||
try {
|
||||
urls = env.getDataModel().get("urls");
|
||||
State state = getCurrentLoginState(request);
|
||||
State state = getCurrentLoginState(vreq);
|
||||
log.debug("State on exit: " + state);
|
||||
|
||||
switch (state) {
|
||||
|
@ -82,17 +83,17 @@ public class LoginWidget extends Widget {
|
|||
// On the login page itself, show a message that the user is already logged in.
|
||||
// Otherwise, when redirecting to login page from a page that the logged-in user
|
||||
// doesn't have access to, we would just show a blank page.
|
||||
if (request.getServletPath().equals(Route.LOGIN.path())) {
|
||||
values = showMessageToLoggedInUser(request);
|
||||
if (vreq.getServletPath().equals(Route.LOGIN.path())) {
|
||||
values = showMessageToLoggedInUser(vreq);
|
||||
break;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
case FORCED_PASSWORD_CHANGE:
|
||||
values = showPasswordChangeScreen(request);
|
||||
values = showPasswordChangeScreen(vreq);
|
||||
break;
|
||||
default:
|
||||
values = showLoginScreen(request);
|
||||
values = showLoginScreen(vreq);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e);
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -25,7 +24,7 @@ public class SelectListWidget extends Widget {
|
|||
|
||||
@Override
|
||||
protected WidgetTemplateValues process(Environment env, Map params,
|
||||
HttpServletRequest request, ServletContext context) {
|
||||
VitroRequest vreq, ServletContext context) {
|
||||
|
||||
Object obj = params.get("fieldName");
|
||||
if( obj == null || !(obj instanceof SimpleScalar)){
|
||||
|
@ -37,10 +36,9 @@ public class SelectListWidget extends Widget {
|
|||
log.error("SelectListWidget must have a parameter 'fieldName'");
|
||||
throw new Error("SelectListWidget must have a parameter 'fieldName' of type String");
|
||||
}
|
||||
|
||||
VitroRequest vreq = new VitroRequest(request);
|
||||
HttpSession session = request.getSession(false);
|
||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,request);
|
||||
|
||||
HttpSession session = vreq.getSession(false);
|
||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(session,vreq);
|
||||
|
||||
WebappDaoFactory wdf;
|
||||
if (editConfig != null) {
|
||||
|
|
|
@ -6,19 +6,19 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import freemarker.core.Environment;
|
||||
|
||||
public class TestWidget extends Widget {
|
||||
|
||||
@Override
|
||||
protected WidgetTemplateValues process(Environment env, Map params,
|
||||
HttpServletRequest request, ServletContext context) {
|
||||
VitroRequest vreq, ServletContext context) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
String macroName;
|
||||
if (LoginStatusBean.getBean(request).isLoggedIn()) {
|
||||
if (LoginStatusBean.getBean(vreq).isLoggedIn()) {
|
||||
map.put("status", "logged in");
|
||||
macroName = "loggedIn";
|
||||
} else {
|
||||
|
|
|
@ -10,11 +10,11 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.core.Macro;
|
||||
import freemarker.template.Template;
|
||||
|
@ -52,13 +52,13 @@ public abstract class Widget {
|
|||
}
|
||||
|
||||
public String doMarkup(Environment env, Map params) {
|
||||
HttpServletRequest request = (HttpServletRequest) env.getCustomAttribute("request");
|
||||
VitroRequest vreq = (VitroRequest) env.getCustomAttribute("vreq");
|
||||
ServletContext context = (ServletContext) env.getCustomAttribute("context");
|
||||
|
||||
WidgetTemplateValues values = null;
|
||||
|
||||
try {
|
||||
values = process(env, params, request, context);
|
||||
values = process(env, params, vreq, context);
|
||||
} catch (Exception e) {
|
||||
log.error(e, e);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public abstract class Widget {
|
|||
// }
|
||||
|
||||
protected abstract WidgetTemplateValues process(Environment env, Map params,
|
||||
HttpServletRequest request, ServletContext context) throws Exception;
|
||||
VitroRequest vreq, ServletContext context) throws Exception;
|
||||
|
||||
private String processMacroToString(Environment env, String widgetName, Macro macro, Map<String, Object> map) {
|
||||
StringWriter out = new StringWriter();
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
<#-- Default object property statement short view template -->
|
||||
|
||||
<a href="${statement.objectUrl}">${statement.name!}</a> ${statement.moniker!}
|
||||
<a href="${url(statement.object)}">${statement.name!}</a> ${statement.moniker!}
|
||||
|
|
Loading…
Add table
Reference in a new issue