Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 58929 invoked from network); 16 Apr 2007 10:41:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Apr 2007 10:41:09 -0000 Received: (qmail 12659 invoked by uid 500); 16 Apr 2007 10:41:15 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 12116 invoked by uid 500); 16 Apr 2007 10:41:13 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 12105 invoked by uid 500); 16 Apr 2007 10:41:13 -0000 Received: (qmail 12102 invoked by uid 99); 16 Apr 2007 10:41:13 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Apr 2007 03:41:13 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Apr 2007 03:41:06 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 3399D1A9838; Mon, 16 Apr 2007 03:40:45 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commons-cvs@jakarta.apache.org From: ebourg@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070416104045.3399D1A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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. * Do not use this class ! 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 @@ + + File configurations can now be saved to FTP URLs, or any other URL + protocol supporting data output. + 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 @@
  • ConfigurationConverter - 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.
  • --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org