aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2017-06-24 13:53:47 +0000
committerPJ Fanning <fanningpj@apache.org>2017-06-24 13:53:47 +0000
commit3f4267c3bce399e6970de82224a672450fa2ce77 (patch)
tree6f9d0e1cf01b8826abf6248b0913bd497784a61c /src/java/org/apache
parent68ea3a9254e38dfe9ae17f53924ea0fe60b064ca (diff)
downloadpoi-3f4267c3bce399e6970de82224a672450fa2ce77.tar.gz
poi-3f4267c3bce399e6970de82224a672450fa2ce77.zip
expand StaxHelper
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1799772 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache')
-rw-r--r--src/java/org/apache/poi/util/StaxHelper.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/util/StaxHelper.java b/src/java/org/apache/poi/util/StaxHelper.java
index ae526d73b7..8c0d284304 100644
--- a/src/java/org/apache/poi/util/StaxHelper.java
+++ b/src/java/org/apache/poi/util/StaxHelper.java
@@ -17,7 +17,9 @@
package org.apache.poi.util;
+import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
/**
@@ -39,6 +41,22 @@ public final class StaxHelper {
trySetProperty(factory, XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
return factory;
}
+
+ /**
+ * Creates a new StAX XMLOutputFactory, with sensible defaults
+ */
+ public static XMLOutputFactory newXMLOutputFactory() {
+ XMLOutputFactory factory = XMLOutputFactory.newFactory();
+ trySetProperty(factory, XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
+ return factory;
+ }
+
+ /**
+ * Creates a new StAX XMLEventFactory, with sensible defaults
+ */
+ public static XMLEventFactory newXMLEventFactory() {
+ return XMLEventFactory.newFactory();
+ }
private static void trySetProperty(XMLInputFactory factory, String feature, boolean flag) {
try {
@@ -49,4 +67,14 @@ public final class StaxHelper {
logger.log(POILogger.WARN, "Cannot set StAX property because outdated StAX parser in classpath", feature, ame);
}
}
+
+ private static void trySetProperty(XMLOutputFactory factory, String feature, boolean flag) {
+ try {
+ factory.setProperty(feature, flag);
+ } catch (Exception e) {
+ logger.log(POILogger.WARN, "StAX Property unsupported", feature, e);
+ } catch (AbstractMethodError ame) {
+ logger.log(POILogger.WARN, "Cannot set StAX property because outdated StAX parser in classpath", feature, ame);
+ }
+ }
}