Author: veithen Date: Fri Mar 13 23:09:33 2009 New Revision: 753469 URL: http://svn.apache.org/viewvc?rev=753469&view=rev Log: * Merged changes in r425401 (!) (Implementing the getElementText support as per the API contract) from OMStAXWrapper to DOMStAXWrapper. * Moved the test case in OMElementGetElementTextTest to OMStAXWrapperTestBase, so that it is also executed for DOOM.
Removed: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/impl/llom/OMElementGetElementTextTest.java Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMStAXWrapper.java Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java?rev=753469&r1=753468&r2=753469&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperTestBase.java Fri Mar 13 23:09:33 2009 @@ -30,6 +30,7 @@ import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMMetaFactory; +import org.apache.axiom.om.OMNamespace; import org.apache.axiom.om.OMNode; import org.apache.axiom.om.OMText; import org.apache.axiom.om.impl.builder.StAXOMBuilder; @@ -117,4 +118,23 @@ } assertEquals("comment text", text.toString()); } + + public void testGetElementText() throws Exception { + OMFactory factory = omMetaFactory.getOMFactory(); + + OMNamespace namespace = factory.createOMNamespace("http://testuri.org", "test"); + OMElement documentElement = factory.createOMElement("DocumentElement", namespace); + factory.createOMText(documentElement, "this is a TEXT"); + factory.createOMComment(documentElement, "this is a comment"); + factory.createOMText(documentElement, "this is a TEXT block 2"); + + XMLStreamReader xmlStreamReader = documentElement.getXMLStreamReader(); + //move to the Start_Element + while (xmlStreamReader.getEventType() != XMLStreamReader.START_ELEMENT) { + xmlStreamReader.next(); + } + + String elementText = xmlStreamReader.getElementText(); + assertEquals("this is a TEXTthis is a TEXT block 2", elementText); + } } Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMStAXWrapper.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMStAXWrapper.java?rev=753469&r1=753468&r2=753469&view=diff ============================================================================== --- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMStAXWrapper.java (original) +++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DOMStAXWrapper.java Fri Mar 13 23:09:33 2009 @@ -800,13 +800,37 @@ throw new OMStreamingException(e); } } else { - if (currentNode.getType() == OMNode.ELEMENT_NODE) { - return ((OMElement) currentNode).getText(); - } else if (currentNode.getType() == OMNode.TEXT_NODE) { - return ((OMText) currentNode).getText(); - } else { - return ""; + /////////////////////////////////////////////////////// + //// Code block directly from the API documentation /// + if (getEventType() != XMLStreamConstants.START_ELEMENT) { + throw new XMLStreamException( + "parser must be on START_ELEMENT to read next text", getLocation()); + } + int eventType = next(); + StringBuffer content = new StringBuffer(); + while (eventType != XMLStreamConstants.END_ELEMENT) { + if (eventType == XMLStreamConstants.CHARACTERS + || eventType == XMLStreamConstants.CDATA + || eventType == XMLStreamConstants.SPACE + || eventType == XMLStreamConstants.ENTITY_REFERENCE) { + content.append(getText()); + } else if (eventType == XMLStreamConstants.PROCESSING_INSTRUCTION + || eventType == XMLStreamConstants.COMMENT) { + // skipping + } else if (eventType == XMLStreamConstants.END_DOCUMENT) { + throw new XMLStreamException( + "unexpected end of document when reading element text content"); + } else if (eventType == XMLStreamConstants.START_ELEMENT) { + throw new XMLStreamException( + "element text content may not contain START_ELEMENT"); + } else { + throw new XMLStreamException( + "Unexpected event type " + eventType, getLocation()); + } + eventType = next(); } + return content.toString(); + /////////////////////////////////////////////////////////////// } }