Author: gdaniels
Date: Fri Mar 28 19:12:04 2008
New Revision: 642488

URL: http://svn.apache.org/viewvc?rev=642488&view=rev
Log:
Fix https://issues.apache.org/jira/browse/WSCOMMONS-305.

Make sure we return CDATA text as part of the getText() value.

Unit test.

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.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
    
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMTextTest.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.java?rev=642488&r1=642487&r2=642488&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMText.java
 Fri Mar 28 19:12:04 2008
@@ -44,7 +44,7 @@
     /**
      * Returns the Namespace if this contains a QName Return null otherwise
      *
-     * @deprecate This API is going away.  Please use getTextAsQName() instead.
+     * @deprecated This API is going away.  Please use getTextAsQName() 
instead.
      * @return OMNamespace
      */
     OMNamespace getNamespace();
@@ -62,7 +62,7 @@
     /**
      * Sets the optimize flag.
      *
-     * @param value
+     * @param value true to optimize binary content (usually w/MTOM)
      */
     void setOptimize(boolean value);
 
@@ -72,7 +72,7 @@
     /**
      * Sets the isBinary flag.
      *
-     * @param value
+     * @param value true if the content is binary
      */
     void setBinary(boolean value);
 

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=642488&r1=642487&r2=642488&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
 Fri Mar 28 19:12:04 2008
@@ -926,7 +926,8 @@
         OMText textNode;
 
         while (child != null) {
-            if (child.getType() == OMNode.TEXT_NODE) {
+            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())) {

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=642488&r1=642487&r2=642488&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
 Fri Mar 28 19:12:04 2008
@@ -797,7 +797,8 @@
         OMNode child = this.getFirstOMChild();
 
         while (child != null) {
-            if (child.getType() == OMNode.TEXT_NODE) {
+            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) {

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMTextTest.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMTextTest.java?rev=642488&r1=642487&r2=642488&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMTextTest.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMTextTest.java
 Fri Mar 28 19:12:04 2008
@@ -22,6 +22,7 @@
 import junit.framework.TestCase;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
 import java.util.Iterator;
 
 public class OMTextTest extends TestCase {
@@ -63,5 +64,20 @@
 
         QName textAsQName = omElement.getTextAsQName();
         assertTrue(textAsQName.equals(new QName(SOME_TEXT)));
+    }
+
+    public void testCDATA() throws Exception {
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+        OMElement omElement = factory.createOMElement("TestElement", null);
+        final String text = "this is <some> text in a CDATA";
+        factory.createOMText(omElement, text, XMLStreamConstants.CDATA);
+        assertEquals(text, omElement.getText());
+
+        // OK, CDATA on its own worked - now confirm that a plain text + a 
CDATA works
+        omElement = factory.createOMElement("element2", null);
+        final String normalText = "regular text and ";
+        factory.createOMText(omElement, normalText);
+        factory.createOMText(omElement, text, XMLStreamConstants.CDATA);
+        assertEquals(normalText + text, omElement.getText());
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to