Polish
This commit is contained in:
parent
80f4ea13c7
commit
d23b0fec0c
|
@ -34,6 +34,7 @@ public class GroovyMarkupBeanDefinitionParser extends AbstractSimpleBeanDefiniti
|
|||
|
||||
public static final String BEAN_NAME = "mvcGroovyMarkupConfigurer";
|
||||
|
||||
|
||||
@Override
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) {
|
||||
return BEAN_NAME;
|
||||
|
@ -45,8 +46,8 @@ public class GroovyMarkupBeanDefinitionParser extends AbstractSimpleBeanDefiniti
|
|||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return attributeName.equals("resource-loader-path");
|
||||
protected boolean isEligibleAttribute(String name) {
|
||||
return (name.equals("auto-indent") || name.equals("cache-templates") || name.equals("resource-loader-path"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class ViewResolversBeanDefinitionParser implements BeanDefinitionParser {
|
|||
|
||||
ManagedList<Object> resolvers = new ManagedList<Object>(4);
|
||||
resolvers.setSource(context.extractSource(element));
|
||||
String[] names = new String[] {"jsp", "tiles", "bean-name", "freemarker", "velocity", "groovy-markup", "bean", "ref"};
|
||||
String[] names = new String[] {"jsp", "tiles", "bean-name", "freemarker", "velocity", "groovy", "bean", "ref"};
|
||||
|
||||
for (Element resolverElement : DomUtils.getChildElementsByTagName(element, names)) {
|
||||
String name = resolverElement.getLocalName();
|
||||
|
@ -105,14 +105,14 @@ public class ViewResolversBeanDefinitionParser implements BeanDefinitionParser {
|
|||
resolverBeanDef.getPropertyValues().add("suffix", ".vm");
|
||||
addUrlBasedViewResolverProperties(resolverElement, resolverBeanDef);
|
||||
}
|
||||
else if ("bean-name".equals(name)) {
|
||||
resolverBeanDef = new RootBeanDefinition(BeanNameViewResolver.class);
|
||||
}
|
||||
else if ("groovy-markup".equals(name)) {
|
||||
else if ("groovy".equals(name)) {
|
||||
resolverBeanDef = new RootBeanDefinition(GroovyMarkupViewResolver.class);
|
||||
resolverBeanDef.getPropertyValues().add("suffix", ".tpl");
|
||||
addUrlBasedViewResolverProperties(resolverElement, resolverBeanDef);
|
||||
}
|
||||
else if ("bean-name".equals(name)) {
|
||||
resolverBeanDef = new RootBeanDefinition(BeanNameViewResolver.class);
|
||||
}
|
||||
else {
|
||||
// Should never happen
|
||||
throw new IllegalStateException("Unexpected element name: " + name);
|
||||
|
|
|
@ -218,21 +218,12 @@ public class ViewResolverRegistry {
|
|||
}
|
||||
|
||||
/**
|
||||
* Register a bean name view resolver that interprets view names as the names
|
||||
* of {@link org.springframework.web.servlet.View} beans.
|
||||
*/
|
||||
public void beanName() {
|
||||
BeanNameViewResolver resolver = new BeanNameViewResolver();
|
||||
this.viewResolvers.add(resolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a Groovy Markup Template view resolver with an empty default view name
|
||||
* Register a Groovy markup view resolver with an empty default view name
|
||||
* prefix and a default suffix of ".tpl".
|
||||
*/
|
||||
public UrlBasedViewResolverRegistration groovyMarkup() {
|
||||
public UrlBasedViewResolverRegistration groovy() {
|
||||
if (this.applicationContext != null && !hasBeanOfType(GroovyMarkupConfigurer.class)) {
|
||||
throw new BeanInitializationException("In addition to a Groovy Markup Template view resolver " +
|
||||
throw new BeanInitializationException("In addition to a Groovy markup view resolver " +
|
||||
"there must also be a single GroovyMarkupConfig bean in this web application context " +
|
||||
"(or its parent): GroovyMarkupConfigurer is the usual implementation. " +
|
||||
"This bean may be given any name.");
|
||||
|
@ -242,6 +233,15 @@ public class ViewResolverRegistry {
|
|||
return registration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a bean name view resolver that interprets view names as the names
|
||||
* of {@link org.springframework.web.servlet.View} beans.
|
||||
*/
|
||||
public void beanName() {
|
||||
BeanNameViewResolver resolver = new BeanNameViewResolver();
|
||||
this.viewResolvers.add(resolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a {@link ViewResolver} bean instance. This may be useful to
|
||||
* configure a custom (or 3rd party) resolver implementation. It may also be
|
||||
|
|
|
@ -741,11 +741,21 @@
|
|||
<xsd:documentation><![CDATA[
|
||||
Register a VelocityViewResolver.
|
||||
By default ".vm" is configured as a view name suffix.
|
||||
To configure Velocity you must also add a top-level <mvc:velocity> element.
|
||||
To configure Velocity you must also add a top-level <mvc:velocity> element
|
||||
or declare a VelocityConfigurer bean.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
<xsd:element name="groovy" type="urlViewResolverType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Register a GroovyMarkupViewResolver.
|
||||
By default ".tpl" is configured as a view name suffix.
|
||||
To configure the Groovy markup template engine you must also add a top-level <mvc:groovy-markup> element
|
||||
or declare a GroovyMarkupConfigurer bean.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
<xsd:element name="bean-name" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
|
@ -753,16 +763,6 @@
|
|||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
<xsd:element name="groovy-markup" type="urlViewResolverType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Register a GroovyMarkupViewResolver.
|
||||
By default ".tpl" is configured as a view name suffix.
|
||||
To configure Groovy Markup Template you must also add a top-level <mvc:groovy-markup> element.
|
||||
or declare a GroovyMarkupConfigurer bean.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
<xsd:element ref="beans:bean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
|
@ -866,15 +866,31 @@
|
|||
<xsd:element name="groovy-markup">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Configure Groovy Markup Template for view resolution by registering a GroovyMarkupConfigurer bean.
|
||||
Configure the Groovy markup template engine for view resolution by registering a GroovyMarkupConfigurer bean.
|
||||
This is a shortcut alternative to declaring a GroovyMarkupConfigurer bean directly.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="auto-indent" type="xsd:boolean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Whether you want the template engine to render indents automatically.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="cache-templates" type="xsd:boolean">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
If enabled templates are compiled once for each source (URL or File).
|
||||
It is recommended to keep this flag to true unless you are in development mode
|
||||
and want automatic reloading of templates.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="resource-loader-path" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The Groovy Markup Template resource loader path via a Spring resource location.
|
||||
The Groovy markup template engine resource loader path via a Spring resource location.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
|
|
|
@ -567,7 +567,7 @@ public class MvcNamespaceTests {
|
|||
|
||||
ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class);
|
||||
assertNotNull(compositeResolver);
|
||||
assertEquals(8, compositeResolver.getViewResolvers().size());
|
||||
assertEquals("Actual: " + compositeResolver.getViewResolvers(), 8, compositeResolver.getViewResolvers().size());
|
||||
assertEquals(0, compositeResolver.getOrder());
|
||||
|
||||
List<ViewResolver> resolvers = compositeResolver.getViewResolvers();
|
||||
|
@ -628,8 +628,9 @@ public class MvcNamespaceTests {
|
|||
|
||||
GroovyMarkupConfigurer groovyMarkupConfigurer = appContext.getBean(GroovyMarkupConfigurer.class);
|
||||
assertNotNull(groovyMarkupConfigurer);
|
||||
accessor = new DirectFieldAccessor(groovyMarkupConfigurer);
|
||||
assertEquals("/test", accessor.getPropertyValue("resourceLoaderPath"));
|
||||
assertEquals("/test", groovyMarkupConfigurer.getResourceLoaderPath());
|
||||
assertTrue(groovyMarkupConfigurer.isAutoIndent());
|
||||
assertFalse(groovyMarkupConfigurer.isCacheTemplates());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -97,7 +97,7 @@ public class ViewResolutionIntegrationTests {
|
|||
|
||||
@Test
|
||||
public void groovyMarkupInvalidConfig() throws Exception {
|
||||
this.thrown.expectMessage("In addition to a Groovy Markup Template view resolver ");
|
||||
this.thrown.expectMessage("In addition to a Groovy markup view resolver ");
|
||||
runTest(InvalidGroovyMarkupWebConfig.class);
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ public class ViewResolutionIntegrationTests {
|
|||
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.groovyMarkup();
|
||||
registry.groovy();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
@ -235,7 +235,7 @@ public class ViewResolutionIntegrationTests {
|
|||
|
||||
@Override
|
||||
public void configureViewResolvers(ViewResolverRegistry registry) {
|
||||
registry.groovyMarkup();
|
||||
registry.groovy();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -170,14 +170,14 @@ public class ViewResolverRegistryTests {
|
|||
|
||||
@Test
|
||||
public void groovyMarkup() {
|
||||
this.registry.groovyMarkup().prefix("/").suffix(".groovy").cache(true);
|
||||
this.registry.groovy().prefix("/").suffix(".groovy").cache(true);
|
||||
GroovyMarkupViewResolver resolver = checkAndGetResolver(GroovyMarkupViewResolver.class);
|
||||
checkPropertyValues(resolver, "prefix", "/", "suffix", ".groovy", "cacheLimit", 1024);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groovyMarkupDefaultValues() {
|
||||
this.registry.groovyMarkup();
|
||||
this.registry.groovy();
|
||||
GroovyMarkupViewResolver resolver = checkAndGetResolver(GroovyMarkupViewResolver.class);
|
||||
checkPropertyValues(resolver, "prefix", "", "suffix", ".tpl");
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<mvc:tiles />
|
||||
<mvc:freemarker />
|
||||
<mvc:velocity />
|
||||
<mvc:groovy-markup />
|
||||
<mvc:groovy />
|
||||
</mvc:view-resolvers>
|
||||
|
||||
<mvc:tiles check-refresh="true">
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<mvc:tiles />
|
||||
<mvc:freemarker prefix="freemarker-" suffix=".freemarker" view-names="my*,*Report" />
|
||||
<mvc:velocity cache-views="false" />
|
||||
<mvc:groovy-markup />
|
||||
<mvc:groovy />
|
||||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
|
||||
<ref bean="customResolver" />
|
||||
</mvc:view-resolvers>
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
<mvc:velocity resource-loader-path="/test" />
|
||||
|
||||
<mvc:groovy-markup resource-loader-path="/test" />
|
||||
<mvc:groovy-markup resource-loader-path="/test" cache-templates="false" auto-indent="true" />
|
||||
|
||||
</beans>
|
||||
|
Loading…
Reference in New Issue