util:properties supports multiple resource locations and ignore-resource-not-found
Issue: SPR-10614
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -120,12 +120,14 @@ public class UtilNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String listClass = element.getAttribute("list-class");
|
||||
List<Object> parsedList = parserContext.getDelegate().parseListElement(element, builder.getRawBeanDefinition());
|
||||
builder.addPropertyValue("sourceList", parsedList);
|
||||
|
||||
String listClass = element.getAttribute("list-class");
|
||||
if (StringUtils.hasText(listClass)) {
|
||||
builder.addPropertyValue("targetListClass", listClass);
|
||||
}
|
||||
|
||||
String scope = element.getAttribute(SCOPE_ATTRIBUTE);
|
||||
if (StringUtils.hasLength(scope)) {
|
||||
builder.setScope(scope);
|
||||
@@ -143,12 +145,14 @@ public class UtilNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String setClass = element.getAttribute("set-class");
|
||||
Set<Object> parsedSet = parserContext.getDelegate().parseSetElement(element, builder.getRawBeanDefinition());
|
||||
builder.addPropertyValue("sourceSet", parsedSet);
|
||||
|
||||
String setClass = element.getAttribute("set-class");
|
||||
if (StringUtils.hasText(setClass)) {
|
||||
builder.addPropertyValue("targetSetClass", setClass);
|
||||
}
|
||||
|
||||
String scope = element.getAttribute(SCOPE_ATTRIBUTE);
|
||||
if (StringUtils.hasLength(scope)) {
|
||||
builder.setScope(scope);
|
||||
@@ -166,12 +170,14 @@ public class UtilNamespaceHandler extends NamespaceHandlerSupport {
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String mapClass = element.getAttribute("map-class");
|
||||
Map<Object, Object> parsedMap = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition());
|
||||
builder.addPropertyValue("sourceMap", parsedMap);
|
||||
|
||||
String mapClass = element.getAttribute("map-class");
|
||||
if (StringUtils.hasText(mapClass)) {
|
||||
builder.addPropertyValue("targetMapClass", mapClass);
|
||||
}
|
||||
|
||||
String scope = element.getAttribute(SCOPE_ATTRIBUTE);
|
||||
if (StringUtils.hasLength(scope)) {
|
||||
builder.setScope(scope);
|
||||
@@ -180,23 +186,30 @@ public class UtilNamespaceHandler extends NamespaceHandlerSupport {
|
||||
}
|
||||
|
||||
|
||||
private static class PropertiesBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
|
||||
private static class PropertiesBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return PropertiesFactoryBean.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return super.isEligibleAttribute(attributeName) && !SCOPE_ATTRIBUTE.equals(attributeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
Properties parsedProps = parserContext.getDelegate().parsePropsElement(element);
|
||||
builder.addPropertyValue("properties", parsedProps);
|
||||
|
||||
String location = element.getAttribute("location");
|
||||
if (StringUtils.hasLength(location)) {
|
||||
String[] locations = StringUtils.commaDelimitedListToStringArray(location);
|
||||
builder.addPropertyValue("locations", locations);
|
||||
}
|
||||
|
||||
builder.addPropertyValue("ignoreResourceNotFound",
|
||||
Boolean.valueOf(element.getAttribute("ignore-resource-not-found")));
|
||||
|
||||
builder.addPropertyValue("localOverride",
|
||||
Boolean.valueOf(element.getAttribute("local-override")));
|
||||
|
||||
String scope = element.getAttribute(SCOPE_ATTRIBUTE);
|
||||
if (StringUtils.hasLength(scope)) {
|
||||
builder.setScope(scope);
|
||||
|
||||
@@ -177,14 +177,23 @@
|
||||
<xsd:attribute name="id" type="xsd:string"/>
|
||||
<xsd:attribute name="location" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:expected-type type="org.springframework.core.io.Resource"/>
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
<xsd:documentation><![CDATA[
|
||||
The location of the properties file, as a Spring resource location: a URL,
|
||||
a "classpath:" pseudo URL, or a relative file path. Multiple locations may be
|
||||
specified, separated by commas.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="local-override" type="xsd:boolean">
|
||||
<xsd:attribute name="ignore-resource-not-found" type="xsd:boolean" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies if failure to find the property resource location should be ignored.
|
||||
Default is "false", meaning that if there is no file in the location specified
|
||||
an exception will be raised at runtime.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="local-override" type="xsd:boolean" default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies whether local properties override properties from files.
|
||||
|
||||
Reference in New Issue
Block a user