Author: ggregory
Date: Wed Apr 5 03:52:45 2017
New Revision: 1790174
URL: http://svn.apache.org/viewvc?rev=1790174&view=rev
Log:
[CONFIGURATION-659] Add API
org.apache.commons.configuration2.ImmutableConfiguration.getURL(String).
Modified:
commons/proper/configuration/trunk/src/changes/changes.xml
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ImmutableConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java
Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1790174&r1=1790173&r2=1790174&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Wed Apr 5
03:52:45 2017
@@ -38,6 +38,9 @@
<action dev="ggregory" type="add" issue="CONFIGURATION-658">
Add API
org.apache.commons.configuration2.ImmutableConfiguration.getURI(String).
</action>
+ <action dev="ggregory" type="add" issue="CONFIGURATION-659">
+ Add API
org.apache.commons.configuration2.ImmutableConfiguration.getURL(String).
+ </action>
</release>
<release version="2.1.1" date="2017-02-05"
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java?rev=1790174&r1=1790173&r2=1790174&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
(original)
+++
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/AbstractConfiguration.java
Wed Apr 5 03:52:45 2017
@@ -20,6 +20,7 @@ package org.apache.commons.configuration
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -1368,6 +1369,18 @@ public abstract class AbstractConfigurat
}
@Override
+ public URL getURL(String key)
+ {
+ return convert(URL.class, key, null, true);
+ }
+
+ @Override
+ public URL getURL(String key, URL defaultValue)
+ {
+ return convert(URL.class, key, defaultValue, false);
+ }
+
+ @Override
public String getString(String key, String defaultValue)
{
String result = convert(String.class, key, null, false);
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ImmutableConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ImmutableConfiguration.java?rev=1790174&r1=1790173&r2=1790174&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ImmutableConfiguration.java
(original)
+++
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/ImmutableConfiguration.java
Wed Apr 5 03:52:45 2017
@@ -19,6 +19,7 @@ package org.apache.commons.configuration
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
+import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -488,6 +489,32 @@ public interface ImmutableConfiguration
URI getURI(String key, URI defaultValue);
/**
+ * Gets a URL associated with the given configuration key.
+ *
+ * @param key The configuration key.
+ * @return The associated string.
+ *
+ * @throws org.apache.commons.configuration2.ex.ConversionException is
thrown if the key maps to an object that
+ * is not a String.
+ */
+ URL getURL(String key);
+
+ /**
+ * Gets a URL associated with the given configuration key.
+ * If the key doesn't map to an existing object, the default value
+ * is returned.
+ *
+ * @param key The configuration key.
+ * @param defaultValue The default value.
+ * @return The associated URL if key is found and has valid
+ * format, default value otherwise.
+ *
+ * @throws org.apache.commons.configuration2.ex.ConversionException is
thrown if the key maps to an object that
+ * is not a String.
+ */
+ URL getURL(String key, URL defaultValue);
+
+ /**
* Get the value of a string property that is stored in encoded form in
this
* configuration. This method obtains the value of the string property
* identified by the given key. This value is then passed to the provided
Modified:
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java?rev=1790174&r1=1790173&r2=1790174&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java
(original)
+++
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestBaseConfiguration.java
Wed Apr 5 03:52:45 2017
@@ -25,7 +25,9 @@ import static org.junit.Assert.assertTru
import java.math.BigDecimal;
import java.math.BigInteger;
+import java.net.MalformedURLException;
import java.net.URI;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -290,6 +292,18 @@ public class TestBaseConfiguration
assertEquals("Missing key with default value", defaultValue,
config.getURI("stringNotInConfig", defaultValue));
}
+ @Test
+ public void testGetURL() throws MalformedURLException
+ {
+ config.setProperty("testURL", new URL("http://example.com"));
+ URL uri = new URL("http://example.com");
+ URL defaultValue = new URL("http://localhost");
+
+ assertEquals("Existing key", uri, config.getURL("testURL"));
+ assertEquals("Existing key with default value", uri,
config.getURL("testURL", defaultValue));
+ assertEquals("Missing key with default value", defaultValue,
config.getURL("stringNotInConfig", defaultValue));
+ }
+
@Test(expected = NoSuchElementException.class)
public void testGetStringUnknown()
{