Support XML properties in ResourcePropertySource
JDK 5 introduced an XML-based properties file syntax. This commit ensures that when such files are supplied as the underlying resource for a ResourcePropertySource instance, they are routed appropriately to Properties#loadFromXML as opposed to Properties#load. Issue: SPR-9896
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties version="1.0">
|
||||
<entry key="foo">bar</entry>
|
||||
</properties>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -39,6 +39,10 @@ public class ResourcePropertySourceTests {
|
||||
private static final String PROPERTIES_LOCATION = "classpath:" + PROPERTIES_PATH;
|
||||
private static final String PROPERTIES_RESOURCE_DESCRIPTION = "class path resource [" + PROPERTIES_PATH + "]";
|
||||
|
||||
private static final String XML_PROPERTIES_PATH = "org/springframework/core/io/example.xml";
|
||||
private static final String XML_PROPERTIES_LOCATION = "classpath:" + XML_PROPERTIES_PATH;
|
||||
private static final String XML_PROPERTIES_RESOURCE_DESCRIPTION = "class path resource [" + XML_PROPERTIES_PATH + "]";
|
||||
|
||||
@Test
|
||||
public void withLocationAndGeneratedName() throws IOException {
|
||||
PropertySource<?> ps = new ResourcePropertySource(PROPERTIES_LOCATION);
|
||||
@@ -46,6 +50,13 @@ public class ResourcePropertySourceTests {
|
||||
assertThat(ps.getName(), is(PROPERTIES_RESOURCE_DESCRIPTION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlWithLocationAndGeneratedName() throws IOException {
|
||||
PropertySource<?> ps = new ResourcePropertySource(XML_PROPERTIES_LOCATION);
|
||||
assertEquals(ps.getProperty("foo"), "bar");
|
||||
assertThat(ps.getName(), is(XML_PROPERTIES_RESOURCE_DESCRIPTION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withLocationAndExplicitName() throws IOException {
|
||||
PropertySource<?> ps = new ResourcePropertySource("ps1", PROPERTIES_LOCATION);
|
||||
|
||||
Reference in New Issue
Block a user