NIHVIVO-2164 Fix jsp compile errors in propDelete.jsp. Some refactoring.

This commit is contained in:
ryounes 2011-08-11 15:36:28 +00:00
parent 428e917de9
commit 3cbc60d357
8 changed files with 30 additions and 25 deletions

View file

@ -34,7 +34,7 @@ public class FreemarkerComponentGenerator extends FreemarkerHttpServlet {
// Mimic what FreemarkerHttpServlet does for a new request // Mimic what FreemarkerHttpServlet does for a new request
VitroRequest vreq = new VitroRequest(request); VitroRequest vreq = new VitroRequest(request);
VitroFreemarkerConfiguration config = getConfig(vreq); FreemarkerConfiguration config = getConfig(vreq);
vreq.setAttribute("freemarkerConfig", config); vreq.setAttribute("freemarkerConfig", config);
config.resetRequestSpecificSharedVariables(); config.resetRequestSpecificSharedVariables();
Map<String, Object> map = getPageTemplateValues(vreq); Map<String, Object> map = getPageTemplateValues(vreq);

View file

@ -34,9 +34,9 @@ import freemarker.template.TemplateException;
import freemarker.template.TemplateModel; import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException; import freemarker.template.TemplateModelException;
public class VitroFreemarkerConfiguration extends Configuration { public class FreemarkerConfiguration extends Configuration {
private static final Log log = LogFactory.getLog(VitroFreemarkerConfiguration.class); private static final Log log = LogFactory.getLog(FreemarkerConfiguration.class);
private final String themeDir; private final String themeDir;
private final ServletContext context; private final ServletContext context;
@ -46,7 +46,7 @@ public class VitroFreemarkerConfiguration extends Configuration {
private final Tags scripts; private final Tags scripts;
private final Tags headScripts; private final Tags headScripts;
VitroFreemarkerConfiguration(String themeDir, VitroRequest vreq, ServletContext context) { FreemarkerConfiguration(String themeDir, VitroRequest vreq, ServletContext context) {
this.themeDir = themeDir; this.themeDir = themeDir;
this.context = context; this.context = context;
@ -103,8 +103,12 @@ public class VitroFreemarkerConfiguration extends Configuration {
/** Some template variables are shared so that they are accessible to /** Some template variables are shared so that they are accessible to
* all templates, but they are request-specific and so need to be * all templates, but they are request-specific and so need to be
* reset at the beginning of a new request. * reset at the beginning of a new request.
*
* This is public for now because it's accessed by propDelete.jsp.
* Once the property deletion is integrated into Freemarker and generated
* with a Freemarker page, the visibility can be reduced to package.
*/ */
void resetRequestSpecificSharedVariables() { public void resetRequestSpecificSharedVariables() {
stylesheets.reset(); stylesheets.reset();
scripts.reset(); scripts.reset();
headScripts.reset(); headScripts.reset();

View file

@ -42,7 +42,7 @@ public class FreemarkerConfigurationLoader {
} }
} }
public VitroFreemarkerConfiguration getConfig(VitroRequest vreq) { public FreemarkerConfiguration getConfig(VitroRequest vreq) {
String themeDir = getThemeDir(vreq.getAppBean()); String themeDir = getThemeDir(vreq.getAppBean());
return getConfigForTheme(themeDir, vreq); return getConfigForTheme(themeDir, vreq);
} }
@ -63,15 +63,15 @@ public class FreemarkerConfigurationLoader {
} }
protected VitroFreemarkerConfiguration getConfigForTheme(String themeDir, VitroRequest vreq) { protected FreemarkerConfiguration getConfigForTheme(String themeDir, VitroRequest vreq) {
/* The Configuration is theme-specific because: /* The Configuration is theme-specific because:
* 1. The template loader is theme-specific, since it specifies a theme directory to load templates from. * 1. The template loader is theme-specific, since it specifies a theme directory to load templates from.
* 2. Shared variables like stylesheets are theme-specific. * 2. Shared variables like stylesheets are theme-specific.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, VitroFreemarkerConfiguration> themeToConfigMap = Map<String, FreemarkerConfiguration> themeToConfigMap =
(Map<String, VitroFreemarkerConfiguration>) context.getAttribute("themeToConfigMap"); (Map<String, FreemarkerConfiguration>) context.getAttribute("themeToConfigMap");
if( themeToConfigMap == null ) { if( themeToConfigMap == null ) {
log.error("The templating system is not configured correctly. Make sure that you have the FreemarkerSetup context listener in your web.xml."); log.error("The templating system is not configured correctly. Make sure that you have the FreemarkerSetup context listener in your web.xml.");
@ -81,7 +81,7 @@ public class FreemarkerConfigurationLoader {
} else if (themeToConfigMap.containsKey(themeDir)) { } else if (themeToConfigMap.containsKey(themeDir)) {
return themeToConfigMap.get(themeDir); return themeToConfigMap.get(themeDir);
} else { } else {
VitroFreemarkerConfiguration config = new VitroFreemarkerConfiguration(themeDir, vreq, context); FreemarkerConfiguration config = new FreemarkerConfiguration(themeDir, vreq, context);
themeToConfigMap.put(themeDir, config); themeToConfigMap.put(themeDir, config);
return config; return config;
} }

View file

@ -89,7 +89,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
return; return;
} }
VitroFreemarkerConfiguration config = getConfig(vreq); FreemarkerConfiguration config = getConfig(vreq);
vreq.setAttribute("freemarkerConfig", config); vreq.setAttribute("freemarkerConfig", config);
config.resetRequestSpecificSharedVariables(); config.resetRequestSpecificSharedVariables();
@ -124,7 +124,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
doGet(request, response); doGet(request, response);
} }
protected VitroFreemarkerConfiguration getConfig(VitroRequest vreq) { protected FreemarkerConfiguration getConfig(VitroRequest vreq) {
FreemarkerConfigurationLoader loader = FreemarkerConfigurationLoader loader =
FreemarkerConfigurationLoader.getFreemarkerConfigurationLoader(getServletContext()); FreemarkerConfigurationLoader.getFreemarkerConfigurationLoader(getServletContext());
return loader.getConfig(vreq); return loader.getConfig(vreq);
@ -270,7 +270,7 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
*/ */
private void setRequestUrls(VitroRequest vreq) { private void setRequestUrls(VitroRequest vreq) {
VitroFreemarkerConfiguration config = (VitroFreemarkerConfiguration)vreq.getAttribute("freemarkerConfig"); FreemarkerConfiguration config = (FreemarkerConfiguration)vreq.getAttribute("freemarkerConfig");
TemplateModel urlModel = config.getSharedVariable("urls"); TemplateModel urlModel = config.getSharedVariable("urls");
try { try {

View file

@ -26,7 +26,7 @@ public class FreemarkerSetup implements ServletContextListener {
} }
ServletContext sc = event.getServletContext(); ServletContext sc = event.getServletContext();
sc.setAttribute("themeToConfigMap", new HashMap<String, VitroFreemarkerConfiguration>()); sc.setAttribute("themeToConfigMap", new HashMap<String, FreemarkerConfiguration>());
BaseTemplateModel.setServletContext(sc); BaseTemplateModel.setServletContext(sc);
FreemarkerComponentGenerator.setServletContext(sc); FreemarkerComponentGenerator.setServletContext(sc);
UrlBuilder.contextPath = sc.getContextPath(); UrlBuilder.contextPath = sc.getContextPath();

View file

@ -17,7 +17,7 @@ import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.VitroFreemarkerConfiguration; import edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
@ -109,8 +109,7 @@ public class DateTimeWithPrecision extends BaseEditElement {
@Override @Override
public String draw(String fieldName, EditConfiguration editConfig, public String draw(String fieldName, EditConfiguration editConfig,
EditSubmission editSub, Configuration fmConfig) { EditSubmission editSub, Configuration fmConfig) {
Map map = getMapForTemplate( editConfig, editSub); Map map = getMapForTemplate( editConfig, editSub);
//map.putAll( VitroFreemarkerConfiguration.getDirectives());
return merge( fmConfig, TEMPLATE_NAME, map); return merge( fmConfig, TEMPLATE_NAME, map);
} }

View file

@ -155,7 +155,6 @@ public class FreemarkerEmailMessage {
} }
public void processTemplate() { public void processTemplate() {
//bodyMap.putAll(FreemarkerHttpServlet.getDirectivesForAllEnvironments());
bodyMap.put("email", new EmailDirective(this)); bodyMap.put("email", new EmailDirective(this));
try { try {

View file

@ -20,6 +20,7 @@
<%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%> <%@page import="edu.cornell.mannlib.vitro.webapp.web.MiscWebUtils"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel" %> <%@page import="edu.cornell.mannlib.vitro.webapp.web.templatemodels.individual.IndividualTemplateModel" %>
<%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader"%> <%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfigurationLoader"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerConfiguration" %>
<%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet"%> <%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet"%>
<%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper"%> <%@page import="edu.cornell.mannlib.vitro.webapp.controller.freemarker.TemplateProcessingHelper"%>
@ -98,9 +99,7 @@ public WebappDaoFactory getUnfilteredDaoFactory() {
if( subject == null ) throw new Error("could not find subject " + subjectUri); if( subject == null ) throw new Error("could not find subject " + subjectUri);
request.setAttribute("subjectName",subject.getName()); request.setAttribute("subjectName",subject.getName());
// Get the statement data to display // Get the statement data to be displayed
// rjy7 Alternative implementation: have the template put the markup into a url or form param
// which can then just be spit out here.
String templateName = request.getParameter("templateName"); String templateName = request.getParameter("templateName");
Map params = request.getParameterMap(); Map params = request.getParameterMap();
Map<String, String> statement = new HashMap<String, String>(); Map<String, String> statement = new HashMap<String, String>();
@ -121,16 +120,20 @@ public WebappDaoFactory getUnfilteredDaoFactory() {
/* Some propStatements (propStatement-educationalTraining.ftl) make reference to the individual, /* Some propStatements (propStatement-educationalTraining.ftl) make reference to the individual,
* but instead of adding it to the data model we'll test in the template for non-existence. If * but instead of adding it to the data model we'll test in the template for non-existence. If
* this becomes more common, add it here instead. * this becomes more common, add it here instead. We don't want to generate the property
* list for the individual, though, so should modify IndividualTemplateModel to make that
* conditional, or perhaps use a different template model that contains only the limited
* information needed in the propStatement templates.
*/ */
//map.put("individual", new IndividualTemplateModel(subject, vreq)); //map.put("individual", new IndividualTemplateModel(subject, vreq));
map.putAll(FreemarkerHttpServlet.getDirectives()); //map.putAll(FreemarkerHttpServlet.getDirectives());
map.putAll(FreemarkerHttpServlet.getMethods()); //map.putAll(FreemarkerHttpServlet.getMethods());
ServletContext context = getServletContext(); ServletContext context = getServletContext();
FreemarkerConfigurationLoader loader = FreemarkerConfigurationLoader loader =
FreemarkerConfigurationLoader.getFreemarkerConfigurationLoader(context); FreemarkerConfigurationLoader.getFreemarkerConfigurationLoader(context);
Configuration fmConfig = loader.getConfig(vreq); FreemarkerConfiguration fmConfig = loader.getConfig(vreq);
fmConfig.resetRequestSpecificSharedVariables();
TemplateProcessingHelper helper = new TemplateProcessingHelper(fmConfig, vreq, context); TemplateProcessingHelper helper = new TemplateProcessingHelper(fmConfig, vreq, context);
statementDisplay = helper.processTemplateToString(templateName, map); statementDisplay = helper.processTemplateToString(templateName, map);
} }