Polishing
This commit is contained in:
parent
23925edc95
commit
93e6238f92
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
|
|
@ -24,24 +24,24 @@ import javax.xml.transform.sax.SAXResult;
|
|||
import org.xml.sax.ContentHandler;
|
||||
|
||||
/**
|
||||
* Implementation of the {@code Result} tagging interface for StAX writers. Can be constructed with a
|
||||
* {@code XMLEventConsumer} or a {@code XMLStreamWriter}.
|
||||
* Implementation of the {@code Result} tagging interface for StAX writers. Can be constructed with
|
||||
* an {@code XMLEventConsumer} or an {@code XMLStreamWriter}.
|
||||
*
|
||||
* <p>This class is necessary because there is no implementation of {@code Source} for StaxReaders in JAXP 1.3.
|
||||
* There is a {@code StAXResult} in JAXP 1.4 (JDK 1.6), but this class is kept around for back-ward compatibility
|
||||
* reasons.
|
||||
* <p>This class is necessary because there is no implementation of {@code Source} for StaxReaders
|
||||
* in JAXP 1.3. There is a {@code StAXResult} in JAXP 1.4 (JDK 1.6), but this class is kept around
|
||||
* for backwards compatibility reasons.
|
||||
*
|
||||
* <p>Even though {@code StaxResult} extends from {@code SAXResult}, calling the methods of
|
||||
* {@code SAXResult} is <strong>not supported</strong>. In general, the only supported operation on this class is
|
||||
* to use the {@code ContentHandler} obtained via {@link #getHandler()} to parse an input source using an
|
||||
* {@code XMLReader}. Calling {@link #setHandler(org.xml.sax.ContentHandler)} will result in
|
||||
* {@code UnsupportedOperationException}s.
|
||||
* {@code SAXResult} is <strong>not supported</strong>. In general, the only supported operation
|
||||
* on this class is to use the {@code ContentHandler} obtained via {@link #getHandler()} to parse an
|
||||
* input source using an {@code XMLReader}. Calling {@link #setHandler(org.xml.sax.ContentHandler)}
|
||||
* will result in {@code UnsupportedOperationException}s.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 3.0
|
||||
* @see XMLEventWriter
|
||||
* @see XMLStreamWriter
|
||||
* @see javax.xml.transform.Transformer
|
||||
* @since 3.0
|
||||
*/
|
||||
class StaxResult extends SAXResult {
|
||||
|
||||
|
|
@ -49,9 +49,9 @@ class StaxResult extends SAXResult {
|
|||
|
||||
private XMLStreamWriter streamWriter;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the {@code StaxResult} with the specified {@code XMLStreamWriter}.
|
||||
*
|
||||
* Construct a new instance of the {@code StaxResult} with the specified {@code XMLStreamWriter}.
|
||||
* @param streamWriter the {@code XMLStreamWriter} to write to
|
||||
*/
|
||||
StaxResult(XMLStreamWriter streamWriter) {
|
||||
|
|
@ -60,8 +60,7 @@ class StaxResult extends SAXResult {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the {@code StaxResult} with the specified {@code XMLEventWriter}.
|
||||
*
|
||||
* Construct a new instance of the {@code StaxResult} with the specified {@code XMLEventWriter}.
|
||||
* @param eventWriter the {@code XMLEventWriter} to write to
|
||||
*/
|
||||
StaxResult(XMLEventWriter eventWriter) {
|
||||
|
|
@ -70,9 +69,8 @@ class StaxResult extends SAXResult {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the {@code StaxResult} with the specified {@code XMLEventWriter} and
|
||||
* {@code XMLEventFactory}.
|
||||
*
|
||||
* Construct a new instance of the {@code StaxResult} with the specified {@code XMLEventWriter}
|
||||
* and {@code XMLEventFactory}.
|
||||
* @param eventWriter the {@code XMLEventWriter} to write to
|
||||
* @param eventFactory the {@code XMLEventFactory} to use for creating events
|
||||
*/
|
||||
|
|
@ -81,35 +79,35 @@ class StaxResult extends SAXResult {
|
|||
this.eventWriter = eventWriter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the {@code XMLEventWriter} used by this {@code StaxResult}. If this {@code StaxResult} was
|
||||
* created with an {@code XMLStreamWriter}, the result will be {@code null}.
|
||||
*
|
||||
* Return the {@code XMLEventWriter} used by this {@code StaxResult}. If this {@code StaxResult}
|
||||
* was created with an {@code XMLStreamWriter}, the result will be {@code null}.
|
||||
* @return the StAX event writer used by this result
|
||||
* @see #StaxResult(javax.xml.stream.XMLEventWriter)
|
||||
*/
|
||||
XMLEventWriter getXMLEventWriter() {
|
||||
return eventWriter;
|
||||
return this.eventWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@code XMLStreamWriter} used by this {@code StaxResult}. If this {@code StaxResult} was
|
||||
* created with an {@code XMLEventConsumer}, the result will be {@code null}.
|
||||
*
|
||||
* Return the {@code XMLStreamWriter} used by this {@code StaxResult}. If this {@code StaxResult}
|
||||
* was created with an {@code XMLEventConsumer}, the result will be {@code null}.
|
||||
* @return the StAX stream writer used by this result
|
||||
* @see #StaxResult(javax.xml.stream.XMLStreamWriter)
|
||||
*/
|
||||
XMLStreamWriter getXMLStreamWriter() {
|
||||
return streamWriter;
|
||||
return this.streamWriter;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws a {@code UnsupportedOperationException}.
|
||||
*
|
||||
* Throws an {@code UnsupportedOperationException}.
|
||||
* @throws UnsupportedOperationException always
|
||||
*/
|
||||
@Override
|
||||
public void setHandler(ContentHandler handler) {
|
||||
throw new UnsupportedOperationException("setHandler is not supported");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
|
|
@ -24,24 +24,24 @@ import org.xml.sax.InputSource;
|
|||
import org.xml.sax.XMLReader;
|
||||
|
||||
/**
|
||||
* Implementation of the {@code Source} tagging interface for StAX readers. Can be constructed with a
|
||||
* {@code XMLEventReader} or a {@code XMLStreamReader}.
|
||||
* Implementation of the {@code Source} tagging interface for StAX readers. Can be constructed with
|
||||
* an {@code XMLEventReader} or an {@code XMLStreamReader}.
|
||||
*
|
||||
* <p>This class is necessary because there is no implementation of {@code Source} for StAX Readers in JAXP 1.3.
|
||||
* There is a {@code StAXSource} in JAXP 1.4 (JDK 1.6), but this class is kept around for back-ward compatibility
|
||||
* reasons.
|
||||
* <p>This class is necessary because there is no implementation of {@code Source} for StAX Readers
|
||||
* in JAXP 1.3. There is a {@code StAXSource} in JAXP 1.4 (JDK 1.6), but this class is kept around
|
||||
* for backwards compatibility reasons.
|
||||
*
|
||||
* <p>Even though {@code StaxSource} extends from {@code SAXSource}, calling the methods of
|
||||
* {@code SAXSource} is <strong>not supported</strong>. In general, the only supported operation on this class is
|
||||
* to use the {@code XMLReader} obtained via {@link #getXMLReader()} to parse the input source obtained via {@link
|
||||
* #getInputSource()}. Calling {@link #setXMLReader(XMLReader)} or {@link #setInputSource(InputSource)} will result in
|
||||
* {@code UnsupportedOperationException}s.
|
||||
* {@code SAXSource} is <strong>not supported</strong>. In general, the only supported operation
|
||||
* on this class is to use the {@code XMLReader} obtained via {@link #getXMLReader()} to parse the
|
||||
* input source obtained via {@link #getInputSource()}. Calling {@link #setXMLReader(XMLReader)}
|
||||
* or {@link #setInputSource(InputSource)} will result in {@code UnsupportedOperationException}s.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 3.0
|
||||
* @see XMLEventReader
|
||||
* @see XMLStreamReader
|
||||
* @see javax.xml.transform.Transformer
|
||||
* @since 3.0
|
||||
*/
|
||||
class StaxSource extends SAXSource {
|
||||
|
||||
|
|
@ -49,11 +49,11 @@ class StaxSource extends SAXSource {
|
|||
|
||||
private XMLStreamReader streamReader;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the {@code StaxSource} with the specified {@code XMLStreamReader}. The
|
||||
* supplied stream reader must be in {@code XMLStreamConstants.START_DOCUMENT} or
|
||||
* Construct a new instance of the {@code StaxSource} with the specified {@code XMLStreamReader}.
|
||||
* The supplied stream reader must be in {@code XMLStreamConstants.START_DOCUMENT} or
|
||||
* {@code XMLStreamConstants.START_ELEMENT} state.
|
||||
*
|
||||
* @param streamReader the {@code XMLStreamReader} to read from
|
||||
* @throws IllegalStateException if the reader is not at the start of a document or element
|
||||
*/
|
||||
|
|
@ -63,10 +63,9 @@ class StaxSource extends SAXSource {
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the {@code StaxSource} with the specified {@code XMLEventReader}. The
|
||||
* supplied event reader must be in {@code XMLStreamConstants.START_DOCUMENT} or
|
||||
* Construct a new instance of the {@code StaxSource} with the specified {@code XMLEventReader}.
|
||||
* The supplied event reader must be in {@code XMLStreamConstants.START_DOCUMENT} or
|
||||
* {@code XMLStreamConstants.START_ELEMENT} state.
|
||||
*
|
||||
* @param eventReader the {@code XMLEventReader} to read from
|
||||
* @throws IllegalStateException if the reader is not at the start of a document or element
|
||||
*/
|
||||
|
|
@ -75,31 +74,30 @@ class StaxSource extends SAXSource {
|
|||
this.eventReader = eventReader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the {@code XMLEventReader} used by this {@code StaxSource}. If this {@code StaxSource} was
|
||||
* created with an {@code XMLStreamReader}, the result will be {@code null}.
|
||||
*
|
||||
* Return the {@code XMLEventReader} used by this {@code StaxSource}. If this {@code StaxSource}
|
||||
* was created with an {@code XMLStreamReader}, the result will be {@code null}.
|
||||
* @return the StAX event reader used by this source
|
||||
* @see StaxSource#StaxSource(javax.xml.stream.XMLEventReader)
|
||||
*/
|
||||
XMLEventReader getXMLEventReader() {
|
||||
return eventReader;
|
||||
return this.eventReader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@code XMLStreamReader} used by this {@code StaxSource}. If this {@code StaxSource} was
|
||||
* created with an {@code XMLEventReader}, the result will be {@code null}.
|
||||
*
|
||||
* Return the {@code XMLStreamReader} used by this {@code StaxSource}. If this {@code StaxSource}
|
||||
* was created with an {@code XMLEventReader}, the result will be {@code null}.
|
||||
* @return the StAX event reader used by this source
|
||||
* @see StaxSource#StaxSource(javax.xml.stream.XMLEventReader)
|
||||
*/
|
||||
XMLStreamReader getXMLStreamReader() {
|
||||
return streamReader;
|
||||
return this.streamReader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Throws a {@code UnsupportedOperationException}.
|
||||
*
|
||||
* Throws an {@code UnsupportedOperationException}.
|
||||
* @throws UnsupportedOperationException always
|
||||
*/
|
||||
@Override
|
||||
|
|
@ -108,12 +106,12 @@ class StaxSource extends SAXSource {
|
|||
}
|
||||
|
||||
/**
|
||||
* Throws a {@code UnsupportedOperationException}.
|
||||
*
|
||||
* Throws an {@code UnsupportedOperationException}.
|
||||
* @throws UnsupportedOperationException always
|
||||
*/
|
||||
@Override
|
||||
public void setXMLReader(XMLReader reader) {
|
||||
throw new UnsupportedOperationException("setXMLReader is not supported");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
|
|
@ -45,14 +45,15 @@ import org.springframework.util.ClassUtils;
|
|||
*/
|
||||
public abstract class StaxUtils {
|
||||
|
||||
// JAXP 1.4 is only available on JDK 1.6+
|
||||
private static boolean jaxp14Available =
|
||||
ClassUtils.isPresent("javax.xml.transform.stax.StAXSource", StaxUtils.class.getClassLoader());
|
||||
|
||||
|
||||
// Stax Source
|
||||
|
||||
/**
|
||||
* Create a custom, non-JAXP 1.4 StAX {@link Source} for the given {@link XMLStreamReader}.
|
||||
*
|
||||
* @param streamReader the StAX stream reader
|
||||
* @return a source wrapping the {@code streamReader}
|
||||
*/
|
||||
|
|
@ -62,9 +63,8 @@ public abstract class StaxUtils {
|
|||
|
||||
/**
|
||||
* Create a StAX {@link Source} for the given {@link XMLStreamReader}.
|
||||
*
|
||||
* <p>If JAXP 1.4 is available, this method returns a {@link StAXSource}; otherwise it returns a
|
||||
* custom StAX Source.
|
||||
* <p>If JAXP 1.4 is available, this method returns a {@link StAXSource};
|
||||
* otherwise it returns a custom StAX Source.
|
||||
* @param streamReader the StAX stream reader
|
||||
* @return a source wrapping the {@code streamReader}
|
||||
* @see #createCustomStaxSource(XMLStreamReader)
|
||||
|
|
@ -80,7 +80,6 @@ public abstract class StaxUtils {
|
|||
|
||||
/**
|
||||
* Create a custom, non-JAXP 1.4 StAX {@link Source} for the given {@link XMLEventReader}.
|
||||
*
|
||||
* @param eventReader the StAX event reader
|
||||
* @return a source wrapping the {@code eventReader}
|
||||
*/
|
||||
|
|
@ -90,9 +89,8 @@ public abstract class StaxUtils {
|
|||
|
||||
/**
|
||||
* Create a StAX {@link Source} for the given {@link XMLEventReader}.
|
||||
*
|
||||
* <p>If JAXP 1.4 is available, this method returns a {@link StAXSource}; otherwise it returns a
|
||||
* custom StAX Source.
|
||||
* <p>If JAXP 1.4 is available, this method returns a {@link StAXSource};
|
||||
* otherwise it returns a custom StAX Source.
|
||||
* @param eventReader the StAX event reader
|
||||
* @return a source wrapping the {@code eventReader}
|
||||
* @throws XMLStreamException in case of StAX errors
|
||||
|
|
@ -116,11 +114,11 @@ public abstract class StaxUtils {
|
|||
return (source instanceof StaxSource || (jaxp14Available && Jaxp14StaxHandler.isStaxSource(source)));
|
||||
}
|
||||
|
||||
|
||||
// Stax Result
|
||||
|
||||
/**
|
||||
* Create a custom, non-JAXP 1.4 StAX {@link Result} for the given {@link XMLStreamWriter}.
|
||||
*
|
||||
* @param streamWriter the StAX stream writer
|
||||
* @return a source wrapping the {@code streamWriter}
|
||||
*/
|
||||
|
|
@ -130,9 +128,8 @@ public abstract class StaxUtils {
|
|||
|
||||
/**
|
||||
* Create a StAX {@link Result} for the given {@link XMLStreamWriter}.
|
||||
*
|
||||
* <p>If JAXP 1.4 is available, this method returns a {@link StAXResult}; otherwise it returns a
|
||||
* custom StAX Result.
|
||||
* <p>If JAXP 1.4 is available, this method returns a {@link StAXResult};
|
||||
* otherwise it returns a custom StAX Result.
|
||||
* @param streamWriter the StAX stream writer
|
||||
* @return a result wrapping the {@code streamWriter}
|
||||
* @see #createCustomStaxResult(XMLStreamWriter)
|
||||
|
|
@ -148,7 +145,6 @@ public abstract class StaxUtils {
|
|||
|
||||
/**
|
||||
* Create a custom, non-JAXP 1.4 StAX {@link Result} for the given {@link XMLEventWriter}.
|
||||
*
|
||||
* @param eventWriter the StAX event writer
|
||||
* @return a source wrapping the {@code eventWriter}
|
||||
*/
|
||||
|
|
@ -158,7 +154,6 @@ public abstract class StaxUtils {
|
|||
|
||||
/**
|
||||
* Create a StAX {@link Result} for the given {@link XMLEventWriter}.
|
||||
*
|
||||
* <p>If JAXP 1.4 is available, this method returns a {@link StAXResult}; otherwise it returns a
|
||||
* custom StAX Result.
|
||||
* @param eventWriter the StAX event writer
|
||||
|
|
@ -177,8 +172,8 @@ public abstract class StaxUtils {
|
|||
|
||||
/**
|
||||
* Indicate whether the given {@link javax.xml.transform.Result} is a StAX Result.
|
||||
* @return {@code true} if {@code result} is a custom Stax Result or JAXP
|
||||
* 1.4 {@link StAXResult}; {@code false} otherwise.
|
||||
* @return {@code true} if {@code result} is a custom Stax Result or JAXP 1.4
|
||||
* {@link StAXResult}; {@code false} otherwise.
|
||||
*/
|
||||
public static boolean isStaxResult(Result result) {
|
||||
return (result instanceof StaxResult || (jaxp14Available && Jaxp14StaxHandler.isStaxResult(result)));
|
||||
|
|
@ -327,6 +322,7 @@ public abstract class StaxUtils {
|
|||
return new XMLEventStreamWriter(eventWriter, eventFactory);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a static JAXP 1.4 dependency.
|
||||
*/
|
||||
|
|
@ -349,11 +345,11 @@ public abstract class StaxUtils {
|
|||
}
|
||||
|
||||
private static boolean isStaxSource(Source source) {
|
||||
return source instanceof StAXSource;
|
||||
return (source instanceof StAXSource);
|
||||
}
|
||||
|
||||
private static boolean isStaxResult(Result result) {
|
||||
return result instanceof StAXResult;
|
||||
return (result instanceof StAXResult);
|
||||
}
|
||||
|
||||
private static XMLStreamReader getXMLStreamReader(Source source) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue