You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ru...@apache.org on 2005/10/25 07:42:52 UTC

svn commit: r328264 - in /webservices/axis2/trunk/java/modules/xml: src/org/apache/axis2/om/impl/dom/ src/org/apache/axis2/om/impl/llom/ test/org/apache/axis2/om/impl/dom/

Author: ruchithf
Date: Mon Oct 24 22:42:32 2005
New Revision: 328264

URL: http://svn.apache.org/viewcvs?rev=328264&view=rev
Log:
- Completed NodeListImpl and completed some TODOs in the DOM classes
- Added some more tests to DOM test cases, a lot more to come :-)
- Added and commented code in OMTextImpl, to do line wrapping of base64 content (using 76 character length) , for others to review, this is required to support Encrypt, Sign , MTOM optimizing, cipher content to work properly (XMLSec lib uses line wrapping of length 76)


Modified:
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeListImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/TextImpl.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/DocumentImplTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/ElementImplTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/TextImplTest.java

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ChildNode.java Mon Oct 24 22:42:32 2005
@@ -111,7 +111,10 @@
 	 * Insert the given sibling next to this item
 	 */
 	public void insertSiblingAfter(OMNode sibling) throws OMException {
-		((OMNodeEx)sibling).setParent(this.parentNode);
+		
+		if(this.parentNode != null) {
+			((OMNodeEx)sibling).setParent(this.parentNode);
+		}
 		
 		if(sibling instanceof ChildNode) {
 			ChildNode domSibling = (ChildNode)sibling;

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ElementImpl.java Mon Oct 24 22:42:32 2005
@@ -53,6 +53,7 @@
 	private String tagName;
 	private AttributeMap attributes;
 	private HashMap namespaces;
+	
 	/**
 	 * @param ownerDocument
 	 */
@@ -389,17 +390,15 @@
 	/* (non-Javadoc)
 	 * @see org.w3c.dom.Element#getElementsByTagNameNS(java.lang.String, java.lang.String)
 	 */
-	public NodeList getElementsByTagNameNS(String arg0, String arg1) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
+		return new NodeListImpl(this, namespaceURI, localName);
 	}
 
 	/* (non-Javadoc)
 	 * @see org.w3c.dom.Element#getElementsByTagName(java.lang.String)
 	 */
-	public NodeList getElementsByTagName(String arg0) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public NodeList getElementsByTagName(String name) {
+		return new NodeListImpl(this, name);
 	}
 	
 	///

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeImpl.java Mon Oct 24 22:42:32 2005
@@ -113,7 +113,10 @@
 		return null;
 	}
 
-
+	
+	/*
+	 * Overidden in ElementImpl and AttrImpl
+	 */
     public String getPrefix()
     {
         return null;
@@ -124,7 +127,6 @@
 	}
 
 
-
     public void setPrefix(String prefix) throws DOMException {
     	throw new DOMException(DOMException.NAMESPACE_ERR, 
               DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
@@ -356,8 +358,6 @@
         //Document, DocumentFragment, and Attribute will never have parents.
 	}
 
-
-
 	/* (non-Javadoc)
 	 * @see org.apache.axis.om.OMNode#isComplete()
 	 */
@@ -365,8 +365,6 @@
 		return this.done;
 	}
 
-	/**
-	 */
 	public void setComplete(boolean state) {
 		this.done = state;
 		

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeListImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeListImpl.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeListImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/NodeListImpl.java Mon Oct 24 22:42:32 2005
@@ -15,12 +15,20 @@
  */
 package org.apache.axis2.om.impl.dom;
 
-import java.util.Vector;
-
+import org.apache.axis2.om.impl.OMContainerEx;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import java.util.Iterator;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
 
+/**
+ * Implementation of org.w3c.dom.NodeList
+ *  
+ * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ */
 public class NodeListImpl implements NodeList  {
 	
     protected NodeImpl rootNode; 
@@ -40,25 +48,52 @@
 
     /** Constructor for Namespace support. */
     public NodeListImpl(NodeImpl rootNode,
-                            String nsName, String tagName) {
-        this(rootNode, tagName);
-        this.nsName = (nsName != null && !nsName.equals("")) ? nsName : null;
+                            String namespaceURI, String localName) {
+        this(rootNode, localName);
+        this.nsName = (namespaceURI != null && !namespaceURI.equals("")) ? namespaceURI : null;
         enableNS = true;
     }
 
-	/* (non-Javadoc)
+	/**
+	 * Returns the numbre of nodes
 	 * @see org.w3c.dom.NodeList#getLength()
 	 */
 	public int getLength() {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		Iterator children;
+		if(enableNS) {
+			children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.tagName));
+		} else {
+			children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.nsName, this.tagName));
+		}
+		int count  = 0;
+		while (children.hasNext()) {
+			count++;
+			children.next();
+		}
+		return count;
 	}
 
-	/* (non-Javadoc)
+	/**
+	 * Returns the node at the given index.
+	 * returns null if the index is invalid. 
 	 * @see org.w3c.dom.NodeList#item(int)
 	 */
-	public Node item(int arg0) {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+	public Node item(int index) {
+		Iterator children;
+		if(enableNS) {
+			children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.tagName));
+		} else {
+			children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.nsName, this.tagName));
+		}
+		int count  = 0;
+		while (children.hasNext()) {
+			count++;
+			if(count == index) {
+				return (Node)children.next();
+			} else {
+				children.next();
+			}
+		}
+		return null;
 	}
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/ParentNode.java Mon Oct 24 22:42:32 2005
@@ -69,15 +69,32 @@
 		return new OMChildrenIterator(this.firstChild);
 	}
 	
+	/**
+	 * Returns an iterator of child nodes having a given qname
+	 * @see org.apache.axis2.om.OMContainer#getChildrenWithName(javax.xml.namespace.QName)
+	 */
 	public Iterator getChildrenWithName(QName elementQName) throws OMException {
 		return new OMChildrenQNameIterator(getFirstOMChild(),
                 elementQName);
 	}
 	
+	/**
+	 * Return the first OMElement child node
+	 * @see org.apache.axis2.om.OMContainer#getFirstChildWithName(javax.xml.namespace.QName)
+	 */
 	public OMElement getFirstChildWithName(QName elementQName)
 			throws OMException {
-		//TODO
-		throw new UnsupportedOperationException("TODO");
+		Iterator children = new OMChildrenQNameIterator(getFirstOMChild(),
+                elementQName);
+		while (children.hasNext()) {
+			OMNode node = (OMNode) children.next();
+			
+			//Return the first OMElement node that is found
+			if(node instanceof OMElement) {
+				return (OMElement)node;
+			}
+		}
+		return null;
 	}
 	
 	public OMNode getFirstOMChild() {

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/TextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/TextImpl.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/TextImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/dom/TextImpl.java Mon Oct 24 22:42:32 2005
@@ -184,12 +184,15 @@
 		this.deleteData(offset, this.textValue.length());
 		
 		TextImpl newText = (TextImpl)this.getOwnerDocument().createTextNode(newValue);
-		newText.setParent(this.parentNode);
+		
+		if(this.parentNode != null) {
+			newText.setParent(this.parentNode);
+		}
 		
 		this.insertSiblingAfter(newText);
 		
 
-		return null;
+		return newText;
 	}
 	
 	///
@@ -202,10 +205,13 @@
 		return OMNode.TEXT_NODE;
 	}
 	
+	
 	///
 	///OMNode methods
 	///
 		
+
+
 	/* (non-Javadoc)
 	 * @see org.apache.axis2.om.OMNode#getType()
 	 */
@@ -295,6 +301,10 @@
         }
 	}
 	
+	public String getNodeValue() throws DOMException {
+		return this.getText();
+	}
+	
 	public String getContentID() {
         if (contentID == null) {
             contentID = UUIDGenerator.getUUID()
@@ -308,7 +318,7 @@
          * reperesented by the Base64 strings stored in OMText
          */
         if (textValue != null & isBinary) {
-            return org.apache.axis2.attachments.DataHandlerUtils.getDataHandlerFromText(textValue.toString() ,mimeType);
+        	return org.apache.axis2.attachments.DataHandlerUtils.getDataHandlerFromText(textValue.toString() ,mimeType);
         } else {
 
             if (dataHandlerObject == null) {
@@ -456,5 +466,6 @@
         }
     }
 
+    
 	
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMTextImpl.java Mon Oct 24 22:42:32 2005
@@ -217,6 +217,21 @@
                 	}
 
                 } while (inStream.available() > 0);
+                
+                //Breakup the base64 encoded text
+                StringBuffer newText = new StringBuffer();
+                
+//                while(72 <= text.length()) {
+//                	newText.append(text.substring(0,Base64.BASE64DEFAULTLENGTH));
+//                	newText.append("\n");
+//                	text = text.delete(0,Base64.BASE64DEFAULTLENGTH);
+//                }
+//                
+//                if(text.length() > 0) {
+//                	newText.append(text.toString());
+//                }
+                
+//                return newText.toString();
                 return text.toString();
             } catch (Exception e) {
                 throw new OMException(e);
@@ -247,7 +262,7 @@
          * reperesented by the Base64 strings stored in OMText
          */
         if (value != null & isBinary) {
-            return org.apache.axis2.attachments.DataHandlerUtils.getDataHandlerFromText(value,mimeType);
+        	return org.apache.axis2.attachments.DataHandlerUtils.getDataHandlerFromText(value,mimeType);
         } else {
 
             if (dataHandlerObject == null) {

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/DocumentImplTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/DocumentImplTest.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/DocumentImplTest.java (original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/DocumentImplTest.java Mon Oct 24 22:42:32 2005
@@ -17,6 +17,7 @@
 
 import org.w3c.dom.Attr;
 import org.w3c.dom.Element;
+import org.w3c.dom.Text;
 
 import junit.framework.TestCase;
 
@@ -68,7 +69,12 @@
 	}
 	
 	public void testCreateText() {
+		String textValue = "temp text value";
 		
+		DocumentImpl doc = new DocumentImpl();
+		Text txt = doc.createTextNode(textValue);
+		
+		assertEquals("Text value mismatch", textValue, txt.getData());
 	}
 
 }

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/ElementImplTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/ElementImplTest.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/ElementImplTest.java (original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/ElementImplTest.java Mon Oct 24 22:42:32 2005
@@ -19,6 +19,9 @@
 import org.apache.axis2.om.OMText;
 import org.apache.axis2.om.impl.OMOutputImpl;
 import org.apache.axis2.om.impl.dom.factory.OMDOMFactory;
+import org.apache.axis2.om.impl.dom.jaxp.DocumentBuilderFactoryImpl;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
 import org.w3c.dom.Text;
 
 import java.io.ByteArrayOutputStream;
@@ -101,4 +104,36 @@
 		}
 		assertEquals("In correct number of children", 1, count );
 	}
+	
+	public void testAppendChild() {
+		try {
+			String elementName = "TestElem";
+			String childElemName = "TestChildElem";
+			String childTextValue = "text value of the child text node";
+			
+			//Apending am Element node
+			Document doc = DocumentBuilderFactoryImpl.newInstance().newDocumentBuilder().newDocument();
+			Element elem = doc.createElement(elementName);
+			Element childElem = doc.createElement(childElemName);
+			
+			elem.appendChild(childElem);
+			
+			Element addedChild = (Element)elem.getFirstChild();
+			assertNotNull("Child Element node missing",addedChild);
+			assertEquals("Incorre node object", childElem, addedChild);
+			
+			elem = doc.createElement(elementName);
+			Text text = doc.createTextNode(childTextValue);
+			elem.appendChild(text);
+			
+			Text addedTextnode = (Text)elem.getFirstChild();
+			assertNotNull("Child Text node missing", addedTextnode);
+			assertEquals("Incorrect node object", text, addedTextnode);
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail(e.getMessage());
+		}
+	}
+	
 }

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/TextImplTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/TextImplTest.java?rev=328264&r1=328263&r2=328264&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/TextImplTest.java (original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/impl/dom/TextImplTest.java Mon Oct 24 22:42:32 2005
@@ -31,20 +31,20 @@
 	public TextImplTest(String name) {
 		super(name);
 	}
-	
+
 	public void testSetText() {
 		OMDOMFactory factory = new OMDOMFactory();
 		String localName = "TestLocalName";
 		String namespace = "http://ws.apache.org/axis2/ns";
 		String prefix = "axis2";
 		String tempText = "The quick brown fox jumps over the lazy dog";
-		
-		OMElement elem = factory.createOMElement(localName,namespace,prefix);
-		OMText textNode = factory.createText(elem,tempText);
-		
+
+		OMElement elem = factory.createOMElement(localName, namespace, prefix);
+		OMText textNode = factory.createText(elem, tempText);
+
 		assertEquals("Text value mismatch", tempText, textNode.getText());
 	}
-	
+
 	public void testAppendText() {
 		OMDOMFactory factory = new OMDOMFactory();
 		String localName = "TestLocalName";
@@ -52,15 +52,36 @@
 		String prefix = "axis2";
 		String tempText = "The quick brown fox jumps over the lazy dog";
 		String textToAppend = " followed by another fox";
-		
-		OMElement elem = factory.createOMElement(localName,namespace,prefix);
-		OMText textNode = factory.createText(elem,tempText);
-		
-		((Text)textNode).appendData(textToAppend);
-		
-		assertEquals("Text value mismatch", tempText+textToAppend, textNode.getText());
+
+		OMElement elem = factory.createOMElement(localName, namespace, prefix);
+		OMText textNode = factory.createText(elem, tempText);
+
+		((Text) textNode).appendData(textToAppend);
+
+		assertEquals("Text value mismatch", tempText + textToAppend, textNode
+				.getText());
+	}
+
+	public void testSplitText() {
+		String textValue = "temp text value";
+
+		DocumentImpl doc = new DocumentImpl();
+
+		Text txt = doc.createTextNode(textValue);
+		txt.splitText(3);
+
+		assertNotNull("Text value missing in the original Text node", txt
+				.getNodeValue());
+
+		assertNotNull("Sibling missing after split", txt.getNextSibling());
+		assertNotNull("Text value missing in the new split Text node", txt
+				.getNextSibling().getNodeValue());
+
+		assertEquals("Incorrect split point", textValue.substring(0, 3), txt
+				.getNodeValue());
+		assertEquals("Incorrect split point", textValue.substring(3, textValue
+				.length()), txt.getNextSibling().getNodeValue());
+
 	}
-	
-	
 
 }