Skip to content

Commit a032ce1

Browse files
committed
renamed "mapping-order" to "order"; added "cache-period"
1 parent ecb351c commit a032ce1

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
package org.springframework.web.servlet.config;
1818

19-
import java.util.List;
2019
import java.util.Map;
2120

2221
import org.w3c.dom.Element;
2322

2423
import org.springframework.beans.factory.config.BeanDefinition;
2524
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
26-
import org.springframework.beans.factory.support.ManagedList;
2725
import org.springframework.beans.factory.support.ManagedMap;
2826
import org.springframework.beans.factory.support.RootBeanDefinition;
2927
import org.springframework.beans.factory.xml.BeanDefinitionParser;
@@ -54,7 +52,7 @@ public void doParse(Element element, ParserContext parserContext) {
5452

5553
private void registerResourceMappings(ParserContext parserContext, Element element, Object source) {
5654
String resourceHandlerName = registerResourceHandler(parserContext, element, source);
57-
if (!StringUtils.hasText(resourceHandlerName)) {
55+
if (resourceHandlerName == null) {
5856
return;
5957
}
6058

@@ -71,8 +69,9 @@ private void registerResourceMappings(ParserContext parserContext, Element eleme
7169
handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
7270
handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
7371

74-
String mappingOrder = element.getAttribute("mapping-order");
75-
handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(mappingOrder) ? mappingOrder : Ordered.LOWEST_PRECEDENCE - 1);
72+
String order = element.getAttribute("order");
73+
// use a default of near-lowest precedence, still allowing for even lower precedence in other mappings
74+
handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(order) ? order : Ordered.LOWEST_PRECEDENCE - 1);
7675

7776
String beanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
7877
parserContext.getRegistry().registerBeanDefinition(beanName, handlerMappingDef);
@@ -83,20 +82,23 @@ private String registerResourceHandler(ParserContext parserContext, Element elem
8382
String locationAttr = element.getAttribute("location");
8483
if (!StringUtils.hasText(locationAttr)) {
8584
parserContext.getReaderContext().error("The 'location' attribute is required.", parserContext.extractSource(element));
86-
return "";
85+
return null;
8786
}
88-
String[] locationPatterns = locationAttr.split(",\\s*");
89-
List<String> locations = new ManagedList<String>();
90-
for (String location : locationPatterns) {
91-
locations.add(location);
92-
}
87+
9388
RootBeanDefinition resourceHandlerDef = new RootBeanDefinition(ResourceHttpRequestHandler.class);
9489
resourceHandlerDef.setSource(source);
9590
resourceHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
96-
resourceHandlerDef.getPropertyValues().add("locations", locations);
91+
resourceHandlerDef.getPropertyValues().add("locations", StringUtils.commaDelimitedListToStringArray(locationAttr));
92+
93+
String cacheSeconds = element.getAttribute("cache-period");
94+
if (StringUtils.hasText(cacheSeconds)) {
95+
resourceHandlerDef.getPropertyValues().add("cacheSeconds", cacheSeconds);
96+
}
97+
9798
String beanName = parserContext.getReaderContext().generateBeanName(resourceHandlerDef);
9899
parserContext.getRegistry().registerBeanDefinition(beanName, resourceHandlerDef);
99100
parserContext.registerComponent(new BeanComponentDefinition(resourceHandlerDef, beanName));
100101
return beanName;
101102
}
103+
102104
}

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

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
<xsd:element name="annotation-driven">
1212
<xsd:annotation>
13-
<xsd:documentation
14-
source="java:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><![CDATA[
13+
<xsd:documentation source="java:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><![CDATA[
1514
Configures the annotation-driven Spring MVC Controller programming model.
1615
Note that, with Spring 3.0, this tag works in Servlet MVC only!
1716
]]></xsd:documentation>
@@ -54,41 +53,49 @@
5453
<xsd:documentation
5554
source="java:org.springframework.web.servlet.resource.ResourceHttpRequestHandler"><![CDATA[
5655
Configures a handler for serving static resources such as images, js, and, css files with cache headers optimized for efficient
57-
loading in a web browser. Allows resources to be served out of any path that is reachable via Spring's Resource handling.
56+
loading in a web browser. Allows resources to be served out of any path that is reachable via Spring's Resource handling.
5857
]]></xsd:documentation>
5958
</xsd:annotation>
6059
<xsd:complexType>
6160
<xsd:attribute name="mapping" use="required" type="xsd:string">
6261
<xsd:annotation>
63-
<xsd:documentation>
64-
<![CDATA[
65-
The URL mapping pattern, within the current Sevlet context, to use for serving resources from this handler, such as "/resources/**"
66-
]]>
67-
</xsd:documentation>
62+
<xsd:documentation><![CDATA[
63+
The URL mapping pattern, within the current Servlet context, to use for serving resources from this handler, such as "/resources/**"
64+
]]></xsd:documentation>
6865
</xsd:annotation>
6966
</xsd:attribute>
7067
<xsd:attribute name="location" use="required" type="xsd:string">
68+
<xsd:annotation>
69+
<xsd:documentation><![CDATA[
70+
The resource location from which to serve static content, specified at a Spring Resource pattern.
71+
Each location must point to a valid directory. Multiple locations may be specified as a comma-separated list,
72+
and the locations will be checked for a given resource in the order specified. For example, a value of
73+
"/, classpath:/META-INF/public-web-resources/" will allow resources to be served both from the web app
74+
root and from any JAR on the classpath that contains a /META-INF/public-web-resources/ directory,
75+
with resources in the web app root taking precedence.
76+
]]></xsd:documentation>
77+
</xsd:annotation>
78+
</xsd:attribute>
79+
<xsd:attribute name="cache-period" type="xsd:string">
7180
<xsd:annotation>
7281
<xsd:documentation>
7382
<![CDATA[
74-
The resource location from which to serve static content, specified at a Spring Resource pattern. Each location must point to a valid directory.
75-
Multiple locations may be specified as a comma-seperated list, and the locations will be checked for a given resource in the order specified. For example,
76-
a value of "/, classpath:/META-INF/public-web-resources/" will allow resources to be served both from the web app root and from any JAR on the classpath
77-
that contains a /META-INF/public-web-resources/ directory, with resources in the web app root taking precedence.
78-
]]>
79-
</xsd:documentation>
83+
Specifies the cache period for the resources served by this resource handler, in seconds.
84+
The default is to not send any cache headers but rather to rely on last-modified timestamps only.
85+
Set this to 0 in order to send cache headers that prevent caching, or to a positive number of
86+
seconds in order to send cache headers with the given max-age value.
87+
]]></xsd:documentation>
8088
</xsd:annotation>
8189
</xsd:attribute>
82-
<xsd:attribute name="mapping-order" type="xsd:string">
90+
<xsd:attribute name="order" type="xsd:int">
8391
<xsd:annotation>
8492
<xsd:documentation>
8593
<![CDATA[
86-
Specifies the order of the HandlerMapping for the resource handler. The default order is Ordered.LOWEST_PRECEDENCE - 1.
87-
]]>
88-
</xsd:documentation>
94+
Specifies the order of the HandlerMapping for the resource handler. The default order is Ordered.LOWEST_PRECEDENCE - 1.
95+
]]></xsd:documentation>
8996
</xsd:annotation>
9097
</xsd:attribute>
91-
</xsd:complexType>
98+
</xsd:complexType>
9299
</xsd:element>
93100

94101
<xsd:element name="default-servlet-handler">

org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/config/MvcNamespaceTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ public void testInterceptors() throws Exception {
203203
chain = mapping.getHandler(request);
204204
assertEquals(5, chain.getInterceptors().length);
205205
assertTrue(chain.getInterceptors()[4] instanceof WebRequestHandlerInterceptorAdapter);
206-
207206
}
208207

209208
@Test
@@ -465,7 +464,6 @@ public boolean supports(Class<?> clazz) {
465464
public void validate(Object target, Errors errors) {
466465
this.validatorInvoked = true;
467466
}
468-
469467
}
470468

471469
private static class TestBean {
@@ -482,7 +480,6 @@ public String getField() {
482480
public void setField(String field) {
483481
this.field = field;
484482
}
485-
486483
}
487484

488485
private static class TestMockServletContext extends MockServletContext {
@@ -495,7 +492,6 @@ public RequestDispatcher getNamedDispatcher(String path) {
495492
return null;
496493
}
497494
}
498-
499495
}
500496

501497
}

org.springframework.web.servlet/src/test/resources/org/springframework/web/servlet/config/mvc-config-resources-optional-attrs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
66
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
77

8-
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/" mapping-order="5"/>
8+
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/" cache-period="3600" order="5"/>
99

1010
</beans>

0 commit comments

Comments
 (0)