Author: veithen
Date: Sat Apr  4 23:23:51 2009
New Revision: 762029

URL: http://svn.apache.org/viewvc?rev=762029&view=rev
Log:
Fixed whitespace handling.

Added:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/spaces.xml
   (with props)
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java
   (with props)
Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java?rev=762029&r1=762028&r2=762029&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMStAXWrapper.java
 Sat Apr  4 23:23:51 2009
@@ -750,13 +750,29 @@
      * @return Returns boolean.
      */
     public boolean isWhiteSpace() {
-        boolean b;
         if (parser != null) {
-            b = parser.isWhiteSpace();
+            return parser.isWhiteSpace();
         } else {
-            b = (currentEvent == SPACE);
+            switch (currentEvent) {
+                case SPACE:
+                    return true;
+                case CHARACTERS:
+                    // XMLStreamReader Javadoc says that isWhiteSpace "returns 
true if the cursor
+                    // points to a character data event that consists of all 
whitespace". This
+                    // means that this method may return true for a CHARACTER 
event and we need
+                    // to scan the text of the node.
+                    String text = getTextFromNode();
+                    for (int i=0; i<text.length(); i++) {
+                        char c = text.charAt(i);
+                        if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
+                            return false;
+                        }
+                    }
+                    return true;
+                default:
+                    return false;
+            }
         }
-        return b;
     }
 
     /**
@@ -1331,37 +1347,33 @@
      * @return Returns int.
      */
     private int generateTextEvents(OMNode node) {
-        if (!isInlineMTOM()) {
-            // If this is an optimized MTOM text node
-            // then simulate an XOP_INCLUDE element.
-            if (node instanceof OMText) {
-                OMText text = (OMText) node;
-                if (text.isOptimized()) {
-                    
-                    if (nodeStack == null) {
-                        nodeStack = new Stack();
-                    }
-                    
-                    if (!nodeStack.isEmpty() && nodeStack.peek().equals(text)) 
{
-                        // Process the end tag of the XOP:Include
-                        nodeStack.pop();
-                        xopIncludeStart = false;
-                        return END_ELEMENT;
-                    } else {
-
-                        // Create an XOPInclude element to represent this node
-                        xopIncludeText = text;
-                        xopInclude = 
node.getOMFactory().createOMElement(XOP_INCLUDE);
-                        String cid = text.getContentID();
-                        xopInclude.addAttribute("href", "cid:" + cid, null);
-                        xopIncludeStart = true;
-                        nodeStack.push(text);
-                        return START_ELEMENT;
-                    }
-                }
+        OMText text = (OMText) node;
+        // If this is an optimized MTOM text node
+        // then simulate an XOP_INCLUDE element.
+        if (!isInlineMTOM() && text.isOptimized()) {
+            if (nodeStack == null) {
+                nodeStack = new Stack();
+            }
+            
+            if (!nodeStack.isEmpty() && nodeStack.peek().equals(text)) {
+                // Process the end tag of the XOP:Include
+                nodeStack.pop();
+                xopIncludeStart = false;
+                return END_ELEMENT;
+            } else {
+
+                // Create an XOPInclude element to represent this node
+                xopIncludeText = text;
+                xopInclude = node.getOMFactory().createOMElement(XOP_INCLUDE);
+                String cid = text.getContentID();
+                xopInclude.addAttribute("href", "cid:" + cid, null);
+                xopIncludeStart = true;
+                nodeStack.push(text);
+                return START_ELEMENT;
             }
+        } else {
+            return text.getType();
         }
-        return CHARACTERS;
     }
     
     /**

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java?rev=762029&r1=762028&r2=762029&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/om/impl/OMStAXWrapperConformanceTestCase.java
 Sat Apr  4 23:23:51 2009
@@ -51,7 +51,11 @@
         InputStream in2 = getTestResource(file);
         try {
             XMLStreamReader expected = StAXUtils.createXMLStreamReader(in1);
-            expected.nextTag();
+            // Skip to document element. Note that nextTag is not appropriate 
here because
+            // there could be a DTD event.
+            while (expected.next() != XMLStreamReader.START_ELEMENT) {
+                // just loop
+            }
             XMLStreamReader actual = new 
StAXOMBuilder(omMetaFactory.getOMFactory(),
                     
StAXUtils.createXMLStreamReader(in2)).getDocumentElement().getXMLStreamReader();
             new XMLStreamReaderComparator(new 
XMLFragmentStreamReader(expected), actual).compare();

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/spaces.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/spaces.xml?rev=762029&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/spaces.xml
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/spaces.xml
 Sat Apr  4 23:23:51 2009
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<!DOCTYPE test [
+  <!ELEMENT root (child*)>
+  <!ELEMENT child (#PCDATA)>
+]>
+<root>
+    <child>
+    </child>
+    <child>  text  </child>
+</root>

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/conformance/spaces.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java?rev=762029&view=auto
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java
 (added)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java
 Sat Apr  4 23:23:51 2009
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.om.impl.dom;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.axiom.om.OMDocType;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.NamedNodeMap;
+
+public class DocumentTypeImpl extends ChildNode implements DocumentType, 
OMDocType {
+    public DocumentTypeImpl(DocumentImpl ownerDocument, OMFactory factory) {
+        super(ownerDocument, factory);
+        done = true;
+    }
+
+    public String getNodeName() {
+        return getName();
+    }
+
+    public short getNodeType() {
+        return DOCUMENT_TYPE_NODE;
+    }
+
+    public void internalSerialize(XMLStreamWriter writer) throws 
XMLStreamException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void internalSerializeAndConsume(XMLStreamWriter writer) throws 
XMLStreamException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void setType(int nodeType) throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    public int getType() {
+        return DTD_NODE;
+    }
+
+    public NamedNodeMap getEntities() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getInternalSubset() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getName() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public NamedNodeMap getNotations() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getPublicId() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getSystemId() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getValue() {
+        return null;
+    }
+
+    public void setValue(String text) {
+    }
+}

Propchange: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentTypeImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=762029&r1=762028&r2=762029&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
 Sat Apr  4 23:23:51 2009
@@ -237,10 +237,8 @@
                 ((DocumentImpl) this).documentElement = (ElementImpl) 
newDomChild;
             } else if (!(newDomChild instanceof CommentImpl
                     || newDomChild instanceof ProcessingInstructionImpl
-                    || newDomChild instanceof DocumentFragmentImpl)) {
-                // TODO: we should also check for DocumentType,
-                //       but since we don't have an implementation yet, we can 
leave it
-                //       like this for now
+                    || newDomChild instanceof DocumentFragmentImpl
+                    || newDomChild instanceof DocumentTypeImpl)) {
                 throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                         DOMMessageFormatter.formatMessage(
                                 DOMMessageFormatter.DOM_DOMAIN,

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java?rev=762029&r1=762028&r2=762029&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/TextImpl.java
 Sat Apr  4 23:23:51 2009
@@ -45,6 +45,7 @@
 import java.io.InputStream;
 
 public class TextImpl extends CharacterImpl implements Text, OMText {
+    private boolean isWhitespace;
 
     private String mimeType;
 
@@ -300,7 +301,7 @@
      * @see org.apache.axiom.om.OMNode#getType()
      */
     public int getType() throws OMException {
-        return OMNode.TEXT_NODE;
+        return isWhitespace ? OMNode.SPACE_NODE : OMNode.TEXT_NODE;
     }
 
     /*
@@ -309,8 +310,17 @@
      * @see org.apache.axiom.om.OMNode#setType(int)
      */
     public void setType(int nodeType) throws OMException {
-        // do not do anything here
-        // Its not clear why we should let someone change the type of a node
+        switch (nodeType) {
+            case OMNode.TEXT_NODE:
+            case OMNode.CDATA_SECTION_NODE: // TODO: this is not entirely 
correct
+                isWhitespace = false;
+                break;
+            case OMNode.SPACE_NODE:
+                isWhitespace = true;
+                break;
+            default:
+                throw new UnsupportedOperationException();
+        }
     }
 
     public void internalSerialize(XMLStreamWriter writer) throws 
XMLStreamException {

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=762029&r1=762028&r2=762029&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
 Sat Apr  4 23:23:51 2009
@@ -40,6 +40,7 @@
 import org.apache.axiom.om.impl.dom.CommentImpl;
 import org.apache.axiom.om.impl.dom.DocumentFragmentImpl;
 import org.apache.axiom.om.impl.dom.DocumentImpl;
+import org.apache.axiom.om.impl.dom.DocumentTypeImpl;
 import org.apache.axiom.om.impl.dom.ElementImpl;
 import org.apache.axiom.om.impl.dom.NamespaceImpl;
 import org.apache.axiom.om.impl.dom.OMDOMException;
@@ -351,8 +352,9 @@
     }
 
     public OMDocType createOMDocType(OMContainer parent, String content) {
-        // TODO
-        throw new UnsupportedOperationException("TODO");
+        DocumentTypeImpl docType = new DocumentTypeImpl(this.getDocument(), 
this);
+        parent.addChild(docType);
+        return docType;
     }
 
     public OMProcessingInstruction createOMProcessingInstruction(


Reply via email to