From 4cf573ba9870553e9086defc7bd1b6f2d43ac61e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 19 Apr 2009 22:22:56 +0000 Subject: [PATCH] updated to FreeMarker 2.3.15 (SPR-4962) --- .../context-support.iml | 338 ++--- org.springframework.context.support/ivy.xml | 2 +- org.springframework.context.support/pom.xml | 7 +- .../integration-tests.iml | 1134 ++++++++--------- org.springframework.integration-tests/ivy.xml | 2 +- org.springframework.integration-tests/pom.xml | 2 +- org.springframework.web.servlet/ivy.xml | 2 +- org.springframework.web.servlet/pom.xml | 2 +- .../view/freemarker/FreeMarkerView.java | 34 +- .../view/freemarker/FreeMarkerMacroTests.java | 13 +- .../view/freemarker/FreeMarkerViewTests.java | 14 +- .../web-servlet.iml | 4 +- 12 files changed, 787 insertions(+), 767 deletions(-) diff --git a/org.springframework.context.support/context-support.iml b/org.springframework.context.support/context-support.iml index 68c5a88bb9b..c5a4106c4de 100644 --- a/org.springframework.context.support/context-support.iml +++ b/org.springframework.context.support/context-support.iml @@ -1,169 +1,169 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.springframework.context.support/ivy.xml b/org.springframework.context.support/ivy.xml index 2a824b83107..8a6ba7b858b 100644 --- a/org.springframework.context.support/ivy.xml +++ b/org.springframework.context.support/ivy.xml @@ -29,7 +29,7 @@ - + diff --git a/org.springframework.context.support/pom.xml b/org.springframework.context.support/pom.xml index 146cfa11aa7..6ccfe99a74d 100644 --- a/org.springframework.context.support/pom.xml +++ b/org.springframework.context.support/pom.xml @@ -24,9 +24,6 @@ jta 1.1 - - - quartz quartz @@ -38,12 +35,10 @@ 1.6.0 true - - org.freemarker freemarker - 2.3.12 + 2.3.15 true diff --git a/org.springframework.integration-tests/integration-tests.iml b/org.springframework.integration-tests/integration-tests.iml index 78d6b5e0d9d..58e09c619df 100644 --- a/org.springframework.integration-tests/integration-tests.iml +++ b/org.springframework.integration-tests/integration-tests.iml @@ -1,567 +1,567 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.springframework.integration-tests/ivy.xml b/org.springframework.integration-tests/ivy.xml index ad68a980a8b..3202abf1a36 100644 --- a/org.springframework.integration-tests/ivy.xml +++ b/org.springframework.integration-tests/ivy.xml @@ -69,7 +69,7 @@ - + diff --git a/org.springframework.integration-tests/pom.xml b/org.springframework.integration-tests/pom.xml index 4fb666682f9..51ad2068018 100644 --- a/org.springframework.integration-tests/pom.xml +++ b/org.springframework.integration-tests/pom.xml @@ -309,7 +309,7 @@ org.freemarker freemarker - 2.3.12 + 2.3.15 test diff --git a/org.springframework.web.servlet/ivy.xml b/org.springframework.web.servlet/ivy.xml index ad6389a4966..5fb9370b7c0 100644 --- a/org.springframework.web.servlet/ivy.xml +++ b/org.springframework.web.servlet/ivy.xml @@ -34,7 +34,7 @@ conf="optional, feed->compile"/> - diff --git a/org.springframework.web.servlet/pom.xml b/org.springframework.web.servlet/pom.xml index e235f8f4260..c4ca0f9c57c 100644 --- a/org.springframework.web.servlet/pom.xml +++ b/org.springframework.web.servlet/pom.xml @@ -28,7 +28,7 @@ org.freemarker freemarker - 2.3.12 + 2.3.15 true diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java index 70e7db84424..ac3a7dcadd2 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/freemarker/FreeMarkerView.java @@ -34,6 +34,7 @@ import javax.servlet.http.HttpSession; import freemarker.core.ParseException; import freemarker.ext.jsp.TaglibFactory; +import freemarker.ext.servlet.AllHttpScopesHashModel; import freemarker.ext.servlet.FreemarkerServlet; import freemarker.ext.servlet.HttpRequestHashModel; import freemarker.ext.servlet.HttpRequestParametersHashModel; @@ -41,6 +42,7 @@ import freemarker.ext.servlet.HttpSessionHashModel; import freemarker.ext.servlet.ServletContextHashModel; import freemarker.template.Configuration; import freemarker.template.ObjectWrapper; +import freemarker.template.SimpleHash; import freemarker.template.Template; import freemarker.template.TemplateException; @@ -250,7 +252,7 @@ public class FreeMarkerView extends AbstractTemplateView { * library hash model. *

Can be overridden to customize the behavior, for example to render * multiple templates into a single view. - * @param model the template model to use for rendering + * @param model the model to use for rendering * @param request current HTTP request * @param response current servlet response * @throws IOException if the template file could not be retrieved @@ -264,20 +266,34 @@ public class FreeMarkerView extends AbstractTemplateView { protected void doRender(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { // Expose model to JSP tags (as request attributes). exposeModelAsRequestAttributes(model, request); - // Expose all standard FreeMarker hash models. - model.put(FreemarkerServlet.KEY_JSP_TAGLIBS, this.taglibFactory); - model.put(FreemarkerServlet.KEY_APPLICATION, this.servletContextHashModel); - model.put(FreemarkerServlet.KEY_SESSION, buildSessionModel(request, response)); - model.put(FreemarkerServlet.KEY_REQUEST, new HttpRequestHashModel(request, response, getObjectWrapper())); - model.put(FreemarkerServlet.KEY_REQUEST_PARAMETERS, new HttpRequestParametersHashModel(request)); + SimpleHash fmModel = buildTemplateModel(model, request, response); if (logger.isDebugEnabled()) { logger.debug("Rendering FreeMarker template [" + getUrl() + "] in FreeMarkerView '" + getBeanName() + "'"); } // Grab the locale-specific version of the template. Locale locale = RequestContextUtils.getLocale(request); - processTemplate(getTemplate(locale), model, response); + processTemplate(getTemplate(locale), fmModel, response); + } + + /** + * Build a FreeMarker template model for the given model Map. + *

The default implementation builds a {@link AllHttpScopesHashModel}. + * @param model the model to use for rendering + * @param request current HTTP request + * @param response current servlet response + * @return the FreeMarker template model, as a {@link SimpleHash} or subclass thereof + */ + protected SimpleHash buildTemplateModel(Map model, HttpServletRequest request, HttpServletResponse response) { + AllHttpScopesHashModel fmModel = new AllHttpScopesHashModel(getObjectWrapper(), getServletContext(), request); + fmModel.put(FreemarkerServlet.KEY_JSP_TAGLIBS, this.taglibFactory); + fmModel.put(FreemarkerServlet.KEY_APPLICATION, this.servletContextHashModel); + fmModel.put(FreemarkerServlet.KEY_SESSION, buildSessionModel(request, response)); + fmModel.put(FreemarkerServlet.KEY_REQUEST, new HttpRequestHashModel(request, response, getObjectWrapper())); + fmModel.put(FreemarkerServlet.KEY_REQUEST_PARAMETERS, new HttpRequestParametersHashModel(request)); + fmModel.putAll(model); + return fmModel; } /** @@ -338,7 +354,7 @@ public class FreeMarkerView extends AbstractTemplateView { * @throws TemplateException if thrown by FreeMarker * @see freemarker.template.Template#process(Object, java.io.Writer) */ - protected void processTemplate(Template template, Map model, HttpServletResponse response) + protected void processTemplate(Template template, SimpleHash model, HttpServletResponse response) throws IOException, TemplateException { template.process(model, response.getWriter()); diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerMacroTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerMacroTests.java index 5623fef0897..65adaec3ed9 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerMacroTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerMacroTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,9 @@ import javax.servlet.http.HttpServletResponse; import freemarker.template.Configuration; import freemarker.template.Template; +import freemarker.template.TemplateModel; +import freemarker.template.SimpleHash; +import freemarker.template.TemplateException; import junit.framework.TestCase; import org.springframework.beans.TestBean; @@ -79,7 +82,9 @@ public class FreeMarkerMacroTests extends TestCase { public void testExposeSpringMacroHelpers() throws Exception { FreeMarkerView fv = new FreeMarkerView() { - protected void processTemplate(Template template, Map model, HttpServletResponse response) { + @Override + protected void processTemplate(Template template, SimpleHash fmModel, HttpServletResponse response) throws TemplateException { + Map model = fmModel.toMap(); assertTrue(model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext); RequestContext rc = (RequestContext) model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE); BindStatus status = rc.getBindStatus("tb.name"); @@ -100,7 +105,8 @@ public class FreeMarkerMacroTests extends TestCase { final String helperTool = "wrongType"; FreeMarkerView fv = new FreeMarkerView() { - protected void processTemplate(Template template, Map model, HttpServletResponse response) { + @Override + protected void processTemplate(Template template, SimpleHash model, HttpServletResponse response) { fail(); } }; @@ -155,6 +161,7 @@ public class FreeMarkerMacroTests extends TestCase { view.setUrl("test.ftl"); view.setExposeSpringMacroHelpers(false); view.setConfiguration(config); + view.setServletContext(new MockServletContext()); view.render(model, request, response); diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerViewTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerViewTests.java index d668be6f309..e1fa20605b1 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerViewTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerViewTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,9 @@ import java.util.Locale; import java.util.Map; import javax.servlet.http.HttpServletResponse; +import freemarker.ext.servlet.AllHttpScopesHashModel; import freemarker.template.Configuration; +import freemarker.template.SimpleScalar; import freemarker.template.Template; import freemarker.template.TemplateException; import org.easymock.MockControl; @@ -104,7 +106,7 @@ public class FreeMarkerViewTests { wac.getParentBeanFactory(); wmc.setReturnValue(null); wac.getServletContext(); - wmc.setReturnValue(sc, 4); + wmc.setReturnValue(sc, 5); wmc.replay(); fv.setUrl("templateName"); @@ -141,7 +143,7 @@ public class FreeMarkerViewTests { wac.getParentBeanFactory(); wmc.setReturnValue(null); wac.getServletContext(); - wmc.setReturnValue(sc, 4); + wmc.setReturnValue(sc, 5); wmc.replay(); fv.setUrl("templateName"); @@ -170,9 +172,9 @@ public class FreeMarkerViewTests { return new Template(name, new StringReader("test")) { public void process(Object model, Writer writer) throws TemplateException, IOException { assertEquals(Locale.US, locale); - assertTrue(model instanceof Map); - Map modelMap = (Map) model; - assertEquals("myvalue", modelMap.get("myattr")); + assertTrue(model instanceof AllHttpScopesHashModel); + AllHttpScopesHashModel fmModel = (AllHttpScopesHashModel) model; + assertEquals("myvalue", fmModel.get("myattr").toString()); } }; } diff --git a/org.springframework.web.servlet/web-servlet.iml b/org.springframework.web.servlet/web-servlet.iml index d8920a93af4..200e168e20a 100644 --- a/org.springframework.web.servlet/web-servlet.iml +++ b/org.springframework.web.servlet/web-servlet.iml @@ -43,11 +43,11 @@ - + - +