revised OXM package: no provider-specific exceptions anymore, etc
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,8 +31,7 @@ public abstract class Md5HashUtils {
|
||||
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
/**
|
||||
* Calculates the MD5 hash of the given bytes.
|
||||
*
|
||||
* Calculate the MD5 hash of the given bytes.
|
||||
* @param bytes the bytes to calculate the hash over
|
||||
* @return the hash
|
||||
*/
|
||||
@@ -59,8 +58,7 @@ public abstract class Md5HashUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hex string representation of the MD5 hash of the given bytes.
|
||||
*
|
||||
* Return a hex string representation of the MD5 hash of the given bytes.
|
||||
* @param bytes the bytes to calculate the hash over
|
||||
* @return a hexadecimal hash string
|
||||
*/
|
||||
@@ -69,9 +67,8 @@ public abstract class Md5HashUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends a hex string representation of the MD5 hash of the given bytes to the given {@link StringBuilder}.
|
||||
*
|
||||
* @param bytes the bytes to calculate the hash over
|
||||
* Append a hex string representation of the MD5 hash of the given bytes to the given {@link StringBuilder}.
|
||||
* @param bytes the bytes to calculate the hash over
|
||||
* @param builder the string builder to append the hash to
|
||||
* @return the given string builder
|
||||
*/
|
||||
|
||||
@@ -34,11 +34,11 @@ import org.springframework.util.StringUtils;
|
||||
* Abstract base class for SAX <code>XMLReader</code> implementations that use StAX as a basis.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 3.0
|
||||
* @see #setContentHandler(org.xml.sax.ContentHandler)
|
||||
* @see #setDTDHandler(org.xml.sax.DTDHandler)
|
||||
* @see #setEntityResolver(org.xml.sax.EntityResolver)
|
||||
* @see #setErrorHandler(org.xml.sax.ErrorHandler)
|
||||
* @since 3.0
|
||||
*/
|
||||
abstract class AbstractStaxXMLReader extends AbstractXMLReader {
|
||||
|
||||
@@ -48,23 +48,25 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader {
|
||||
|
||||
private static final String IS_STANDALONE_FEATURE_NAME = "http://xml.org/sax/features/is-standalone";
|
||||
|
||||
|
||||
private boolean namespacesFeature = true;
|
||||
|
||||
private boolean namespacePrefixesFeature = false;
|
||||
|
||||
private Boolean isStandalone;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException {
|
||||
if (NAMESPACES_FEATURE_NAME.equals(name)) {
|
||||
return namespacesFeature;
|
||||
return this.namespacesFeature;
|
||||
}
|
||||
else if (NAMESPACE_PREFIXES_FEATURE_NAME.equals(name)) {
|
||||
return namespacePrefixesFeature;
|
||||
return this.namespacePrefixesFeature;
|
||||
}
|
||||
else if (IS_STANDALONE_FEATURE_NAME.equals(name)) {
|
||||
if (isStandalone != null) {
|
||||
return isStandalone;
|
||||
if (this.isStandalone != null) {
|
||||
return this.isStandalone;
|
||||
}
|
||||
else {
|
||||
throw new SAXNotSupportedException("startDocument() callback not completed yet");
|
||||
@@ -88,35 +90,66 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader {
|
||||
}
|
||||
}
|
||||
|
||||
/** Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces</code> is turned on. */
|
||||
protected boolean hasNamespacesFeature() {
|
||||
return namespacesFeature;
|
||||
}
|
||||
|
||||
/** Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces-prefixes</code> is turned on. */
|
||||
protected boolean hasNamespacePrefixesFeature() {
|
||||
return namespacePrefixesFeature;
|
||||
}
|
||||
|
||||
protected void setStandalone(boolean standalone) {
|
||||
isStandalone = (standalone) ? Boolean.TRUE : Boolean.FALSE;
|
||||
this.isStandalone = standalone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the StAX XML reader passed at construction-time. <p/> <strong>Note</strong> that the given
|
||||
* <code>InputSource</code> is not read, but ignored.
|
||||
*
|
||||
* Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces</code> is turned on.
|
||||
*/
|
||||
protected boolean hasNamespacesFeature() {
|
||||
return this.namespacesFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the SAX feature <code>http://xml.org/sax/features/namespaces-prefixes</code> is turned on.
|
||||
*/
|
||||
protected boolean hasNamespacePrefixesFeature() {
|
||||
return this.namespacePrefixesFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sett the SAX <code>Locator</code> based on the given StAX <code>Location</code>.
|
||||
* @param location the location
|
||||
* @see ContentHandler#setDocumentLocator(org.xml.sax.Locator)
|
||||
*/
|
||||
protected void setLocator(Location location) {
|
||||
if (getContentHandler() != null) {
|
||||
getContentHandler().setDocumentLocator(new StaxLocator(location));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a <code>QName</code> to a qualified name, as used by DOM and SAX.
|
||||
* The returned string has a format of <code>prefix:localName</code> if the
|
||||
* prefix is set, or just <code>localName</code> if not.
|
||||
* @param qName the <code>QName</code>
|
||||
* @return the qualified name
|
||||
*/
|
||||
protected String toQualifiedName(QName qName) {
|
||||
String prefix = qName.getPrefix();
|
||||
if (!StringUtils.hasLength(prefix)) {
|
||||
return qName.getLocalPart();
|
||||
}
|
||||
else {
|
||||
return prefix + ":" + qName.getLocalPart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse the StAX XML reader passed at construction-time.
|
||||
* <p><b>NOTE:</b>: The given <code>InputSource</code> is not read, but ignored.
|
||||
* @param ignored is ignored
|
||||
* @throws SAXException A SAX exception, possibly wrapping a <code>XMLStreamException</code>
|
||||
* @throws SAXException a SAX exception, possibly wrapping a <code>XMLStreamException</code>
|
||||
*/
|
||||
public final void parse(InputSource ignored) throws SAXException {
|
||||
parse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the StAX XML reader passed at construction-time. <p/> <strong>Note</strong> that the given system identifier
|
||||
* is not read, but ignored.
|
||||
*
|
||||
* Parse the StAX XML reader passed at construction-time.
|
||||
* <p><b>NOTE:</b>: The given system identifier is not read, but ignored.
|
||||
* @param ignored is ignored
|
||||
* @throws SAXException A SAX exception, possibly wrapping a <code>XMLStreamException</code>
|
||||
*/
|
||||
@@ -144,40 +177,13 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the SAX <code>Locator</code> based on the given StAX <code>Location</code>.
|
||||
*
|
||||
* @param location the location
|
||||
* @see ContentHandler#setDocumentLocator(org.xml.sax.Locator)
|
||||
* Template-method that parses the StAX reader passed at construction-time.
|
||||
*/
|
||||
protected void setLocator(Location location) {
|
||||
if (getContentHandler() != null) {
|
||||
getContentHandler().setDocumentLocator(new StaxLocator(location));
|
||||
}
|
||||
}
|
||||
|
||||
/** Template-method that parses the StAX reader passed at construction-time. */
|
||||
protected abstract void parseInternal() throws SAXException, XMLStreamException;
|
||||
|
||||
/**
|
||||
* Convert a <code>QName</code> to a qualified name, as used by DOM and SAX. The returned string has a format of
|
||||
* <code>prefix:localName</code> if the prefix is set, or just <code>localName</code> if not.
|
||||
*
|
||||
* @param qName the <code>QName</code>
|
||||
* @return the qualified name
|
||||
*/
|
||||
protected String toQualifiedName(QName qName) {
|
||||
String prefix = qName.getPrefix();
|
||||
if (!StringUtils.hasLength(prefix)) {
|
||||
return qName.getLocalPart();
|
||||
}
|
||||
else {
|
||||
return prefix + ":" + qName.getLocalPart();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the <code>Locator</code> interface that is based on a StAX <code>Location</code>.
|
||||
*
|
||||
* @see Locator
|
||||
* @see Location
|
||||
*/
|
||||
@@ -205,4 +211,5 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader {
|
||||
return location.getColumnNumber();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed 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.springframework.util.xml;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Helper class used to find the current version of JAXP. We cannot depend on the Java version, since JAXP can be
|
||||
* upgraded independently of the Java version. <p/> Only distinguishes between JAXP 1.0, 1.1, 1.3, and 1.4, since JAXP
|
||||
* 1.2 was a maintenance release with no new classes.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 3.0.0
|
||||
*/
|
||||
abstract class JaxpVersion {
|
||||
|
||||
public static final int JAXP_10 = 0;
|
||||
|
||||
public static final int JAXP_11 = 1;
|
||||
|
||||
public static final int JAXP_13 = 3;
|
||||
|
||||
public static final int JAXP_14 = 4;
|
||||
|
||||
private static final String JAXP_14_CLASS_NAME = "javax.xml.transform.stax.StAXSource";
|
||||
|
||||
private static int jaxpVersion;
|
||||
|
||||
static {
|
||||
try {
|
||||
ClassUtils.forName(JAXP_14_CLASS_NAME);
|
||||
jaxpVersion = JAXP_14;
|
||||
}
|
||||
catch (ClassNotFoundException ignored) {
|
||||
// default to JAXP 1.3, since Spring 3 requires JDK 1.5
|
||||
jaxpVersion = JAXP_13;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the JAXP version. This means we can do things like if <code>(getJaxpVersion() < JAXP_13)</code>.
|
||||
*
|
||||
* @return a code comparable to the JAXP_XX codes in this class
|
||||
* @see #JAXP_10
|
||||
* @see #JAXP_11
|
||||
* @see #JAXP_13
|
||||
* @see #JAXP_14
|
||||
*/
|
||||
public static int getJaxpVersion() {
|
||||
return jaxpVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to determine if the current JAXP version is at least 1.3 (packaged with JDK 1.5).
|
||||
*
|
||||
* @return <code>true</code> if the current JAXP version is at least JAXP 1.3
|
||||
* @see #getJaxpVersion()
|
||||
* @see #JAXP_13
|
||||
*/
|
||||
public static boolean isAtLeastJaxp13() {
|
||||
return getJaxpVersion() >= JAXP_13;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to determine if the current JAXP version is at least 1.4 (packaged with JDK 1.6).
|
||||
*
|
||||
* @return <code>true</code> if the current JAXP version is at least JAXP 1.4
|
||||
* @see #getJaxpVersion()
|
||||
* @see #JAXP_14
|
||||
*/
|
||||
public static boolean isAtLeastJaxp14() {
|
||||
return getJaxpVersion() >= JAXP_14;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed 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.springframework.util.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* Convenient utility methods for dealing with SAX.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 3.0
|
||||
*/
|
||||
public abstract class SaxUtils {
|
||||
|
||||
/**
|
||||
* Creates a SAX <code>InputSource</code> from the given resource. Sets the system identifier to the resource's
|
||||
* <code>URL</code>, if available.
|
||||
*
|
||||
* @param resource the resource
|
||||
* @return the input source created from the resource
|
||||
* @throws IOException if an I/O exception occurs
|
||||
* @see InputSource#setSystemId(String)
|
||||
* @see #getSystemId(org.springframework.core.io.Resource)
|
||||
*/
|
||||
public static InputSource createInputSource(Resource resource) throws IOException {
|
||||
InputSource inputSource = new InputSource(resource.getInputStream());
|
||||
inputSource.setSystemId(getSystemId(resource));
|
||||
return inputSource;
|
||||
}
|
||||
|
||||
/** Retrieves the URL from the given resource as System ID. Returns <code>null</code> if it cannot be openened. */
|
||||
private static String getSystemId(Resource resource) {
|
||||
try {
|
||||
return resource.getURI().toString();
|
||||
}
|
||||
catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,27 +30,32 @@ import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Convenience methods for working with the StAX API.
|
||||
*
|
||||
* In particular, methods for using StAX in combination with the TrAX API (<code>javax.xml.transform</code>), and
|
||||
* converting StAX readers/writers into SAX readers/handlers and vice-versa.
|
||||
* <p>In particular, methods for using StAX in combination with the TrAX API
|
||||
* (<code>javax.xml.transform</code>), and converting StAX readers/writers
|
||||
* into SAX readers/handlers and vice-versa.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
*/
|
||||
public abstract class StaxUtils {
|
||||
|
||||
private static boolean jaxp14Available =
|
||||
ClassUtils.isPresent("javax.xml.transform.stax.StAXSource", StaxUtils.class.getClassLoader());
|
||||
|
||||
|
||||
/**
|
||||
* Creates a StAX {@link Source} for the given {@link XMLStreamReader}. Returns a {@link StAXSource} under JAXP 1.4 or
|
||||
* higher, or a {@link StaxSource} otherwise.
|
||||
*
|
||||
* Create a StAX {@link Source} for the given {@link XMLStreamReader}.
|
||||
* @param streamReader the StAX stream reader
|
||||
* @return a source wrapping <code>streamReader</code>
|
||||
*/
|
||||
public static Source createStaxSource(XMLStreamReader streamReader) {
|
||||
if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
if (jaxp14Available) {
|
||||
return Jaxp14StaxHandler.createStaxSource(streamReader);
|
||||
}
|
||||
else {
|
||||
@@ -59,15 +64,13 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a StAX {@link Source} for the given {@link XMLEventReader}. Returns a {@link StAXSource} under JAXP 1.4 or
|
||||
* higher, or a {@link StaxSource} otherwise.
|
||||
*
|
||||
* Create a StAX {@link Source} for the given {@link XMLEventReader}.
|
||||
* @param eventReader the StAX event reader
|
||||
* @return a source wrapping <code>streamReader</code>
|
||||
* @throws XMLStreamException in case of StAX errors
|
||||
*/
|
||||
public static Source createStaxSource(XMLEventReader eventReader) throws XMLStreamException {
|
||||
if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
if (jaxp14Available) {
|
||||
return Jaxp14StaxHandler.createStaxSource(eventReader);
|
||||
}
|
||||
else {
|
||||
@@ -76,14 +79,21 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a StAX {@link Result} for the given {@link XMLStreamWriter}. Returns a {@link StAXResult} under JAXP 1.4 or
|
||||
* higher, or a {@link StaxResult} otherwise.
|
||||
*
|
||||
* Indicate whether the given {@link javax.xml.transform.Source} is a StAX Source.
|
||||
* @return <code>true</code> if <code>source</code> is a Spring StaxSource or JAXP
|
||||
* 1.4 {@link javax.xml.transform.stax.StAXSource}; <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isStaxSource(Source source) {
|
||||
return (source instanceof StaxSource || (jaxp14Available && Jaxp14StaxHandler.isStaxSource(source)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a StAX {@link Result} for the given {@link XMLStreamWriter}.
|
||||
* @param streamWriter the StAX stream writer
|
||||
* @return a result wrapping <code>streamWriter</code>
|
||||
*/
|
||||
public static Result createStaxResult(XMLStreamWriter streamWriter) {
|
||||
if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
if (jaxp14Available) {
|
||||
return Jaxp14StaxHandler.createStaxResult(streamWriter);
|
||||
}
|
||||
else {
|
||||
@@ -92,15 +102,13 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a StAX {@link Result} for the given {@link XMLEventWriter}. Returns a {@link StAXResult} under JAXP 1.4 or
|
||||
* higher, or a {@link StaxResult} otherwise.
|
||||
*
|
||||
* Create a StAX {@link Result} for the given {@link XMLEventWriter}.
|
||||
* @param eventWriter the StAX event writer
|
||||
* @return a result wrapping <code>streamReader</code>
|
||||
* @throws XMLStreamException in case of StAX errors
|
||||
*/
|
||||
public static Result createStaxResult(XMLEventWriter eventWriter) throws XMLStreamException {
|
||||
if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
if (jaxp14Available) {
|
||||
return Jaxp14StaxHandler.createStaxResult(eventWriter);
|
||||
}
|
||||
else {
|
||||
@@ -109,54 +117,26 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the given {@link javax.xml.transform.Source} is a StAX Source.
|
||||
*
|
||||
* @return <code>true</code> if <code>source</code> is a Spring {@link org.springframework.util.xml.StaxSource} or JAXP
|
||||
* 1.4 {@link javax.xml.transform.stax.StAXSource}; <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isStaxSource(Source source) {
|
||||
if (source instanceof StaxSource) {
|
||||
return true;
|
||||
}
|
||||
else if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
return Jaxp14StaxHandler.isStaxSource(source);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the given {@link javax.xml.transform.Result} is a StAX Result.
|
||||
*
|
||||
* @return <code>true</code> if <code>result</code> is a Spring {@link org.springframework.util.xml.StaxResult} or JAXP
|
||||
* 1.4 {@link javax.xml.transform.stax.StAXResult}; <code>false</code> otherwise.
|
||||
* Indicate whether the given {@link javax.xml.transform.Result} is a StAX Result.
|
||||
* @return <code>true</code> if <code>result</code> is a Spring StaxResult or JAXP
|
||||
* 1.4 {@link javax.xml.transform.stax.StAXResult}; <code>false</code> otherwise.
|
||||
*/
|
||||
public static boolean isStaxResult(Result result) {
|
||||
if (result instanceof StaxResult) {
|
||||
return true;
|
||||
}
|
||||
else if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
return Jaxp14StaxHandler.isStaxResult(result);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return (result instanceof StaxResult || (jaxp14Available && Jaxp14StaxHandler.isStaxResult(result)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link javax.xml.stream.XMLStreamReader} for the given StAX Source.
|
||||
*
|
||||
* @param source a Spring {@link org.springframework.util.xml.StaxSource} or {@link javax.xml.transform.stax.StAXSource}
|
||||
* Return the {@link javax.xml.stream.XMLStreamReader} for the given StAX Source.
|
||||
* @param source a Spring StaxSource or JAXP 1.4 {@link javax.xml.transform.stax.StAXSource}
|
||||
* @return the {@link javax.xml.stream.XMLStreamReader}
|
||||
* @throws IllegalArgumentException if <code>source</code> is neither a Spring-WS {@link org.springframework.util.xml.StaxSource}
|
||||
* or {@link javax.xml.transform.stax.StAXSource}
|
||||
* @throws IllegalArgumentException if <code>source</code> is neither a Spring StaxSource
|
||||
* nor JAXP 1.4 {@link javax.xml.transform.stax.StAXSource}
|
||||
*/
|
||||
public static XMLStreamReader getXMLStreamReader(Source source) {
|
||||
if (source instanceof StaxSource) {
|
||||
return ((StaxSource) source).getXMLStreamReader();
|
||||
}
|
||||
else if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
else if (jaxp14Available) {
|
||||
return Jaxp14StaxHandler.getXMLStreamReader(source);
|
||||
}
|
||||
else {
|
||||
@@ -165,18 +145,17 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link javax.xml.stream.XMLEventReader} for the given StAX Source.
|
||||
*
|
||||
* @param source a Spring {@link org.springframework.util.xml.StaxSource} or {@link javax.xml.transform.stax.StAXSource}
|
||||
* Return the {@link javax.xml.stream.XMLEventReader} for the given StAX Source.
|
||||
* @param source a Spring StaxSource or JAXP 1.4 {@link javax.xml.transform.stax.StAXSource}
|
||||
* @return the {@link javax.xml.stream.XMLEventReader}
|
||||
* @throws IllegalArgumentException if <code>source</code> is neither a Spring {@link org.springframework.util.xml.StaxSource}
|
||||
* or {@link javax.xml.transform.stax.StAXSource}
|
||||
* @throws IllegalArgumentException if <code>source</code> is neither a Spring StaxSource
|
||||
* nor a JAXP 1.4 {@link javax.xml.transform.stax.StAXSource}
|
||||
*/
|
||||
public static XMLEventReader getXMLEventReader(Source source) {
|
||||
if (source instanceof StaxSource) {
|
||||
return ((StaxSource) source).getXMLEventReader();
|
||||
}
|
||||
else if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
else if (jaxp14Available) {
|
||||
return Jaxp14StaxHandler.getXMLEventReader(source);
|
||||
}
|
||||
else {
|
||||
@@ -185,18 +164,17 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link javax.xml.stream.XMLStreamWriter} for the given StAX Result.
|
||||
*
|
||||
* @param result a Spring {@link org.springframework.util.xml.StaxResult} or {@link javax.xml.transform.stax.StAXResult}
|
||||
* Return the {@link javax.xml.stream.XMLStreamWriter} for the given StAX Result.
|
||||
* @param result a Spring StaxResult or JAXP 1.4 {@link javax.xml.transform.stax.StAXResult}
|
||||
* @return the {@link javax.xml.stream.XMLStreamReader}
|
||||
* @throws IllegalArgumentException if <code>source</code> is neither a Spring {@link org.springframework.util.xml.StaxResult}
|
||||
* or {@link javax.xml.transform.stax.StAXResult}
|
||||
* @throws IllegalArgumentException if <code>source</code> is neither a Spring StaxResult
|
||||
* nor a JAXP 1.4 {@link javax.xml.transform.stax.StAXResult}
|
||||
*/
|
||||
public static XMLStreamWriter getXMLStreamWriter(Result result) {
|
||||
if (result instanceof StaxResult) {
|
||||
return ((StaxResult) result).getXMLStreamWriter();
|
||||
}
|
||||
else if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
else if (jaxp14Available) {
|
||||
return Jaxp14StaxHandler.getXMLStreamWriter(result);
|
||||
}
|
||||
else {
|
||||
@@ -205,18 +183,17 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link XMLEventWriter} for the given StAX Result.
|
||||
*
|
||||
* @param result a Spring {@link org.springframework.util.xml.StaxResult} or {@link javax.xml.transform.stax.StAXResult}
|
||||
* Return the {@link XMLEventWriter} for the given StAX Result.
|
||||
* @param result a Spring StaxResult or JAXP 1.4 {@link javax.xml.transform.stax.StAXResult}
|
||||
* @return the {@link javax.xml.stream.XMLStreamReader}
|
||||
* @throws IllegalArgumentException if <code>source</code> is neither a Spring {@link org.springframework.util.xml.StaxResult}
|
||||
* or {@link javax.xml.transform.stax.StAXResult}
|
||||
* @throws IllegalArgumentException if <code>source</code> is neither a Spring StaxResult
|
||||
* nor a JAXP 1.4 {@link javax.xml.transform.stax.StAXResult}
|
||||
*/
|
||||
public static XMLEventWriter getXMLEventWriter(Result result) {
|
||||
if (result instanceof StaxResult) {
|
||||
return ((StaxResult) result).getXMLEventWriter();
|
||||
}
|
||||
else if (JaxpVersion.isAtLeastJaxp14()) {
|
||||
else if (jaxp14Available) {
|
||||
return Jaxp14StaxHandler.getXMLEventWriter(result);
|
||||
}
|
||||
else {
|
||||
@@ -225,8 +202,7 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SAX {@link ContentHandler} that writes to the given StAX {@link XMLStreamWriter}.
|
||||
*
|
||||
* Create a SAX {@link ContentHandler} that writes to the given StAX {@link XMLStreamWriter}.
|
||||
* @param streamWriter the StAX stream writer
|
||||
* @return a content handler writing to the <code>streamWriter</code>
|
||||
*/
|
||||
@@ -235,8 +211,7 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SAX {@link ContentHandler} that writes events to the given StAX {@link XMLEventWriter}.
|
||||
*
|
||||
* Create a SAX {@link ContentHandler} that writes events to the given StAX {@link XMLEventWriter}.
|
||||
* @param eventWriter the StAX event writer
|
||||
* @return a content handler writing to the <code>eventWriter</code>
|
||||
*/
|
||||
@@ -245,8 +220,7 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SAX {@link XMLReader} that reads from the given StAX {@link XMLStreamReader}.
|
||||
*
|
||||
* Create a SAX {@link XMLReader} that reads from the given StAX {@link XMLStreamReader}.
|
||||
* @param streamReader the StAX stream reader
|
||||
* @return a XMLReader reading from the <code>streamWriter</code>
|
||||
*/
|
||||
@@ -255,8 +229,7 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a SAX {@link XMLReader} that reads from the given StAX {@link XMLEventReader}.
|
||||
*
|
||||
* Create a SAX {@link XMLReader} that reads from the given StAX {@link XMLEventReader}.
|
||||
* @param eventReader the StAX event reader
|
||||
* @return a XMLReader reading from the <code>eventWriter</code>
|
||||
*/
|
||||
@@ -265,16 +238,18 @@ public abstract class StaxUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link XMLStreamReader} that reads from a {@link XMLEventReader}. Useful, because the StAX
|
||||
* Return a {@link XMLStreamReader} that reads from a {@link XMLEventReader}. Useful, because the StAX
|
||||
* <code>XMLInputFactory</code> allows one to create a event reader from a stream reader, but not vice-versa.
|
||||
*
|
||||
* @return a stream reader that reads from an event reader
|
||||
*/
|
||||
public static XMLStreamReader createEventStreamReader(XMLEventReader eventReader) throws XMLStreamException {
|
||||
return new XMLEventStreamReader(eventReader);
|
||||
}
|
||||
|
||||
/** Inner class to avoid a static JAXP 1.4 dependency. */
|
||||
|
||||
/**
|
||||
* Inner class to avoid a static JAXP 1.4 dependency.
|
||||
*/
|
||||
private static class Jaxp14StaxHandler {
|
||||
|
||||
private static Source createStaxSource(XMLStreamReader streamReader) {
|
||||
|
||||
Reference in New Issue
Block a user