sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1528038 - /sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
Date Tue, 01 Oct 2013 10:37:08 GMT
Author: desruisseaux
Date: Tue Oct  1 10:37:08 2013
New Revision: 1528038

URL: http://svn.apache.org/r1528038
Log:
XML output shall take in account the --encoding argument (SIS-138).

Modified:
    sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java

Modified: sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java?rev=1528038&r1=1528037&r2=1528038&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
[UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/main/java/org/apache/sis/console/MetadataSC.java
[UTF-8] Tue Oct  1 10:37:08 2013
@@ -17,6 +17,7 @@
 package org.apache.sis.console;
 
 import java.util.EnumSet;
+import java.io.Console;
 import java.io.IOException;
 import javax.xml.bind.Marshaller;
 import javax.xml.bind.JAXBException;
@@ -90,7 +91,14 @@ final class MetadataSC extends SubComman
                 final Marshaller marshaller = pool.acquireMarshaller();
                 marshaller.setProperty(XML.LOCALE,   locale);
                 marshaller.setProperty(XML.TIMEZONE, timezone);
-                marshaller.marshal(metadata, out);
+                if (isConsole()) {
+                    marshaller.marshal(metadata, out);
+                } else {
+                    out.flush();
+                    marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding.name());
+                    marshaller.marshal(metadata, System.out); // Use OutputStream instead
than Writer.
+                    System.out.flush();
+                }
             } else {
                 final TreeTable tree = MetadataStandard.ISO_19115.asTreeTable(metadata, ValueExistencePolicy.NON_EMPTY);
                 final TreeTableFormat tf = new TreeTableFormat(locale, timezone);
@@ -101,4 +109,16 @@ final class MetadataSC extends SubComman
         }
         return 0;
     }
+
+    /**
+     * Returns {@code true} if {@link #out} is sending its output to the console.
+     * If not, then we are probably writing to a file or the user specified his own encoding.
+     * In such case, we will send the XML output to an {@code OutputStream} instead than
to a
+     * {@code Writer} and let the marshaller apply the encoding itself.
+     */
+    private boolean isConsole() {
+        if (outputBuffer != null) return true; // Special case for JUnit tests only.
+        final Console console = System.console();
+        return (console != null) && console.writer() == out;
+    }
 }



Mime
View raw message