You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2022/06/03 22:10:33 UTC
[ws-axiom] branch master updated: Enforce consistent formatting in core-streams
This is an automated email from the ASF dual-hosted git repository.
veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
The following commit(s) were added to refs/heads/master by this push:
new c8d627b5c Enforce consistent formatting in core-streams
c8d627b5c is described below
commit c8d627b5c93908363c36f5b1a0df2a6f386bb71f
Author: Andreas Veithen <an...@gmail.com>
AuthorDate: Fri Jun 3 21:46:52 2022 +0000
Enforce consistent formatting in core-streams
---
components/core-streams/pom.xml | 16 ++
.../apache/axiom/core/stream/CharacterData.java | 2 +
.../axiom/core/stream/CharacterDataSink.java | 1 +
.../DocumentElementExtractingFilterHandler.java | 19 +-
.../apache/axiom/core/stream/FilteredXmlInput.java | 2 +-
.../core/stream/NamespaceRepairingFilter.java | 11 +-
.../stream/NamespaceRepairingFilterHandler.java | 57 +++--
.../stream/NamespaceURIInterningFilterHandler.java | 15 +-
.../apache/axiom/core/stream/NullXmlHandler.java | 69 +++---
.../apache/axiom/core/stream/StreamException.java | 4 +-
.../org/apache/axiom/core/stream/XmlHandler.java | 157 ++++++------
.../axiom/core/stream/XmlHandlerWrapper.java | 20 +-
.../org/apache/axiom/core/stream/XmlReader.java | 8 +-
.../axiom/core/stream/dom/input/DOMInput.java | 22 +-
.../axiom/core/stream/dom/input/DOMReader.java | 70 ++++--
.../axiom/core/stream/sax/input/SAXInput.java | 4 +-
.../axiom/core/stream/sax/input/SAXReader.java | 10 +-
.../stream/sax/input/XmlHandlerContentHandler.java | 122 +++++-----
.../stream/sax/output/ContentHandlerWriter.java | 6 +-
.../sax/output/ContentHandlerXmlHandler.java | 61 +++--
.../axiom/core/stream/serializer/Serializer.java | 270 ++++++++++-----------
.../core/stream/serializer/SerializerWriter.java | 10 +-
.../writer/ASCIICompatibleXmlWriter.java | 31 ++-
.../stream/serializer/writer/Latin1XmlWriter.java | 8 +-
.../serializer/writer/OutputStreamXmlWriter.java | 32 +--
.../stream/serializer/writer/UTF8XmlWriter.java | 21 +-
.../writer/UnmappableCharacterHandler.java | 31 ++-
.../stream/serializer/writer/WriterXmlWriter.java | 7 +-
.../core/stream/serializer/writer/XmlWriter.java | 10 +-
.../axiom/core/stream/stax/StAXExceptionUtil.java | 8 +-
.../core/stream/stax/pull/input/StAXPullInput.java | 11 +-
.../stream/stax/pull/input/StAXPullReader.java | 123 +++++-----
.../stream/stax/pull/output/DummyLocation.java | 9 +-
.../stax/pull/output/InternalXMLStreamReader.java | 3 +
.../core/stream/stax/pull/output/StAXPivot.java | 231 +++++++++++-------
.../XMLStreamWriterNamespaceContextProvider.java | 45 ++--
.../stax/push/input/XmlHandlerStreamWriter.java | 86 +++----
.../core/stream/util/CharacterDataAccumulator.java | 14 +-
.../xop/AbstractXOPDecodingFilterHandler.java | 27 ++-
.../xop/AbstractXOPEncodingFilterHandler.java | 49 ++--
.../apache/axiom/core/stream/xop/XOPConstants.java | 4 +-
.../core/stream/NamespaceRepairingFilterTest.java | 6 +-
.../axiom/core/stream/dom/input/DOMReaderTest.java | 10 +-
.../serializer/SerializerConformanceTest.java | 8 +-
.../core/stream/serializer/SerializerTest.java | 33 +--
.../writer/OutputStreamXmlWriterTest.java | 6 +-
.../axiom/core/stream/stax/pull/output/Action.java | 3 +-
.../core/stream/stax/pull/output/FakeReader.java | 3 +-
.../stream/stax/pull/output/StAXPivotTest.java | 138 ++++++-----
.../stax/pull/output/StAXPivotTransformerTest.java | 9 +-
50 files changed, 1046 insertions(+), 876 deletions(-)
diff --git a/components/core-streams/pom.xml b/components/core-streams/pom.xml
index 86cb01762..613b8b434 100644
--- a/components/core-streams/pom.xml
+++ b/components/core-streams/pom.xml
@@ -80,4 +80,20 @@
<scope>test</scope>
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>com.spotify.fmt</groupId>
+ <artifactId>fmt-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterData.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterData.java
index 52220473a..315fd024a 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterData.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterData.java
@@ -29,6 +29,8 @@ import java.io.IOException;
public interface CharacterData {
@Override
String toString();
+
void writeTo(CharacterDataSink sink) throws IOException;
+
void appendTo(StringBuilder buffer);
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java
index d55b377b5..cd886fa8b 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/CharacterDataSink.java
@@ -24,5 +24,6 @@ import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
public interface CharacterDataSink {
Writer getWriter();
+
AbstractBase64EncodingOutputStream getBase64EncodingOutputStream();
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/DocumentElementExtractingFilterHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/DocumentElementExtractingFilterHandler.java
index 59980ca22..8eb9a6854 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/DocumentElementExtractingFilterHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/DocumentElementExtractingFilterHandler.java
@@ -26,19 +26,19 @@ public final class DocumentElementExtractingFilterHandler extends XmlHandlerWrap
}
@Override
- public void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone) throws StreamException {
- }
+ public void startDocument(
+ String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone)
+ throws StreamException {}
@Override
- public void startFragment() throws StreamException {
- }
+ public void startFragment() throws StreamException {}
@Override
- public void completed() throws StreamException {
- }
+ public void completed() throws StreamException {}
@Override
- public void startElement(String namespaceURI, String localName, String prefix) throws StreamException {
+ public void startElement(String namespaceURI, String localName, String prefix)
+ throws StreamException {
super.startElement(namespaceURI, localName, prefix);
depth++;
}
@@ -50,8 +50,9 @@ public final class DocumentElementExtractingFilterHandler extends XmlHandlerWrap
}
@Override
- public void processDocumentTypeDeclaration(String rootName, String publicId, String systemId, String internalSubset) throws StreamException {
- }
+ public void processDocumentTypeDeclaration(
+ String rootName, String publicId, String systemId, String internalSubset)
+ throws StreamException {}
@Override
public void processCharacterData(Object data, boolean ignorable) throws StreamException {
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/FilteredXmlInput.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/FilteredXmlInput.java
index f3621f40e..625ca0bb3 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/FilteredXmlInput.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/FilteredXmlInput.java
@@ -21,7 +21,7 @@ package org.apache.axiom.core.stream;
public final class FilteredXmlInput implements XmlInput {
private final XmlInput parent;
private final XmlFilter filter;
-
+
public FilteredXmlInput(XmlInput parent, XmlFilter filter) {
this.parent = parent;
this.filter = filter;
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceRepairingFilter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceRepairingFilter.java
index b47a8a926..4e7b636f6 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceRepairingFilter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceRepairingFilter.java
@@ -19,20 +19,21 @@
package org.apache.axiom.core.stream;
public final class NamespaceRepairingFilter implements XmlFilter {
- public static final NamespaceRepairingFilter DEFAULT = new NamespaceRepairingFilter(null, false);
+ public static final NamespaceRepairingFilter DEFAULT =
+ new NamespaceRepairingFilter(null, false);
private final NamespaceContextProvider parentNamespaceContext;
private final boolean removeRedundantDeclarations;
- public NamespaceRepairingFilter(NamespaceContextProvider parentNamespaceContext,
- boolean removeRedundantDeclarations) {
+ public NamespaceRepairingFilter(
+ NamespaceContextProvider parentNamespaceContext, boolean removeRedundantDeclarations) {
this.parentNamespaceContext = parentNamespaceContext;
this.removeRedundantDeclarations = removeRedundantDeclarations;
}
@Override
public XmlHandler createFilterHandler(XmlHandler parent) {
- return new NamespaceRepairingFilterHandler(parent, parentNamespaceContext,
- removeRedundantDeclarations);
+ return new NamespaceRepairingFilterHandler(
+ parent, parentNamespaceContext, removeRedundantDeclarations);
}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceRepairingFilterHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceRepairingFilterHandler.java
index 0010be408..432b537be 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceRepairingFilterHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceRepairingFilterHandler.java
@@ -28,32 +28,37 @@ public final class NamespaceRepairingFilterHandler extends XmlHandlerWrapper {
private int[] scopeStack = new int[8];
private int scopes;
- public NamespaceRepairingFilterHandler(XmlHandler parent, NamespaceContextProvider parentNamespaceContext, boolean removeRedundantDeclarations) {
+ public NamespaceRepairingFilterHandler(
+ XmlHandler parent,
+ NamespaceContextProvider parentNamespaceContext,
+ boolean removeRedundantDeclarations) {
super(parent);
this.parentNamespaceContext = parentNamespaceContext;
this.removeRedundantDeclarations = removeRedundantDeclarations;
}
private void setPrefix(String prefix, String namespaceURI) {
- if (bindings*2 == namespaceStack.length) {
+ if (bindings * 2 == namespaceStack.length) {
int len = namespaceStack.length;
- String[] newNamespaceStack = new String[len*2];
+ String[] newNamespaceStack = new String[len * 2];
System.arraycopy(namespaceStack, 0, newNamespaceStack, 0, len);
namespaceStack = newNamespaceStack;
}
- namespaceStack[bindings*2] = prefix;
- namespaceStack[bindings*2+1] = namespaceURI;
+ namespaceStack[bindings * 2] = prefix;
+ namespaceStack[bindings * 2 + 1] = namespaceURI;
bindings++;
}
-
- private void ensureNamespaceDeclared(String prefix, String namespaceURI) throws StreamException {
- if (prefix.equals(XMLConstants.XML_NS_PREFIX) && namespaceURI.equals(XMLConstants.XML_NS_URI)) {
+
+ private void ensureNamespaceDeclared(String prefix, String namespaceURI)
+ throws StreamException {
+ if (prefix.equals(XMLConstants.XML_NS_PREFIX)
+ && namespaceURI.equals(XMLConstants.XML_NS_URI)) {
return;
}
boolean prefixFound = false;
- for (int i=(bindings-1)*2; i>=0; i-=2) {
+ for (int i = (bindings - 1) * 2; i >= 0; i -= 2) {
if (prefix.equals(namespaceStack[i])) {
- if (namespaceURI.equals(namespaceStack[i+1])) {
+ if (namespaceURI.equals(namespaceStack[i + 1])) {
return;
} else {
prefixFound = true;
@@ -72,19 +77,20 @@ public final class NamespaceRepairingFilterHandler extends XmlHandlerWrapper {
setPrefix(prefix, namespaceURI);
}
}
-
+
@Override
- public void startElement(String namespaceURI, String localName, String prefix) throws StreamException {
+ public void startElement(String namespaceURI, String localName, String prefix)
+ throws StreamException {
super.startElement(namespaceURI, localName, prefix);
if (scopes == scopeStack.length) {
- int[] newScopeStack = new int[scopeStack.length*2];
+ int[] newScopeStack = new int[scopeStack.length * 2];
System.arraycopy(scopeStack, 0, newScopeStack, 0, scopeStack.length);
scopeStack = newScopeStack;
}
scopeStack[scopes++] = bindings;
ensureNamespaceDeclared(prefix, namespaceURI);
}
-
+
@Override
public void endElement() throws StreamException {
bindings = scopeStack[--scopes];
@@ -92,24 +98,33 @@ public final class NamespaceRepairingFilterHandler extends XmlHandlerWrapper {
}
@Override
- public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) throws StreamException {
+ public void processAttribute(
+ String namespaceURI,
+ String localName,
+ String prefix,
+ String value,
+ String type,
+ boolean specified)
+ throws StreamException {
super.processAttribute(namespaceURI, localName, prefix, value, type, specified);
if (!namespaceURI.isEmpty()) {
ensureNamespaceDeclared(prefix, namespaceURI);
}
}
-
+
@Override
- public void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException {
+ public void processNamespaceDeclaration(String prefix, String namespaceURI)
+ throws StreamException {
if (removeRedundantDeclarations) {
ensureNamespaceDeclared(prefix, namespaceURI);
} else {
- for (int i = scopeStack[scopes-1]; i < bindings; i++) {
- if (namespaceStack[i*2].equals(prefix)) {
- if (namespaceStack[i*2+1].equals(namespaceURI)) {
+ for (int i = scopeStack[scopes - 1]; i < bindings; i++) {
+ if (namespaceStack[i * 2].equals(prefix)) {
+ if (namespaceStack[i * 2 + 1].equals(namespaceURI)) {
return;
} else {
- throw new ConflictingNamespaceDeclarationException("The same prefix cannot be bound to two different namespaces");
+ throw new ConflictingNamespaceDeclarationException(
+ "The same prefix cannot be bound to two different namespaces");
}
}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java
index 0ae7a7331..6d989fa6b 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/NamespaceURIInterningFilterHandler.java
@@ -24,17 +24,26 @@ public final class NamespaceURIInterningFilterHandler extends XmlHandlerWrapper
}
@Override
- public void startElement(String namespaceURI, String localName, String prefix) throws StreamException {
+ public void startElement(String namespaceURI, String localName, String prefix)
+ throws StreamException {
super.startElement(namespaceURI.intern(), localName, prefix);
}
@Override
- public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) throws StreamException {
+ public void processAttribute(
+ String namespaceURI,
+ String localName,
+ String prefix,
+ String value,
+ String type,
+ boolean specified)
+ throws StreamException {
super.processAttribute(namespaceURI.intern(), localName, prefix, value, type, specified);
}
@Override
- public void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException {
+ public void processNamespaceDeclaration(String prefix, String namespaceURI)
+ throws StreamException {
super.processNamespaceDeclaration(prefix, namespaceURI.intern());
}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/NullXmlHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/NullXmlHandler.java
index 82f8e4f04..3f86d68e6 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/NullXmlHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/NullXmlHandler.java
@@ -24,82 +24,73 @@ public final class NullXmlHandler implements XmlHandler {
private NullXmlHandler() {}
@Override
- public void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding,
- Boolean standalone) throws StreamException {
- }
+ public void startDocument(
+ String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone)
+ throws StreamException {}
@Override
- public void startFragment() throws StreamException {
- }
+ public void startFragment() throws StreamException {}
@Override
- public void processDocumentTypeDeclaration(String rootName, String publicId, String systemId,
- String internalSubset) throws StreamException {
- }
+ public void processDocumentTypeDeclaration(
+ String rootName, String publicId, String systemId, String internalSubset)
+ throws StreamException {}
@Override
public void startElement(String namespaceURI, String localName, String prefix)
- throws StreamException {
- }
+ throws StreamException {}
@Override
- public void endElement() throws StreamException {
- }
+ public void endElement() throws StreamException {}
@Override
- public void processAttribute(String namespaceURI, String localName, String prefix, String value,
- String type, boolean specified) throws StreamException {
- }
+ public void processAttribute(
+ String namespaceURI,
+ String localName,
+ String prefix,
+ String value,
+ String type,
+ boolean specified)
+ throws StreamException {}
@Override
public void processAttribute(String name, String value, String type, boolean specified)
- throws StreamException {
- }
+ throws StreamException {}
@Override
public void processNamespaceDeclaration(String prefix, String namespaceURI)
- throws StreamException {
- }
+ throws StreamException {}
@Override
- public void attributesCompleted() throws StreamException {
- }
+ public void attributesCompleted() throws StreamException {}
@Override
- public void processCharacterData(Object data, boolean ignorable) throws StreamException {
- }
+ public void processCharacterData(Object data, boolean ignorable) throws StreamException {}
@Override
- public void startProcessingInstruction(String target) throws StreamException {
- }
+ public void startProcessingInstruction(String target) throws StreamException {}
@Override
- public void endProcessingInstruction() throws StreamException {
- }
+ public void endProcessingInstruction() throws StreamException {}
@Override
- public void startComment() throws StreamException {
- }
+ public void startComment() throws StreamException {}
@Override
- public void endComment() throws StreamException {
- }
+ public void endComment() throws StreamException {}
@Override
- public void startCDATASection() throws StreamException {
- }
+ public void startCDATASection() throws StreamException {}
@Override
- public void endCDATASection() throws StreamException {
- }
+ public void endCDATASection() throws StreamException {}
@Override
- public void processEntityReference(String name, String replacementText) throws StreamException {
- }
+ public void processEntityReference(String name, String replacementText)
+ throws StreamException {}
@Override
- public void completed() throws StreamException {
- }
+ public void completed() throws StreamException {}
@Override
public boolean drain() throws StreamException {
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/StreamException.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/StreamException.java
index 5658c3e2a..5116722a4 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/StreamException.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/StreamException.java
@@ -19,9 +19,7 @@
package org.apache.axiom.core.stream;
// TODO: update Javadoc
-/**
- * Wraps an exception thrown by the underlying API (StAX, SAX, etc.) while writing data.
- */
+/** Wraps an exception thrown by the underlying API (StAX, SAX, etc.) while writing data. */
public class StreamException extends Exception {
private static final long serialVersionUID = 7173617216602466028L;
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlHandler.java
index 44d4fa92a..2abbc86c7 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlHandler.java
@@ -19,148 +19,137 @@
package org.apache.axiom.core.stream;
public interface XmlHandler {
- void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone) throws StreamException;
-
+ void startDocument(
+ String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone)
+ throws StreamException;
+
/**
* Notify the handler of the beginning of a fragment.
- *
- * @throws StreamException
- * if an error occurs when processing the event
+ *
+ * @throws StreamException if an error occurs when processing the event
*/
void startFragment() throws StreamException;
-
- void processDocumentTypeDeclaration(String rootName, String publicId,
- String systemId, String internalSubset) throws StreamException;
+
+ void processDocumentTypeDeclaration(
+ String rootName, String publicId, String systemId, String internalSubset)
+ throws StreamException;
/**
* Prepare to write an element start tag. A call to this method will be followed by zero or more
- * calls to {@link #processNamespaceDeclaration(String, String)} and
- * {@link #processAttribute(String, String, String, String, String)} and a single call to
- * {@link #attributesCompleted()}.
- *
- * @param namespaceURI
- * the namespace URI of the element; never <code>null</code>
- * @param localName
- * the local name of the element; never <code>null</code>
- * @param prefix
- * the prefix of the element; never <code>null</code>
+ * calls to {@link #processNamespaceDeclaration(String, String)} and {@link
+ * #processAttribute(String, String, String, String, String)} and a single call to {@link
+ * #attributesCompleted()}.
+ *
+ * @param namespaceURI the namespace URI of the element; never <code>null</code>
+ * @param localName the local name of the element; never <code>null</code>
+ * @param prefix the prefix of the element; never <code>null</code>
* @throws StreamException
*/
void startElement(String namespaceURI, String localName, String prefix) throws StreamException;
-
+
void endElement() throws StreamException;
-
+
/**
* Add the given namespace aware attribute to the element.
- *
- * @param namespaceURI
- * the namespace URI of the attribute; never <code>null</code>
- * @param localName
- * the local name of the attribute; never <code>null</code>
- * @param prefix
- * the namespace prefix of the attribute; never <code>null</code>
- * @param value
- * the value of the attribute; never <code>null</code>
- * @param type
- * the attribute type (e.g. {@code CDATA}); never <code>null</code>
+ *
+ * @param namespaceURI the namespace URI of the attribute; never <code>null</code>
+ * @param localName the local name of the attribute; never <code>null</code>
+ * @param prefix the namespace prefix of the attribute; never <code>null</code>
+ * @param value the value of the attribute; never <code>null</code>
+ * @param type the attribute type (e.g. {@code CDATA}); never <code>null</code>
* @throws StreamException
*/
- void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) throws StreamException;
-
+ void processAttribute(
+ String namespaceURI,
+ String localName,
+ String prefix,
+ String value,
+ String type,
+ boolean specified)
+ throws StreamException;
+
/**
* Add the given namespece unaware attribute to the element.
- *
- * @param name
- * the name of the attribute; never <code>null</code>
- * @param value
- * the value of the attribute; never <code>null</code>
- * @param type
- * the attribute type (e.g. {@code CDATA}); never <code>null</code>
+ *
+ * @param name the name of the attribute; never <code>null</code>
+ * @param value the value of the attribute; never <code>null</code>
+ * @param type the attribute type (e.g. {@code CDATA}); never <code>null</code>
* @throws StreamException
*/
- void processAttribute(String name, String value, String type, boolean specified) throws StreamException;
-
+ void processAttribute(String name, String value, String type, boolean specified)
+ throws StreamException;
+
/**
* Add the given namespace declaration to the element.
- *
- * @param prefix
- * the namespace prefix; never <code>null</code>
- * @param namespaceURI
- * the namespace URI; never <code>null</code>
+ *
+ * @param prefix the namespace prefix; never <code>null</code>
+ * @param namespaceURI the namespace URI; never <code>null</code>
* @throws StreamException
*/
void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException;
-
+
void attributesCompleted() throws StreamException;
-
+
void processCharacterData(Object data, boolean ignorable) throws StreamException;
-
+
/**
* Notify the handler of the beginning of a processing instruction.
- *
- * @param target
- * the target of the processing instruction
- * @throws StreamException
- * if an error occurs when processing the event
+ *
+ * @param target the target of the processing instruction
+ * @throws StreamException if an error occurs when processing the event
*/
void startProcessingInstruction(String target) throws StreamException;
-
+
/**
* Notify the handler of the end of a processing instruction.
- *
- * @throws StreamException
- * if an error occurs when processing the event
+ *
+ * @throws StreamException if an error occurs when processing the event
*/
void endProcessingInstruction() throws StreamException;
-
+
/**
* Notify the handler of the beginning of a comment.
- *
- * @throws StreamException
- * if an error occurs when processing the event
+ *
+ * @throws StreamException if an error occurs when processing the event
*/
void startComment() throws StreamException;
-
+
/**
* Notify the handler of the end of a comment.
- *
- * @throws StreamException
- * if an error occurs when processing the event
+ *
+ * @throws StreamException if an error occurs when processing the event
*/
void endComment() throws StreamException;
-
+
/**
* Notify the handler of the beginning of a CDATA section.
- *
- * @throws StreamException
- * if an error occurs when processing the event
+ *
+ * @throws StreamException if an error occurs when processing the event
*/
void startCDATASection() throws StreamException;
-
+
/**
* Notify the handler of the end of a CDATA section.
- *
- * @throws StreamException
- * if an error occurs when processing the event
+ *
+ * @throws StreamException if an error occurs when processing the event
*/
void endCDATASection() throws StreamException;
-
+
void processEntityReference(String name, String replacementText) throws StreamException;
-
+
/**
* Notify the handler that the document or fragment is complete.
- *
- * @throws StreamException
- * if an error occurs when processing the event
+ *
+ * @throws StreamException if an error occurs when processing the event
*/
void completed() throws StreamException;
-
+
/**
* Drain the pipeline by pushing pending events to the next handler in the chain.
- *
+ *
* @return {@code true} if the pipeline was already drained and no new events were pushed,
- * {@code false} if at least one event was pushed and this method should be called again
- * to continue draining the pipeline
+ * {@code false} if at least one event was pushed and this method should be called again to
+ * continue draining the pipeline
* @throws StreamException
*/
boolean drain() throws StreamException;
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlHandlerWrapper.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlHandlerWrapper.java
index 134c36167..6466c50b3 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlHandlerWrapper.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlHandlerWrapper.java
@@ -30,8 +30,9 @@ public class XmlHandlerWrapper implements XmlHandler {
}
@Override
- public void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding,
- Boolean standalone) throws StreamException {
+ public void startDocument(
+ String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone)
+ throws StreamException {
parent.startDocument(inputEncoding, xmlVersion, xmlEncoding, standalone);
}
@@ -41,8 +42,9 @@ public class XmlHandlerWrapper implements XmlHandler {
}
@Override
- public void processDocumentTypeDeclaration(String rootName, String publicId, String systemId,
- String internalSubset) throws StreamException {
+ public void processDocumentTypeDeclaration(
+ String rootName, String publicId, String systemId, String internalSubset)
+ throws StreamException {
parent.processDocumentTypeDeclaration(rootName, publicId, systemId, internalSubset);
}
@@ -58,8 +60,14 @@ public class XmlHandlerWrapper implements XmlHandler {
}
@Override
- public void processAttribute(String namespaceURI, String localName, String prefix, String value,
- String type, boolean specified) throws StreamException {
+ public void processAttribute(
+ String namespaceURI,
+ String localName,
+ String prefix,
+ String value,
+ String type,
+ boolean specified)
+ throws StreamException {
parent.processAttribute(namespaceURI, localName, prefix, value, type, specified);
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlReader.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlReader.java
index dc903fdd2..e62cb36f8 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlReader.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/XmlReader.java
@@ -21,10 +21,10 @@ package org.apache.axiom.core.stream;
public interface XmlReader {
/**
* Output one or more events to the {@link XmlHandler} connected to this {@link XmlReader}.
- *
- * @return {@code true} if the last event sent to the {@link XmlHandler} was
- * {@link XmlHandler#completed()} and there are no more events to produce; {@code false}
- * if {@link #proceed()} should be called again to produce more events
+ *
+ * @return {@code true} if the last event sent to the {@link XmlHandler} was {@link
+ * XmlHandler#completed()} and there are no more events to produce; {@code false} if {@link
+ * #proceed()} should be called again to produce more events
* @throws StreamException
*/
boolean proceed() throws StreamException;
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/dom/input/DOMInput.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/dom/input/DOMInput.java
index f1c6bf06a..925ad3d9d 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/dom/input/DOMInput.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/dom/input/DOMInput.java
@@ -27,20 +27,18 @@ import org.w3c.dom.Node;
public class DOMInput implements XmlInput {
private final Node node;
private final boolean expandEntityReferences;
-
+
/**
* Constructor.
- *
- * @param node
- * The root node of the tree from which events will be generated.
- * @param expandEntityReferences
- * Determines how {@link EntityReference} nodes are handled by this instance. When
- * set to {@code false}, a single
- * {@link XmlHandler#processEntityReference(String, String)} event will be emitted
- * for each {@link EntityReference}. When set to {@code true}, no
- * {@link XmlHandler#processEntityReference(String, String)} events are generated.
- * Instead, the implementation will traverse the descendants of the
- * {@link EntityReference} nodes (which effectively expands these entity references).
+ *
+ * @param node The root node of the tree from which events will be generated.
+ * @param expandEntityReferences Determines how {@link EntityReference} nodes are handled by
+ * this instance. When set to {@code false}, a single {@link
+ * XmlHandler#processEntityReference(String, String)} event will be emitted for each {@link
+ * EntityReference}. When set to {@code true}, no {@link
+ * XmlHandler#processEntityReference(String, String)} events are generated. Instead, the
+ * implementation will traverse the descendants of the {@link EntityReference} nodes (which
+ * effectively expands these entity references).
*/
public DOMInput(Node node, boolean expandEntityReferences) {
this.node = node;
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/dom/input/DOMReader.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/dom/input/DOMReader.java
index 5def79fa3..5023435a7 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/dom/input/DOMReader.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/dom/input/DOMReader.java
@@ -37,21 +37,21 @@ final class DOMReader implements XmlReader {
private static final int NOT_VISITED = 1;
private static final int VISITED = 2;
private static final int COMPLETE = 3;
-
+
private final XmlHandler handler;
private final Node rootNode;
private final boolean expandEntityReferences;
private final boolean dom3;
private Node currentNode;
private int state = START;
-
+
DOMReader(XmlHandler handler, Node node, boolean expandEntityReferences) {
this.handler = handler;
rootNode = node;
this.expandEntityReferences = expandEntityReferences;
Document ownerDocument;
if (node.getNodeType() == Node.DOCUMENT_NODE) {
- ownerDocument = (Document)node;
+ ownerDocument = (Document) node;
} else {
ownerDocument = node.getOwnerDocument();
}
@@ -61,12 +61,13 @@ final class DOMReader implements XmlReader {
private static String nullToEmptyString(String s) {
return s == null ? "" : s;
}
-
+
@Override
public boolean proceed() throws StreamException {
Node currentNode = this.currentNode;
int state = this.state;
- loop: while (true) {
+ loop:
+ while (true) {
switch (state) {
case START:
if (rootNode instanceof Document) {
@@ -120,9 +121,13 @@ final class DOMReader implements XmlReader {
switch (nodeType) {
case Node.DOCUMENT_NODE:
if (currentNode != null) {
- Document document = (Document)currentNode;
+ Document document = (Document) currentNode;
if (dom3) {
- handler.startDocument(document.getInputEncoding(), document.getXmlVersion(), document.getXmlEncoding(), document.getXmlStandalone());
+ handler.startDocument(
+ document.getInputEncoding(),
+ document.getXmlVersion(),
+ document.getXmlEncoding(),
+ document.getXmlStandalone());
} else {
handler.startDocument(null, "1.0", null, null);
}
@@ -131,38 +136,61 @@ final class DOMReader implements XmlReader {
}
break loop;
case Node.DOCUMENT_TYPE_NODE:
- DocumentType docType = (DocumentType)currentNode;
- handler.processDocumentTypeDeclaration(docType.getName(), docType.getPublicId(), docType.getSystemId(), docType.getInternalSubset());
+ DocumentType docType = (DocumentType) currentNode;
+ handler.processDocumentTypeDeclaration(
+ docType.getName(),
+ docType.getPublicId(),
+ docType.getSystemId(),
+ docType.getInternalSubset());
break loop;
case Node.ELEMENT_NODE:
- Element element = (Element)currentNode;
+ Element element = (Element) currentNode;
String localName = element.getLocalName();
if (localName == null) {
// TODO
throw new UnsupportedOperationException();
} else {
- handler.startElement(nullToEmptyString(element.getNamespaceURI()), localName, nullToEmptyString(element.getPrefix()));
+ handler.startElement(
+ nullToEmptyString(element.getNamespaceURI()),
+ localName,
+ nullToEmptyString(element.getPrefix()));
}
NamedNodeMap attributes = element.getAttributes();
// TODO: we should not push all attributes at once
- for (int length=attributes.getLength(), i=0; i<length; i++) {
- Attr attr = (Attr)attributes.item(i);
+ for (int length = attributes.getLength(), i = 0; i < length; i++) {
+ Attr attr = (Attr) attributes.item(i);
String attrLocalName = attr.getLocalName();
if (attrLocalName == null) {
- handler.processAttribute(attr.getName(), attr.getValue(), "CDATA", attr.getSpecified());
+ handler.processAttribute(
+ attr.getName(),
+ attr.getValue(),
+ "CDATA",
+ attr.getSpecified());
} else {
String namespaceURI = attr.getNamespaceURI();
if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) {
- handler.processNamespaceDeclaration(attrLocalName.equals(XMLConstants.XMLNS_ATTRIBUTE) ? "" : attrLocalName, attr.getValue());
+ handler.processNamespaceDeclaration(
+ attrLocalName.equals(XMLConstants.XMLNS_ATTRIBUTE)
+ ? ""
+ : attrLocalName,
+ attr.getValue());
} else {
- handler.processAttribute(nullToEmptyString(namespaceURI), attrLocalName, nullToEmptyString(attr.getPrefix()), attr.getValue(), "CDATA", attr.getSpecified());
+ handler.processAttribute(
+ nullToEmptyString(namespaceURI),
+ attrLocalName,
+ nullToEmptyString(attr.getPrefix()),
+ attr.getValue(),
+ "CDATA",
+ attr.getSpecified());
}
}
}
handler.attributesCompleted();
break loop;
case Node.TEXT_NODE:
- handler.processCharacterData(currentNode.getNodeValue(), dom3 && ((Text)currentNode).isElementContentWhitespace());
+ handler.processCharacterData(
+ currentNode.getNodeValue(),
+ dom3 && ((Text) currentNode).isElementContentWhitespace());
break loop;
case Node.CDATA_SECTION_NODE:
handler.startCDATASection();
@@ -175,7 +203,7 @@ final class DOMReader implements XmlReader {
handler.endComment();
break loop;
case Node.PROCESSING_INSTRUCTION_NODE:
- ProcessingInstruction pi = (ProcessingInstruction)currentNode;
+ ProcessingInstruction pi = (ProcessingInstruction) currentNode;
handler.startProcessingInstruction(pi.getTarget());
handler.processCharacterData(pi.getData(), false);
handler.endProcessingInstruction();
@@ -191,7 +219,8 @@ final class DOMReader implements XmlReader {
}
default:
// TODO
- throw new UnsupportedOperationException("Unsupported node type " + nodeType);
+ throw new UnsupportedOperationException(
+ "Unsupported node type " + nodeType);
}
}
}
@@ -201,6 +230,5 @@ final class DOMReader implements XmlReader {
}
@Override
- public void dispose() {
- }
+ public void dispose() {}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/SAXInput.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/SAXInput.java
index d84dccb60..b25bfca93 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/SAXInput.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/SAXInput.java
@@ -28,12 +28,12 @@ import org.apache.axiom.core.stream.XmlReader;
public final class SAXInput implements XmlInput {
private final boolean expandEntityReferences;
private final SAXSource source;
-
+
public SAXInput(SAXSource source, boolean expandEntityReferences) {
this.expandEntityReferences = expandEntityReferences;
this.source = source;
}
-
+
@Override
public XmlReader createReader(XmlHandler handler) {
return new SAXReader(handler, source, expandEntityReferences);
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/SAXReader.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/SAXReader.java
index 2e06a2c63..8273bc9b3 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/SAXReader.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/SAXReader.java
@@ -33,17 +33,18 @@ public final class SAXReader implements XmlReader {
private final XmlHandler handler;
private final boolean expandEntityReferences;
private final SAXSource source;
-
+
SAXReader(XmlHandler handler, SAXSource source, boolean expandEntityReferences) {
this.handler = handler;
this.expandEntityReferences = expandEntityReferences;
this.source = source;
}
-
+
@Override
public boolean proceed() throws StreamException {
XMLReader reader = source.getXMLReader();
- XmlHandlerContentHandler contentHandler = new XmlHandlerContentHandler(handler, expandEntityReferences);
+ XmlHandlerContentHandler contentHandler =
+ new XmlHandlerContentHandler(handler, expandEntityReferences);
reader.setContentHandler(contentHandler);
reader.setDTDHandler(contentHandler);
try {
@@ -67,6 +68,5 @@ public final class SAXReader implements XmlReader {
}
@Override
- public void dispose() {
- }
+ public void dispose() {}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/XmlHandlerContentHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/XmlHandlerContentHandler.java
index 7b1e21d4f..f903eabaf 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/XmlHandlerContentHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/input/XmlHandlerContentHandler.java
@@ -33,53 +33,40 @@ import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
-public final class XmlHandlerContentHandler implements ContentHandler, LexicalHandler, DeclHandler, DTDHandler {
+public final class XmlHandlerContentHandler
+ implements ContentHandler, LexicalHandler, DeclHandler, DTDHandler {
private final XmlHandler handler;
private final boolean expandEntityReferences;
-
- /**
- * Stores the root name if there is a DTD.
- */
+
+ /** Stores the root name if there is a DTD. */
private String dtdName;
-
- /**
- * Stores the public ID if there is a DTD.
- */
+
+ /** Stores the public ID if there is a DTD. */
private String dtdPublicId;
-
- /**
- * Stores the system ID if there is a DTD.
- */
+
+ /** Stores the system ID if there is a DTD. */
private String dtdSystemId;
-
- /**
- * Stores the internal subset if there is a DTD.
- */
+
+ /** Stores the internal subset if there is a DTD. */
private StringWriter internalSubset;
private Serializer internalSubsetSerializer;
- /**
- * Stores the replacement values for entities.
- */
- private Map<String,String> entities;
-
- /**
- * Flag indicating that the parser is processing the external subset.
- */
+ /** Stores the replacement values for entities. */
+ private Map<String, String> entities;
+
+ /** Flag indicating that the parser is processing the external subset. */
private boolean inExternalSubset;
/**
* Stores namespace declarations reported to {@link #startPrefixMapping(String, String)}. These
- * declarations will be passed to the {@link XmlHandler} by
- * {@link #startElement(String, String, String, Attributes)}. Each declaration is stored as
- * (prefix, uri) pair using two array elements.
+ * declarations will be passed to the {@link XmlHandler} by {@link #startElement(String, String,
+ * String, Attributes)}. Each declaration is stored as (prefix, uri) pair using two array
+ * elements.
*/
private String[] namespaces = new String[16];
- /**
- * The number of namespace declarations stored in {@link #namespaces}.
- */
+ /** The number of namespace declarations stored in {@link #namespaces}. */
private int namespaceCount;
private boolean inEntityReference;
@@ -89,19 +76,18 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
this.handler = handler;
this.expandEntityReferences = expandEntityReferences;
}
-
+
private static SAXException toSAXException(StreamException ex) {
Throwable cause = ex.getCause();
if (cause instanceof SAXException) {
- return (SAXException)cause;
+ return (SAXException) cause;
} else {
return new SAXException(ex);
}
}
-
+
@Override
- public void setDocumentLocator(Locator locator) {
- }
+ public void setDocumentLocator(Locator locator) {}
@Override
public void startDocument() throws SAXException {
@@ -154,7 +140,8 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
}
@Override
- public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException {
+ public void externalEntityDecl(String name, String publicId, String systemId)
+ throws SAXException {
if (!inExternalSubset) {
try {
internalSubsetSerializer.externalEntityDecl(name, publicId, systemId);
@@ -167,7 +154,7 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
@Override
public void internalEntityDecl(String name, String value) throws SAXException {
if (entities == null) {
- entities = new HashMap<String,String>();
+ entities = new HashMap<String, String>();
}
entities.put(name, value);
if (!inExternalSubset) {
@@ -191,7 +178,8 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
}
@Override
- public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName)
+ public void unparsedEntityDecl(
+ String name, String publicId, String systemId, String notationName)
throws SAXException {
if (!inExternalSubset) {
try {
@@ -209,7 +197,10 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
}
try {
String internalSubset = this.internalSubset.toString();
- handler.processDocumentTypeDeclaration(dtdName, dtdPublicId, dtdSystemId,
+ handler.processDocumentTypeDeclaration(
+ dtdName,
+ dtdPublicId,
+ dtdSystemId,
internalSubset.length() == 0 ? null : internalSubset);
} catch (StreamException ex) {
throw toSAXException(ex);
@@ -225,24 +216,22 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
* java.lang.String)
*/
@Override
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
+ public void startPrefixMapping(String prefix, String uri) throws SAXException {
if (!inEntityReference) {
- int index = namespaceCount*2;
+ int index = namespaceCount * 2;
if (index == namespaces.length) {
- String[] newNamespaces = new String[namespaces.length*2];
+ String[] newNamespaces = new String[namespaces.length * 2];
System.arraycopy(namespaces, 0, newNamespaces, 0, namespaces.length);
namespaces = newNamespaces;
}
namespaces[index] = prefix;
- namespaces[index+1] = uri;
+ namespaces[index + 1] = uri;
namespaceCount++;
}
}
@Override
- public void endPrefixMapping(String prefix) throws SAXException {
- }
+ public void endPrefixMapping(String prefix) throws SAXException {}
/*
* (non-Javadoc)
@@ -251,8 +240,8 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
* java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
@Override
- public void startElement(String namespaceURI, String localName,
- String qName, Attributes atts) throws SAXException {
+ public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
+ throws SAXException {
if (inEntityReference) {
return;
}
@@ -263,23 +252,30 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
String prefix = idx == -1 ? "" : qName.substring(0, idx);
handler.startElement(namespaceURI, localName, prefix);
for (int i = 0; i < namespaceCount; i++) {
- handler.processNamespaceDeclaration(namespaces[2*i], namespaces[2*i+1]);
+ handler.processNamespaceDeclaration(namespaces[2 * i], namespaces[2 * i + 1]);
}
namespaceCount = 0;
-
+
int j = atts.getLength();
for (int i = 0; i < j; i++) {
String attrQName = atts.getQName(i);
- // Note that some SAX parsers report namespace declarations as attributes in addition
- // to calling start/endPrefixMapping.
+ // Note that some SAX parsers report namespace declarations as attributes in
+ // addition to calling start/endPrefixMapping.
// NOTE: This filter was introduced to make SAXOMBuilder work with some versions of
// XMLBeans (2.3.0). It is not clear whether this is a bug in XMLBeans or not.
- // See http://forum.springframework.org/showthread.php?t=43958 for a discussion.
- // If this test causes problems with other parsers, don't hesitate to remove it.
+ // See http://forum.springframework.org/showthread.php?t=43958 for a
+ // discussion. If this test causes problems with other parsers, don't hesitate
+ // to remove it.
if (!attrQName.startsWith("xmlns")) {
idx = attrQName.indexOf(':');
String attrPrefix = idx == -1 ? "" : attrQName.substring(0, idx);
- handler.processAttribute(atts.getURI(i), atts.getLocalName(i), attrPrefix, atts.getValue(i), atts.getType(i), true);
+ handler.processAttribute(
+ atts.getURI(i),
+ atts.getLocalName(i),
+ attrPrefix,
+ atts.getValue(i),
+ atts.getType(i),
+ true);
}
}
handler.attributesCompleted();
@@ -295,8 +291,7 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
* java.lang.String, java.lang.String)
*/
@Override
- public void endElement(String uri, String localName, String qName)
- throws SAXException {
+ public void endElement(String uri, String localName, String qName) throws SAXException {
if (!inEntityReference) {
try {
handler.endElement();
@@ -329,8 +324,7 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
}
@Override
- public void characters(char[] ch, int start, int length)
- throws SAXException {
+ public void characters(char[] ch, int start, int length) throws SAXException {
if (!inEntityReference) {
try {
handler.processCharacterData(new String(ch, start, length), false);
@@ -339,10 +333,9 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
}
}
}
-
+
@Override
- public void ignorableWhitespace(char[] ch, int start, int length)
- throws SAXException {
+ public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
if (!inEntityReference) {
try {
handler.processCharacterData(new String(ch, start, length), true);
@@ -353,8 +346,7 @@ public final class XmlHandlerContentHandler implements ContentHandler, LexicalHa
}
@Override
- public void processingInstruction(String piTarget, String data)
- throws SAXException {
+ public void processingInstruction(String piTarget, String data) throws SAXException {
if (!inEntityReference) {
try {
handler.startProcessingInstruction(piTarget);
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/output/ContentHandlerWriter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/output/ContentHandlerWriter.java
index 291e257c6..ec4aba32b 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/output/ContentHandlerWriter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/output/ContentHandlerWriter.java
@@ -45,10 +45,8 @@ final class ContentHandlerWriter extends Writer {
}
@Override
- public void close() throws IOException {
- }
+ public void close() throws IOException {}
@Override
- public void flush() throws IOException {
- }
+ public void flush() throws IOException {}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/output/ContentHandlerXmlHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/output/ContentHandlerXmlHandler.java
index eae728706..2ce35cae3 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/output/ContentHandlerXmlHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/output/ContentHandlerXmlHandler.java
@@ -35,8 +35,13 @@ import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
- private enum CharacterDataMode { PASS_THROUGH, BUFFER, SKIP, ACCUMULATE };
-
+ private enum CharacterDataMode {
+ PASS_THROUGH,
+ BUFFER,
+ SKIP,
+ ACCUMULATE
+ };
+
private final ContentHandler contentHandler;
private final LexicalHandler lexicalHandler;
private String[] prefixStack = new String[16];
@@ -53,7 +58,7 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
private int bufferPos;
private CharacterDataAccumulator accumulator;
private String piTarget;
-
+
public ContentHandlerXmlHandler(ContentHandler contentHandler, LexicalHandler lexicalHandler) {
this.contentHandler = contentHandler;
this.lexicalHandler = lexicalHandler;
@@ -66,17 +71,18 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
return prefix + ":" + localName;
}
}
-
+
@Override
- public void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding,
- Boolean standalone) throws StreamException {
+ public void startDocument(
+ String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone)
+ throws StreamException {
try {
contentHandler.startDocument();
} catch (SAXException ex) {
throw new StreamException(ex);
}
}
-
+
@Override
public void startFragment() throws StreamException {
try {
@@ -87,7 +93,9 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
}
@Override
- public void processDocumentTypeDeclaration(String rootName, String publicId, String systemId, String internalSubset) throws StreamException {
+ public void processDocumentTypeDeclaration(
+ String rootName, String publicId, String systemId, String internalSubset)
+ throws StreamException {
if (lexicalHandler != null) {
try {
lexicalHandler.startDTD(rootName, publicId, systemId);
@@ -99,12 +107,13 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
}
@Override
- public void startElement(String namespaceURI, String localName, String prefix) throws StreamException {
+ public void startElement(String namespaceURI, String localName, String prefix)
+ throws StreamException {
elementURI = namespaceURI;
elementLocalName = localName;
elementQName = getQName(prefix, localName);
if (depth == scopeStack.length) {
- int[] newScopeStack = new int[scopeStack.length*2];
+ int[] newScopeStack = new int[scopeStack.length * 2];
System.arraycopy(scopeStack, 0, newScopeStack, 0, scopeStack.length);
scopeStack = newScopeStack;
}
@@ -112,9 +121,10 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
}
@Override
- public void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException {
+ public void processNamespaceDeclaration(String prefix, String namespaceURI)
+ throws StreamException {
if (bindings == prefixStack.length) {
- String[] newPrefixStack = new String[prefixStack.length*2];
+ String[] newPrefixStack = new String[prefixStack.length * 2];
System.arraycopy(prefixStack, 0, newPrefixStack, 0, prefixStack.length);
prefixStack = newPrefixStack;
}
@@ -124,11 +134,19 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
} catch (SAXException ex) {
throw new StreamException(ex);
}
- // TODO: depending on the http://xml.org/sax/features/xmlns-uris feature, we also need to add an attribute
+ // TODO: depending on the http://xml.org/sax/features/xmlns-uris feature, we also need to
+ // add an attribute
}
@Override
- public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) throws StreamException {
+ public void processAttribute(
+ String namespaceURI,
+ String localName,
+ String prefix,
+ String value,
+ String type,
+ boolean specified)
+ throws StreamException {
attributes.addAttribute(namespaceURI, localName, getQName(prefix, localName), type, value);
}
@@ -162,7 +180,7 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
String elementLocalName = elementNameStack.pop();
String elementURI = elementNameStack.pop();
contentHandler.endElement(elementURI, elementLocalName, elementQName);
- for (int i=bindings-1; i>=scopeStack[depth-1]; i--) {
+ for (int i = bindings - 1; i >= scopeStack[depth - 1]; i--) {
contentHandler.endPrefixMapping(prefixStack[i]);
}
bindings = scopeStack[--depth];
@@ -173,11 +191,11 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
private void writeToBuffer(String data) {
int dataLen = data.length();
- if (buffer.length-bufferPos < dataLen) {
+ if (buffer.length - bufferPos < dataLen) {
int newLength = buffer.length;
do {
newLength *= 2;
- } while (newLength-bufferPos < dataLen);
+ } while (newLength - bufferPos < dataLen);
char[] newBuffer = new char[newLength];
System.arraycopy(buffer, 0, newBuffer, 0, bufferPos);
buffer = newBuffer;
@@ -207,12 +225,12 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
bufferPos = 0;
} else if (data instanceof CharacterData) {
try {
- ((CharacterData)data).writeTo(this);
+ ((CharacterData) data).writeTo(this);
} catch (IOException ex) {
Throwable cause = ex.getCause();
SAXException saxException;
if (cause instanceof SAXException) {
- saxException = (SAXException)cause;
+ saxException = (SAXException) cause;
} else {
saxException = new SAXException(ex);
}
@@ -236,7 +254,7 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
throw new StreamException(ex);
}
}
-
+
@Override
public void startCDATASection() throws StreamException {
try {
@@ -261,7 +279,8 @@ public class ContentHandlerXmlHandler implements XmlHandler, CharacterDataSink {
@Override
public void startComment() throws StreamException {
- characterDataMode = lexicalHandler == null ? CharacterDataMode.SKIP : CharacterDataMode.BUFFER;
+ characterDataMode =
+ lexicalHandler == null ? CharacterDataMode.SKIP : CharacterDataMode.BUFFER;
}
@Override
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
index 99b95734c..ab8754895 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
@@ -34,9 +34,9 @@ import org.apache.axiom.core.stream.serializer.writer.XmlWriter;
import org.apache.axiom.util.base64.AbstractBase64EncodingOutputStream;
/**
- * This abstract class is a base class for other stream
- * serializers (xml, html, text ...) that write output to a stream.
- *
+ * This abstract class is a base class for other stream serializers (xml, html, text ...) that write
+ * output to a stream.
+ *
* @xsl.usage internal
*/
public final class Serializer implements XmlHandler, CharacterDataSink {
@@ -45,7 +45,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
* and large enough to reduce method invocation overhead.
*/
private static final int CHUNK_SIZE = 4096;
-
+
private static final int MIXED_CONTENT = 0;
private static final int TAG = 1;
private static final int ATTRIBUTE_VALUE = 2;
@@ -53,27 +53,24 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
private static final int PROCESSING_INSTRUCTION = 4;
private static final int CDATA_SECTION = 5;
- private static final String[] illegalCharacterSequences = { null, null, null, "--", "?>", "]]>" };
+ private static final String[] illegalCharacterSequences = {null, null, null, "--", "?>", "]]>"};
private static final UnmappableCharacterHandler[] unmappableCharacterHandlers = {
- UnmappableCharacterHandler.CONVERT_TO_CHARACTER_REFERENCE,
- UnmappableCharacterHandler.THROW_EXCEPTION,
- UnmappableCharacterHandler.CONVERT_TO_CHARACTER_REFERENCE,
- UnmappableCharacterHandler.THROW_EXCEPTION,
- UnmappableCharacterHandler.THROW_EXCEPTION,
- UnmappableCharacterHandler.THROW_EXCEPTION };
-
+ UnmappableCharacterHandler.CONVERT_TO_CHARACTER_REFERENCE,
+ UnmappableCharacterHandler.THROW_EXCEPTION,
+ UnmappableCharacterHandler.CONVERT_TO_CHARACTER_REFERENCE,
+ UnmappableCharacterHandler.THROW_EXCEPTION,
+ UnmappableCharacterHandler.THROW_EXCEPTION,
+ UnmappableCharacterHandler.THROW_EXCEPTION
+ };
+
private final XmlWriter writer;
private final OutputStream outputStream;
-
- /**
- * Add space before '/>' for XHTML.
- */
+
+ /** Add space before '/>' for XHTML. */
protected boolean spaceBeforeClose = false;
- /**
- * Tells if we're in an internal document type subset.
- */
+ /** Tells if we're in an internal document type subset. */
protected boolean inDoctype = false;
private int context = MIXED_CONTENT;
@@ -90,10 +87,8 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
private boolean startTagOpen;
/**
- * A utility buffer for converting Strings passed to
- * character() methods to character arrays.
- * Reusing this buffer means not creating a new character array
- * everytime and it runs faster.
+ * A utility buffer for converting Strings passed to character() methods to character arrays.
+ * Reusing this buffer means not creating a new character array everytime and it runs faster.
*/
private final char[] charsBuff = new char[CHUNK_SIZE];
@@ -123,7 +118,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
* flush all pending data before returning the output stream.
*
* @return the output stream, or {@code null} if this serializer is not writing to an output
- * stream (but to a {@link Writer} e.g.)
+ * stream (but to a {@link Writer} e.g.)
* @throws StreamException
*/
public OutputStream getOutputStream() throws StreamException {
@@ -137,17 +132,15 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
/**
- * Report an element type declaration.
- *
- * <p>The content model will consist of the string "EMPTY", the
- * string "ANY", or a parenthesised group, optionally followed
- * by an occurrence indicator. The model will be normalized so
- * that all whitespace is removed,and will include the enclosing
- * parentheses.</p>
- *
- * @param name The element type name.
- * @param model The content model as a normalized string.
- * @exception StreamException The application may raise an exception.
+ * Report an element type declaration.
+ *
+ * <p>The content model will consist of the string "EMPTY", the string "ANY", or a parenthesised
+ * group, optionally followed by an occurrence indicator. The model will be normalized so that
+ * all whitespace is removed,and will include the enclosing parentheses.
+ *
+ * @param name The element type name.
+ * @param model The content model as a normalized string.
+ * @exception StreamException The application may raise an exception.
*/
public void elementDecl(String name, String model) throws StreamException {
try {
@@ -165,11 +158,10 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
/**
* Report an internal entity declaration.
*
- * <p>Only the effective (first) declaration for each entity
- * will be reported.</p>
+ * <p>Only the effective (first) declaration for each entity will be reported.
*
- * @param name The name of the entity. If it is a parameter
- * entity, the name will begin with '%'.
+ * @param name The name of the entity. If it is a parameter entity, the name will begin with
+ * '%'.
* @param value The replacement text of the entity.
* @exception StreamException The application may raise an exception.
* @see #externalEntityDecl
@@ -187,9 +179,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
/**
* Output the doc type declaration.
*
- * @param name non-null reference to document type name.
- * NEEDSDOC @param value
- *
+ * @param name non-null reference to document type name. NEEDSDOC @param value
* @throws StreamException
*/
private void outputEntityDecl(String name, String value) throws IOException {
@@ -201,8 +191,9 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
@Override
- public void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding,
- Boolean standalone) throws StreamException {
+ public void startDocument(
+ String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone)
+ throws StreamException {
switchContext(TAG);
try {
writer.write("<?xml version=\"");
@@ -226,30 +217,27 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
@Override
- public void startFragment() throws StreamException {
- }
+ public void startFragment() throws StreamException {}
/**
* Report an attribute type declaration.
*
- * <p>Only the effective (first) declaration for an attribute will
- * be reported. The type will be one of the strings "CDATA",
- * "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY",
- * "ENTITIES", or "NOTATION", or a parenthesized token group with
- * the separator "|" and all whitespace removed.</p>
+ * <p>Only the effective (first) declaration for an attribute will be reported. The type will be
+ * one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY",
+ * "ENTITIES", or "NOTATION", or a parenthesized token group with the separator "|" and all
+ * whitespace removed.
*
* @param eName The name of the associated element.
* @param aName The name of the attribute.
* @param type A string representing the attribute type.
- * @param valueDefault A string representing the attribute default
- * ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if
- * none of these applies.
- * @param value A string representing the attribute's default value,
- * or null if there is none.
+ * @param valueDefault A string representing the attribute default ("#IMPLIED", "#REQUIRED", or
+ * "#FIXED") or null if none of these applies.
+ * @param value A string representing the attribute's default value, or null if there is none.
* @exception StreamException The application may raise an exception.
*/
- public void attributeDecl(String eName, String aName, String type, String valueDefault,
- String value) throws StreamException {
+ public void attributeDecl(
+ String eName, String aName, String type, String valueDefault, String value)
+ throws StreamException {
try {
DTDprolog();
writer.write("<!ATTLIST ");
@@ -262,8 +250,8 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
writer.write(' ');
writer.write(valueDefault);
}
- //writer.write(" ");
- //writer.write(value);
+ // writer.write(" ");
+ // writer.write(value);
writer.write(">\n");
} catch (IOException ex) {
throw new StreamException(ex);
@@ -273,19 +261,18 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
/**
* Report a parsed external entity declaration.
*
- * <p>Only the effective (first) declaration for each entity
- * will be reported.</p>
+ * <p>Only the effective (first) declaration for each entity will be reported.
*
- * @param name The name of the entity. If it is a parameter
- * entity, the name will begin with '%'.
- * @param publicId The declared public identifier of the entity, or
- * null if none was declared.
+ * @param name The name of the entity. If it is a parameter entity, the name will begin with
+ * '%'.
+ * @param publicId The declared public identifier of the entity, or null if none was declared.
* @param systemId The declared system identifier of the entity.
* @exception StreamException The application may raise an exception.
* @see #internalEntityDecl
* @see org.xml.sax.DTDHandler#unparsedEntityDecl
*/
- public void externalEntityDecl(String name, String publicId, String systemId) throws StreamException {
+ public void externalEntityDecl(String name, String publicId, String systemId)
+ throws StreamException {
try {
DTDprolog();
writer.write("<!ENTITY ");
@@ -306,65 +293,63 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
/**
* Receive notification of character data.
*
- * <p>The Parser will call this method to report each chunk of
- * character data. SAX parsers may return all contiguous character
- * data in a single chunk, or they may split it into several
- * chunks; however, all of the characters in any single event
- * must come from the same external entity, so that the Locator
- * provides useful information.</p>
+ * <p>The Parser will call this method to report each chunk of character data. SAX parsers may
+ * return all contiguous character data in a single chunk, or they may split it into several
+ * chunks; however, all of the characters in any single event must come from the same external
+ * entity, so that the Locator provides useful information.
*
- * <p>The application must not attempt to read from the array
- * outside of the specified range.</p>
+ * <p>The application must not attempt to read from the array outside of the specified range.
*
- * <p>Note that some parsers will report whitespace using the
- * ignorableWhitespace() method rather than this one (validating
- * parsers must do so).</p>
+ * <p>Note that some parsers will report whitespace using the ignorableWhitespace() method
+ * rather than this one (validating parsers must do so).
*
* @param chars The characters from the XML document.
* @param start The start position in the array.
* @param length The number of characters to read from the array.
- * @throws StreamException Any SAX exception, possibly
- * wrapping another exception.
+ * @throws StreamException Any SAX exception, possibly wrapping another exception.
* @see #ignorableWhitespace
* @see org.xml.sax.Locator
- *
* @throws StreamException
*/
public void characters(char chars[], int start, int length) throws StreamException {
- // It does not make sense to continue with rest of the method if the number of
+ // It does not make sense to continue with rest of the method if the number of
// characters to read from array is 0.
// Section 7.6.1 of XSLT 1.0 (http://www.w3.org/TR/xslt#value-of) suggest no text node
// is created if string is empty.
- if (length == 0)
- return;
-
+ if (length == 0) return;
+
final XmlWriter writer = this.writer;
final int context = this.context;
final String illegalCharacterSequence = illegalCharacterSequences[context];
-
+
try {
int i;
-
+
final int end = start + length;
- int lastDirtyCharProcessed = start - 1; // last non-clean character that was processed
- // that was processed
+ // last non-clean character that was processed that was processed
+ int lastDirtyCharProcessed = start - 1;
int matchedIllegalCharacters = this.matchedIllegalCharacters;
int squareBrackets = this.squareBrackets;
for (i = start; i < end; i++) {
char ch = chars[i];
-
+
if (illegalCharacterSequence != null) {
while (true) {
if (ch == illegalCharacterSequence.charAt(matchedIllegalCharacters)) {
if (++matchedIllegalCharacters == illegalCharacterSequence.length()) {
- throw new IllegalCharacterSequenceException("Illegal character sequence \"" + illegalCharacterSequence + "\"");
+ throw new IllegalCharacterSequenceException(
+ "Illegal character sequence \""
+ + illegalCharacterSequence
+ + "\"");
}
break;
} else if (matchedIllegalCharacters > 0) {
int offset = 1;
- loop: while (offset < matchedIllegalCharacters) {
+ loop:
+ while (offset < matchedIllegalCharacters) {
for (int j = 0; j < matchedIllegalCharacters - offset; j++) {
- if (illegalCharacterSequence.charAt(j) != illegalCharacterSequence.charAt(j+offset)) {
+ if (illegalCharacterSequence.charAt(j)
+ != illegalCharacterSequence.charAt(j + offset)) {
offset++;
continue loop;
}
@@ -377,10 +362,10 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
}
}
-
+
String replacement = null;
boolean generateCharacterReference = false;
-
+
if (context == MIXED_CONTENT || context == ATTRIBUTE_VALUE) {
if (ch <= 0x1F) {
// Range 0x00 through 0x1F inclusive
@@ -393,8 +378,8 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
// 0xD CARRIAGE RETURN
//
// We also cover 0x0 ... It isn't valid
- // but we will output "�"
-
+ // but we will output "�"
+
// The default will handle this just fine, but this
// is a little performance boost to handle the more
// common TAB, NEW-LINE, CARRIAGE-RETURN
@@ -443,17 +428,19 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
// LINE SEPARATOR
replacement = "
";
}
-
+
if (ch == ']') {
squareBrackets++;
} else {
squareBrackets = 0;
}
}
-
+
int startClean = lastDirtyCharProcessed + 1;
int lengthClean = i - startClean;
- if (replacement != null || generateCharacterReference || lengthClean == CHUNK_SIZE) {
+ if (replacement != null
+ || generateCharacterReference
+ || lengthClean == CHUNK_SIZE) {
if (startClean < i) {
writer.write(chars, startClean, lengthClean);
}
@@ -465,7 +452,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
lastDirtyCharProcessed = i;
}
}
-
+
// we've reached the end. Any clean characters at the
// end of the array than need to be written out?
int startClean = lastDirtyCharProcessed + 1;
@@ -487,7 +474,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
void characters(String s, int start, int length) throws StreamException {
while (length > 0) {
int count = Math.min(length, CHUNK_SIZE);
- s.getChars(start, start+count, charsBuff, 0);
+ s.getChars(start, start + count, charsBuff, 0);
characters(charsBuff, 0, count);
start += count;
length -= count;
@@ -509,11 +496,11 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
closeStartTag();
if (data instanceof CharacterData) {
try {
- ((CharacterData)data).writeTo(this);
+ ((CharacterData) data).writeTo(this);
} catch (IOException ex) {
Throwable cause = ex.getCause();
if (cause instanceof StreamException) {
- throw (StreamException)cause;
+ throw (StreamException) cause;
} else {
throw new StreamException(ex);
}
@@ -524,10 +511,10 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
@Override
- public void startElement(String namespaceURI, String localName, String prefix) throws StreamException {
+ public void startElement(String namespaceURI, String localName, String prefix)
+ throws StreamException {
closeStartTag();
- try
- {
+ try {
switchContext(TAG);
writer.write('<');
if (!prefix.isEmpty()) {
@@ -535,24 +522,24 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
writer.write(':');
}
writer.write(localName);
- }
- catch (IOException e)
- {
+ } catch (IOException e) {
throw new StreamException(e);
}
- if (2*(depth+1) > elementNameStack.length) {
- String[] newElementNameStack = new String[elementNameStack.length*2];
+ if (2 * (depth + 1) > elementNameStack.length) {
+ String[] newElementNameStack = new String[elementNameStack.length * 2];
System.arraycopy(elementNameStack, 0, newElementNameStack, 0, elementNameStack.length);
elementNameStack = newElementNameStack;
}
- elementNameStack[2*depth] = prefix;
- elementNameStack[2*depth+1] = localName;
+ elementNameStack[2 * depth] = prefix;
+ elementNameStack[2 * depth + 1] = localName;
depth++;
startTagOpen = true;
}
@Override
- public void processDocumentTypeDeclaration(String rootName, String publicId, String systemId, String internalSubset) throws StreamException {
+ public void processDocumentTypeDeclaration(
+ String rootName, String publicId, String systemId, String internalSubset)
+ throws StreamException {
startDTD(rootName, publicId, systemId);
if (internalSubset != null) {
writeInternalSubset(internalSubset);
@@ -560,8 +547,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
endDTD();
}
- public void startDTD(String name, String publicId, String systemId) throws StreamException
- {
+ public void startDTD(String name, String publicId, String systemId) throws StreamException {
inDoctype = true;
try {
writer.write("<!DOCTYPE ");
@@ -580,13 +566,13 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
writer.write(systemId);
writer.write('\"');
}
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
throw new StreamException(ex);
}
}
- private void writeAttribute(String prefix, String localName, String value) throws StreamException {
+ private void writeAttribute(String prefix, String localName, String value)
+ throws StreamException {
try {
writer.write(' ');
if (!prefix.isEmpty()) {
@@ -607,7 +593,8 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
@Override
- public void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException {
+ public void processNamespaceDeclaration(String prefix, String namespaceURI)
+ throws StreamException {
if (prefix.isEmpty()) {
writeAttribute("", "xmlns", namespaceURI);
} else {
@@ -616,18 +603,25 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
@Override
- public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) throws StreamException {
+ public void processAttribute(
+ String namespaceURI,
+ String localName,
+ String prefix,
+ String value,
+ String type,
+ boolean specified)
+ throws StreamException {
writeAttribute(prefix, localName, value);
}
@Override
- public void processAttribute(String name, String value, String type, boolean specified) throws StreamException {
+ public void processAttribute(String name, String value, String type, boolean specified)
+ throws StreamException {
writeAttribute("", name, value);
}
@Override
- public void attributesCompleted() throws StreamException {
- }
+ public void attributesCompleted() throws StreamException {}
@Override
public void endElement() throws StreamException {
@@ -642,12 +636,12 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
} else {
switchContext(TAG);
writer.write("</");
- String prefix = elementNameStack[2*depth];
+ String prefix = elementNameStack[2 * depth];
if (!prefix.isEmpty()) {
writer.write(prefix);
writer.write(':');
}
- writer.write(elementNameStack[2*depth+1]);
+ writer.write(elementNameStack[2 * depth + 1]);
writer.write('>');
}
switchContext(MIXED_CONTENT);
@@ -679,8 +673,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
@Override
- public void endCDATASection() throws StreamException
- {
+ public void endCDATASection() throws StreamException {
try {
writer.write("]]>");
} catch (IOException ex) {
@@ -691,6 +684,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
/**
* Report the end of DTD declarations.
+ *
* @throws StreamException The application may raise an exception.
* @see #startDTD
*/
@@ -718,8 +712,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
/**
- * For the enclosing elements starting tag write out
- * out any attributes followed by ">"
+ * For the enclosing elements starting tag write out out any attributes followed by ">"
*
* @throws StreamException
*/
@@ -794,7 +787,8 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
}
}
- public void unparsedEntityDecl(String name, String pubID, String sysID, String notationName) throws StreamException {
+ public void unparsedEntityDecl(String name, String pubID, String sysID, String notationName)
+ throws StreamException {
try {
DTDprolog();
writer.write("<!ENTITY ");
@@ -813,9 +807,10 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
throw new StreamException(ex);
}
}
-
+
/**
- * A private helper method to output the
+ * A private helper method to output the
+ *
* @throws StreamException
* @throws IOException
*/
@@ -825,8 +820,9 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
inDoctype = false;
}
}
-
- public void writeRaw(String s, UnmappableCharacterHandler unmappableCharacterHandler) throws StreamException {
+
+ public void writeRaw(String s, UnmappableCharacterHandler unmappableCharacterHandler)
+ throws StreamException {
try {
writer.setUnmappableCharacterHandler(unmappableCharacterHandler);
writer.write(s);
@@ -843,7 +839,7 @@ public final class Serializer implements XmlHandler, CharacterDataSink {
writer.write('&');
writer.write(name);
writer.write(';');
- } catch(IOException ex) {
+ } catch (IOException ex) {
throw new StreamException(ex);
}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/SerializerWriter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/SerializerWriter.java
index c1de9b402..6c24b2aa5 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/SerializerWriter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/SerializerWriter.java
@@ -24,8 +24,8 @@ import java.io.Writer;
import org.apache.axiom.core.stream.StreamException;
/**
- * {@link Writer} that writes character data as {@link ToXMLStream#characters(char[], int, int)}
- * to a {@link ToXMLStream}.
+ * {@link Writer} that writes character data as {@link ToXMLStream#characters(char[], int, int)} to
+ * a {@link ToXMLStream}.
*/
final class SerializerWriter extends Writer {
private final Serializer serializer;
@@ -53,10 +53,8 @@ final class SerializerWriter extends Writer {
}
@Override
- public void close() throws IOException {
- }
+ public void close() throws IOException {}
@Override
- public void flush() throws IOException {
- }
+ public void flush() throws IOException {}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
index e49d140d5..7031f9548 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
@@ -28,7 +28,7 @@ abstract class ASCIICompatibleXmlWriter extends XmlWriter {
final byte[] buffer = new byte[4096];
int bufferPosition;
private char highSurrogate;
-
+
ASCIICompatibleXmlWriter(OutputStream out) {
this.out = out;
}
@@ -48,7 +48,7 @@ abstract class ASCIICompatibleXmlWriter extends XmlWriter {
if (bufferPosition == buffer.length) {
flushBuffer();
}
- buffer[bufferPosition++] = (byte)c;
+ buffer[bufferPosition++] = (byte) c;
} else {
internalWrite(c);
}
@@ -81,14 +81,14 @@ abstract class ASCIICompatibleXmlWriter extends XmlWriter {
final int bufferLength = buffer.length;
int bufferPosition = this.bufferPosition;
int highSurrogate = this.highSurrogate;
- for (int i=0, length=s.length(); i<length; i++) {
+ for (int i = 0, length = s.length(); i < length; i++) {
char c = s.charAt(i);
if (c < 128 && highSurrogate == 0) {
if (bufferPosition == bufferLength) {
out.write(buffer, 0, bufferLength);
bufferPosition = 0;
}
- buffer[bufferPosition++] = (byte)c;
+ buffer[bufferPosition++] = (byte) c;
} else {
this.bufferPosition = bufferPosition;
internalWrite(c);
@@ -105,14 +105,14 @@ abstract class ASCIICompatibleXmlWriter extends XmlWriter {
final int bufferLength = buffer.length;
int bufferPosition = this.bufferPosition;
int highSurrogate = this.highSurrogate;
- for (int i=0; i<length; i++) {
- char c = chars[start+i];
+ for (int i = 0; i < length; i++) {
+ char c = chars[start + i];
if (c < 128 && highSurrogate == 0) {
if (bufferPosition == bufferLength) {
out.write(buffer, 0, bufferLength);
bufferPosition = 0;
}
- buffer[bufferPosition++] = (byte)c;
+ buffer[bufferPosition++] = (byte) c;
} else {
this.bufferPosition = bufferPosition;
internalWrite(c);
@@ -128,24 +128,21 @@ abstract class ASCIICompatibleXmlWriter extends XmlWriter {
return new AbstractBase64EncodingOutputStream() {
@Override
protected void doWrite(byte[] b) throws IOException {
- if (buffer.length-bufferPosition < 4) {
+ if (buffer.length - bufferPosition < 4) {
ASCIICompatibleXmlWriter.this.flushBuffer();
}
System.arraycopy(b, 0, buffer, bufferPosition, 4);
bufferPosition += 4;
}
-
+
@Override
- protected void flushBuffer() throws IOException {
- }
-
+ protected void flushBuffer() throws IOException {}
+
@Override
- protected void doFlush() throws IOException {
- }
-
+ protected void doFlush() throws IOException {}
+
@Override
- protected void doClose() throws IOException {
- }
+ protected void doClose() throws IOException {}
};
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/Latin1XmlWriter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/Latin1XmlWriter.java
index edda80fcd..fc131771f 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/Latin1XmlWriter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/Latin1XmlWriter.java
@@ -23,7 +23,8 @@ import java.io.OutputStream;
final class Latin1XmlWriter extends ASCIICompatibleXmlWriter {
private final int maxChar;
- private UnmappableCharacterHandler unmappableCharacterHandler = UnmappableCharacterHandler.THROW_EXCEPTION;
+ private UnmappableCharacterHandler unmappableCharacterHandler =
+ UnmappableCharacterHandler.THROW_EXCEPTION;
Latin1XmlWriter(OutputStream out, int maxChar) {
super(out);
@@ -31,7 +32,8 @@ final class Latin1XmlWriter extends ASCIICompatibleXmlWriter {
}
@Override
- public void setUnmappableCharacterHandler(UnmappableCharacterHandler unmappableCharacterHandler) throws IOException {
+ public void setUnmappableCharacterHandler(UnmappableCharacterHandler unmappableCharacterHandler)
+ throws IOException {
this.unmappableCharacterHandler = unmappableCharacterHandler;
}
@@ -40,7 +42,7 @@ final class Latin1XmlWriter extends ASCIICompatibleXmlWriter {
if (codePoint > maxChar) {
unmappableCharacterHandler.processUnmappableCharacter(codePoint, this);
} else {
- writeByte((byte)codePoint);
+ writeByte((byte) codePoint);
}
}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriter.java
index 48bd4c67f..44f49eecc 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriter.java
@@ -34,7 +34,8 @@ final class OutputStreamXmlWriter extends XmlWriter {
private final CharBuffer encoderIn;
private final ByteBuffer encoderOut;
private final CharsetEncoder encoder;
- private UnmappableCharacterHandler unmappableCharacterHandler = UnmappableCharacterHandler.THROW_EXCEPTION;
+ private UnmappableCharacterHandler unmappableCharacterHandler =
+ UnmappableCharacterHandler.THROW_EXCEPTION;
private boolean processingUnmappableCharacter;
private CharBuffer encoderInAlt;
@@ -48,7 +49,7 @@ final class OutputStreamXmlWriter extends XmlWriter {
private void flushEncodingOut() throws IOException {
out.write(encoderOut.array(), 0, encoderOut.position());
// Cast ensures compatibility with Java 8.
- ((Buffer)encoderOut).clear();
+ ((Buffer) encoderOut).clear();
}
private CharBuffer getEncoderIn() throws IOException {
@@ -64,7 +65,7 @@ final class OutputStreamXmlWriter extends XmlWriter {
private void flush(CharBuffer encoderIn) throws IOException {
// Cast ensures compatibility with Java 8.
- ((Buffer)encoderIn).flip();
+ ((Buffer) encoderIn).flip();
while (true) {
CoderResult coderResult = encoder.encode(encoderIn, encoderOut, false);
if (coderResult.isUnderflow()) {
@@ -80,7 +81,8 @@ final class OutputStreamXmlWriter extends XmlWriter {
try {
switch (coderResult.length()) {
case 1:
- unmappableCharacterHandler.processUnmappableCharacter(encoderIn.get(), this);
+ unmappableCharacterHandler.processUnmappableCharacter(
+ encoderIn.get(), this);
break;
case 2:
throw new UnsupportedOperationException("TODO");
@@ -98,7 +100,8 @@ final class OutputStreamXmlWriter extends XmlWriter {
}
@Override
- public void setUnmappableCharacterHandler(UnmappableCharacterHandler unmappableCharacterHandler) throws IOException {
+ public void setUnmappableCharacterHandler(UnmappableCharacterHandler unmappableCharacterHandler)
+ throws IOException {
if (unmappableCharacterHandler != this.unmappableCharacterHandler) {
flush(encoderIn);
this.unmappableCharacterHandler = unmappableCharacterHandler;
@@ -153,22 +156,19 @@ final class OutputStreamXmlWriter extends XmlWriter {
if (encoderIn.remaining() < 4) {
OutputStreamXmlWriter.this.flush(encoderIn);
}
- for (int i=0; i<4; i++) {
- encoderIn.put((char)(b[i] & 0xFF));
+ for (int i = 0; i < 4; i++) {
+ encoderIn.put((char) (b[i] & 0xFF));
}
}
-
+
@Override
- protected void flushBuffer() throws IOException {
- }
-
+ protected void flushBuffer() throws IOException {}
+
@Override
- protected void doFlush() throws IOException {
- }
-
+ protected void doFlush() throws IOException {}
+
@Override
- protected void doClose() throws IOException {
- }
+ protected void doClose() throws IOException {}
};
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UTF8XmlWriter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UTF8XmlWriter.java
index 596615e02..20decfed4 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UTF8XmlWriter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UTF8XmlWriter.java
@@ -27,24 +27,25 @@ final class UTF8XmlWriter extends ASCIICompatibleXmlWriter {
}
@Override
- public void setUnmappableCharacterHandler(UnmappableCharacterHandler unmappableCharacterHandler) {
+ public void setUnmappableCharacterHandler(
+ UnmappableCharacterHandler unmappableCharacterHandler) {
// There are no unmappable characters in UTF-8
}
@Override
protected void writeNonASCIICharacter(int codePoint) throws IOException {
if (codePoint < 0x800) {
- writeByte((byte)(0xc0 + (codePoint >> 6)));
- writeByte((byte)(0x80 + (codePoint & 0x3f)));
+ writeByte((byte) (0xc0 + (codePoint >> 6)));
+ writeByte((byte) (0x80 + (codePoint & 0x3f)));
} else if (codePoint < 0x10000) {
- writeByte((byte)(0xe0 + (codePoint >> 12)));
- writeByte((byte)(0x80 + ((codePoint >> 6) & 0x3f)));
- writeByte((byte)(0x80 + (codePoint & 0x3f)));
+ writeByte((byte) (0xe0 + (codePoint >> 12)));
+ writeByte((byte) (0x80 + ((codePoint >> 6) & 0x3f)));
+ writeByte((byte) (0x80 + (codePoint & 0x3f)));
} else {
- writeByte((byte)(0xf0 + (codePoint >> 18)));
- writeByte((byte)(0x80 + ((codePoint >> 12) & 0x3f)));
- writeByte((byte)(0x80 + ((codePoint >> 6) & 0x3f)));
- writeByte((byte)(0x80 + (codePoint & 0x3f)));
+ writeByte((byte) (0xf0 + (codePoint >> 18)));
+ writeByte((byte) (0x80 + ((codePoint >> 12) & 0x3f)));
+ writeByte((byte) (0x80 + ((codePoint >> 6) & 0x3f)));
+ writeByte((byte) (0x80 + (codePoint & 0x3f)));
}
}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UnmappableCharacterHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UnmappableCharacterHandler.java
index 0e900f310..61a6ba5e8 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UnmappableCharacterHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UnmappableCharacterHandler.java
@@ -21,19 +21,24 @@ package org.apache.axiom.core.stream.serializer.writer;
import java.io.IOException;
public abstract class UnmappableCharacterHandler {
- public static final UnmappableCharacterHandler THROW_EXCEPTION = new UnmappableCharacterHandler() {
- @Override
- public void processUnmappableCharacter(int codePoint, XmlWriter writer) throws IOException {
- throw new IOException("Unmappable character (code point " + codePoint + ")");
- }
- };
+ public static final UnmappableCharacterHandler THROW_EXCEPTION =
+ new UnmappableCharacterHandler() {
+ @Override
+ public void processUnmappableCharacter(int codePoint, XmlWriter writer)
+ throws IOException {
+ throw new IOException("Unmappable character (code point " + codePoint + ")");
+ }
+ };
- public static final UnmappableCharacterHandler CONVERT_TO_CHARACTER_REFERENCE = new UnmappableCharacterHandler() {
- @Override
- public void processUnmappableCharacter(int codePoint, XmlWriter writer) throws IOException {
- writer.writeCharacterReference(codePoint);
- }
- };
+ public static final UnmappableCharacterHandler CONVERT_TO_CHARACTER_REFERENCE =
+ new UnmappableCharacterHandler() {
+ @Override
+ public void processUnmappableCharacter(int codePoint, XmlWriter writer)
+ throws IOException {
+ writer.writeCharacterReference(codePoint);
+ }
+ };
- public abstract void processUnmappableCharacter(int codePoint, XmlWriter writer) throws IOException;
+ public abstract void processUnmappableCharacter(int codePoint, XmlWriter writer)
+ throws IOException;
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/WriterXmlWriter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/WriterXmlWriter.java
index 999db4824..75eb8d6ba 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/WriterXmlWriter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/WriterXmlWriter.java
@@ -32,8 +32,8 @@ public final class WriterXmlWriter extends XmlWriter {
}
@Override
- public void setUnmappableCharacterHandler(UnmappableCharacterHandler unmappableCharacterHandler) {
- }
+ public void setUnmappableCharacterHandler(
+ UnmappableCharacterHandler unmappableCharacterHandler) {}
@Override
public void write(char c) throws IOException {
@@ -56,6 +56,5 @@ public final class WriterXmlWriter extends XmlWriter {
}
@Override
- public void flushBuffer() throws IOException {
- }
+ public void flushBuffer() throws IOException {}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/XmlWriter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/XmlWriter.java
index 9899364e1..0904b053b 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/XmlWriter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/XmlWriter.java
@@ -39,20 +39,24 @@ public abstract class XmlWriter {
}
}
- public abstract void setUnmappableCharacterHandler(UnmappableCharacterHandler unmappableCharacterHandler) throws IOException;
+ public abstract void setUnmappableCharacterHandler(
+ UnmappableCharacterHandler unmappableCharacterHandler) throws IOException;
+
public abstract void write(char c) throws IOException;
+
public abstract void write(String s) throws IOException;
+
public abstract void write(char chars[], int start, int length) throws IOException;
public abstract AbstractBase64EncodingOutputStream getBase64EncodingOutputStream();
/**
* Write any pending data to the underlying stream, without flushing the stream itself.
- *
+ *
* @throws IOException
*/
public abstract void flushBuffer() throws IOException;
-
+
public final void writeCharacterReference(int codePoint) throws IOException {
write("&#");
// TODO: optimize this
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/StAXExceptionUtil.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/StAXExceptionUtil.java
index b19894581..4b3980e2f 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/StAXExceptionUtil.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/StAXExceptionUtil.java
@@ -24,20 +24,20 @@ import org.apache.axiom.core.stream.StreamException;
public final class StAXExceptionUtil {
private StAXExceptionUtil() {}
-
+
public static StreamException toStreamException(XMLStreamException ex) {
Throwable cause = ex.getCause();
if (cause instanceof StreamException) {
- return (StreamException)cause;
+ return (StreamException) cause;
} else {
return new StreamException(ex);
}
}
-
+
public static XMLStreamException toXMLStreamException(StreamException ex) {
Throwable cause = ex.getCause();
if (cause instanceof XMLStreamException) {
- return (XMLStreamException)cause;
+ return (XMLStreamException) cause;
} else {
return new XMLStreamException(ex.getMessage(), ex);
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/input/StAXPullInput.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/input/StAXPullInput.java
index e2f03b3fd..b675911c1 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/input/StAXPullInput.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/input/StAXPullInput.java
@@ -31,8 +31,12 @@ public final class StAXPullInput implements XmlInput {
private final XMLStreamReaderHelperFactory helperFactory;
private final boolean autoClose;
private final Closeable closeable;
-
- public StAXPullInput(XMLStreamReader reader, XMLStreamReaderHelperFactory helperFactory, boolean autoClose, Closeable closeable) {
+
+ public StAXPullInput(
+ XMLStreamReader reader,
+ XMLStreamReaderHelperFactory helperFactory,
+ boolean autoClose,
+ Closeable closeable) {
this.reader = reader;
this.helperFactory = helperFactory;
this.autoClose = autoClose;
@@ -45,6 +49,7 @@ public final class StAXPullInput implements XmlInput {
@Override
public XmlReader createReader(XmlHandler handler) {
- return new StAXPullReader(reader, helperFactory.createHelper(reader), handler, closeable, autoClose);
+ return new StAXPullReader(
+ reader, helperFactory.createHelper(reader), handler, closeable, autoClose);
}
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/input/StAXPullReader.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/input/StAXPullReader.java
index a5e4cd621..4499107d1 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/input/StAXPullReader.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/input/StAXPullReader.java
@@ -35,20 +35,20 @@ import java.io.Closeable;
/* Implementation note about error handling
* ----------------------------------------
- *
+ *
* Usually, code that uses StAX directly just stops processing of an XML document
* once the first parsing error has been reported. However, since Axiom
* uses deferred parsing, and client code accesses the XML infoset using
* an object model, things are more complicated. Indeed, if the XML
* document is not well formed, the corresponding error might be reported
* as a runtime exception by any call to a method of an OM node.
- *
+ *
* Typically the client code will have some error handling that will intercept
* runtime exceptions and take appropriate action. Very often this error handling
* code might want to access the object model again, for example to log the request that caused the
* failure. This causes no problem except if the runtime exception was caused by a
* parsing error, in which case Axiom would again try to pull events from the parser.
- *
+ *
* This would lead to a situation where Axiom accesses a parser that has reported a parsing
* error before. While one would expect that after a first error reported by the parser, all
* subsequent invocations of the parser will fail, this is not the case for all parsers
@@ -58,40 +58,46 @@ import java.io.Closeable;
* (incorrect) events afterwards. The explanation for this behaviour might be that
* the situation described here is quite uncommon when StAX is used directly (i.e. not through
* Axiom).
- *
+ *
* To avoid this, the builder remembers exceptions thrown by the parser and rethrows
* them during a call to next().
*/
final class StAXPullReader implements XmlReader {
private static final Log log = LogFactory.getLog(StAXPullReader.class);
-
+
/** Field parser */
private XMLStreamReader reader;
+
private XMLStreamReaderHelper helper;
private final XmlHandler handler;
private final Closeable closeable;
-
+
/**
- * Specifies whether the builder/parser should be automatically closed when the
- * {@link XMLStreamConstants#END_DOCUMENT} event is reached.
+ * Specifies whether the builder/parser should be automatically closed when the {@link
+ * XMLStreamConstants#END_DOCUMENT} event is reached.
*/
private final boolean autoClose;
-
- private boolean isClosed = false; // Indicate if parser is closed
+
+ private boolean isClosed = false; // Indicate if parser is closed
/**
- * Stores exceptions thrown by the parser. Used to avoid accessing the parser
- * again after is has thrown a parse exception.
+ * Stores exceptions thrown by the parser. Used to avoid accessing the parser again after is has
+ * thrown a parse exception.
*/
private Exception parserException;
-
+
private boolean start = true;
-
- StAXPullReader(XMLStreamReader reader, XMLStreamReaderHelper helper, XmlHandler handler,
- Closeable closeable, boolean autoClose) {
+
+ StAXPullReader(
+ XMLStreamReader reader,
+ XMLStreamReaderHelper helper,
+ XmlHandler handler,
+ Closeable closeable,
+ boolean autoClose) {
if (reader.getEventType() != XMLStreamReader.START_DOCUMENT) {
- throw new IllegalStateException("The XMLStreamReader must be positioned on a START_DOCUMENT event");
+ throw new IllegalStateException(
+ "The XMLStreamReader must be positioned on a START_DOCUMENT event");
}
this.reader = reader;
this.helper = helper;
@@ -99,11 +105,11 @@ final class StAXPullReader implements XmlReader {
this.closeable = closeable;
this.autoClose = autoClose;
}
-
+
private static String normalize(String s) {
return s == null ? "" : s;
}
-
+
private void processText(int textType) throws StreamException {
if (textType == XMLStreamConstants.CHARACTERS) {
CharacterData data = helper.getCharacterData();
@@ -151,12 +157,12 @@ final class StAXPullReader implements XmlReader {
// Can't see a reason why we would want to surface an exception
// while closing the parser.
if (log.isDebugEnabled()) {
- log.debug("Exception occurred during parser close. " +
- "Processing continues. " + e);
+ log.debug(
+ "Exception occurred during parser close. " + "Processing continues. " + e);
}
} finally {
isClosed = true;
-// builderHandler.done = true;
+ // builderHandler.done = true;
// Release the parser so that it can be GC'd or reused. This is important because the
// object model keeps a reference to the builder even after the builder is complete.
reader = null;
@@ -167,18 +173,22 @@ final class StAXPullReader implements XmlReader {
@Override
public boolean proceed() throws StreamException {
int token = parserNext();
-
+
// Note: if autoClose is enabled, then the parser may be null at this point
-
+
switch (token) {
case XMLStreamConstants.START_DOCUMENT:
- handler.startDocument(reader.getEncoding(), reader.getVersion(), reader.getCharacterEncodingScheme(),
+ handler.startDocument(
+ reader.getEncoding(),
+ reader.getVersion(),
+ reader.getCharacterEncodingScheme(),
reader.standaloneSet() ? reader.isStandalone() : null);
break;
- case XMLStreamConstants.START_ELEMENT: {
- processElement();
- break;
- }
+ case XMLStreamConstants.START_ELEMENT:
+ {
+ processElement();
+ break;
+ }
case XMLStreamConstants.CHARACTERS:
case XMLStreamConstants.CDATA:
case XMLStreamConstants.SPACE:
@@ -206,13 +216,13 @@ final class StAXPullReader implements XmlReader {
case XMLStreamConstants.ENTITY_REFERENCE:
handler.processEntityReference(reader.getLocalName(), reader.getText());
break;
- default :
+ default:
throw new IllegalStateException();
}
-
+
return token == XMLStreamReader.END_DOCUMENT;
}
-
+
private void processElement() throws StreamException {
String namespaceURI = normalize(reader.getNamespaceURI());
String localName = reader.getLocalName();
@@ -220,8 +230,7 @@ final class StAXPullReader implements XmlReader {
handler.startElement(namespaceURI, localName, prefix);
for (int i = 0, count = reader.getNamespaceCount(); i < count; i++) {
handler.processNamespaceDeclaration(
- normalize(reader.getNamespacePrefix(i)),
- normalize(reader.getNamespaceURI(i)));
+ normalize(reader.getNamespacePrefix(i)), normalize(reader.getNamespaceURI(i)));
}
for (int i = 0, count = reader.getAttributeCount(); i < count; i++) {
handler.processAttribute(
@@ -234,7 +243,7 @@ final class StAXPullReader implements XmlReader {
}
handler.attributesCompleted();
}
-
+
private void processDTD() throws StreamException {
DTDInfo dtdInfo = helper.getDTDInfo();
String internalSubset = getDTDText();
@@ -242,15 +251,17 @@ final class StAXPullReader implements XmlReader {
if (internalSubset != null && internalSubset.length() == 0) {
internalSubset = null;
}
- handler.processDocumentTypeDeclaration(dtdInfo.getRootName(), dtdInfo.getPublicId(),
- dtdInfo.getSystemId(), internalSubset);
+ handler.processDocumentTypeDeclaration(
+ dtdInfo.getRootName(),
+ dtdInfo.getPublicId(),
+ dtdInfo.getSystemId(),
+ internalSubset);
}
-
+
/**
- * The getText() method for a DOCTYPE returns the
- * subset of the DOCTYPE (not the direct infoset).
- * This may force the parser to get information from
- * the network.
+ * The getText() method for a DOCTYPE returns the subset of the DOCTYPE (not the direct
+ * infoset). This may force the parser to get information from the network.
+ *
* @return doctype subset
*/
private String getDTDText() {
@@ -262,24 +273,27 @@ final class StAXPullReader implements XmlReader {
// attempts to load the external subset even if
// external enties is false. So ignore this error
// if external entity support is explicitly disabled.
- Boolean b = (Boolean) reader.getProperty(
- XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
+ Boolean b =
+ (Boolean) reader.getProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
if (b == null || b == Boolean.TRUE) {
throw e;
}
if (log.isDebugEnabled()) {
- log.debug("An exception occurred while calling getText() for a DOCTYPE. " +
- "The exception is ignored because external " +
- "entites support is disabled. " +
- "The ignored exception is " + e);
+ log.debug(
+ "An exception occurred while calling getText() for a DOCTYPE. "
+ + "The exception is ignored because external "
+ + "entites support is disabled. "
+ + "The ignored exception is "
+ + e);
}
}
return text;
}
/**
- * Pushes the virtual parser ahead one token.
- * If a look ahead token was calculated it is returned.
+ * Pushes the virtual parser ahead one token. If a look ahead token was calculated it is
+ * returned.
+ *
* @return next token
* @throws StreamException
*/
@@ -290,12 +304,13 @@ final class StAXPullReader implements XmlReader {
} else {
try {
if (parserException != null) {
- log.warn("Attempt to access a parser that has thrown a parse exception before; " +
- "rethrowing the original exception.");
+ log.warn(
+ "Attempt to access a parser that has thrown a parse exception before; "
+ + "rethrowing the original exception.");
if (parserException instanceof XMLStreamException) {
- throw (XMLStreamException)parserException;
+ throw (XMLStreamException) parserException;
} else {
- throw (RuntimeException)parserException;
+ throw (RuntimeException) parserException;
}
}
int event;
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/DummyLocation.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/DummyLocation.java
index a269af44b..c67c23243 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/DummyLocation.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/DummyLocation.java
@@ -21,16 +21,15 @@ package org.apache.axiom.core.stream.stax.pull.output;
import javax.xml.stream.Location;
/**
- * Dummy {@link Location} implementation. It always returns -1 for the location
- * and <code>null</code> for the publicId and systemId. It may be used by
- * {@link javax.xml.stream.XMLStreamReader} implementations that don't support
- * the concept of location.
+ * Dummy {@link Location} implementation. It always returns -1 for the location and <code>null
+ * </code> for the publicId and systemId. It may be used by {@link javax.xml.stream.XMLStreamReader}
+ * implementations that don't support the concept of location.
*/
class DummyLocation implements Location {
static final DummyLocation INSTANCE = new DummyLocation();
private DummyLocation() {}
-
+
@Override
public int getLineNumber() {
return -1;
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/InternalXMLStreamReader.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/InternalXMLStreamReader.java
index 6d94b409c..4364a918c 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/InternalXMLStreamReader.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/InternalXMLStreamReader.java
@@ -22,7 +22,10 @@ import javax.xml.stream.XMLStreamReader;
public interface InternalXMLStreamReader extends XMLStreamReader {
String getRootName();
+
String getPublicId();
+
String getSystemId();
+
Object getCharacterData();
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivot.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivot.java
index f98f43dd0..8bac715aa 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivot.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivot.java
@@ -60,11 +60,12 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
return XMLConstants.XMLNS_ATTRIBUTE;
} else {
int bindings = getNamespaceBindingsCount();
- outer: for (int i=(bindings-1)*2; i>=0; i-=2) {
- if (namespaceURI.equals(namespaceStack[i+1])) {
+ outer:
+ for (int i = (bindings - 1) * 2; i >= 0; i -= 2) {
+ if (namespaceURI.equals(namespaceStack[i + 1])) {
String prefix = namespaceStack[i];
// Now check that the prefix is not masked
- for (int j=i+2; j<bindings*2; j+=2) {
+ for (int j = i + 2; j < bindings * 2; j += 2) {
if (prefix.equals(namespaceStack[j])) {
continue outer;
}
@@ -93,12 +94,13 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
@Override
public boolean hasNext() {
if (next == null) {
- outer: while (--binding >= 0) {
- if (namespaceURI.equals(namespaceStack[binding*2+1])) {
- String prefix = namespaceStack[binding*2];
+ outer:
+ while (--binding >= 0) {
+ if (namespaceURI.equals(namespaceStack[binding * 2 + 1])) {
+ String prefix = namespaceStack[binding * 2];
// Now check that the prefix is not masked
- for (int j=binding+1; j<bindings; j++) {
- if (prefix.equals(namespaceStack[j*2])) {
+ for (int j = binding + 1; j < bindings; j++) {
+ if (prefix.equals(namespaceStack[j * 2])) {
continue outer;
}
}
@@ -129,22 +131,22 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
}
}
-
+
private static final int STATE_DEFAULT = 0;
-
+
/**
* All data for the current StAX event has been received and the instance is not ready to
* receive more data.
*/
private static final int STATE_EVENT_COMPLETE = 1;
-
+
/**
* Indicates that all character data should be collected until a non character event is
* encountered. This state is used to implement comment and CDATA section processing as well as
* {@link XMLStreamReader#getElementText()}.
*/
private static final int STATE_COLLECT_TEXT = 2;
-
+
/**
* Used in a CDATA section to indicate that the character data inside the CDATA section should
* be coalesced with the character data around the CDATA section. This state is used to
@@ -152,13 +154,13 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
* state transitions back to {@link #STATE_COLLECT_TEXT}.
*/
private static final int STATE_COALESCE_CDATA_SECTION = 3;
-
+
/**
* Indicates that all events should be skipped until a start or end element event is
* encountered. This state is used to implement {@link XMLStreamReader#nextTag()}.
*/
private static final int STATE_NEXT_TAG = 4;
-
+
/**
* Indicates that all content (character data) in a comment or processing instruction should be
* skipped. This state is used when comment or processing instruction is encountered in states
@@ -167,15 +169,13 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
* comment or processing instruction is reached.
*/
private static final int STATE_SKIP_CONTENT = 5;
-
- /**
- * Indicates that an error has occurred an that the instance is no longer usable.
- */
+
+ /** Indicates that an error has occurred an that the instance is no longer usable. */
private static final int STATE_ERROR = 6;
-
+
private final XMLStreamReaderExtensionFactory extensionFactory;
private XmlReader reader;
- private Map<String,Object> extensions;
+ private Map<String, Object> extensions;
private int state = STATE_DEFAULT;
private int previousState = -1;
private int eventType = -1;
@@ -198,7 +198,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
private String text;
// Entity reference name or processing instruction target
private String name;
-
+
// TODO: The constructor should take an XmlInput object as input
public StAXPivot(XMLStreamReaderExtensionFactory extensionFactory) {
this.extensionFactory = extensionFactory;
@@ -227,13 +227,13 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
private void putNamespaceDeclaration(int index, String prefix, String namespaceURI) {
- if (index*2 == namespaceStack.length) {
- String[] newNamespaceStack = new String[namespaceStack.length*2];
+ if (index * 2 == namespaceStack.length) {
+ String[] newNamespaceStack = new String[namespaceStack.length * 2];
System.arraycopy(namespaceStack, 0, newNamespaceStack, 0, namespaceStack.length);
namespaceStack = newNamespaceStack;
}
- namespaceStack[2*index] = prefix;
- namespaceStack[2*index+1] = namespaceURI;
+ namespaceStack[2 * index] = prefix;
+ namespaceStack[2 * index + 1] = namespaceURI;
}
private void checkState() {
@@ -241,23 +241,25 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
throw new IllegalStateException();
}
}
-
+
private void startCollectingText() {
state = STATE_COLLECT_TEXT;
if (accumulator == null) {
accumulator = new CharacterDataAccumulator();
}
}
-
+
private String stopCollectingText() {
String data = accumulator.toString();
accumulator.clear();
state = STATE_EVENT_COMPLETE;
return data;
}
-
+
@Override
- public void startDocument(String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone) throws StreamException {
+ public void startDocument(
+ String inputEncoding, String xmlVersion, String xmlEncoding, Boolean standalone)
+ throws StreamException {
checkState();
eventType = START_DOCUMENT;
encoding = inputEncoding;
@@ -275,7 +277,9 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
@Override
- public void processDocumentTypeDeclaration(String rootName, String publicId, String systemId, String internalSubset) throws StreamException {
+ public void processDocumentTypeDeclaration(
+ String rootName, String publicId, String systemId, String internalSubset)
+ throws StreamException {
checkState();
eventType = DTD;
this.rootName = rootName;
@@ -286,26 +290,27 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
@Override
- public void startElement(String namespaceURI, String localName, String prefix) throws StreamException {
+ public void startElement(String namespaceURI, String localName, String prefix)
+ throws StreamException {
checkState();
eventType = START_ELEMENT;
if (state == STATE_NEXT_TAG) {
state = STATE_DEFAULT;
}
- if (depth*3 == elementStack.length) {
- String[] newElementStack = new String[elementStack.length*2];
+ if (depth * 3 == elementStack.length) {
+ String[] newElementStack = new String[elementStack.length * 2];
System.arraycopy(elementStack, 0, newElementStack, 0, elementStack.length);
elementStack = newElementStack;
}
- elementStack[depth*3] = namespaceURI;
- elementStack[depth*3+1] = localName;
- elementStack[depth*3+2] = prefix;
- if (depth+1 == scopeStack.length) {
- int[] newScopeStack = new int[scopeStack.length*2];
+ elementStack[depth * 3] = namespaceURI;
+ elementStack[depth * 3 + 1] = localName;
+ elementStack[depth * 3 + 2] = prefix;
+ if (depth + 1 == scopeStack.length) {
+ int[] newScopeStack = new int[scopeStack.length * 2];
System.arraycopy(scopeStack, 0, newScopeStack, 0, scopeStack.length);
scopeStack = newScopeStack;
}
- scopeStack[depth+1] = scopeStack[depth];
+ scopeStack[depth + 1] = scopeStack[depth];
attributeCount = 0;
}
@@ -318,17 +323,24 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
@Override
- public void processAttribute(String namespaceURI, String localName, String prefix, String value, String type, boolean specified) throws StreamException {
- if (attributeCount*5 == attributeStack.length) {
- String[] newAttributeStack = new String[attributeStack.length*2];
+ public void processAttribute(
+ String namespaceURI,
+ String localName,
+ String prefix,
+ String value,
+ String type,
+ boolean specified)
+ throws StreamException {
+ if (attributeCount * 5 == attributeStack.length) {
+ String[] newAttributeStack = new String[attributeStack.length * 2];
System.arraycopy(attributeStack, 0, newAttributeStack, 0, attributeStack.length);
attributeStack = newAttributeStack;
}
- attributeStack[5*attributeCount] = namespaceURI;
- attributeStack[5*attributeCount+1] = localName;
- attributeStack[5*attributeCount+2] = prefix;
- attributeStack[5*attributeCount+3] = value;
- attributeStack[5*attributeCount+4] = type;
+ attributeStack[5 * attributeCount] = namespaceURI;
+ attributeStack[5 * attributeCount + 1] = localName;
+ attributeStack[5 * attributeCount + 2] = prefix;
+ attributeStack[5 * attributeCount + 3] = value;
+ attributeStack[5 * attributeCount + 4] = type;
attributeCount++;
}
@@ -340,8 +352,9 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
@Override
- public void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException {
- putNamespaceDeclaration(scopeStack[depth+1]++, prefix, namespaceURI);
+ public void processNamespaceDeclaration(String prefix, String namespaceURI)
+ throws StreamException {
+ putNamespaceDeclaration(scopeStack[depth + 1]++, prefix, namespaceURI);
}
@Override
@@ -504,7 +517,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
Object extension = extensionFactory.createExtension(name, this);
if (extension != null) {
if (extensions == null) {
- extensions = new HashMap<String,Object>();
+ extensions = new HashMap<String, Object>();
}
extensions.put(name, extension);
return extension;
@@ -558,35 +571,53 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
@Override
- public void require(int expectedType, String expectedNamespaceURI, String expectedLocalName) throws XMLStreamException {
+ public void require(int expectedType, String expectedNamespaceURI, String expectedLocalName)
+ throws XMLStreamException {
if (expectedType != eventType) {
- throw new XMLStreamException("Required type " + XMLEventUtils.getEventTypeString(expectedType)
- + ", actual type " + XMLEventUtils.getEventTypeString(eventType));
+ throw new XMLStreamException(
+ "Required type "
+ + XMLEventUtils.getEventTypeString(expectedType)
+ + ", actual type "
+ + XMLEventUtils.getEventTypeString(eventType));
}
if (expectedLocalName != null) {
- if (eventType != START_ELEMENT && eventType != END_ELEMENT
- && eventType != ENTITY_REFERENCE) {
- throw new XMLStreamException("Required a non-null local name, but current token " +
- "not a START_ELEMENT, END_ELEMENT or ENTITY_REFERENCE (was " +
- XMLEventUtils.getEventTypeString(eventType) + ")");
+ if (eventType != START_ELEMENT
+ && eventType != END_ELEMENT
+ && eventType != ENTITY_REFERENCE) {
+ throw new XMLStreamException(
+ "Required a non-null local name, but current token "
+ + "not a START_ELEMENT, END_ELEMENT or ENTITY_REFERENCE (was "
+ + XMLEventUtils.getEventTypeString(eventType)
+ + ")");
}
String localName = getLocalName();
if (!localName.equals(expectedLocalName)) {
- throw new XMLStreamException("Required local name '" + expectedLocalName +
- "'; current local name '" + localName + "'.");
+ throw new XMLStreamException(
+ "Required local name '"
+ + expectedLocalName
+ + "'; current local name '"
+ + localName
+ + "'.");
}
}
-
+
if (expectedNamespaceURI != null) {
if (eventType != START_ELEMENT && eventType != END_ELEMENT) {
- throw new XMLStreamException("Required non-null namespace URI, but current token " +
- "not a START_ELEMENT or END_ELEMENT (was " +
- XMLEventUtils.getEventTypeString(eventType) + ")");
+ throw new XMLStreamException(
+ "Required non-null namespace URI, but current token "
+ + "not a START_ELEMENT or END_ELEMENT (was "
+ + XMLEventUtils.getEventTypeString(eventType)
+ + ")");
}
- String namespaceURI = elementStack[3*depth];
+ String namespaceURI = elementStack[3 * depth];
if (!expectedNamespaceURI.equals(namespaceURI)) {
- throw new XMLStreamException("Required namespace '" + expectedNamespaceURI + "'; have '" + namespaceURI +"'.");
+ throw new XMLStreamException(
+ "Required namespace '"
+ + expectedNamespaceURI
+ + "'; have '"
+ + namespaceURI
+ + "'.");
}
}
}
@@ -656,24 +687,25 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
int getNamespaceBindingsCount() {
- return scopeStack[eventType == START_ELEMENT || eventType == END_ELEMENT ? depth + 1 : depth];
+ return scopeStack[
+ eventType == START_ELEMENT || eventType == END_ELEMENT ? depth + 1 : depth];
}
-
+
String lookupNamespaceURI(String prefix) {
if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
return XMLConstants.XML_NS_URI;
} else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
} else {
- for (int i=(getNamespaceBindingsCount()-1)*2; i>=0; i-=2) {
+ for (int i = (getNamespaceBindingsCount() - 1) * 2; i >= 0; i -= 2) {
if (prefix.equals(namespaceStack[i])) {
- return namespaceStack[i+1];
+ return namespaceStack[i + 1];
}
}
return prefix.isEmpty() ? "" : null;
}
}
-
+
@Override
public String getNamespaceURI(String prefix) {
return emptyToNull(lookupNamespaceURI(nullToEmpty(prefix)));
@@ -705,7 +737,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
// means that this method may return true for a CHARACTER event and we need
// to scan the text of the node.
String text = internalGetText();
- for (int i=0; i<text.length(); i++) {
+ for (int i = 0; i < text.length(); i++) {
char c = text.charAt(i);
if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
return false;
@@ -729,7 +761,10 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
@Override
public QName getAttributeName(int index) {
if (eventType == START_ELEMENT) {
- return QNameCache.getQName(attributeStack[5*index], attributeStack[5*index+1], attributeStack[5*index+2]);
+ return QNameCache.getQName(
+ attributeStack[5 * index],
+ attributeStack[5 * index + 1],
+ attributeStack[5 * index + 2]);
} else {
throw new IllegalStateException();
}
@@ -738,7 +773,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
@Override
public String getAttributeNamespace(int index) {
if (eventType == START_ELEMENT) {
- return emptyToNull(attributeStack[5*index]);
+ return emptyToNull(attributeStack[5 * index]);
} else {
throw new IllegalStateException();
}
@@ -747,7 +782,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
@Override
public String getAttributeLocalName(int index) {
if (eventType == START_ELEMENT) {
- return attributeStack[5*index+1];
+ return attributeStack[5 * index + 1];
} else {
throw new IllegalStateException();
}
@@ -756,7 +791,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
@Override
public String getAttributePrefix(int index) {
if (eventType == START_ELEMENT) {
- return emptyToNull(attributeStack[5*index+2]);
+ return emptyToNull(attributeStack[5 * index + 2]);
} else {
throw new IllegalStateException();
}
@@ -765,7 +800,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
@Override
public String getAttributeValue(int index) {
if (eventType == START_ELEMENT) {
- return attributeStack[5*index+3];
+ return attributeStack[5 * index + 3];
} else {
throw new IllegalStateException();
}
@@ -774,7 +809,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
@Override
public String getAttributeType(int index) {
if (eventType == START_ELEMENT) {
- return attributeStack[5*index+4];
+ return attributeStack[5 * index + 4];
} else {
throw new IllegalStateException();
}
@@ -794,9 +829,10 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
public String getAttributeValue(String namespaceURI, String localName) {
if (eventType == START_ELEMENT) {
namespaceURI = nullToEmpty(namespaceURI);
- for (int i=0; i<attributeCount; i++) {
- if (localName.equals(attributeStack[i*5+1]) && namespaceURI.equals(attributeStack[i*5])) {
- return attributeStack[i*5+3];
+ for (int i = 0; i < attributeCount; i++) {
+ if (localName.equals(attributeStack[i * 5 + 1])
+ && namespaceURI.equals(attributeStack[i * 5])) {
+ return attributeStack[i * 5 + 3];
}
}
return null;
@@ -810,7 +846,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
switch (eventType) {
case START_ELEMENT:
case END_ELEMENT:
- return scopeStack[depth+1]-scopeStack[depth];
+ return scopeStack[depth + 1] - scopeStack[depth];
default:
throw new IllegalStateException();
}
@@ -821,7 +857,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
switch (eventType) {
case START_ELEMENT:
case END_ELEMENT:
- return emptyToNull(namespaceStack[2*(scopeStack[depth]+index)]);
+ return emptyToNull(namespaceStack[2 * (scopeStack[depth] + index)]);
default:
throw new IllegalStateException();
}
@@ -834,7 +870,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
case END_ELEMENT:
// The XSLT implementation in the JRE doesn't like null values returned here.
// Returning empty strings is also what Woodstox does.
- return namespaceStack[2*(scopeStack[depth]+index)+1];
+ return namespaceStack[2 * (scopeStack[depth] + index) + 1];
default:
throw new IllegalStateException();
}
@@ -859,7 +895,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
return text;
}
-
+
@Override
public String getText() {
switch (eventType) {
@@ -890,9 +926,10 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
}
@Override
- public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException {
+ public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length)
+ throws XMLStreamException {
String text = internalGetText();
- int copied = Math.min(length, text.length()-sourceStart);
+ int copied = Math.min(length, text.length() - sourceStart);
text.getChars(sourceStart, sourceStart + copied, target, targetStart);
return copied;
}
@@ -926,9 +963,12 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
@Override
public boolean hasText() {
- return eventType == CHARACTERS || eventType == DTD
- || eventType == CDATA || eventType == ENTITY_REFERENCE
- || eventType == COMMENT || eventType == SPACE;
+ return eventType == CHARACTERS
+ || eventType == DTD
+ || eventType == CDATA
+ || eventType == ENTITY_REFERENCE
+ || eventType == COMMENT
+ || eventType == SPACE;
}
@Override
@@ -941,7 +981,10 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
switch (eventType) {
case START_ELEMENT:
case END_ELEMENT:
- return QNameCache.getQName(elementStack[3*depth], elementStack[3*depth+1], elementStack[3*depth+2]);
+ return QNameCache.getQName(
+ elementStack[3 * depth],
+ elementStack[3 * depth + 1],
+ elementStack[3 * depth + 2]);
default:
throw new IllegalStateException();
}
@@ -957,7 +1000,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
switch (eventType) {
case START_ELEMENT:
case END_ELEMENT:
- return emptyToNull(elementStack[3*depth]);
+ return emptyToNull(elementStack[3 * depth]);
default:
throw new IllegalStateException();
}
@@ -968,7 +1011,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
switch (eventType) {
case START_ELEMENT:
case END_ELEMENT:
- return emptyToNull(elementStack[3*depth+1]);
+ return emptyToNull(elementStack[3 * depth + 1]);
case ENTITY_REFERENCE:
return name;
default:
@@ -982,7 +1025,7 @@ public final class StAXPivot implements InternalXMLStreamReader, XmlHandler {
case START_ELEMENT:
case END_ELEMENT:
// Saxon assumes that getPrefix returns "" instead of null.
- return elementStack[3*depth+2];
+ return elementStack[3 * depth + 2];
default:
throw new IllegalStateException();
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/push/input/XMLStreamWriterNamespaceContextProvider.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/push/input/XMLStreamWriterNamespaceContextProvider.java
index 21905dffd..07bd53c61 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/push/input/XMLStreamWriterNamespaceContextProvider.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/push/input/XMLStreamWriterNamespaceContextProvider.java
@@ -29,37 +29,40 @@ import javax.xml.stream.XMLStreamWriter;
public class XMLStreamWriterNamespaceContextProvider implements NamespaceContextProvider {
private static final Log log = LogFactory.getLog(XMLStreamWriterNamespaceContextProvider.class);
-
+
private final XMLStreamWriter writer;
-
+
public XMLStreamWriterNamespaceContextProvider(XMLStreamWriter writer) {
this.writer = writer;
}
/**
- * @param prefix
+ * @param prefix
* @param namespace
* @return true if the prefix is associated with the namespace in the current context
*/
@Override
public boolean isBound(String prefix, String namespace) throws StreamException {
try {
- // The "xml" prefix is always (implicitly) associated. Returning true here makes sure that
+ // The "xml" prefix is always (implicitly) associated. Returning true here makes sure
+ // that
// we never write a declaration for the xml namespace. See AXIOM-37 for a discussion
// of this issue.
if ("xml".equals(prefix)) {
return true;
}
-
- // NOTE: Calling getNamespaceContext() on many XMLStreamWriter implementations is expensive.
+
+ // NOTE: Calling getNamespaceContext() on many XMLStreamWriter implementations is
+ // expensive.
// Please use other writer methods first.
-
+
// For consistency, convert null arguments.
// This helps get around the parser implementation differences.
- // In addition, the getPrefix/getNamespace methods cannot be called with null parameters.
+ // In addition, the getPrefix/getNamespace methods cannot be called with null
+ // parameters.
prefix = (prefix == null) ? "" : prefix;
namespace = (namespace == null) ? "" : namespace;
-
+
if (namespace.length() > 0) {
// QUALIFIED NAMESPACE
// Get the namespace associated with the prefix
@@ -67,12 +70,12 @@ public class XMLStreamWriterNamespaceContextProvider implements NamespaceContext
if (prefix.equals(writerPrefix)) {
return true;
}
-
+
// It is possible that the namespace is associated with multiple prefixes,
// So try getting the namespace as a second step.
if (writerPrefix != null) {
NamespaceContext nsContext = writer.getNamespaceContext();
- if(nsContext != null) {
+ if (nsContext != null) {
String writerNS = nsContext.getNamespaceURI(prefix);
return namespace.equals(writerNS);
}
@@ -80,15 +83,17 @@ public class XMLStreamWriterNamespaceContextProvider implements NamespaceContext
return false;
} else {
// UNQUALIFIED NAMESPACE
-
- // Neither XML 1.0 nor XML 1.1 allow to associate a prefix with an unqualified name (see also AXIOM-372).
+
+ // Neither XML 1.0 nor XML 1.1 allow to associate a prefix with an unqualified name
+ // (see also AXIOM-372).
if (prefix.length() > 0) {
- throw new StreamException("Invalid namespace declaration: Prefixed namespace bindings may not be empty.");
+ throw new StreamException(
+ "Invalid namespace declaration: Prefixed namespace bindings may not be empty.");
}
-
+
// Get the namespace associated with the prefix.
// It is illegal to call getPrefix with null, but the specification is not
- // clear on what happens if called with "". So the following code is
+ // clear on what happens if called with "". So the following code is
// protected
try {
String writerPrefix = writer.getPrefix("");
@@ -97,12 +102,12 @@ public class XMLStreamWriterNamespaceContextProvider implements NamespaceContext
}
} catch (Throwable t) {
if (log.isDebugEnabled()) {
- log.debug("Caught exception from getPrefix(\"\"). Processing continues: " + t);
+ log.debug(
+ "Caught exception from getPrefix(\"\"). Processing continues: "
+ + t);
}
}
-
-
-
+
// Fallback to using the namespace context
NamespaceContext nsContext = writer.getNamespaceContext();
if (nsContext != null) {
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/push/input/XmlHandlerStreamWriter.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/push/input/XmlHandlerStreamWriter.java
index 7065dbd88..e7fe96e2b 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/push/input/XmlHandlerStreamWriter.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/stax/push/input/XmlHandlerStreamWriter.java
@@ -41,45 +41,41 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
private final XmlHandler handler;
private final Serializer serializer;
private final XMLStreamWriterExtensionFactory extensionFactory;
- private Map<String,Object> extensions;
+ private Map<String, Object> extensions;
private boolean inStartElement;
private boolean inEmptyElement;
- /**
- * Array containing the prefixes for the namespace bindings.
- */
+ /** Array containing the prefixes for the namespace bindings. */
private String[] prefixArray = new String[16];
-
- /**
- * Array containing the URIs for the namespace bindings.
- */
+
+ /** Array containing the URIs for the namespace bindings. */
private String[] uriArray = new String[16];
-
- /**
- * The number of currently defined namespace bindings.
- */
+
+ /** The number of currently defined namespace bindings. */
private int bindings;
-
+
/**
- * Tracks the scopes defined for this namespace context. Each entry in the array identifies
- * the first namespace binding defined in the corresponding scope and points to an entry
- * in {@link #prefixArray}/{@link #uriArray}.
+ * Tracks the scopes defined for this namespace context. Each entry in the array identifies the
+ * first namespace binding defined in the corresponding scope and points to an entry in {@link
+ * #prefixArray}/{@link #uriArray}.
*/
private int[] scopeIndexes = new int[16];
-
+
/**
* The number of currently defined scopes. This is the same as the depth of the current scope,
* where the depth of the root scope is 0.
*/
private int scopes;
- public XmlHandlerStreamWriter(XmlHandler handler, Serializer serializer,
+ public XmlHandlerStreamWriter(
+ XmlHandler handler,
+ Serializer serializer,
XMLStreamWriterExtensionFactory extensionFactory) {
this.handler = handler;
this.serializer = serializer;
this.extensionFactory = extensionFactory;
}
-
+
public XmlHandler getHandler() {
return handler;
}
@@ -87,16 +83,16 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
private static String normalize(String s) {
return s == null ? "" : s;
}
-
+
private static XMLStreamException toXMLStreamException(StreamException ex) {
Throwable cause = ex.getCause();
if (cause instanceof XMLStreamException) {
- return (XMLStreamException)cause;
+ return (XMLStreamException) cause;
} else {
return new XMLStreamException(ex);
}
}
-
+
@Override
public Object getProperty(String name) throws IllegalArgumentException {
if (extensions != null) {
@@ -109,7 +105,7 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
Object extension = extensionFactory.createExtension(name, this);
if (extension != null) {
if (extensions == null) {
- extensions = new HashMap<String,Object>();
+ extensions = new HashMap<String, Object>();
}
extensions.put(name, extension);
return extension;
@@ -138,11 +134,12 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
} else if (uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) {
return XMLConstants.XMLNS_ATTRIBUTE;
} else {
- outer: for (int i=bindings-1; i>=0; i--) {
+ outer:
+ for (int i = bindings - 1; i >= 0; i--) {
if (uri.equals(uriArray[i])) {
String prefix = prefixArray[i];
// Now check that the prefix is not masked
- for (int j=i+1; j<bindings; j++) {
+ for (int j = i + 1; j < bindings; j++) {
if (prefix.equals(prefixArray[j])) {
continue outer;
}
@@ -162,17 +159,18 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
@Override
public void setPrefix(String prefix, String uri) throws XMLStreamException {
if (inEmptyElement) {
- log.warn("The behavior of XMLStreamWriter#setPrefix and " +
- "XMLStreamWriter#setDefaultNamespace is undefined when invoked in the " +
- "context of an empty element");
+ log.warn(
+ "The behavior of XMLStreamWriter#setPrefix and "
+ + "XMLStreamWriter#setDefaultNamespace is undefined when invoked in the "
+ + "context of an empty element");
}
internalSetPrefix(normalize(prefix), normalize(uri));
}
-
+
private void internalSetPrefix(String prefix, String uri) {
if (bindings == prefixArray.length) {
int len = prefixArray.length;
- int newLen = len*2;
+ int newLen = len * 2;
String[] newPrefixArray = new String[newLen];
System.arraycopy(prefixArray, 0, newPrefixArray, 0, len);
String[] newUriArray = new String[newLen];
@@ -234,7 +232,8 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
}
}
- private void doWriteStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
+ private void doWriteStartElement(String prefix, String localName, String namespaceURI)
+ throws XMLStreamException {
finishStartElement();
try {
handler.startElement(normalize(namespaceURI), localName, normalize(prefix));
@@ -249,7 +248,7 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
throws XMLStreamException {
doWriteStartElement(prefix, localName, namespaceURI);
if (scopes == scopeIndexes.length) {
- int[] newScopeIndexes = new int[scopeIndexes.length*2];
+ int[] newScopeIndexes = new int[scopeIndexes.length * 2];
System.arraycopy(scopeIndexes, 0, newScopeIndexes, 0, scopeIndexes.length);
scopeIndexes = newScopeIndexes;
}
@@ -288,7 +287,7 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
inStartElement = false;
}
}
-
+
@Override
public void writeEmptyElement(String prefix, String localName, String namespaceURI)
throws XMLStreamException {
@@ -307,7 +306,8 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
public void writeAttribute(String prefix, String namespaceURI, String localName, String value)
throws XMLStreamException {
try {
- handler.processAttribute(normalize(namespaceURI), localName, normalize(prefix), value, "CDATA", true);
+ handler.processAttribute(
+ normalize(namespaceURI), localName, normalize(prefix), value, "CDATA", true);
} catch (StreamException ex) {
throw toXMLStreamException(ex);
}
@@ -343,15 +343,14 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
return prefix;
}
}
-
+
@Override
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
writeStartElement(internalGetPrefix(namespaceURI), localName, namespaceURI);
}
@Override
- public void writeEmptyElement(String namespaceURI, String localName)
- throws XMLStreamException {
+ public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
writeEmptyElement(internalGetPrefix(namespaceURI), localName, namespaceURI);
}
@@ -420,8 +419,7 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
}
@Override
- public void writeProcessingInstruction(String target, String data)
- throws XMLStreamException {
+ public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
finishStartElement();
try {
handler.startProcessingInstruction(target);
@@ -463,12 +461,13 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
} else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
} else {
- for (int i=bindings-1; i>=0; i--) {
+ for (int i = bindings - 1; i >= 0; i--) {
if (prefix.equals(prefixArray[i])) {
return uriArray[i];
}
}
- // The Javadoc of NamespaceContext#getNamespaceURI specifies that XMLConstants.NULL_NS_URI
+ // The Javadoc of NamespaceContext#getNamespaceURI specifies that
+ // XMLConstants.NULL_NS_URI
// is returned both for unbound prefixes and the null namespace
return XMLConstants.NULL_NS_URI;
}
@@ -490,11 +489,12 @@ public final class XmlHandlerStreamWriter implements InternalXMLStreamWriter, Na
@Override
public boolean hasNext() {
if (next == null) {
- outer: while (--binding >= 0) {
+ outer:
+ while (--binding >= 0) {
if (namespaceURI.equals(uriArray[binding])) {
String prefix = prefixArray[binding];
// Now check that the prefix is not masked
- for (int j=binding+1; j<bindings; j++) {
+ for (int j = binding + 1; j < bindings; j++) {
if (prefix.equals(prefixArray[j])) {
continue outer;
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/util/CharacterDataAccumulator.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/util/CharacterDataAccumulator.java
index c78202e05..134e72d06 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/util/CharacterDataAccumulator.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/util/CharacterDataAccumulator.java
@@ -22,40 +22,40 @@ import org.apache.axiom.core.stream.CharacterData;
public class CharacterDataAccumulator {
private Object content;
-
+
public void append(Object data) {
if (content == null) {
content = data;
} else {
StringBuilder buffer;
if (content instanceof StringBuilder) {
- buffer = (StringBuilder)content;
+ buffer = (StringBuilder) content;
} else {
if (content instanceof CharacterData) {
buffer = new StringBuilder();
- ((CharacterData)content).appendTo(buffer);
+ ((CharacterData) content).appendTo(buffer);
} else {
buffer = new StringBuilder(content.toString());
}
content = buffer;
}
if (data instanceof CharacterData) {
- ((CharacterData)data).appendTo(buffer);
+ ((CharacterData) data).appendTo(buffer);
} else {
buffer.append(data);
}
}
}
-
+
public boolean isEmpty() {
return content == null;
}
-
+
@Override
public String toString() {
return content == null ? "" : content.toString();
}
-
+
public void clear() {
content = null;
}
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/AbstractXOPDecodingFilterHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/AbstractXOPDecodingFilterHandler.java
index 8d454f345..4e22f246c 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/AbstractXOPDecodingFilterHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/AbstractXOPDecodingFilterHandler.java
@@ -29,11 +29,14 @@ import org.apache.axiom.core.stream.XmlHandlerWrapper;
public abstract class AbstractXOPDecodingFilterHandler extends XmlHandlerWrapper {
private static final String SOLE_CHILD_MSG =
- "Expected xop:Include as the sole child of an element information item (see section " +
- "3.2 of http://www.w3.org/TR/xop10/)";
+ "Expected xop:Include as the sole child of an element information item (see section "
+ + "3.2 of http://www.w3.org/TR/xop10/)";
private enum State {
- AFTER_START_ELEMENT, CONTENT_SEEN, IN_XOP_INCLUDE, AFTER_XOP_INCLUDE
+ AFTER_START_ELEMENT,
+ CONTENT_SEEN,
+ IN_XOP_INCLUDE,
+ AFTER_XOP_INCLUDE
}
private State state = State.CONTENT_SEEN;
@@ -89,12 +92,19 @@ public abstract class AbstractXOPDecodingFilterHandler extends XmlHandlerWrapper
}
@Override
- public void processAttribute(String namespaceURI, String localName, String prefix, String value,
- String type, boolean specified) throws StreamException {
+ public void processAttribute(
+ String namespaceURI,
+ String localName,
+ String prefix,
+ String value,
+ String type,
+ boolean specified)
+ throws StreamException {
if (state == State.IN_XOP_INCLUDE) {
if (namespaceURI.isEmpty() && localName.equals(XOPConstants.HREF)) {
if (!value.startsWith("cid:")) {
- throw new StreamException("Expected href attribute containing a URL in the cid scheme");
+ throw new StreamException(
+ "Expected href attribute containing a URL in the cid scheme");
}
try {
// URIs should always be decoded using UTF-8. On the other hand, since non ASCII
@@ -106,7 +116,10 @@ public abstract class AbstractXOPDecodingFilterHandler extends XmlHandlerWrapper
throw new StreamException(ex);
}
} else {
- throw new StreamException("Encountered unexpected attribute " + new QName(namespaceURI, localName) + " on xop:Include element");
+ throw new StreamException(
+ "Encountered unexpected attribute "
+ + new QName(namespaceURI, localName)
+ + " on xop:Include element");
}
} else {
super.processAttribute(namespaceURI, localName, prefix, value, type, specified);
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/AbstractXOPEncodingFilterHandler.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/AbstractXOPEncodingFilterHandler.java
index 9a049fd03..e50c5eeb4 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/AbstractXOPEncodingFilterHandler.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/AbstractXOPEncodingFilterHandler.java
@@ -33,31 +33,33 @@ public abstract class AbstractXOPEncodingFilterHandler extends XmlHandlerWrapper
/**
* Build a cid URL from the given content ID as described in RFC2392.
- * <p>
- * Note that this implementation only encodes the percent character (replacing it by "%25"). The
- * reason is given by the following quotes from RFC3986:
+ *
+ * <p>Note that this implementation only encodes the percent character (replacing it by "%25").
+ * The reason is given by the following quotes from RFC3986:
+ *
* <blockquote>
- * If a reserved character is
- * found in a URI component and no delimiting role is known for that character, then it must be
- * interpreted as representing the data octet corresponding to that character's encoding in
- * US-ASCII. [...]
- * <p>
- * Under normal circumstances, the only time when octets within a URI are percent-encoded is
+ *
+ * If a reserved character is found in a URI component and no delimiting role is known for that
+ * character, then it must be interpreted as representing the data octet corresponding to that
+ * character's encoding in US-ASCII. [...]
+ *
+ * <p>Under normal circumstances, the only time when octets within a URI are percent-encoded is
* during the process of producing the URI from its component parts. This is when an
* implementation determines which of the reserved characters are to be used as subcomponent
* delimiters and which can be safely used as data. [...]
- * <p>
- * Because the percent ("%") character serves as the indicator for percent-encoded octets, it
+ *
+ * <p>Because the percent ("%") character serves as the indicator for percent-encoded octets, it
* must be percent-encoded as "%25" for that octet to be used as data within a URI.
+ *
* </blockquote>
- * <p>
- * Since RFC2392 doesn't define any subcomponents for the cid scheme and since RFC2045 specifies
- * that only US-ASCII characters are allowed in content IDs, the percent character (which is
- * specifically allowed by RFC2045) is the only character that needs URL encoding.
- * <p>
- * Another reason to strictly limit the set of characters to be encoded is that some
+ *
+ * <p>Since RFC2392 doesn't define any subcomponents for the cid scheme and since RFC2045
+ * specifies that only US-ASCII characters are allowed in content IDs, the percent character
+ * (which is specifically allowed by RFC2045) is the only character that needs URL encoding.
+ *
+ * <p>Another reason to strictly limit the set of characters to be encoded is that some
* applications fail to decode cid URLs correctly if they contain percent encoded octets.
- *
+ *
* @param contentID the content ID (without enclosing angle brackets)
* @return the corresponding URL in the cid scheme
*/
@@ -93,9 +95,14 @@ public abstract class AbstractXOPEncodingFilterHandler extends XmlHandlerWrapper
if (!ignorable) {
String contentID = processCharacterData(data);
if (contentID != null) {
- super.startElement(XOPConstants.NAMESPACE_URI, XOPConstants.INCLUDE, XOPConstants.DEFAULT_PREFIX);
- super.processNamespaceDeclaration(XOPConstants.DEFAULT_PREFIX, XOPConstants.NAMESPACE_URI);
- super.processAttribute("", XOPConstants.HREF, "", getURLForContentID(contentID), "CDATA", true);
+ super.startElement(
+ XOPConstants.NAMESPACE_URI,
+ XOPConstants.INCLUDE,
+ XOPConstants.DEFAULT_PREFIX);
+ super.processNamespaceDeclaration(
+ XOPConstants.DEFAULT_PREFIX, XOPConstants.NAMESPACE_URI);
+ super.processAttribute(
+ "", XOPConstants.HREF, "", getURLForContentID(contentID), "CDATA", true);
super.attributesCompleted();
inXOPInclude = true;
return;
diff --git a/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/XOPConstants.java b/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/XOPConstants.java
index 4c11db8bc..debd7ef5e 100644
--- a/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/XOPConstants.java
+++ b/components/core-streams/src/main/java/org/apache/axiom/core/stream/xop/XOPConstants.java
@@ -19,8 +19,8 @@
package org.apache.axiom.core.stream.xop;
/**
- * Interface defining constants used by {@link XOPDecodingFilterHandler} and
- * {@link XOPEncodingFilterHandler}.
+ * Interface defining constants used by {@link XOPDecodingFilterHandler} and {@link
+ * XOPEncodingFilterHandler}.
*/
interface XOPConstants {
String INCLUDE = "Include";
diff --git a/components/core-streams/src/test/java/org/apache/axiom/core/stream/NamespaceRepairingFilterTest.java b/components/core-streams/src/test/java/org/apache/axiom/core/stream/NamespaceRepairingFilterTest.java
index ca341bd0a..9e20fe6a3 100644
--- a/components/core-streams/src/test/java/org/apache/axiom/core/stream/NamespaceRepairingFilterTest.java
+++ b/components/core-streams/src/test/java/org/apache/axiom/core/stream/NamespaceRepairingFilterTest.java
@@ -21,9 +21,11 @@ package org.apache.axiom.core.stream;
import org.junit.Test;
public class NamespaceRepairingFilterTest {
- @Test(expected=ConflictingNamespaceDeclarationException.class)
+ @Test(expected = ConflictingNamespaceDeclarationException.class)
public void testNamespaceDeclarationConflictingWithElementName() throws StreamException {
- XmlHandler handler = new NamespaceRepairingFilter(null, false).createFilterHandler(NullXmlHandler.INSTANCE);
+ XmlHandler handler =
+ new NamespaceRepairingFilter(null, false)
+ .createFilterHandler(NullXmlHandler.INSTANCE);
handler.startFragment();
handler.startElement("urn:ns1", "test", "p");
handler.processNamespaceDeclaration("p", "urn:ns2");
diff --git a/components/core-streams/src/test/java/org/apache/axiom/core/stream/dom/input/DOMReaderTest.java b/components/core-streams/src/test/java/org/apache/axiom/core/stream/dom/input/DOMReaderTest.java
index 5a96de197..e6ca582f6 100644
--- a/components/core-streams/src/test/java/org/apache/axiom/core/stream/dom/input/DOMReaderTest.java
+++ b/components/core-streams/src/test/java/org/apache/axiom/core/stream/dom/input/DOMReaderTest.java
@@ -38,24 +38,24 @@ public class DOMReaderTest {
root.setTextContent("test");
XmlHandler handler = mock(XmlHandler.class);
DOMReader reader = new DOMReader(handler, document, false);
-
+
assertThat(reader.proceed()).isFalse();
verify(handler).startDocument(null, "1.0", null, false);
verifyNoMoreInteractions(handler);
-
+
assertThat(reader.proceed()).isFalse();
verify(handler).startElement("urn:test", "root", "p");
verify(handler).attributesCompleted();
verifyNoMoreInteractions(handler);
-
+
assertThat(reader.proceed()).isFalse();
verify(handler).processCharacterData("test", false);
verifyNoMoreInteractions(handler);
-
+
assertThat(reader.proceed()).isFalse();
verify(handler).endElement();
verifyNoMoreInteractions(handler);
-
+
assertThat(reader.proceed()).isTrue();
verify(handler).completed();
verifyNoMoreInteractions(handler);
diff --git a/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerConformanceTest.java b/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerConformanceTest.java
index 4506d11fb..6d50e6ae9 100644
--- a/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerConformanceTest.java
+++ b/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerConformanceTest.java
@@ -59,10 +59,10 @@ public class SerializerConformanceTest extends MatrixTestCase {
InputSource is = new InputSource(new StringReader(sw.toString()));
is.setSystemId(sample.getUrl().toString());
assertAbout(xml())
- .that(is)
- .ignoringWhitespaceInPrologAndEpilog()
- .treatingElementContentWhitespaceAsText() // TODO
- .hasSameContentAs(document);
+ .that(is)
+ .ignoringWhitespaceInPrologAndEpilog()
+ .treatingElementContentWhitespaceAsText() // TODO
+ .hasSameContentAs(document);
}
public static TestSuite suite() {
diff --git a/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerTest.java b/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerTest.java
index 231748da1..884ea49f3 100644
--- a/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerTest.java
+++ b/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/SerializerTest.java
@@ -43,7 +43,7 @@ public class SerializerTest {
/**
* Tests the scenario described in AXIOM-509.
- *
+ *
* @throws Exception
*/
@Test
@@ -61,7 +61,7 @@ public class SerializerTest {
/**
* Test that characters are converted to entities only when necessary.
- *
+ *
* @throws Exception
*/
@Test
@@ -71,10 +71,11 @@ public class SerializerTest {
handler.startFragment();
handler.startElement("", "test", "");
handler.attributesCompleted();
- handler.processCharacterData("a\u03A3\u20AC", false); // 20AC = Euro sign
+ handler.processCharacterData("a\u03A3\u20AC", false); // 20AC = Euro sign
handler.endElement();
handler.completed();
- assertThat(new String(baos.toByteArray(), "iso-8859-15")).isEqualTo("<test>aΣ\u20AC</test>");
+ assertThat(new String(baos.toByteArray(), "iso-8859-15"))
+ .isEqualTo("<test>aΣ\u20AC</test>");
}
@Test
@@ -87,12 +88,13 @@ public class SerializerTest {
handler.attributesCompleted();
handler.endElement();
handler.completed();
- assertThat(new String(baos.toByteArray(), "ascii")).isEqualTo("<test attr=\"néant\"/>");
+ assertThat(new String(baos.toByteArray(), "ascii"))
+ .isEqualTo("<test attr=\"néant\"/>");
}
/**
* Tests the scenario described in XALANJ-2593.
- *
+ *
* @throws Exception
*/
@Test
@@ -105,10 +107,11 @@ public class SerializerTest {
handler.attributesCompleted();
handler.endElement();
handler.completed();
- assertThat(new String(baos.toByteArray(), "ascii")).isEqualTo("<x y=\"𣎴 - 𠘨\"/>");
+ assertThat(new String(baos.toByteArray(), "ascii"))
+ .isEqualTo("<x y=\"𣎴 - 𠘨\"/>");
}
- @Test(expected=StreamException.class)
+ @Test(expected = StreamException.class)
public void testUnmappableCharacterInComment() throws Exception {
Serializer handler = new Serializer(NullOutputStream.NULL_OUTPUT_STREAM, "iso-8859-1");
handler.startFragment();
@@ -118,7 +121,7 @@ public class SerializerTest {
handler.completed();
}
- @Test(expected=StreamException.class)
+ @Test(expected = StreamException.class)
public void testUnmappableCharacterInCDATASection() throws Exception {
Serializer handler = new Serializer(NullOutputStream.NULL_OUTPUT_STREAM, "ascii");
handler.startFragment();
@@ -128,7 +131,7 @@ public class SerializerTest {
handler.completed();
}
- @Test(expected=StreamException.class)
+ @Test(expected = StreamException.class)
public void testUnmappableCharacterInProcessingInstruction() throws Exception {
Serializer handler = new Serializer(NullOutputStream.NULL_OUTPUT_STREAM, "ascii");
handler.startFragment();
@@ -138,7 +141,7 @@ public class SerializerTest {
handler.completed();
}
- @Test(expected=StreamException.class)
+ @Test(expected = StreamException.class)
public void testUnmappableCharacterInName() throws Exception {
Serializer handler = new Serializer(NullOutputStream.NULL_OUTPUT_STREAM, "iso-8859-15");
handler.startFragment();
@@ -148,7 +151,7 @@ public class SerializerTest {
handler.completed();
}
- @Test(expected=IllegalCharacterSequenceException.class)
+ @Test(expected = IllegalCharacterSequenceException.class)
public void testIllegalCharacterSequenceInComment() throws Exception {
Serializer handler = new Serializer(new NullWriter());
handler.startFragment();
@@ -158,7 +161,7 @@ public class SerializerTest {
handler.completed();
}
- @Test(expected=IllegalCharacterSequenceException.class)
+ @Test(expected = IllegalCharacterSequenceException.class)
public void testIllegalCharacterSequenceInProcessingInstruction() throws Exception {
Serializer handler = new Serializer(new NullWriter());
handler.startFragment();
@@ -168,7 +171,7 @@ public class SerializerTest {
handler.completed();
}
- @Test(expected=IllegalCharacterSequenceException.class)
+ @Test(expected = IllegalCharacterSequenceException.class)
public void testIllegalCharacterSequenceInCDATASection() throws Exception {
Serializer handler = new Serializer(new NullWriter());
handler.startFragment();
@@ -182,7 +185,7 @@ public class SerializerTest {
@Test
public void testGTEscapedAfterSquareBrackets() throws Exception {
String sequence = "xxx]]>yyy";
- for (int i=1; i<sequence.length()-1; i++) {
+ for (int i = 1; i < sequence.length() - 1; i++) {
StringWriter sw = new StringWriter();
Serializer handler = new Serializer(sw);
handler.startFragment();
diff --git a/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriterTest.java b/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriterTest.java
index e081c28eb..df1ca8cb7 100644
--- a/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriterTest.java
+++ b/components/core-streams/src/test/java/org/apache/axiom/core/stream/serializer/writer/OutputStreamXmlWriterTest.java
@@ -23,9 +23,6 @@ import static com.google.common.truth.Truth.assertThat;
import java.io.ByteArrayOutputStream;
import java.nio.charset.Charset;
-import org.apache.axiom.core.stream.serializer.writer.OutputStreamXmlWriter;
-import org.apache.axiom.core.stream.serializer.writer.UnmappableCharacterHandler;
-import org.apache.axiom.core.stream.serializer.writer.XmlWriter;
import org.junit.Test;
public class OutputStreamXmlWriterTest {
@@ -33,7 +30,8 @@ public class OutputStreamXmlWriterTest {
public void testUnmappableCharacterToCharacterReference() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XmlWriter writer = new OutputStreamXmlWriter(baos, Charset.forName("iso-8859-1"));
- writer.setUnmappableCharacterHandler(UnmappableCharacterHandler.CONVERT_TO_CHARACTER_REFERENCE);
+ writer.setUnmappableCharacterHandler(
+ UnmappableCharacterHandler.CONVERT_TO_CHARACTER_REFERENCE);
writer.write("abc\u20ACdef");
writer.flushBuffer();
assertThat(baos.toString("iso-8859-1")).isEqualTo("abc€def");
diff --git a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/Action.java b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/Action.java
index 67e8b6833..1674a2547 100644
--- a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/Action.java
+++ b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/Action.java
@@ -22,7 +22,8 @@ import org.apache.axiom.core.stream.StreamException;
import org.apache.axiom.core.stream.XmlHandler;
public interface Action {
- public static final Action DEFAULT_START_DOCUMENT = h -> h.startDocument("utf-8", "1.0", "utf-8", true);
+ public static final Action DEFAULT_START_DOCUMENT =
+ h -> h.startDocument("utf-8", "1.0", "utf-8", true);
void run(XmlHandler handler) throws StreamException;
}
diff --git a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/FakeReader.java b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/FakeReader.java
index d328a4e2c..e45ebd8c3 100644
--- a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/FakeReader.java
+++ b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/FakeReader.java
@@ -49,6 +49,5 @@ public final class FakeReader implements XmlReader {
}
@Override
- public void dispose() {
- }
+ public void dispose() {}
}
diff --git a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTest.java b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTest.java
index 3af4e3278..4a51c5bd3 100644
--- a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTest.java
+++ b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTest.java
@@ -38,13 +38,14 @@ public class StAXPivotTest {
@Test
public void testSuccess() throws Exception {
- StAXPivot pivot = createStAXPivot(
- Action.DEFAULT_START_DOCUMENT,
- h -> h.startElement("urn:test", "test", "p"),
- XmlHandler::attributesCompleted,
- h -> h.processEntityReference("ent", "foobar"),
- XmlHandler::endElement,
- XmlHandler::completed);
+ StAXPivot pivot =
+ createStAXPivot(
+ Action.DEFAULT_START_DOCUMENT,
+ h -> h.startElement("urn:test", "test", "p"),
+ XmlHandler::attributesCompleted,
+ h -> h.processEntityReference("ent", "foobar"),
+ XmlHandler::endElement,
+ XmlHandler::completed);
pivot.require(XMLStreamConstants.START_DOCUMENT, null, null);
pivot.next();
pivot.require(XMLStreamConstants.START_ELEMENT, "urn:test", "test");
@@ -55,60 +56,63 @@ public class StAXPivotTest {
pivot.next();
pivot.require(XMLStreamConstants.END_DOCUMENT, null, null);
}
-
- @Test(expected=XMLStreamException.class)
+
+ @Test(expected = XMLStreamException.class)
public void testEventTypeMismatch() throws Exception {
StAXPivot pivot = createStAXPivot(Action.DEFAULT_START_DOCUMENT);
pivot.require(XMLStreamConstants.CHARACTERS, null, null);
}
-
- @Test(expected=XMLStreamException.class)
+
+ @Test(expected = XMLStreamException.class)
public void testLocalNameOnStartDocument() throws Exception {
StAXPivot pivot = createStAXPivot(Action.DEFAULT_START_DOCUMENT);
pivot.require(XMLStreamConstants.START_DOCUMENT, null, "test");
}
-
- @Test(expected=XMLStreamException.class)
+
+ @Test(expected = XMLStreamException.class)
public void testLocalNameMismatchOnStartElement() throws Exception {
- StAXPivot pivot = createStAXPivot(
- Action.DEFAULT_START_DOCUMENT,
- h -> h.startElement("urn:test", "test", "p"),
- XmlHandler::attributesCompleted);
+ StAXPivot pivot =
+ createStAXPivot(
+ Action.DEFAULT_START_DOCUMENT,
+ h -> h.startElement("urn:test", "test", "p"),
+ XmlHandler::attributesCompleted);
pivot.next();
pivot.require(XMLStreamConstants.START_ELEMENT, "urn:test", "wrong_name");
}
-
- @Test(expected=XMLStreamException.class)
+
+ @Test(expected = XMLStreamException.class)
public void testNamespaceURIOnStartDocument() throws Exception {
StAXPivot pivot = createStAXPivot(Action.DEFAULT_START_DOCUMENT);
pivot.require(XMLStreamConstants.START_DOCUMENT, "http://example.org", null);
}
-
- @Test(expected=XMLStreamException.class)
+
+ @Test(expected = XMLStreamException.class)
public void testNamespaceURIMismatchOnStartElement() throws Exception {
- StAXPivot pivot = createStAXPivot(
- Action.DEFAULT_START_DOCUMENT,
- h -> h.startElement("urn:test", "test", "p"),
- XmlHandler::attributesCompleted);
+ StAXPivot pivot =
+ createStAXPivot(
+ Action.DEFAULT_START_DOCUMENT,
+ h -> h.startElement("urn:test", "test", "p"),
+ XmlHandler::attributesCompleted);
pivot.next();
pivot.require(XMLStreamConstants.START_ELEMENT, "urn:wrong_uri", "test");
}
@Test
public void testCDATASection() throws Exception {
- StAXPivot pivot = createStAXPivot(
- Action.DEFAULT_START_DOCUMENT,
- h -> {
- h.startElement("", "root", "");
- h.attributesCompleted();
- },
- h -> {
- h.startCDATASection();
- h.processCharacterData("test", false);
- h.endCDATASection();
- },
- XmlHandler::endElement,
- XmlHandler::completed);
+ StAXPivot pivot =
+ createStAXPivot(
+ Action.DEFAULT_START_DOCUMENT,
+ h -> {
+ h.startElement("", "root", "");
+ h.attributesCompleted();
+ },
+ h -> {
+ h.startCDATASection();
+ h.processCharacterData("test", false);
+ h.endCDATASection();
+ },
+ XmlHandler::endElement,
+ XmlHandler::completed);
assertThat(pivot.getEventType()).isEqualTo(XMLStreamReader.START_DOCUMENT);
assertThat(pivot.next()).isEqualTo(XMLStreamReader.START_ELEMENT);
assertThat(pivot.next()).isEqualTo(XMLStreamReader.CDATA);
@@ -119,27 +123,28 @@ public class StAXPivotTest {
@Test
public void testGetElementText() throws Exception {
- StAXPivot pivot = createStAXPivot(
- Action.DEFAULT_START_DOCUMENT,
- h -> h.startElement("", "root", ""),
- XmlHandler::attributesCompleted,
- h -> h.processCharacterData("abc", false),
- XmlHandler::startCDATASection,
- h -> h.processCharacterData("def", false),
- XmlHandler::endCDATASection,
- h -> h.processCharacterData("ghi", false),
- XmlHandler::startComment,
- h -> h.processCharacterData("jkl", false),
- XmlHandler::endComment,
- h -> h.processCharacterData("mno", false),
- h -> h.startProcessingInstruction("pi"),
- h -> h.processCharacterData("pqr", false),
- XmlHandler::endProcessingInstruction,
- h -> h.processCharacterData("stu", false),
- h -> h.processEntityReference("ent", "vwx"),
- h -> h.processCharacterData("yz", false),
- XmlHandler::endElement,
- XmlHandler::completed);
+ StAXPivot pivot =
+ createStAXPivot(
+ Action.DEFAULT_START_DOCUMENT,
+ h -> h.startElement("", "root", ""),
+ XmlHandler::attributesCompleted,
+ h -> h.processCharacterData("abc", false),
+ XmlHandler::startCDATASection,
+ h -> h.processCharacterData("def", false),
+ XmlHandler::endCDATASection,
+ h -> h.processCharacterData("ghi", false),
+ XmlHandler::startComment,
+ h -> h.processCharacterData("jkl", false),
+ XmlHandler::endComment,
+ h -> h.processCharacterData("mno", false),
+ h -> h.startProcessingInstruction("pi"),
+ h -> h.processCharacterData("pqr", false),
+ XmlHandler::endProcessingInstruction,
+ h -> h.processCharacterData("stu", false),
+ h -> h.processEntityReference("ent", "vwx"),
+ h -> h.processCharacterData("yz", false),
+ XmlHandler::endElement,
+ XmlHandler::completed);
assertThat(pivot.getEventType()).isEqualTo(XMLStreamReader.START_DOCUMENT);
assertThat(pivot.next()).isEqualTo(XMLStreamReader.START_ELEMENT);
assertThat(pivot.getElementText()).isEqualTo("abcdefghimnostuvwxyz");
@@ -149,13 +154,14 @@ public class StAXPivotTest {
@Test
public void testGetElementTextUnexpectedChildElement() throws Exception {
- StAXPivot pivot = createStAXPivot(
- Action.DEFAULT_START_DOCUMENT,
- h -> h.startElement("", "root", ""),
- XmlHandler::attributesCompleted,
- h -> h.processCharacterData("abc", false),
- h -> h.startElement("", "child", ""),
- XmlHandler::attributesCompleted);
+ StAXPivot pivot =
+ createStAXPivot(
+ Action.DEFAULT_START_DOCUMENT,
+ h -> h.startElement("", "root", ""),
+ XmlHandler::attributesCompleted,
+ h -> h.processCharacterData("abc", false),
+ h -> h.startElement("", "child", ""),
+ XmlHandler::attributesCompleted);
assertThat(pivot.getEventType()).isEqualTo(XMLStreamReader.START_DOCUMENT);
assertThat(pivot.next()).isEqualTo(XMLStreamReader.START_ELEMENT);
assertThrows(XMLStreamException.class, () -> pivot.getElementText());
diff --git a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTransformerTest.java b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTransformerTest.java
index 9d90d77f7..a4af3db25 100644
--- a/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTransformerTest.java
+++ b/components/core-streams/src/test/java/org/apache/axiom/core/stream/stax/pull/output/StAXPivotTransformerTest.java
@@ -59,8 +59,10 @@ public class StAXPivotTransformerTest extends MatrixTestCase {
StAXPivot pivot = new StAXPivot(null);
pivot.setReader(new DOMInput(document, false).createReader(pivot));
StringWriter sw = new StringWriter();
- xsltImplementation.newTransformerFactory().newTransformer().transform(
- new StAXSource(pivot), new StreamResult(sw));
+ xsltImplementation
+ .newTransformerFactory()
+ .newTransformer()
+ .transform(new StAXSource(pivot), new StreamResult(sw));
assertAbout(xml()).that(sw.toString()).hasSameContentAs(document);
}
@@ -68,7 +70,8 @@ public class StAXPivotTransformerTest extends MatrixTestCase {
return new MatrixTestSuiteBuilder() {
@Override
protected void addTests() {
- for (XSLTImplementation xsltImplementation : getInstances(XSLTImplementation.class)) {
+ for (XSLTImplementation xsltImplementation :
+ getInstances(XSLTImplementation.class)) {
if (xsltImplementation.supportsStAXSource()) {
for (XMLSample sample : getInstances(XMLSample.class)) {
if (!sample.hasDTD()) {