commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r529194 - in /jakarta/commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/plist/ src/test/org/apache/commons/configuration/ xdocs/
Date Mon, 16 Apr 2007 10:40:44 GMT
Author: ebourg
Date: Mon Apr 16 03:40:42 2007
New Revision: 529194

URL: http://svn.apache.org/viewvc?view=rev&rev=529194
Log:
AbstractFileConfiguration now supports saving to non file URLs (CONFIGURATION-249)
Fixed a typo on the overview page

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/FileConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
    jakarta/commons/proper/configuration/trunk/xdocs/overview.xml

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java?view=diff&rev=529194&r1=529193&r2=529194
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
Mon Apr 16 03:40:42 2007
@@ -27,8 +27,10 @@
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLConnection;
 import java.util.Iterator;
 
 import org.apache.commons.configuration.reloading.InvariantReloadingStrategy;
@@ -409,7 +411,7 @@
     }
 
     /**
-     * Save the configuration to the specified URL if it's a file URL.
+     * Save the configuration to the specified URL.
      * This doesn't change the source of the configuration, use setURL()
      * if you need it.
      *
@@ -419,6 +421,8 @@
      */
     public void save(URL url) throws ConfigurationException
     {
+        // file URLs have to be converted to Files since FileURLConnection is
+        // read only (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4191800)
         File file = ConfigurationUtils.fileFromURL(url);
         if (file != null)
         {
@@ -426,7 +430,35 @@
         }
         else
         {
-            throw new ConfigurationException("Could not save to URL " + url);
+            // for non file URLs save through an URLConnection
+            try
+            {
+                URLConnection connection = url.openConnection();
+                connection.setDoOutput(true);
+
+                // use the PUT method for http URLs
+                if (connection instanceof HttpURLConnection)
+                {
+                    HttpURLConnection conn = (HttpURLConnection) connection;
+                    conn.setRequestMethod("PUT");
+                }
+
+                save(connection.getOutputStream());
+
+                // check the response code for http URLs and throw an exception if an error
occured
+                if (connection instanceof HttpURLConnection)
+                {
+                    HttpURLConnection conn = (HttpURLConnection) connection;
+                    if (conn.getResponseCode() >= HttpURLConnection.HTTP_BAD_REQUEST)
+                    {
+                        throw new IOException("HTTP Error " + conn.getResponseCode() + "
" + conn.getResponseMessage());
+                    }
+                }
+            }
+            catch (IOException e)
+            {
+                throw new ConfigurationException("Could not save to URL " + url + " : " +
e.getMessage());
+            }
         }
     }
 
@@ -647,8 +679,7 @@
             {
                 try
                 {
-                    path = ConfigurationUtils.getURL(getBasePath(),
-                            getFileName()).getPath();
+                    path = ConfigurationUtils.getURL(getBasePath(), getFileName()).getPath();
                 }
                 catch (MalformedURLException e)
                 {
@@ -877,8 +908,7 @@
      * @param propValue the value of the property
      * @param before the before update flag
      */
-    protected void fireEvent(int type, String propName, Object propValue,
-            boolean before)
+    protected void fireEvent(int type, String propName, Object propValue, boolean before)
     {
         enterNoReload();
         try
@@ -959,8 +989,7 @@
      */
     public Object clone()
     {
-        AbstractFileConfiguration copy = (AbstractFileConfiguration) super
-                .clone();
+        AbstractFileConfiguration copy = (AbstractFileConfiguration) super.clone();
         copy.setBasePath(null);
         copy.setFileName(null);
         copy.initReloadingStrategy();

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/FileConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/FileConfiguration.java?view=diff&rev=529194&r1=529193&r2=529194
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/FileConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/FileConfiguration.java
Mon Apr 16 03:40:42 2007
@@ -126,7 +126,7 @@
     void save(File file) throws ConfigurationException;
 
     /**
-     * Save the configuration to the specified URL if it's a file URL.
+     * Save the configuration to the specified URL.
      *
      * @param url the URL
      *

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java?view=diff&rev=529194&r1=529193&r2=529194
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/plist/XMLPropertyListConfiguration.java
Mon Apr 16 03:40:42 2007
@@ -506,7 +506,7 @@
     }
 
     /**
-     * Node extension with addXXX methods to parse the typed data passed by Digester.
+     * Node extension with addXXX methods to parse the typed data passed by the SAX handler.
      * <b>Do not use this class !</b> It is used internally by XMLPropertyConfiguration
      * to parse the configuration file, it may be removed at any moment in the future.
      */

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java?view=diff&rev=529194&r1=529193&r2=529194
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestFileConfiguration.java
Mon Apr 16 03:40:42 2007
@@ -49,8 +49,7 @@
         FileConfiguration config = new PropertiesConfiguration();
         config.setURL(new URL("http://jakarta.apache.org/commons/configuration/index.html"));
 
-        assertEquals("base path", "http://jakarta.apache.org/commons/configuration/", config
-                .getBasePath());
+        assertEquals("base path", "http://jakarta.apache.org/commons/configuration/", config.getBasePath());
         assertEquals("file name", "index.html", config.getFileName());
 
         // file URL
@@ -62,13 +61,10 @@
     public void testSetURLWithParams() throws Exception
     {
         FileConfiguration config = new PropertiesConfiguration();
-        URL url = new URL(
-                "http://issues.apache.org/bugzilla/show_bug.cgi?id=37886");
+        URL url = new URL("http://issues.apache.org/bugzilla/show_bug.cgi?id=37886");
         config.setURL(url);
-        assertEquals("Base path incorrect",
-                "http://issues.apache.org/bugzilla/", config.getBasePath());
-        assertEquals("File name incorrect", "show_bug.cgi", config
-                .getFileName());
+        assertEquals("Base path incorrect", "http://issues.apache.org/bugzilla/", config.getBasePath());
+        assertEquals("File name incorrect", "show_bug.cgi", config.getFileName());
         assertEquals("URL was not correctly stored", url, config.getURL());
     }
 
@@ -202,9 +198,10 @@
     public void testSaveInvalidURL() throws Exception
     {
         FileConfiguration config = new PropertiesConfiguration();
+
         try
         {
-            config.save(new URL("http://jakarta.apache.org"));
+            config.save(new URL("http://jakarta.apache.org/test.properties"));
             fail("Should throw a ConfigurationException!");
         }
         catch (ConfigurationException cex)
@@ -214,7 +211,7 @@
 
         try
         {
-            config.save("http://www.apache.org");
+            config.save("http://www.apache.org/test.properties");
             fail("Should throw a ConfigurationException!");
         }
         catch (ConfigurationException cex)

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?view=diff&rev=529194&r1=529193&r2=529194
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Mon Apr 16 03:40:42 2007
@@ -23,6 +23,10 @@
 
   <body>
     <release version="1.5-SNAPSHOT" date="in SVN" description="">
+      <action dev="ebourg" type="add" issue="CONFIGURATION-249">
+        File configurations can now be saved to FTP URLs, or any other URL
+        protocol supporting data output.
+      </action>
       <action dev="ebourg" type="fix" issue="CONFIGURATION-180">
         Fixed a potential issue in DatabaseConfiguration where an error on
         closing a statement would prevent the connection from being closed.

Modified: jakarta/commons/proper/configuration/trunk/xdocs/overview.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/configuration/trunk/xdocs/overview.xml?view=diff&rev=529194&r1=529193&r2=529194
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/overview.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/overview.xml Mon Apr 16 03:40:42 2007
@@ -82,7 +82,7 @@
           </li>
           <li>
               <strong>ConfigurationConverter</strong>
-              Takes a java.util.Properties or an org.aapache.commons.collections.ExtendedProperties
+              Takes a java.util.Properties or an org.apache.commons.collections.ExtendedProperties
               and converts it to a Configuration object.
           </li>
        </ul>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message