commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1463670 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/io/FileHandler.java test/java/org/apache/commons/configuration/io/TestFileHandler.java
Date Tue, 02 Apr 2013 18:58:38 GMT
Author: oheger
Date: Tue Apr  2 18:58:37 2013
New Revision: 1463670

URL: http://svn.apache.org/r1463670
Log:
The FileLocator injected by FileHandler now always contains the encoding set
for the current instance.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileHandler.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileHandler.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileHandler.java?rev=1463670&r1=1463669&r2=1463670&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileHandler.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/io/FileHandler.java
Tue Apr  2 18:58:37 2013
@@ -675,13 +675,16 @@ public class FileHandler
      * {@code FileLocatorAware} interface. If this is the case, a
      * {@code FileLocator} instance is injected which returns only <b>null</b>
      * values. This method is called if no file location is available (e.g. if
-     * data is to be loaded from a stream).
+     * data is to be loaded from a stream). The encoding of the injected locator
+     * is derived from this object.
      */
     private void injectNullFileLocator()
     {
         if (getContent() instanceof FileLocatorAware)
         {
-            ((FileLocatorAware) getContent()).initFileLocator(new FileSpec());
+            FileSpec spec = new FileSpec();
+            spec.setEncoding(getEncoding());
+            ((FileLocatorAware) getContent()).initFileLocator(spec);
         }
     }
 

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileHandler.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileHandler.java?rev=1463670&r1=1463669&r2=1463670&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileHandler.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/io/TestFileHandler.java
Tue Apr  2 18:58:37 2013
@@ -979,6 +979,23 @@ public class TestFileHandler
     }
 
     /**
+     * Tests that the locator injected into the content object has an encoding
+     * set.
+     */
+    @Test
+    public void testLocatorAwareEncoding() throws ConfigurationException
+    {
+        FileBasedFileLocatorAwareTestImpl content =
+                new FileBasedFileLocatorAwareTestImpl();
+        FileHandler handler = new FileHandler(content);
+        String encoding = "testEncoding";
+        handler.setEncoding(encoding);
+        handler.save(new StringWriter());
+        assertEquals("Encoding not set", encoding, content.getLocator()
+                .getEncoding());
+    }
+
+    /**
      * Tries to add a null listener.
      */
     @Test(expected = IllegalArgumentException.class)



Mime
View raw message