commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r949277 - in /commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/ConfigurationUtils.java test/org/apache/commons/configuration/TestConfigurationUtils.java
Date Fri, 28 May 2010 20:12:57 GMT
Author: oheger
Date: Fri May 28 20:12:56 2010
New Revision: 949277

URL: http://svn.apache.org/viewvc?rev=949277&view=rev
Log:
Now we are on JDK 1.4, we can use File.toURI().toURL(). Removed some deprecation warnings.

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java?rev=949277&r1=949276&r2=949277&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationUtils.java
Fri May 28 20:12:56 2010
@@ -35,7 +35,6 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.reloading.Reloadable;
 import org.apache.commons.configuration.tree.ExpressionEngine;
 import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.SystemUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -57,7 +56,7 @@ public final class ConfigurationUtils
     /** Constant for the resource path separator.*/
     static final String RESOURCE_PATH_SEPARATOR = "/";
 
-    /** Constanct for the file URL protocol */
+    /** Constant for the file URL protocol */
     private static final String FILE_SCHEME = "file:";
 
     /** Constant for the name of the clone() method.*/
@@ -66,9 +65,6 @@ public final class ConfigurationUtils
     /** Constant for the encoding for URLs. */
     private static final String ENCODING = "UTF-8";
 
-    /** Constant for Java version 1.4.*/
-    private static final float JAVA_1_4 = 1.4f;
-
     /** The logger.*/
     private static Log log = LogFactory.getLog(ConfigurationUtils.class);
 
@@ -718,36 +714,17 @@ public final class ConfigurationUtils
 
     /**
      * Convert the specified file into an URL. This method is equivalent
-     * to file.toURI().toURL() on Java 1.4 and above, and equivalent to
-     * file.toURL() on Java 1.3. This is to work around a bug in the JDK
+     * to file.toURI().toURL(). It was used to work around a bug in the JDK
      * preventing the transformation of a file into an URL if the file name
      * contains a '#' character. See the issue CONFIGURATION-300 for
-     * more details.
+     * more details. Now that we switched to JDK 1.4 we can directly use
+     * file.toURI().toURL().
      *
      * @param file the file to be converted into an URL
      */
     static URL toURL(File file) throws MalformedURLException
     {
-        if (SystemUtils.isJavaVersionAtLeast(JAVA_1_4))
-        {
-            try
-            {
-                Method toURI = file.getClass().getMethod("toURI", (Class[]) null);
-                Object uri = toURI.invoke(file, (Class[]) null);
-                Method toURL = uri.getClass().getMethod("toURL", (Class[]) null);
-                URL url = (URL) toURL.invoke(uri, (Class[]) null);
-
-                return url;
-            }
-            catch (Exception e)
-            {
-                throw new MalformedURLException(e.getMessage());
-            }
-        }
-        else
-        {
-            return file.toURL();
-        }
+        return file.toURI().toURL();
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java?rev=949277&r1=949276&r2=949277&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationUtils.java
Fri May 28 20:12:56 2010
@@ -93,15 +93,15 @@ public class TestConfigurationUtils exte
                 .toString());
         File absFile = new File("config.xml").getAbsoluteFile();
         assertEquals(
-            absFile.toURL(),
+            absFile.toURI().toURL(),
             ConfigurationUtils.getURL(
                 "http://localhost:8080/webapp/config/baseConfig.xml",
                 absFile.getAbsolutePath()));
         assertEquals(
-            absFile.toURL(),
+            absFile.toURI().toURL(),
             ConfigurationUtils.getURL(null, absFile.getAbsolutePath()));
 
-		assertEquals(absFile.toURL(),
+		assertEquals(absFile.toURI().toURL(),
 		ConfigurationUtils.getURL(absFile.getParent(), "config.xml"));
     }
 
@@ -187,8 +187,8 @@ public class TestConfigurationUtils exte
         assertEquals(reference, ConfigurationUtils.getFile(null, reference.getAbsolutePath()));
         assertEquals(reference, ConfigurationUtils.getFile(directory.getAbsolutePath(), reference.getAbsolutePath()));
         assertEquals(reference, ConfigurationUtils.getFile(directory.getAbsolutePath(), reference.getName()));
-        assertEquals(reference, ConfigurationUtils.getFile(directory.toURL().toString(),
reference.getName()));
-        assertEquals(reference, ConfigurationUtils.getFile("invalid", reference.toURL().toString()));
+        assertEquals(reference, ConfigurationUtils.getFile(directory.toURI().toURL().toString(),
reference.getName()));
+        assertEquals(reference, ConfigurationUtils.getFile("invalid", reference.toURI().toURL().toString()));
         assertEquals(reference, ConfigurationUtils.getFile(
                 "jar:file:/C:/myjar.jar!/my-config.xml/someprops.properties",
                 reference.getAbsolutePath()));



Mime
View raw message