poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1618644 - in /poi/trunk/src: java/org/apache/poi/util/XMLHelper.java ooxml/java/org/apache/poi/util/DocumentHelper.java ooxml/java/org/apache/poi/util/SAXHelper.java
Date Mon, 18 Aug 2014 16:01:35 GMT
Author: uschindler
Date: Mon Aug 18 16:01:35 2014
New Revision: 1618644

URL: http://svn.apache.org/r1618644
Log:
Add Dominik's suggestion to DocumentBuilderFactories. I also removed the setXIncludeAware(false)
in XMLHelper, because it causes the same problem and is disabled by default.

Modified:
    poi/trunk/src/java/org/apache/poi/util/XMLHelper.java
    poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java
    poi/trunk/src/ooxml/java/org/apache/poi/util/SAXHelper.java

Modified: poi/trunk/src/java/org/apache/poi/util/XMLHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/XMLHelper.java?rev=1618644&r1=1618643&r2=1618644&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/XMLHelper.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/XMLHelper.java Mon Aug 18 16:01:35 2014
@@ -19,7 +19,6 @@ package org.apache.poi.util;
 
 import javax.xml.XMLConstants;
 import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
 
 /**
  * Helper methods for working with javax.xml classes.
@@ -27,22 +26,31 @@ import javax.xml.parsers.ParserConfigura
  */
 public final class XMLHelper
 {
+    private static POILogger logger = POILogFactory.getLogger(XMLHelper.class);
+    
     /**
      * Creates a new DocumentBuilderFactory, with sensible defaults
      */
     public static DocumentBuilderFactory getDocumentBuilderFactory() {
+        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+        factory.setExpandEntityReferences(false);
+        trySetSAXFeature(factory, XMLConstants.FEATURE_SECURE_PROCESSING, true);
+        trySetSAXFeature(factory, "http://xml.org/sax/features/external-general-entities",
false);
+        trySetSAXFeature(factory, "http://xml.org/sax/features/external-parameter-entities",
false);
+        trySetSAXFeature(factory, "http://apache.org/xml/features/nonvalidating/load-external-dtd",
false);
+        trySetSAXFeature(factory, "http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
false);
+        return factory;
+    }
+    
+    private static void trySetSAXFeature(DocumentBuilderFactory documentBuilderFactory, String
feature, boolean enabled) {
         try {
-            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-            factory.setXIncludeAware(false);
-            factory.setExpandEntityReferences(false);
-            factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
-            factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
-            factory.setFeature("http://xml.org/sax/features/external-parameter-entities",
false);
-            factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",
false);
-            factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar",
false);
-            return factory;
-        } catch (ParserConfigurationException e) {
-            throw new RuntimeException("Broken XML Setup", e);
+            documentBuilderFactory.setFeature(feature, enabled);
+        } catch (Exception e) {
+            logger.log(POILogger.WARN, "SAX Feature unsupported", feature, e);
+        } catch (AbstractMethodError ame) {
+            logger.log(POILogger.WARN, "Cannot set SAX feature because outdated XML parser
in classpath", feature, ame);
         }
     }
+    
+
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java?rev=1618644&r1=1618643&r2=1618644&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/util/DocumentHelper.java Mon Aug 18 16:01:35 2014
@@ -61,9 +61,12 @@ public final class DocumentHelper {
         try {
             documentBuilderFactory.setFeature(feature, enabled);
         } catch (Exception e) {
-            logger.log(POILogger.INFO, "SAX Feature unsupported", feature, e);
+            logger.log(POILogger.WARN, "SAX Feature unsupported", feature, e);
+        } catch (AbstractMethodError ame) {
+            logger.log(POILogger.WARN, "Cannot set SAX feature because outdated XML parser
in classpath", feature, ame);
         }
     }
+    
     private static void trySetXercesSecurityManager(DocumentBuilderFactory documentBuilderFactory)
{
         // Try built-in JVM one first, standalone if not
         for (String securityManagerClassName : new String[] {
@@ -78,7 +81,7 @@ public final class DocumentHelper {
                 // Stop once one can be setup without error
                 return;
             } catch (Exception e) {
-                logger.log(POILogger.INFO, "SAX Security Manager could not be setup", e);
+                logger.log(POILogger.WARN, "SAX Security Manager could not be setup", e);
             }
         }
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/util/SAXHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/util/SAXHelper.java?rev=1618644&r1=1618643&r2=1618644&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/util/SAXHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/util/SAXHelper.java Mon Aug 18 16:01:35 2014
@@ -69,7 +69,9 @@ public final class SAXHelper {
         try {
             xmlReader.setFeature(feature, enabled);
         } catch (Exception e) {
-            logger.log(POILogger.INFO, "SAX Feature unsupported", feature, e);
+            logger.log(POILogger.WARN, "SAX Feature unsupported", feature, e);
+        } catch (AbstractMethodError ame) {
+            logger.log(POILogger.WARN, "Cannot set SAX feature because outdated XML parser
in classpath", feature, ame);
         }
     }
     
@@ -87,7 +89,7 @@ public final class SAXHelper {
                 // Stop once one can be setup without error
                 return;
             } catch (Exception e) {
-                logger.log(POILogger.INFO, "SAX Security Manager could not be setup", e);
+                logger.log(POILogger.WARN, "SAX Security Manager could not be setup", e);
             }
         }
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message