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/02/27 22:08:08 UTC
svn commit: r1294328 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/
axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/
axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/
Author: veithen
Date: Mon Feb 27 21:08:08 2012
New Revision: 1294328
URL: http://svn.apache.org/viewvc?rev=1294328&view=rev
Log:
AXIOM-29: Use the optimized OMElement#getText() implementation in DOOM as well.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementImplUtil.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementImplUtil.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/OMElementImplUtil.java?rev=1294328&r1=1294327&r2=1294328&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementImplUtil.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMElementImplUtil.java Mon Feb 27 21:08:08 2012
@@ -58,7 +58,46 @@ public class OMElementImplUtil {
return new LiveNamespaceContext(element);
}
}
+
+ public static String getText(OMElement element) {
+ String childText = null;
+ StringBuffer buffer = null;
+ OMNode child = element.getFirstOMChild();
+ while (child != null) {
+ final int type = child.getType();
+ if (type == OMNode.TEXT_NODE || type == OMNode.CDATA_SECTION_NODE) {
+ OMText textNode = (OMText) child;
+ String textValue = textNode.getText();
+ if (textValue != null && textValue.length() != 0) {
+ if (childText == null) {
+ // This is the first non empty text node. Just save the string.
+ childText = textValue;
+ } else {
+ // We've already seen a non empty text node before. Concatenate using
+ // a StringBuffer.
+ if (buffer == null) {
+ // This is the first text node we need to append. Initialize the
+ // StringBuffer.
+ buffer = new StringBuffer(childText);
+ }
+ buffer.append(textValue);
+ }
+ }
+ }
+ child = child.getNextOMSibling();
+ }
+
+ if (childText == null) {
+ // We didn't see any text nodes. Return an empty string.
+ return "";
+ } else if (buffer != null) {
+ return buffer.toString();
+ } else {
+ return childText;
+ }
+ }
+
public static Reader getTextAsStream(OMElement element, boolean cache) {
// If the element is not an OMSourcedElement and has not more than one child, then the most
// efficient way to get the Reader is to build a StringReader
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1294328&r1=1294327&r2=1294328&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Mon Feb 27 21:08:08 2012
@@ -26,7 +26,6 @@ import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.impl.OMElementEx;
import org.apache.axiom.om.impl.OMNodeEx;
@@ -1005,29 +1004,8 @@ public class ElementImpl extends ParentN
return qName;
}
- /**
- * Gets all the text children and concatinates them to a single string.
- *
- * @see org.apache.axiom.om.OMElement#getText()
- */
public String getText() {
- String childText = "";
- OMNode child = this.getFirstOMChild();
- OMText textNode;
-
- while (child != null) {
- final int type = child.getType();
- if (type == OMNode.TEXT_NODE || type == OMNode.CDATA_SECTION_NODE) {
- textNode = (OMText) child;
- if (textNode.getText() != null
- && !"".equals(textNode.getText())) {
- childText += textNode.getText();
- }
- }
- child = child.getNextOMSibling();
- }
-
- return childText;
+ return OMElementImplUtil.getText(this);
}
public Reader getTextAsStream(boolean cache) {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=1294328&r1=1294327&r2=1294328&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java Mon Feb 27 21:08:08 2012
@@ -28,7 +28,6 @@ import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.OMText;
import org.apache.axiom.om.OMXMLParserWrapper;
import org.apache.axiom.om.OMXMLStreamReaderConfiguration;
import org.apache.axiom.om.impl.OMContainerEx;
@@ -825,48 +824,8 @@ public class OMElementImpl extends OMNod
getOMFactory().createOMText(this, text);
}
- /**
- * Selects all the text children and concatenates them to a single string.
- *
- * @return Returns String.
- */
public String getText() {
- String childText = null;
- StringBuffer buffer = null;
- OMNode child = this.getFirstOMChild();
-
- while (child != null) {
- final int type = child.getType();
- if (type == OMNode.TEXT_NODE || type == OMNode.CDATA_SECTION_NODE) {
- OMText textNode = (OMText) child;
- String textValue = textNode.getText();
- if (textValue != null && textValue.length() != 0) {
- if (childText == null) {
- // This is the first non empty text node. Just save the string.
- childText = textValue;
- } else {
- // We've already seen a non empty text node before. Concatenate using
- // a StringBuffer.
- if (buffer == null) {
- // This is the first text node we need to append. Initialize the
- // StringBuffer.
- buffer = new StringBuffer(childText);
- }
- buffer.append(textValue);
- }
- }
- }
- child = child.getNextOMSibling();
- }
-
- if (childText == null) {
- // We didn't see any text nodes. Return an empty string.
- return "";
- } else if (buffer != null) {
- return buffer.toString();
- } else {
- return childText;
- }
+ return OMElementImplUtil.getText(this);
}
public Reader getTextAsStream(boolean cache) {