You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/06/11 09:42:32 UTC

[cxf-fediz] branch 1.4.x-fixes updated (4f93bc9 -> 79fcf6d)

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a change to branch 1.4.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git.


    from 4f93bc9  Updating some plugins
     new 5fe3125  Revert "Switching static DocumentBuilderFactory to use a ThreadLocal instead"
     new 79fcf6d  Removing unused method

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/cxf/fediz/core/util/DOMUtils.java   | 58 +++++++++++-----------
 1 file changed, 28 insertions(+), 30 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

[cxf-fediz] 02/02: Removing unused method

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 1.4.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git

commit 79fcf6d1cd6e9e76825803f992d27d1c93e47dba
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Jun 11 10:20:27 2018 +0100

    Removing unused method
---
 .../src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java    | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java
index 9c533fc..bdf9b67 100644
--- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java
+++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java
@@ -458,14 +458,6 @@ public final class DOMUtils {
         t.transform(new DOMSource(n), new StreamResult(os));
     }
 
-    public static DocumentBuilder createDocumentBuilder() {
-        try {
-            return DBF.newDocumentBuilder();
-        } catch (ParserConfigurationException e) {
-            throw new RuntimeException("Couldn't find a DOM parser.", e);
-        }
-    }
-
     public static Document createDocument() {
         try {
             return DBF.newDocumentBuilder().newDocument();

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

[cxf-fediz] 01/02: Revert "Switching static DocumentBuilderFactory to use a ThreadLocal instead"

Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 1.4.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf-fediz.git

commit 5fe31259af670295d77a55c136c3e13ba572835d
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon Jun 11 10:22:24 2018 +0100

    Revert "Switching static DocumentBuilderFactory to use a ThreadLocal instead"
    
    This reverts commit f4d8caaaccd0ea0428b7def64d8d0607a915d28f.
---
 .../org/apache/cxf/fediz/core/util/DOMUtils.java   | 60 ++++++++++++----------
 1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java
index fc43aef..9c533fc 100644
--- a/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java
+++ b/plugins/core/src/main/java/org/apache/cxf/fediz/core/util/DOMUtils.java
@@ -65,7 +65,23 @@ public final class DOMUtils {
 
     private static final String XMLNAMESPACE = "xmlns";
 
-    private static final ThreadLocal<DocumentBuilder> DOC_BUILDER_TL = new MyThreadLocal();
+    private static final DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance();
+
+    static {
+        try {
+            DBF.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+            DBF.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+
+            DBF.setValidating(false);
+            DBF.setIgnoringComments(false);
+            DBF.setIgnoringElementContentWhitespace(true);
+            DBF.setNamespaceAware(true);
+            // DBF.setCoalescing(true);
+            // DBF.setExpandEntityReferences(true);
+        } catch (ParserConfigurationException ex) {
+            LOG.error("Error configuring DocumentBuilderFactory", ex);
+        }
+    }
 
     private DOMUtils() {
     }
@@ -412,12 +428,14 @@ public final class DOMUtils {
      */
     public static Document readXml(InputStream is) throws SAXException, IOException,
         ParserConfigurationException {
-        return createDocumentBuilder().parse(is);
+        DocumentBuilder db = DBF.newDocumentBuilder();
+        return db.parse(is);
     }
 
     public static Document readXml(Reader is) throws SAXException, IOException, ParserConfigurationException {
         InputSource ips = new InputSource(is);
-        return createDocumentBuilder().parse(ips);
+        DocumentBuilder db = DBF.newDocumentBuilder();
+        return db.parse(ips);
     }
 
     public static Document readXml(StreamSource is) throws SAXException, IOException,
@@ -427,7 +445,8 @@ public final class DOMUtils {
         is2.setByteStream(is.getInputStream());
         is2.setCharacterStream(is.getReader());
 
-        return createDocumentBuilder().parse(is2);
+        DocumentBuilder db = DBF.newDocumentBuilder();
+        return db.parse(is2);
     }
 
     public static void writeXml(Node n, OutputStream os) throws TransformerException {
@@ -440,13 +459,19 @@ public final class DOMUtils {
     }
 
     public static DocumentBuilder createDocumentBuilder() {
-        DocumentBuilder documentBuilder = DOC_BUILDER_TL.get();
-        documentBuilder.reset();
-        return documentBuilder;
+        try {
+            return DBF.newDocumentBuilder();
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException("Couldn't find a DOM parser.", e);
+        }
     }
 
     public static Document createDocument() {
-        return createDocumentBuilder().newDocument();
+        try {
+            return DBF.newDocumentBuilder().newDocument();
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException("Couldn't find a DOM parser.", e);
+        }
     }
 
     public static String getPrefixRecursive(Element el, String ns) {
@@ -633,23 +658,4 @@ public final class DOMUtils {
     public static void addNamespacePrefix(Element element, String namespaceUri, String prefix) {
         element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "xmlns:" + prefix, namespaceUri);
     }
-
-    private static final class MyThreadLocal extends ThreadLocal<DocumentBuilder> {
-
-        @Override
-        protected DocumentBuilder initialValue() {
-            try {
-                DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
-                dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
-                dfactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
-                dfactory.setValidating(false);
-                dfactory.setNamespaceAware(true);
-
-                return dfactory.newDocumentBuilder();
-            } catch (ParserConfigurationException e) {
-                LOG.error("Error configuring DocumentBuilderFactory", e);
-                throw new RuntimeException(e);
-            }
-        }
-    }
 }

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.