polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject polygene-java git commit: javax.xml serialization allows to set provider properties at assembly
Date Mon, 03 Apr 2017 09:35:34 GMT
Repository: polygene-java
Updated Branches:
  refs/heads/develop 30acba2eb -> ef01c64ea


javax.xml serialization allows to set provider properties at assembly

POLYGENE-239


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/ef01c64e
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/ef01c64e
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/ef01c64e

Branch: refs/heads/develop
Commit: ef01c64ea622d9ed1c26aecf85c89a0ca0e46c2e
Parents: 30acba2
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Apr 3 11:35:21 2017 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Apr 3 11:35:21 2017 +0200

----------------------------------------------------------------------
 .../javaxxml/JavaxXmlFactories.java             | 24 ++++++--
 .../javaxxml/JavaxXmlSettings.java              | 65 +++++++++++++++++++-
 2 files changed, 83 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ef01c64e/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlFactories.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlFactories.java
b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlFactories.java
index 72b02fa..613d62d 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlFactories.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlFactories.java
@@ -18,7 +18,7 @@
 package org.apache.polygene.serialization.javaxxml;
 
 import java.io.InputStream;
-import javax.xml.XMLConstants;
+import java.util.Map;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
@@ -75,19 +75,32 @@ public interface JavaxXmlFactories
                 documentBuilderFactory.setValidating( false );
                 documentBuilderFactory.setNamespaceAware( false );
                 documentBuilderFactory.setIgnoringComments( true );
-                documentBuilderFactory.setFeature( XMLConstants.FEATURE_SECURE_PROCESSING,
true );
+                for( Map.Entry<String, Boolean> feature : settings.getDocumentBuilderFactoryFeatures().entrySet()
)
+                {
+                    documentBuilderFactory.setFeature( feature.getKey(), feature.getValue()
);
+                }
+                for( Map.Entry<String, Object> attributes : settings.getDocumentBuilderFactoryAttributes().entrySet()
)
+                {
+                    documentBuilderFactory.setAttribute( attributes.getKey(), attributes.getValue()
);
+                }
 
                 String transformerFactoryClassName = settings.getTransformerFactoryClassName();
                 transformerFactory = transformerFactoryClassName == null
                                      ? TransformerFactory.newInstance()
                                      : TransformerFactory.newInstance( transformerFactoryClassName,
                                                                        getClass().getClassLoader()
);
-                transformerFactory.setFeature( XMLConstants.FEATURE_SECURE_PROCESSING, true
);
-                transformerFactory.setAttribute( XMLConstants.ACCESS_EXTERNAL_DTD, "" );
-                transformerFactory.setAttribute( XMLConstants.ACCESS_EXTERNAL_STYLESHEET,
"" );
+                for( Map.Entry<String, Boolean> feature : settings.getTransformerFactoryFeatures().entrySet()
)
+                {
+                    transformerFactory.setFeature( feature.getKey(), feature.getValue() );
+                }
+                for( Map.Entry<String, Object> attributes : settings.getTransformerFactoryAttributes().entrySet()
)
+                {
+                    transformerFactory.setAttribute( attributes.getKey(), attributes.getValue()
);
+                }
 
                 serializationTransformer = transformerFactory.newTransformer();
                 serializationTransformer.setOutputProperty( OutputKeys.METHOD, "xml" );
+                serializationTransformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION,
"no" );
                 serializationTransformer.setOutputProperty( OutputKeys.VERSION, "1.1" );
                 serializationTransformer.setOutputProperty( OutputKeys.STANDALONE, "yes"
);
                 serializationTransformer.setOutputProperty( OutputKeys.ENCODING, UTF_8.name()
);
@@ -97,6 +110,7 @@ public interface JavaxXmlFactories
                 InputStream xsltStream = getClass().getResourceAsStream( xslPath );
                 normalizationTransformer = transformerFactory.newTransformer( new StreamSource(
xsltStream ) );
                 normalizationTransformer.setOutputProperty( OutputKeys.METHOD, "xml" );
+                normalizationTransformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION,
"no" );
                 normalizationTransformer.setOutputProperty( OutputKeys.VERSION, "1.1" );
                 normalizationTransformer.setOutputProperty( OutputKeys.STANDALONE, "yes"
);
                 normalizationTransformer.setOutputProperty( OutputKeys.ENCODING, UTF_8.name()
);

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/ef01c64e/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
index 9f4d007..ab7448c 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
@@ -17,8 +17,10 @@
  */
 package org.apache.polygene.serialization.javaxxml;
 
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import javax.xml.XMLConstants;
 import org.apache.polygene.api.type.ValueType;
 import org.apache.polygene.spi.serialization.SerializationSettings;
 
@@ -27,7 +29,6 @@ import org.apache.polygene.spi.serialization.SerializationSettings;
  *
  * Must be registered as meta-info at assembly time.
  */
-// TODO javax.xml properties?
 public class JavaxXmlSettings extends SerializationSettings<JavaxXmlSettings>
 {
     public static final JavaxXmlSettings DEFAULT = new JavaxXmlSettings();
@@ -38,7 +39,12 @@ public class JavaxXmlSettings extends SerializationSettings<JavaxXmlSettings>
     }
 
     private String documentBuilderFactoryClassName;
+    private Map<String, Boolean> documentBuilderFactoryFeatures;
+    private Map<String, Object> documentBuilderFactoryAttributes;
+
     private String transformerFactoryClassName;
+    private Map<String, Boolean> transformerFactoryFeatures;
+    private Map<String, Object> transformerFactoryAttributes;
 
     private String rootTagName;
     private String collectionTagName;
@@ -52,6 +58,22 @@ public class JavaxXmlSettings extends SerializationSettings<JavaxXmlSettings>
 
     public JavaxXmlSettings()
     {
+        documentBuilderFactoryFeatures = new HashMap<String, Boolean>()
+        {{
+            put( XMLConstants.FEATURE_SECURE_PROCESSING, true );
+        }};
+        documentBuilderFactoryAttributes = new HashMap<>();
+
+        transformerFactoryFeatures = new HashMap<String, Boolean>()
+        {{
+            put( XMLConstants.FEATURE_SECURE_PROCESSING, true );
+        }};
+        transformerFactoryAttributes = new HashMap<String, Object>()
+        {{
+            put( XMLConstants.ACCESS_EXTERNAL_DTD, "" );
+            put( XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "" );
+        }};
+
         rootTagName = "state";
         collectionTagName = "collection";
         collectionElementTagName = "element";
@@ -59,6 +81,7 @@ public class JavaxXmlSettings extends SerializationSettings<JavaxXmlSettings>
         mapEntryTagName = "entry";
         valueTagName = "value";
         typeInfoTagName = "_type";
+
         adapters = new LinkedHashMap<>();
     }
 
@@ -72,6 +95,26 @@ public class JavaxXmlSettings extends SerializationSettings<JavaxXmlSettings>
         this.documentBuilderFactoryClassName = documentBuilderFactoryClassName;
     }
 
+    public Map<String, Boolean> getDocumentBuilderFactoryFeatures()
+    {
+        return documentBuilderFactoryFeatures;
+    }
+
+    public void setDocumentBuilderFactoryFeatures( Map<String, Boolean> documentBuilderFactoryFeatures
)
+    {
+        this.documentBuilderFactoryFeatures = documentBuilderFactoryFeatures;
+    }
+
+    public Map<String, Object> getDocumentBuilderFactoryAttributes()
+    {
+        return documentBuilderFactoryAttributes;
+    }
+
+    public void setDocumentBuilderFactoryAttributes( Map<String, Object> documentBuilderFactoryAttributes
)
+    {
+        this.documentBuilderFactoryAttributes = documentBuilderFactoryAttributes;
+    }
+
     public String getTransformerFactoryClassName()
     {
         return transformerFactoryClassName;
@@ -82,6 +125,26 @@ public class JavaxXmlSettings extends SerializationSettings<JavaxXmlSettings>
         this.transformerFactoryClassName = transformerFactoryClassName;
     }
 
+    public Map<String, Boolean> getTransformerFactoryFeatures()
+    {
+        return transformerFactoryFeatures;
+    }
+
+    public void setTransformerFactoryFeatures( Map<String, Boolean> transformerFactoryFeatures
)
+    {
+        this.transformerFactoryFeatures = transformerFactoryFeatures;
+    }
+
+    public Map<String, Object> getTransformerFactoryAttributes()
+    {
+        return transformerFactoryAttributes;
+    }
+
+    public void setTransformerFactoryAttributes( Map<String, Object> transformerFactoryAttributes
)
+    {
+        this.transformerFactoryAttributes = transformerFactoryAttributes;
+    }
+
     public String getRootTagName()
     {
         return rootTagName;


Mime
View raw message