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 2012/07/20 08:47:18 UTC
svn commit: r1363666 -
/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
Author: veithen
Date: Fri Jul 20 06:47:18 2012
New Revision: 1363666
URL: http://svn.apache.org/viewvc?rev=1363666&view=rev
Log:
The Javadoc of XMLStreamReader indeed specifies that for a DTD event, only getText is valid, but not the other getTextXxx methods.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java?rev=1363666&r1=1363665&r2=1363666&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/SwitchingWrapper.java Fri Jul 20 06:47:18 2012
@@ -310,9 +310,6 @@ class SwitchingWrapper extends AbstractX
public int getTextLength() {
if (parser != null) {
return parser.getTextLength();
- } else if (currentEvent == DTD) {
- // Not sure if that conforms to the StAX spec, but it is what Woodstox does
- throw new IllegalStateException();
} else {
return getTextFromNode().length();
}
@@ -357,15 +354,10 @@ class SwitchingWrapper extends AbstractX
throw new OMStreamingException(e);
}
} else {
- if (currentEvent == DTD) {
- // Not sure if that conforms to the StAX spec, but it is what Woodstox does
- throw new IllegalStateException();
- } else {
- String text = getTextFromNode();
- int copied = Math.min(length, text.length()-sourceStart);
- text.getChars(sourceStart, sourceStart + copied, target, targetStart);
- return copied;
- }
+ String text = getTextFromNode();
+ int copied = Math.min(length, text.length()-sourceStart);
+ text.getChars(sourceStart, sourceStart + copied, target, targetStart);
+ return copied;
}
}
@@ -376,9 +368,6 @@ class SwitchingWrapper extends AbstractX
public char[] getTextCharacters() {
if (parser != null) {
return parser.getTextCharacters();
- } else if (currentEvent == DTD) {
- // Not sure if that conforms to the StAX spec, but it is what Woodstox does
- throw new IllegalStateException();
} else {
return getTextFromNode().toCharArray();
}
@@ -392,10 +381,23 @@ class SwitchingWrapper extends AbstractX
if (parser != null) {
return parser.getText();
} else {
- return getTextFromNode();
+ if (currentEvent == DTD) {
+ // For a DTD event, only getText is allowed, but not getTextCharacters etc.
+ // (see the table in the Javadoc of XMLStreamReader)
+ return ((OMDocType)lastNode).getValue();
+ } else {
+ return getTextFromNode();
+ }
}
}
+ /**
+ * Get the text for the current node. This methods applies to events for which all
+ * <code>getText</code> methods are valid. This excludes {@link XMLStreamConstants#DTD} events
+ * for which only {@link #getText()} is valid.
+ *
+ * @return the text for the current node
+ */
private String getTextFromNode() {
switch (currentEvent) {
case CHARACTERS:
@@ -404,8 +406,6 @@ class SwitchingWrapper extends AbstractX
return ((OMText)lastNode).getText();
case COMMENT:
return ((OMComment)lastNode).getValue();
- case DTD:
- return ((OMDocType)lastNode).getValue();
default:
throw new IllegalStateException();
}