Skip to content

Commit d23b0fe

Browse files
committed
Polish
1 parent 80f4ea1 commit d23b0fe

File tree

9 files changed

+60
-42
lines changed

9 files changed

+60
-42
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/config/GroovyMarkupBeanDefinitionParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class GroovyMarkupBeanDefinitionParser extends AbstractSimpleBeanDefiniti
3434

3535
public static final String BEAN_NAME = "mvcGroovyMarkupConfigurer";
3636

37+
3738
@Override
3839
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) {
3940
return BEAN_NAME;
@@ -45,8 +46,8 @@ protected String getBeanClassName(Element element) {
4546
}
4647

4748
@Override
48-
protected boolean isEligibleAttribute(String attributeName) {
49-
return attributeName.equals("resource-loader-path");
49+
protected boolean isEligibleAttribute(String name) {
50+
return (name.equals("auto-indent") || name.equals("cache-templates") || name.equals("resource-loader-path"));
5051
}
5152

5253
}

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public BeanDefinition parse(Element element, ParserContext context) {
7676

7777
ManagedList<Object> resolvers = new ManagedList<Object>(4);
7878
resolvers.setSource(context.extractSource(element));
79-
String[] names = new String[] {"jsp", "tiles", "bean-name", "freemarker", "velocity", "groovy-markup", "bean", "ref"};
79+
String[] names = new String[] {"jsp", "tiles", "bean-name", "freemarker", "velocity", "groovy", "bean", "ref"};
8080

8181
for (Element resolverElement : DomUtils.getChildElementsByTagName(element, names)) {
8282
String name = resolverElement.getLocalName();
@@ -105,14 +105,14 @@ else if ("velocity".equals(name)) {
105105
resolverBeanDef.getPropertyValues().add("suffix", ".vm");
106106
addUrlBasedViewResolverProperties(resolverElement, resolverBeanDef);
107107
}
108-
else if ("bean-name".equals(name)) {
109-
resolverBeanDef = new RootBeanDefinition(BeanNameViewResolver.class);
110-
}
111-
else if ("groovy-markup".equals(name)) {
108+
else if ("groovy".equals(name)) {
112109
resolverBeanDef = new RootBeanDefinition(GroovyMarkupViewResolver.class);
113110
resolverBeanDef.getPropertyValues().add("suffix", ".tpl");
114111
addUrlBasedViewResolverProperties(resolverElement, resolverBeanDef);
115112
}
113+
else if ("bean-name".equals(name)) {
114+
resolverBeanDef = new RootBeanDefinition(BeanNameViewResolver.class);
115+
}
116116
else {
117117
// Should never happen
118118
throw new IllegalStateException("Unexpected element name: " + name);

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,21 +218,12 @@ public UrlBasedViewResolverRegistration velocity() {
218218
}
219219

220220
/**
221-
* Register a bean name view resolver that interprets view names as the names
222-
* of {@link org.springframework.web.servlet.View} beans.
223-
*/
224-
public void beanName() {
225-
BeanNameViewResolver resolver = new BeanNameViewResolver();
226-
this.viewResolvers.add(resolver);
227-
}
228-
229-
/**
230-
* Register a Groovy Markup Template view resolver with an empty default view name
221+
* Register a Groovy markup view resolver with an empty default view name
231222
* prefix and a default suffix of ".tpl".
232223
*/
233-
public UrlBasedViewResolverRegistration groovyMarkup() {
224+
public UrlBasedViewResolverRegistration groovy() {
234225
if (this.applicationContext != null && !hasBeanOfType(GroovyMarkupConfigurer.class)) {
235-
throw new BeanInitializationException("In addition to a Groovy Markup Template view resolver " +
226+
throw new BeanInitializationException("In addition to a Groovy markup view resolver " +
236227
"there must also be a single GroovyMarkupConfig bean in this web application context " +
237228
"(or its parent): GroovyMarkupConfigurer is the usual implementation. " +
238229
"This bean may be given any name.");
@@ -242,6 +233,15 @@ public UrlBasedViewResolverRegistration groovyMarkup() {
242233
return registration;
243234
}
244235

236+
/**
237+
* Register a bean name view resolver that interprets view names as the names
238+
* of {@link org.springframework.web.servlet.View} beans.
239+
*/
240+
public void beanName() {
241+
BeanNameViewResolver resolver = new BeanNameViewResolver();
242+
this.viewResolvers.add(resolver);
243+
}
244+
245245
/**
246246
* Register a {@link ViewResolver} bean instance. This may be useful to
247247
* configure a custom (or 3rd party) resolver implementation. It may also be

spring-webmvc/src/main/resources/org/springframework/web/servlet/config/spring-mvc-4.1.xsd

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -741,28 +741,28 @@
741741
<xsd:documentation><![CDATA[
742742
Register a VelocityViewResolver.
743743
By default ".vm" is configured as a view name suffix.
744-
To configure Velocity you must also add a top-level <mvc:velocity> element.
744+
To configure Velocity you must also add a top-level <mvc:velocity> element
745745
or declare a VelocityConfigurer bean.
746746
]]></xsd:documentation>
747747
</xsd:annotation>
748748
</xsd:element>
749-
<xsd:element name="bean-name" maxOccurs="1">
750-
<xsd:annotation>
751-
<xsd:documentation><![CDATA[
752-
Register a BeanNameViewResolver bean.
753-
]]></xsd:documentation>
754-
</xsd:annotation>
755-
</xsd:element>
756-
<xsd:element name="groovy-markup" type="urlViewResolverType">
749+
<xsd:element name="groovy" type="urlViewResolverType">
757750
<xsd:annotation>
758751
<xsd:documentation><![CDATA[
759752
Register a GroovyMarkupViewResolver.
760753
By default ".tpl" is configured as a view name suffix.
761-
To configure Groovy Markup Template you must also add a top-level <mvc:groovy-markup> element.
754+
To configure the Groovy markup template engine you must also add a top-level <mvc:groovy-markup> element
762755
or declare a GroovyMarkupConfigurer bean.
763756
]]></xsd:documentation>
764757
</xsd:annotation>
765758
</xsd:element>
759+
<xsd:element name="bean-name" maxOccurs="1">
760+
<xsd:annotation>
761+
<xsd:documentation><![CDATA[
762+
Register a BeanNameViewResolver bean.
763+
]]></xsd:documentation>
764+
</xsd:annotation>
765+
</xsd:element>
766766
<xsd:element ref="beans:bean">
767767
<xsd:annotation>
768768
<xsd:documentation><![CDATA[
@@ -866,15 +866,31 @@
866866
<xsd:element name="groovy-markup">
867867
<xsd:annotation>
868868
<xsd:documentation><![CDATA[
869-
Configure Groovy Markup Template for view resolution by registering a GroovyMarkupConfigurer bean.
869+
Configure the Groovy markup template engine for view resolution by registering a GroovyMarkupConfigurer bean.
870870
This is a shortcut alternative to declaring a GroovyMarkupConfigurer bean directly.
871871
]]></xsd:documentation>
872872
</xsd:annotation>
873873
<xsd:complexType>
874+
<xsd:attribute name="auto-indent" type="xsd:boolean">
875+
<xsd:annotation>
876+
<xsd:documentation><![CDATA[
877+
Whether you want the template engine to render indents automatically.
878+
]]></xsd:documentation>
879+
</xsd:annotation>
880+
</xsd:attribute>
881+
<xsd:attribute name="cache-templates" type="xsd:boolean">
882+
<xsd:annotation>
883+
<xsd:documentation><![CDATA[
884+
If enabled templates are compiled once for each source (URL or File).
885+
It is recommended to keep this flag to true unless you are in development mode
886+
and want automatic reloading of templates.
887+
]]></xsd:documentation>
888+
</xsd:annotation>
889+
</xsd:attribute>
874890
<xsd:attribute name="resource-loader-path" type="xsd:string">
875891
<xsd:annotation>
876892
<xsd:documentation><![CDATA[
877-
The Groovy Markup Template resource loader path via a Spring resource location.
893+
The Groovy markup template engine resource loader path via a Spring resource location.
878894
]]></xsd:documentation>
879895
</xsd:annotation>
880896
</xsd:attribute>

spring-webmvc/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ public void testViewResolution() throws Exception {
567567

568568
ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class);
569569
assertNotNull(compositeResolver);
570-
assertEquals(8, compositeResolver.getViewResolvers().size());
570+
assertEquals("Actual: " + compositeResolver.getViewResolvers(), 8, compositeResolver.getViewResolvers().size());
571571
assertEquals(0, compositeResolver.getOrder());
572572

573573
List<ViewResolver> resolvers = compositeResolver.getViewResolvers();
@@ -628,8 +628,9 @@ public void testViewResolution() throws Exception {
628628

629629
GroovyMarkupConfigurer groovyMarkupConfigurer = appContext.getBean(GroovyMarkupConfigurer.class);
630630
assertNotNull(groovyMarkupConfigurer);
631-
accessor = new DirectFieldAccessor(groovyMarkupConfigurer);
632-
assertEquals("/test", accessor.getPropertyValue("resourceLoaderPath"));
631+
assertEquals("/test", groovyMarkupConfigurer.getResourceLoaderPath());
632+
assertTrue(groovyMarkupConfigurer.isAutoIndent());
633+
assertFalse(groovyMarkupConfigurer.isCacheTemplates());
633634
}
634635

635636
@Test

spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolutionIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void tilesInvalidConfig() throws Exception {
9797

9898
@Test
9999
public void groovyMarkupInvalidConfig() throws Exception {
100-
this.thrown.expectMessage("In addition to a Groovy Markup Template view resolver ");
100+
this.thrown.expectMessage("In addition to a Groovy markup view resolver ");
101101
runTest(InvalidGroovyMarkupWebConfig.class);
102102
}
103103

@@ -192,7 +192,7 @@ static class GroovyMarkupWebConfig extends AbstractWebConfig {
192192

193193
@Override
194194
public void configureViewResolvers(ViewResolverRegistry registry) {
195-
registry.groovyMarkup();
195+
registry.groovy();
196196
}
197197

198198
@Bean
@@ -235,7 +235,7 @@ static class InvalidGroovyMarkupWebConfig extends WebMvcConfigurationSupport {
235235

236236
@Override
237237
public void configureViewResolvers(ViewResolverRegistry registry) {
238-
registry.groovyMarkup();
238+
registry.groovy();
239239
}
240240
}
241241

spring-webmvc/src/test/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistryTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,14 @@ public void freeMarkerDefaultValues() {
170170

171171
@Test
172172
public void groovyMarkup() {
173-
this.registry.groovyMarkup().prefix("/").suffix(".groovy").cache(true);
173+
this.registry.groovy().prefix("/").suffix(".groovy").cache(true);
174174
GroovyMarkupViewResolver resolver = checkAndGetResolver(GroovyMarkupViewResolver.class);
175175
checkPropertyValues(resolver, "prefix", "/", "suffix", ".groovy", "cacheLimit", 1024);
176176
}
177177

178178
@Test
179179
public void groovyMarkupDefaultValues() {
180-
this.registry.groovyMarkup();
180+
this.registry.groovy();
181181
GroovyMarkupViewResolver resolver = checkAndGetResolver(GroovyMarkupViewResolver.class);
182182
checkPropertyValues(resolver, "prefix", "", "suffix", ".tpl");
183183
}

spring-webmvc/src/test/resources/org/springframework/web/servlet/config/mvc-config-view-resolution-content-negotiation.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<mvc:tiles />
2626
<mvc:freemarker />
2727
<mvc:velocity />
28-
<mvc:groovy-markup />
28+
<mvc:groovy />
2929
</mvc:view-resolvers>
3030

3131
<mvc:tiles check-refresh="true">

spring-webmvc/src/test/resources/org/springframework/web/servlet/config/mvc-config-view-resolution.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<mvc:tiles />
1313
<mvc:freemarker prefix="freemarker-" suffix=".freemarker" view-names="my*,*Report" />
1414
<mvc:velocity cache-views="false" />
15-
<mvc:groovy-markup />
15+
<mvc:groovy />
1616
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" />
1717
<ref bean="customResolver" />
1818
</mvc:view-resolvers>
@@ -31,7 +31,7 @@
3131

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

34-
<mvc:groovy-markup resource-loader-path="/test" />
34+
<mvc:groovy-markup resource-loader-path="/test" cache-templates="false" auto-indent="true" />
3535

3636
</beans>
3737

0 commit comments

Comments
 (0)