renamed "mapping-order" to "order"; added "cache-period"

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3598 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Juergen Hoeller 2010-08-16 19:04:51 +00:00
parent 628eff0773
commit fded7496d5
4 changed files with 43 additions and 38 deletions

View File

@ -16,14 +16,12 @@
package org.springframework.web.servlet.config;
import java.util.List;
import java.util.Map;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
@ -54,7 +52,7 @@ class ResourcesBeanDefinitionParser extends AbstractHttpRequestHandlerBeanDefini
private void registerResourceMappings(ParserContext parserContext, Element element, Object source) {
String resourceHandlerName = registerResourceHandler(parserContext, element, source);
if (!StringUtils.hasText(resourceHandlerName)) {
if (resourceHandlerName == null) {
return;
}
@ -71,8 +69,9 @@ class ResourcesBeanDefinitionParser extends AbstractHttpRequestHandlerBeanDefini
handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
String mappingOrder = element.getAttribute("mapping-order");
handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(mappingOrder) ? mappingOrder : Ordered.LOWEST_PRECEDENCE - 1);
String order = element.getAttribute("order");
// use a default of near-lowest precedence, still allowing for even lower precedence in other mappings
handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(order) ? order : Ordered.LOWEST_PRECEDENCE - 1);
String beanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
parserContext.getRegistry().registerBeanDefinition(beanName, handlerMappingDef);
@ -83,20 +82,23 @@ class ResourcesBeanDefinitionParser extends AbstractHttpRequestHandlerBeanDefini
String locationAttr = element.getAttribute("location");
if (!StringUtils.hasText(locationAttr)) {
parserContext.getReaderContext().error("The 'location' attribute is required.", parserContext.extractSource(element));
return "";
}
String[] locationPatterns = locationAttr.split(",\\s*");
List<String> locations = new ManagedList<String>();
for (String location : locationPatterns) {
locations.add(location);
return null;
}
RootBeanDefinition resourceHandlerDef = new RootBeanDefinition(ResourceHttpRequestHandler.class);
resourceHandlerDef.setSource(source);
resourceHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
resourceHandlerDef.getPropertyValues().add("locations", locations);
resourceHandlerDef.getPropertyValues().add("locations", StringUtils.commaDelimitedListToStringArray(locationAttr));
String cacheSeconds = element.getAttribute("cache-period");
if (StringUtils.hasText(cacheSeconds)) {
resourceHandlerDef.getPropertyValues().add("cacheSeconds", cacheSeconds);
}
String beanName = parserContext.getReaderContext().generateBeanName(resourceHandlerDef);
parserContext.getRegistry().registerBeanDefinition(beanName, resourceHandlerDef);
parserContext.registerComponent(new BeanComponentDefinition(resourceHandlerDef, beanName));
return beanName;
}
}

View File

@ -10,8 +10,7 @@
<xsd:element name="annotation-driven">
<xsd:annotation>
<xsd:documentation
source="java:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><![CDATA[
<xsd:documentation source="java:org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"><![CDATA[
Configures the annotation-driven Spring MVC Controller programming model.
Note that, with Spring 3.0, this tag works in Servlet MVC only!
]]></xsd:documentation>
@ -60,32 +59,40 @@
<xsd:complexType>
<xsd:attribute name="mapping" use="required" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The URL mapping pattern, within the current Sevlet context, to use for serving resources from this handler, such as "/resources/**"
]]>
</xsd:documentation>
<xsd:documentation><![CDATA[
The URL mapping pattern, within the current Servlet context, to use for serving resources from this handler, such as "/resources/**"
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="location" use="required" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The resource location from which to serve static content, specified at a Spring Resource pattern. Each location must point to a valid directory.
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,
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
that contains a /META-INF/public-web-resources/ directory, with resources in the web app root taking precedence.
]]>
</xsd:documentation>
<xsd:documentation><![CDATA[
The resource location from which to serve static content, specified at a Spring Resource pattern.
Each location must point to a valid directory. Multiple locations may be specified as a comma-separated list,
and the locations will be checked for a given resource in the order specified. For example, 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 that contains a /META-INF/public-web-resources/ directory,
with resources in the web app root taking precedence.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="mapping-order" type="xsd:string">
<xsd:attribute name="cache-period" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
Specifies the cache period for the resources served by this resource handler, in seconds.
The default is to not send any cache headers but rather to rely on last-modified timestamps only.
Set this to 0 in order to send cache headers that prevent caching, or to a positive number of
seconds in order to send cache headers with the given max-age value.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order" type="xsd:int">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
Specifies the order of the HandlerMapping for the resource handler. The default order is Ordered.LOWEST_PRECEDENCE - 1.
]]>
</xsd:documentation>
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>

View File

@ -203,7 +203,6 @@ public class MvcNamespaceTests {
chain = mapping.getHandler(request);
assertEquals(5, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[4] instanceof WebRequestHandlerInterceptorAdapter);
}
@Test
@ -465,7 +464,6 @@ public class MvcNamespaceTests {
public void validate(Object target, Errors errors) {
this.validatorInvoked = true;
}
}
private static class TestBean {
@ -482,7 +480,6 @@ public class MvcNamespaceTests {
public void setField(String field) {
this.field = field;
}
}
private static class TestMockServletContext extends MockServletContext {
@ -495,7 +492,6 @@ public class MvcNamespaceTests {
return null;
}
}
}
}

View File

@ -5,6 +5,6 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/" mapping-order="5"/>
<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/" cache-period="3600" order="5"/>
</beans>