You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2022/06/01 13:55:46 UTC

[jena] branch main updated: JENA-2331: isolate setting of XMLInputFactory properties

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

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new bbfc3b1aab JENA-2331: isolate setting of XMLInputFactory properties
     new 4054172899 Merge pull request #1340 from TopQuadrant/JENA-2331
bbfc3b1aab is described below

commit bbfc3b1aab6899f9695168255dad0b5803ac4088
Author: Brian Vosburgh <bv...@topquadrant.com>
AuthorDate: Wed Jun 1 08:00:35 2022 -0400

    JENA-2331: isolate setting of XMLInputFactory properties
---
 .../java/org/apache/jena/util/JenaXMLInput.java    | 29 ++++++++++++++--------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/jena-core/src/main/java/org/apache/jena/util/JenaXMLInput.java b/jena-core/src/main/java/org/apache/jena/util/JenaXMLInput.java
index d4474ffadc..6d7f57912c 100644
--- a/jena-core/src/main/java/org/apache/jena/util/JenaXMLInput.java
+++ b/jena-core/src/main/java/org/apache/jena/util/JenaXMLInput.java
@@ -72,17 +72,26 @@ public class JenaXMLInput {
      * Initialize an XMLInputFactory to jena settings.
      */
     public static void initXMLInputFactory(XMLInputFactory xf) {
+        // This disables DTDs entirely for the factory.
+        // All DTDs are silently ignored; takes precedence over ACCESS_EXTERNAL_DTD
+    	setXMLInputFactoryProperty(xf, XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
+
+        // disable external entities (silently ignore)
+        setXMLInputFactoryProperty(xf, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
+
+        // Disable external DTDs (files and HTTP) - errors unless SUPPORT_DTD is false.
+        setXMLInputFactoryProperty(xf, XMLConstants.ACCESS_EXTERNAL_DTD, "");
+    }
+
+    /**
+     * Catch any {@link IllegalArgumentException}, log it, and continue.
+     */
+    private static void setXMLInputFactoryProperty(XMLInputFactory xf, String name, Object value) {
         try {
-            // This disables DTDs entirely for the factory.
-            // All DTDs are silently ignored; takes precedence over ACCESS_EXTERNAL_DTD
-            xf.setProperty(XMLInputFactory.SUPPORT_DTD, false);
-
-            // Disable external DTDs (files and HTTP) - errors unless SUPPORT_DTD is false.
-            xf.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
-            // disable external entities (silently ignore)
-            xf.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
-        } catch(IllegalArgumentException ex){
-            Log.error(JenaXMLInput.class, "Problem setting StAX property", ex);
+            xf.setProperty(name, value);
+        } catch(IllegalArgumentException ex) {
+            Log.error(JenaXMLInput.class, "Problem setting StAX property - name: \"" +
+            		name + "\" - value: \"" + value + "\" - error: " + ex.getMessage());
         }
     }