Author: veithen
Date: Sun May 16 11:00:04 2010
New Revision: 944793
URL: http://svn.apache.org/viewvc?rev=944793&view=rev
Log:
Introduced a mechanism that allows requesting XMLInputFactory and
XMLStreamReader instances with specific configurations from StAXUtils, while
still preserving the caching feature. This is a generalization of WSCOMMONS-394
and can e.g. be used to request non coalescing parsers. It will also be useful
to solve AXIS2-4450.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXParserConfiguration.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderUtilsTest.java
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXParserConfiguration.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXParserConfiguration.java?rev=944793&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXParserConfiguration.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXParserConfiguration.java
Sun May 16 11:00:04 2010
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.om.util;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLResolver;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.util.stax.dialect.StAXDialect;
+import org.apache.axiom.util.stax.dialect.StAXDialectDetector;
+
+/**
+ * Defines a particular StAX parser configuration. An implementation of this
+ * interface must satisfy the following requirements:
+ * <ol>
+ * <li>It MUST be immutable.
+ * <li>It MUST either be a singleton or properly implement
+ * {...@link Object#equals(Object)} and {...@link Object#hashCode()}.
+ * </ol>
+ * These two requirements ensure that instances of this interface may be used
as
+ * cache keys.
+ */
+public interface StAXParserConfiguration {
+ /**
+ * The default configuration.
+ */
+ StAXParserConfiguration DEFAULT = new StAXParserConfiguration() {
+ public XMLInputFactory configure(XMLInputFactory factory, StAXDialect
dialect) {
+ return factory;
+ }
+
+ public String toString() {
+ return "DEFAULT";
+ }
+ };
+
+ /**
+ * Configuration that forces the parser to process the XML document as
+ * standalone. In this configuration, the parser will ignore any references
+ * to external entities, in particular DTDs. This is especially useful to
+ * process documents referencing DTDs with system IDs that are network
+ * locations, because parsing these documents would otherwise fail on nodes
+ * detached from the network. This configuration should be used with care
+ * because the resulting representation of the document may be incomplete.
+ * E.g. default attribute values defined in the DTD will not be reported.
+ */
+ StAXParserConfiguration STANDALONE = new StAXParserConfiguration() {
+ public XMLInputFactory configure(XMLInputFactory factory, StAXDialect
dialect) {
+
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
Boolean.FALSE);
+ // Some StAX parser such as Woodstox still try to load the
external DTD subset,
+ // even if IS_SUPPORTING_EXTERNAL_ENTITIES is set to false. To
work around this,
+ // we add a custom XMLResolver that returns empty documents. See
WSTX-117 for
+ // an interesting discussion about this.
+ factory.setXMLResolver(new XMLResolver() {
+ public Object resolveEntity(String publicID, String systemID,
String baseURI,
+ String namespace) throws XMLStreamException {
+ return new ByteArrayInputStream(new byte[0]);
+ }
+ });
+ return factory;
+ }
+
+ public String toString() {
+ return "STANDALONE";
+ }
+ };
+
+ /**
+ * Configuration that sets up the parser in non coalescing mode.
+ */
+ StAXParserConfiguration NON_COALESCING = new StAXParserConfiguration() {
+ public XMLInputFactory configure(XMLInputFactory factory, StAXDialect
dialect) {
+ factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
+ return factory;
+ }
+
+ public String toString() {
+ return "NON_COALESCING";
+ }
+ };
+
+ /**
+ * Apply the configuration to the given factory. The method MAY optionally
+ * wrap the factory, e.g. to modify the behavior of the
+ * {...@link javax.xml.stream.XMLStreamReader} instances created by the
+ * factory.
+ *
+ * @param factory
+ * the factory to configure
+ * @param dialect
+ * The dialect of the StAX implementation as detected by
+ * {...@link StAXDialectDetector}. The implementation may use
this
+ * information to configure implementation specific settings.
+ * @return The configured factory. This may be the original factory (if the
+ * implementation only changes the factory properties), or a
+ * wrapper.
+ */
+ XMLInputFactory configure(XMLInputFactory factory, StAXDialect dialect);
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXParserConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java?rev=944793&r1=944792&r2=944793&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/StAXUtils.java
Sun May 16 11:00:04 2010
@@ -30,13 +30,10 @@ import org.apache.axiom.util.stax.wrappe
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLResolver;
-import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
-import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -106,42 +103,73 @@ public class StAXUtils {
// These static singletons are used when the XML*Factory is created with
// the StAXUtils classloader.
- private static XMLInputFactory inputFactory = null;
- private static XMLInputFactory inputNDFactory = null;
+ private static final Map/*<StAXParserConfiguration,XMLInputFactory>*/
inputFactoryMap
+ = Collections.synchronizedMap(new WeakHashMap());
private static XMLOutputFactory outputFactory = null;
// These maps are used for the isFactoryPerClassLoader==true case
// The maps are synchronized and weak.
- private static Map inputFactoryPerCL = Collections.synchronizedMap(new
WeakHashMap());
- private static Map inputNDFactoryPerCL = Collections.synchronizedMap(new
WeakHashMap());
+ private static final
Map/*<StAXParserConfiguration,Map<ClassLoader,XMLInputFactory>>*/
inputFactoryPerCLMap
+ = Collections.synchronizedMap(new WeakHashMap());
private static Map outputFactoryPerCL = Collections.synchronizedMap(new
WeakHashMap());
/**
- * Gets an XMLInputFactory instance from pool.
- *
- * @return an XMLInputFactory instance.
+ * Get a cached {...@link XMLInputFactory} instance using the default
+ * configuration and cache policy (i.e. one instance per class loader).
+ *
+ * @return an {...@link XMLInputFactory} instance.
*/
public static XMLInputFactory getXMLInputFactory() {
-
- if (isFactoryPerClassLoader) {
- return getXMLInputFactory_perClassLoader(false);
- } else {
- return getXMLInputFactory_singleton(false);
- }
+ return getXMLInputFactory(null, isFactoryPerClassLoader);
}
/**
- * Get XMLInputFactory
- * @param factoryPerClassLoaderPolicy
- * (if true, then factory using current classloader.
- * if false, then factory using the classloader that loaded StAXUtils)
- * @return XMLInputFactory
+ * Get a cached {...@link XMLInputFactory} instance using the specified
+ * configuration and the default cache policy.
+ *
+ * @param configuration
+ * the configuration applied to the requested factory
+ * @return an {...@link XMLInputFactory} instance.
+ */
+ public static XMLInputFactory getXMLInputFactory(StAXParserConfiguration
configuration) {
+ return getXMLInputFactory(configuration, isFactoryPerClassLoader);
+ }
+
+ /**
+ * Get a cached {...@link XMLInputFactory} instance using the default
+ * configuration and the specified cache policy.
+ *
+ * @param factoryPerClassLoaderPolicy
+ * the cache policy; see
+ * {...@link #getXMLInputFactory(StAXParserConfiguration,
boolean)}
+ * for more details
+ * @return an {...@link XMLInputFactory} instance.
*/
public static XMLInputFactory getXMLInputFactory(boolean
factoryPerClassLoaderPolicy) {
+ return getXMLInputFactory(null, factoryPerClassLoaderPolicy);
+ }
+
+ /**
+ * Get a cached {...@link XMLInputFactory} instance using the specified
+ * configuration and cache policy.
+ *
+ * @param configuration
+ * the configuration applied to the requested factory
+ * @param factoryPerClassLoaderPolicy
+ * If set to <code>true</code>, the factory cached for the
+ * current class loader will be returned. If set to
+ * <code>false</code>, the singleton factory (instantiated using
+ * the class loader that loaded {...@link StAXUtils}) will be
+ * returned.
+ * @return an {...@link XMLInputFactory} instance.
+ */
+ public static XMLInputFactory getXMLInputFactory(StAXParserConfiguration
configuration,
+ boolean factoryPerClassLoaderPolicy) {
+
if (factoryPerClassLoaderPolicy) {
- return getXMLInputFactory_perClassLoader(false);
+ return getXMLInputFactory_perClassLoader(configuration);
} else {
- return getXMLInputFactory_singleton(false);
+ return getXMLInputFactory_singleton(configuration);
}
}
@@ -156,7 +184,14 @@ public class StAXUtils {
public static XMLStreamReader createXMLStreamReader(final InputStream in,
final String encoding)
throws XMLStreamException {
- final XMLInputFactory inputFactory = getXMLInputFactory();
+
+ return createXMLStreamReader(null, in, encoding);
+ }
+
+ public static XMLStreamReader
createXMLStreamReader(StAXParserConfiguration configuration,
+ final InputStream in, final String encoding) throws
XMLStreamException {
+
+ final XMLInputFactory inputFactory = getXMLInputFactory(configuration);
try {
XMLStreamReader reader =
(XMLStreamReader)
@@ -177,7 +212,14 @@ public class StAXUtils {
public static XMLStreamReader createXMLStreamReader(final InputStream in)
throws XMLStreamException {
- final XMLInputFactory inputFactory = getXMLInputFactory();
+
+ return createXMLStreamReader(null, in);
+ }
+
+ public static XMLStreamReader
createXMLStreamReader(StAXParserConfiguration configuration,
+ final InputStream in) throws XMLStreamException {
+
+ final XMLInputFactory inputFactory = getXMLInputFactory(configuration);
try {
XMLStreamReader reader =
(XMLStreamReader)
@@ -199,7 +241,14 @@ public class StAXUtils {
public static XMLStreamReader createXMLStreamReader(final Reader in)
throws XMLStreamException {
- final XMLInputFactory inputFactory = getXMLInputFactory();
+
+ return createXMLStreamReader(null, in);
+ }
+
+ public static XMLStreamReader
createXMLStreamReader(StAXParserConfiguration configuration,
+ final Reader in) throws XMLStreamException {
+
+ final XMLInputFactory inputFactory = getXMLInputFactory(configuration);
try {
XMLStreamReader reader =
(XMLStreamReader)
@@ -389,7 +438,7 @@ public class StAXUtils {
}
private static XMLInputFactory newXMLInputFactory(final ClassLoader
classLoader,
- final boolean isNetworkDetached) {
+ final StAXParserConfiguration configuration) {
return (XMLInputFactory)AccessController.doPrivileged(new
PrivilegedAction() {
public Object run() {
@@ -414,21 +463,10 @@ public class StAXUtils {
factory.setProperty((String)entry.getKey(),
entry.getValue());
}
}
- if (isNetworkDetached) {
-
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
- Boolean.FALSE);
- // Some StAX parser such as Woodstox still try to load
the external DTD subset,
- // even if IS_SUPPORTING_EXTERNAL_ENTITIES is set to
false. To work around this,
- // we add a custom XMLResolver that returns empty
documents. See WSTX-117 for
- // an interesting discussion about this.
- factory.setXMLResolver(new XMLResolver() {
- public Object resolveEntity(String publicID,
String systemID, String baseURI,
- String namespace) throws
XMLStreamException {
- return new ByteArrayInputStream(new byte[0]);
- }
- });
- }
StAXDialect dialect =
StAXDialectDetector.getDialect(factory.getClass());
+ if (configuration != null) {
+ factory = configuration.configure(factory, dialect);
+ }
return new ImmutableXMLInputFactory(dialect.normalize(
dialect.makeThreadSafe(factory)));
} finally {
@@ -443,18 +481,24 @@ public class StAXUtils {
/**
* @return XMLInputFactory for the current classloader
*/
- private static XMLInputFactory getXMLInputFactory_perClassLoader(final
boolean isNetworkDetached) {
+ private static XMLInputFactory
getXMLInputFactory_perClassLoader(StAXParserConfiguration configuration) {
ClassLoader cl = getContextClassLoader();
XMLInputFactory factory;
if (cl == null) {
- factory = getXMLInputFactory_singleton(isNetworkDetached);
+ factory = getXMLInputFactory_singleton(configuration);
} else {
// Check the cache
- if (isNetworkDetached) {
- factory = (XMLInputFactory) inputNDFactoryPerCL.get(cl);
+ if (configuration == null) {
+ configuration = StAXParserConfiguration.DEFAULT;
+ }
+ Map map = (Map)inputFactoryPerCLMap.get(configuration);
+ if (map == null) {
+ map = Collections.synchronizedMap(new WeakHashMap());
+ inputFactoryPerCLMap.put(configuration, map);
+ factory = null;
} else {
- factory = (XMLInputFactory) inputFactoryPerCL.get(cl);
+ factory = (XMLInputFactory)map.get(cl);
}
// If not found in the cache map, crate a new factory
@@ -468,7 +512,7 @@ public class StAXUtils {
}
factory = null;
try {
- factory = newXMLInputFactory(null, isNetworkDetached);
+ factory = newXMLInputFactory(null, configuration);
} catch (ClassCastException cce) {
if (log.isDebugEnabled()) {
log.debug("Failed creation of XMLInputFactory
implementation with " +
@@ -478,25 +522,23 @@ public class StAXUtils {
XMLInputFactory.class.getClassLoader());
}
factory =
newXMLInputFactory(XMLInputFactory.class.getClassLoader(),
- isNetworkDetached);
+ configuration);
}
if (factory != null) {
// Cache the new factory
- if (isNetworkDetached) {
- inputNDFactoryPerCL.put(cl, factory);
- } else {
- inputFactoryPerCL.put(cl, factory);
- }
+ map.put(cl, factory);
if (log.isDebugEnabled()) {
log.debug("Created XMLInputFactory = " +
factory.getClass() +
" with classloader=" + cl);
- log.debug("Size of XMLInputFactory map =" +
inputFactoryPerCL.size());
- log.debug("isNetworkDetached =" + isNetworkDetached);
+ log.debug("Configuration = " + configuration);
+ log.debug("Size of XMLInputFactory map for this
configuration = " + map.size());
+ log.debug("Configurations for which factories have
been cached = " +
+ inputFactoryPerCLMap.keySet());
}
} else {
- factory = getXMLInputFactory_singleton(isNetworkDetached);
+ factory = getXMLInputFactory_singleton(configuration);
}
}
@@ -507,27 +549,17 @@ public class StAXUtils {
/**
* @return singleton XMLInputFactory loaded with the StAXUtils classloader
*/
- private static XMLInputFactory getXMLInputFactory_singleton(final boolean
isNetworkDetached) {
- XMLInputFactory f;
- if (isNetworkDetached) {
- f = inputNDFactory;
- } else {
- f = inputFactory;
+ private static XMLInputFactory
getXMLInputFactory_singleton(StAXParserConfiguration configuration) {
+ if (configuration == null) {
+ configuration = StAXParserConfiguration.DEFAULT;
}
+ XMLInputFactory f =
(XMLInputFactory)inputFactoryMap.get(configuration);
if (f == null) {
- f = newXMLInputFactory(StAXUtils.class.getClassLoader(),
isNetworkDetached);
- if (isNetworkDetached) {
- inputNDFactory = f;
- } else {
- inputFactory = f;
- }
+ f = newXMLInputFactory(StAXUtils.class.getClassLoader(),
configuration);
+ inputFactoryMap.put(configuration, f);
if (log.isDebugEnabled()) {
if (f != null) {
- if (isNetworkDetached) {
- log.debug("Created singleton network detached
XMLInputFactory = " + f.getClass());
- } else {
- log.debug("Created singleton XMLInputFactory = " +
f.getClass());
- }
+ log.debug("Created singleton XMLInputFactory " +
f.getClass() + " with configuration " + configuration);
}
}
}
@@ -644,110 +676,41 @@ public class StAXUtils {
}
/**
- * Create an XMLStreamReader that will operate when detached from a
network.
- * The XMLStreamReader is created from a OMInputFactory that has external
- * entities disabled. This kind of XMLStreamReader is useful for reading
- * deployment information.
- * @param in
- * @param encoding
- * @return
- * @throws XMLStreamException
+ * @deprecated use {...@link
#createXMLStreamReader(StAXParserConfiguration, InputStream, String)}
+ * with {...@link StAXParserConfiguration#STANDALONE}
*/
- public static XMLStreamReader createNetworkDetachedXMLStreamReader(final
InputStream in, final String encoding)
- throws XMLStreamException {
- final XMLInputFactory inputFactory =
getNetworkDetachedXMLInputFactory();
- try {
- XMLStreamReader reader =
- (XMLStreamReader)
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws XMLStreamException {
- return inputFactory.createXMLStreamReader(in,
encoding);
- }
- }
- );
- if (isDebugEnabled) {
- log.debug("XMLStreamReader is " + reader.getClass().getName());
- }
- return reader;
- } catch (PrivilegedActionException pae) {
- throw (XMLStreamException) pae.getException();
- }
+ public static XMLStreamReader
createNetworkDetachedXMLStreamReader(InputStream in, String encoding)
+ throws XMLStreamException {
+
+ return createXMLStreamReader(StAXParserConfiguration.STANDALONE, in,
encoding);
}
/**
- * Gets an XMLInputFactory instance from pool.
- *
- * @return an XMLInputFactory instance.
+ * @deprecated use {...@link #getXMLInputFactory(StAXParserConfiguration)}
with
+ * {...@link StAXParserConfiguration#STANDALONE}
*/
public static XMLInputFactory getNetworkDetachedXMLInputFactory() {
- if (isFactoryPerClassLoader) {
- return getXMLInputFactory_perClassLoader(true);
- } else {
- return getXMLInputFactory_singleton(true);
- }
+ return getXMLInputFactory(StAXParserConfiguration.STANDALONE);
}
/**
- * Create an XMLStreamReader that will operate when detached from a
network.
- * The XMLStreamReader is created from a OMInputFactory that has external
- * entities disabled. This kind of XMLStreamReader is useful for reading
- * deployment information.
- *
- * @param in
- * @return
- * @throws XMLStreamException
+ * @deprecated use {...@link
#createXMLStreamReader(StAXParserConfiguration, InputStream)}
+ * with {...@link StAXParserConfiguration#STANDALONE}
*/
- public static XMLStreamReader createNetworkDetachedXMLStreamReader(final
InputStream in)
- throws XMLStreamException {
- final XMLInputFactory inputFactory =
getNetworkDetachedXMLInputFactory();
- try {
- XMLStreamReader reader =
- (XMLStreamReader)
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws XMLStreamException {
- return inputFactory.createXMLStreamReader(in);
- }
- }
- );
-
- if (isDebugEnabled) {
- log.debug("XMLStreamReader is " + reader.getClass().getName());
- }
- return reader;
- } catch (PrivilegedActionException pae) {
- throw (XMLStreamException) pae.getException();
- }
+ public static XMLStreamReader
createNetworkDetachedXMLStreamReader(InputStream in)
+ throws XMLStreamException {
+
+ return createXMLStreamReader(StAXParserConfiguration.STANDALONE, in);
}
/**
- * Create an XMLStreamReader that will operate when detached from a
network.
- * The XMLStreamReader is created from a OMInputFactory that has external
- * entities disabled. This kind of XMLStreamReader is useful for reading
- * deployment information.
- *
- * @param in
- * @return
- * @throws XMLStreamException
+ * @deprecated use {...@link
#createXMLStreamReader(StAXParserConfiguration, Reader)}
+ * with {...@link StAXParserConfiguration#STANDALONE}
*/
- public static XMLStreamReader createNetworkDetachedXMLStreamReader(final
Reader in)
- throws XMLStreamException {
- final XMLInputFactory inputFactory =
getNetworkDetachedXMLInputFactory();
- try {
- XMLStreamReader reader =
- (XMLStreamReader)
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws XMLStreamException {
- return inputFactory.createXMLStreamReader(in);
- }
- }
- );
- if (isDebugEnabled) {
- log.debug("XMLStreamReader is " + reader.getClass().getName());
- }
- return reader;
- } catch (PrivilegedActionException pae) {
- throw (XMLStreamException) pae.getException();
- }
+ public static XMLStreamReader createNetworkDetachedXMLStreamReader(Reader
in)
+ throws XMLStreamException {
+
+ return createXMLStreamReader(StAXParserConfiguration.STANDALONE, in);
}
/**
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java?rev=944793&r1=944792&r2=944793&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java
Sun May 16 11:00:04 2010
@@ -23,7 +23,6 @@ import java.io.InputStream;
import java.util.Arrays;
import javax.xml.namespace.NamespaceContext;
-import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import junit.framework.TestCase;
@@ -36,6 +35,8 @@ import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.util.AXIOMUtil;
+import org.apache.axiom.om.util.StAXParserConfiguration;
+import org.apache.axiom.om.util.StAXUtils;
public class OMStAXWrapperTestBase extends TestCase {
protected final OMMetaFactory omMetaFactory;
@@ -46,13 +47,11 @@ public class OMStAXWrapperTestBase exten
// Regression test for WSCOMMONS-338 and WSCOMMONS-341
public void testCDATAEvent_FromParser() throws Exception {
- // Make sure that the parser is non coalescing (otherwise no CDATA
events will be
- // reported). This is not the default for Woodstox (see WSTX-140).
- XMLInputFactory factory = XMLInputFactory.newInstance();
- factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
// Create an element with a CDATA section.
InputStream is = new ByteArrayInputStream("<test><![CDATA[hello
world]]></test>".getBytes());
- XMLStreamReader reader = factory.createXMLStreamReader(is);
+ // Make sure that the parser is non coalescing (otherwise no CDATA
events will be
+ // reported). This is not the default for Woodstox (see WSTX-140).
+ XMLStreamReader reader =
StAXUtils.createXMLStreamReader(StAXParserConfiguration.NON_COALESCING, is);
OMFactory omfactory = omMetaFactory.getOMFactory();
OMElement element = new StAXOMBuilder(omfactory,
reader).getDocumentElement();
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderUtilsTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderUtilsTest.java?rev=944793&r1=944792&r2=944793&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderUtilsTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/stax/XMLStreamReaderUtilsTest.java
Sun May 16 11:00:04 2010
@@ -23,12 +23,12 @@ import java.util.Arrays;
import java.util.Random;
import javax.activation.DataHandler;
-import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import junit.framework.TestCase;
+import org.apache.axiom.om.util.StAXParserConfiguration;
import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.util.base64.Base64EncodingStringBufferOutputStream;
import org.apache.axiom.util.stax.xop.XOPDecodingStreamReader;
@@ -165,10 +165,8 @@ public class XMLStreamReaderUtilsTest ex
out.write(data);
out.complete();
buffer.append("</test>");
- // StAXUtils return coalescing parsers, so we need to use
XMLInputFactory here
- XMLInputFactory factory = XMLInputFactory.newInstance();
- factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE);
- XMLStreamReader reader = factory.createXMLStreamReader(new
StringReader(buffer.toString()));
+ XMLStreamReader reader =
StAXUtils.createXMLStreamReader(StAXParserConfiguration.NON_COALESCING,
+ new StringReader(buffer.toString()));
if (useDHR) {
reader = new XOPDecodingStreamReader(reader, null);
}