sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1548314 - in /sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis: internal/system/XMLOutputFactory.java xml/FilteredNamespaces.java xml/PooledMarshaller.java
Date Thu, 05 Dec 2013 21:59:01 GMT
Author: desruisseaux
Date: Thu Dec  5 21:59:01 2013
New Revision: 1548314

URL: http://svn.apache.org/r1548314
Log:
Use the encoding specified by the JAXB_ENCODING property.

Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java?rev=1548314&r1=1548313&r2=1548314&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/system/XMLOutputFactory.java
[UTF-8] Thu Dec  5 21:59:01 2013
@@ -19,8 +19,9 @@ package org.apache.sis.internal.system;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileNotFoundException;
-import java.io.Writer;
+import java.io.BufferedOutputStream;
 import java.io.OutputStream;
+import java.io.Writer;
 import javax.xml.stream.XMLEventWriter;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.stream.XMLStreamException;
@@ -60,12 +61,13 @@ public final class XMLOutputFactory exte
      * Creates a new writer for the given file.
      *
      * @param  out Where to write to.
+     * @param  encoding The document encoding (usually {@code "UTF-8"}).
      * @return The writer.
      * @throws XMLStreamException If the writer can not be created.
      */
-    public static XMLStreamWriter createXMLStreamWriter(final File out) throws XMLStreamException
{
+    public static XMLStreamWriter createXMLStreamWriter(final File out, String encoding)
throws XMLStreamException {
         try {
-            return FACTORY.createXMLStreamWriter(new FileOutputStream(out));
+            return FACTORY.createXMLStreamWriter(new BufferedOutputStream(new FileOutputStream(out)),
encoding);
         } catch (FileNotFoundException e) {
             throw new XMLStreamException(Errors.format(Errors.Keys.CanNotOpen_1, out), e);
         }
@@ -75,11 +77,12 @@ public final class XMLOutputFactory exte
      * Creates a new writer for the given stream.
      *
      * @param  out Where to write to.
+     * @param  encoding The document encoding (usually {@code "UTF-8"}).
      * @return The writer.
      * @throws XMLStreamException If the writer can not be created.
      */
-    public static XMLStreamWriter createXMLStreamWriter(final OutputStream out) throws XMLStreamException
{
-        return FACTORY.createXMLStreamWriter(out);
+    public static XMLStreamWriter createXMLStreamWriter(OutputStream out, String encoding)
throws XMLStreamException {
+        return FACTORY.createXMLStreamWriter(out, encoding);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java?rev=1548314&r1=1548313&r2=1548314&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/FilteredNamespaces.java
[UTF-8] Thu Dec  5 21:59:01 2013
@@ -55,6 +55,8 @@ import javax.xml.namespace.NamespaceCont
  * @since   0.4
  * @version 0.4
  * @module
+ *
+ * @see <a href="http://issues.apache.org/jira/browse/SIS-152">SIS-152</a>
  */
 final class FilteredNamespaces implements NamespaceContext {
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java?rev=1548314&r1=1548313&r2=1548314&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/PooledMarshaller.java
[UTF-8] Thu Dec  5 21:59:01 2013
@@ -41,13 +41,15 @@ import org.apache.sis.internal.system.XM
 
 /**
  * Wraps a {@link Marshaller} in order to have some control on the modifications applied
on it.
- * This wrapper serves two purpose:
+ * This wrapper serves three purposes:
  *
  * <ul>
  *   <li>Save properties before modification, in order to restore them to their original
values
  *       when the marshaller is recycled.</li>
  *   <li>Constructs a SIS {@link Context} object on marshalling, in order to give
  *       additional information to the SIS object being marshalled.</li>
+ *   <li>Wraps the output stream in a {@link FilteredStreamWriter} if the desired GML
version
+ *       in not the SIS native GML version.</li>
  * </ul>
  *
  * @author  Martin Desruisseaux (Geomatys)
@@ -90,7 +92,7 @@ final class PooledMarshaller extends Poo
         if (key instanceof String) {
             final String k = (String) key;
             if (value == null && (k.endsWith(".xmlHeaders") || k.equals(JAXB_SCHEMA_LOCATION)))
{
-                value = ""; // Null value doesn't seem to be accepted.
+                value = ""; // Null value doesn't seem to be accepted for those properties.
             }
             marshaller.setProperty(k, value);
         } else if (key == AttachmentMarshaller.class) {
@@ -107,8 +109,20 @@ final class PooledMarshaller extends Poo
     }
 
     /**
-     * Returns the {@code FilterVersion} enumeration value to use for the current GML version,
-     * or {@code null} if the SIS default version is suitable.
+     * Returns the encoding of the XML document to write.
+     */
+    private String getEncoding() throws PropertyException {
+        return (String) marshaller.getProperty(JAXB_ENCODING);
+    }
+
+    /**
+     * Returns the {@code FilterVersion} enumeration value to use for the current GML version,
or
+     * {@code null} if the SIS native version is suitable. If this method returns a non-null
value,
+     * then the output generated by JAXB will need to go through a {@link FilteredStreamWriter}
+     * in order to replace the namespace of the GML version implemented by SIS by the namespace
of
+     * the GML version asked by the user.
+     *
+     * @see FilteredNamespaces
      */
     private FilterVersion getFilterVersion() {
         final Version gmlVersion = getGMLVersion();
@@ -122,8 +136,9 @@ final class PooledMarshaller extends Poo
 
     /**
      * Marshals to the given output with on-the-fly substitution of namespaces.
-     * This method is invoked only when the user asked to marshal in an GML version
-     * older than the one supported natively by SIS.
+     * This method is invoked only when the user asked to marshal to a different GML version
+     * than the one supported natively by SIS, i.e. when {@link #getFilterVersion()} returns
+     * a non-null value.
      *
      * @param version Identify the namespace substitutions to perform.
      * @param close   Whether to close the writer after marshalling.
@@ -173,7 +188,7 @@ final class PooledMarshaller extends Poo
     public void marshal(final Object object, final OutputStream output) throws JAXBException
{
         final FilterVersion version = getFilterVersion();
         if (version != null) try {
-            marshal(object, XMLOutputFactory.createXMLStreamWriter(output), version, false);
+            marshal(object, XMLOutputFactory.createXMLStreamWriter(output, getEncoding()),
version, false);
         } catch (XMLStreamException e) {
             throw new JAXBException(e);
         } else {
@@ -194,7 +209,7 @@ final class PooledMarshaller extends Poo
     public void marshal(final Object object, final File output) throws JAXBException {
         final FilterVersion version = getFilterVersion();
         if (version != null) try {
-            marshal(object, XMLOutputFactory.createXMLStreamWriter(output), version, true);
+            marshal(object, XMLOutputFactory.createXMLStreamWriter(output, getEncoding()),
version, true);
         } catch (XMLStreamException e) {
             throw new JAXBException(e);
         } else {
@@ -318,11 +333,17 @@ final class PooledMarshaller extends Poo
      */
     @Override
     public Node getNode(final Object object) throws JAXBException {
-        final Context context = begin();
-        try {
-            return marshaller.getNode(object);
-        } finally {
-            context.finish();
+        final FilterVersion version = getFilterVersion();
+        if (version != null) {
+            // This exception is thrown by javax.xml.bind.helpers.AbstractMarshallerImpl
anyway.
+            throw new UnsupportedOperationException();
+        } else {
+            final Context context = begin();
+            try {
+                return marshaller.getNode(object);
+            } finally {
+                context.finish();
+            }
         }
     }
 



Mime
View raw message