Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 73762 invoked from network); 5 Nov 2009 07:32:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Nov 2009 07:32:35 -0000 Received: (qmail 95944 invoked by uid 500); 5 Nov 2009 07:32:35 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 95864 invoked by uid 500); 5 Nov 2009 07:32:34 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 95855 invoked by uid 99); 5 Nov 2009 07:32:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Nov 2009 07:32:34 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Nov 2009 07:32:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A716B238890A; Thu, 5 Nov 2009 07:32:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r833017 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/base/impl/ test/java/org/apache/commons/configuration2/base/impl/ Date: Thu, 05 Nov 2009 07:32:09 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091105073209.A716B238890A@eris.apache.org> Author: oheger Date: Thu Nov 5 07:32:09 2009 New Revision: 833017 URL: http://svn.apache.org/viewvc?rev=833017&view=rev Log: Added a load(InputStream) method to XMLConfigurationSource, which allows the XML parser to detect the encoding of the document to be loaded. Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/XMLConfigurationSource.java commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestXMLConfigurationSource.java Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/XMLConfigurationSource.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/XMLConfigurationSource.java?rev=833017&r1=833016&r2=833017&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/XMLConfigurationSource.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/base/impl/XMLConfigurationSource.java Thu Nov 5 07:32:09 2009 @@ -17,6 +17,7 @@ package org.apache.commons.configuration2.base.impl; import java.io.IOException; +import java.io.InputStream; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; @@ -172,7 +173,30 @@ public XMLConfigurationSource() { xmlNodeHandler = new XMLNodeHandler(); - locatorSupport = new DefaultLocatorSupport(this); + locatorSupport = new DefaultLocatorSupport(this) + { + /** + * Loads data from the specified {@code InputStream}. This + * implementation directly delegates to the {@code + * load(InputStream)} method of the owning {@code + * XMLConfigurationSource}. + * + * @param in the {@code InputStream} + * @throws ConfigurationException if an error occurs + */ + @Override + public void load(InputStream in) throws ConfigurationException + { + try + { + XMLConfigurationSource.this.load(in); + } + catch (IOException ioex) + { + throw new ConfigurationException(ioex); + } + } + }; } /** @@ -483,6 +507,23 @@ } /** + * Loads the data from the specified {@code InputStream} and adds it to this + * {@code ConfigurationSource} object. Note that the{@code clear()} method + * is not called, so the properties contained in the loaded file will be + * added to the current set of properties. Note: This method is provided in + * addition to {@link #load(Reader)} because it allows the XML parser to + * auto-detect the encoding of the XML document to be loaded. + * + * @param in the input stream + * @throws IOException if an I/O error occurs + * @throws ConfigurationException if an error occurs + */ + public void load(InputStream in) throws IOException, ConfigurationException + { + load(new InputSource(in)); + } + + /** * Writes the content of this configuration source to the specified {@code * Writer}. This implementation calls {@link #createTransformer()} for * obtaining a transformer. This transformer is then used to serialize the Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestXMLConfigurationSource.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestXMLConfigurationSource.java?rev=833017&r1=833016&r2=833017&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestXMLConfigurationSource.java (original) +++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/base/impl/TestXMLConfigurationSource.java Thu Nov 5 07:32:09 2009 @@ -773,6 +773,22 @@ } /** + * Tests whether the encoding is taken into account when loading a document + * if it is explicitly specified. + */ + @Test + public void testLoadWithEncodingExplicit() throws ConfigurationException, + IOException + { + LocatorSupport locSupport = source.getCapability(LocatorSupport.class); + locSupport.setEncoding("UTF-16"); + locSupport.setLocator(new URLLocator(ConfigurationAssert + .getTestURL("testEncoding.xml"))); + locSupport.load(); + assertEquals("Wrong value", "test3_yoge", conf.getString("yoge")); + } + + /** * Tests whether the encoding is correctly detected by the XML parser. This * is done by loading an XML file with the encoding "UTF-16". If this * encoding is not detected correctly, an exception will be thrown that @@ -780,15 +796,13 @@ * 34204. */ @Test - public void testLoadWithEncoding() throws ConfigurationException, - IOException + public void testLoadWithEncoding() throws ConfigurationException { LocatorSupport locSupport = source.getCapability(LocatorSupport.class); - locSupport.setEncoding("UTF-16"); locSupport.setLocator(new URLLocator(ConfigurationAssert .getTestURL("testEncoding.xml"))); locSupport.load(); - assertEquals("Wrong value", "test3_yoge", conf.getString("yoge")); + assertEquals("test3_yoge", conf.getString("yoge")); } /**