Skip to content

Commit

Permalink
mvc:tiles-configurer supports preparer-factory and definitions-factory
Browse files Browse the repository at this point in the history
Issue: SPR-13363
  • Loading branch information
jhoeller committed Aug 25, 2015
1 parent 8cd2837 commit 6aa9e0c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
Expand Down Expand Up @@ -29,9 +29,10 @@

/**
* Parse the <mvc:tiles-configurer> MVC namespace element and register
* TilesConfigurer bean
* a corresponding TilesConfigurer bean.
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 4.1
*/
public class TilesConfigurerBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
Expand All @@ -49,11 +50,6 @@ protected String resolveId(Element element, AbstractBeanDefinition definition, P
return BEAN_NAME;
}

@Override
protected boolean shouldGenerateId() {
return super.shouldGenerateId();
}

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
List<Element> childElements = DomUtils.getChildElementsByTagName(element, "definitions");
Expand All @@ -70,6 +66,12 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
if (element.hasAttribute("validate-definitions")) {
builder.addPropertyValue("validateDefinitions", element.getAttribute("validate-definitions"));
}
if (element.hasAttribute("definitions-factory")) {
builder.addPropertyValue("definitionsFactoryClass", element.getAttribute("definitions-factory"));
}
if (element.hasAttribute("preparer-factory")) {
builder.addPropertyValue("preparerFactoryClass", element.getAttribute("preparer-factory"));
}
}

}
Expand Up @@ -1128,6 +1128,22 @@
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="definitions-factory" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The Tiles DefinitionsFactory class to use. Default is Tiles' default.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="preparer-factory" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The Tiles PreparerFactory class to use. Default is Tiles' default.
Consider "org.springframework.web.servlet.view.tiles3.SimpleSpringPreparerFactory" or
"org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory" (see javadoc).
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>

Expand Down
Expand Up @@ -38,6 +38,7 @@
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory;
import org.hamcrest.Matchers;
import org.joda.time.LocalDate;
import org.junit.Before;
Expand Down Expand Up @@ -136,6 +137,7 @@
import org.springframework.web.servlet.view.groovy.GroovyMarkupViewResolver;
import org.springframework.web.servlet.view.script.ScriptTemplateConfigurer;
import org.springframework.web.servlet.view.script.ScriptTemplateViewResolver;
import org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
Expand Down Expand Up @@ -779,6 +781,8 @@ public void testViewResolution() throws Exception {
accessor = new DirectFieldAccessor(tilesConfigurer);
assertArrayEquals(definitions, (String[]) accessor.getPropertyValue("definitions"));
assertTrue((boolean) accessor.getPropertyValue("checkRefresh"));
assertEquals(UnresolvingLocaleDefinitionsFactory.class, accessor.getPropertyValue("definitionsFactoryClass"));
assertEquals(SpringBeanPreparerFactory.class, accessor.getPropertyValue("preparerFactoryClass"));

FreeMarkerConfigurer freeMarkerConfigurer = appContext.getBean(FreeMarkerConfigurer.class);
assertNotNull(freeMarkerConfigurer);
Expand Down
Expand Up @@ -2,42 +2,43 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<mvc:view-resolvers>
<mvc:bean-name />
<mvc:jsp view-class="org.springframework.web.servlet.view.InternalResourceView" />
<mvc:tiles />
<mvc:freemarker prefix="freemarker-" suffix=".freemarker" view-names="my*,*Report" />
<mvc:velocity cache-views="false" />
<mvc:groovy />
<mvc:script-template />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
<ref bean="customResolver" />
<mvc:bean-name/>
<mvc:jsp view-class="org.springframework.web.servlet.view.InternalResourceView"/>
<mvc:tiles/>
<mvc:freemarker prefix="freemarker-" suffix=".freemarker" view-names="my*,*Report"/>
<mvc:velocity cache-views="false"/>
<mvc:groovy/>
<mvc:script-template/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>
<ref bean="customResolver"/>
</mvc:view-resolvers>

<bean id="customResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
<bean id="customResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>

<mvc:tiles-configurer check-refresh="true" validate-definitions="true">
<mvc:definitions location="/org/springframework/web/servlet/resource/tiles/tiles1.xml" />
<mvc:definitions location="/org/springframework/web/servlet/resource/tiles/tiles2.xml" />
<mvc:tiles-configurer check-refresh="true" validate-definitions="true"
definitions-factory="org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory"
preparer-factory="org.springframework.web.servlet.view.tiles3.SpringBeanPreparerFactory">
<mvc:definitions location="/org/springframework/web/servlet/resource/tiles/tiles1.xml"/>
<mvc:definitions location="/org/springframework/web/servlet/resource/tiles/tiles2.xml"/>
</mvc:tiles-configurer>

<mvc:freemarker-configurer>
<mvc:template-loader-path location="/" />
<mvc:template-loader-path location="/test" />
<mvc:template-loader-path location="/"/>
<mvc:template-loader-path location="/test"/>
</mvc:freemarker-configurer>

<mvc:velocity-configurer resource-loader-path="/test" />
<mvc:velocity-configurer resource-loader-path="/test"/>

<mvc:groovy-configurer resource-loader-path="/test" cache-templates="false" auto-indent="true" />
<mvc:groovy-configurer resource-loader-path="/test" cache-templates="false" auto-indent="true"/>

<mvc:script-template-configurer engine-name="nashorn" render-function="render"
content-type="text/plain" charset="ISO-8859-1"
resource-loader-path="classpath:" shared-engine="false">
<mvc:script location="org/springframework/web/servlet/view/script/nashorn/render.js" />
<mvc:script location="org/springframework/web/servlet/view/script/nashorn/render.js"/>
</mvc:script-template-configurer>

</beans>

0 comments on commit 6aa9e0c

Please sign in to comment.