You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2022/05/31 10:45:35 UTC

[GitHub] [jena] afs commented on a diff in pull request #1340: JENA-2331: change JenaXMLInput to use the JDK XMLInputFactory

afs commented on code in PR #1340:
URL: https://github.com/apache/jena/pull/1340#discussion_r885484348


##########
jena-core/src/main/java/org/apache/jena/util/JenaXMLInput.java:
##########
@@ -72,16 +72,24 @@ public static XMLReader createXMLReader() throws ParserConfigurationException, S
      * 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 DTDs (files and HTTP) - errors unless SUPPORT_DTD is false.
+        setXMLInputFactoryProperty(xf, XMLConstants.ACCESS_EXTERNAL_DTD, "");

Review Comment:
   This could be moved to the end. I don't think order matters. Assuming all XMLInputFactory are supported by Woodstox.



##########
jena-core/src/main/java/org/apache/jena/util/JenaXMLInput.java:
##########
@@ -72,16 +72,24 @@ public static XMLReader createXMLReader() throws ParserConfigurationException, S
      * 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 DTDs (files and HTTP) - errors unless SUPPORT_DTD is false.
+        setXMLInputFactoryProperty(xf, XMLConstants.ACCESS_EXTERNAL_DTD, "");
+
+        // disable external entities (silently ignore)
+        setXMLInputFactoryProperty(xf, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
+    }
+
+    /**
+     * 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){
+            xf.setProperty(name, value);
+        } catch(IllegalArgumentException ex) {
             Log.error(JenaXMLInput.class, "Problem setting StAX property", ex);

Review Comment:
   Assuming this is now to catch specific case, the stacktrace isn't necessary (reduces the log output), if we have the exception message and the specific property `name` included instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org