Author: rr
Date: Tue May 18 03:24:09 2010
New Revision: 945471

URL: http://svn.apache.org/viewvc?rev=945471&view=rev
Log:
ODE-663: Reverted for now

Modified:
    
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
    
ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/DOMUtilsTest.java

Modified: 
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
URL: 
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java?rev=945471&r1=945470&r2=945471&view=diff
==============================================================================
--- 
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
 (original)
+++ 
ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/DOMUtils.java
 Tue May 18 03:24:09 2010
@@ -1109,28 +1109,25 @@ public class DOMUtils {
        
        switch (sourceNode.getNodeType()) {
        case Node.ATTRIBUTE_NODE:
-            if (namespaceURI == null) {
-                clonedNode = document.createAttribute(nodeName);
-                break;
-            } else {
-                String prefix = sourceNode.getPrefix();
-//                String prefix = ((Attr) 
sourceNode).lookupPrefix(namespaceURI);
-                // the prefix for the XML namespace can't be looked up, hence 
this...
-                if (prefix == null && namespaceURI.equals(NS_URI_XMLNS)) {
-                    nodeName = "xmlns";
-                }
-                // if a prefix exists, qualify the name with it
-                if (prefix != null && !"".equals(prefix)) {
-                    nodeName = prefix + ":" + nodeName;
-                }
-                // create the appropriate type of attribute
-                if (prefix != null) {
-                    clonedNode = document.createAttributeNS(namespaceURI, 
nodeName);
-                } else {
-                    clonedNode = document.createAttribute(nodeName);
-                }
-                clonedNode.setNodeValue(sourceNode.getNodeValue());
-            }
+               if (namespaceURI == null) {
+                       clonedNode = document.createAttribute(nodeName);
+               } else {
+                       String prefix = ((Attr) 
sourceNode).lookupPrefix(namespaceURI);
+                       // the prefix for the XML namespace can't be looked up, 
hence this...
+                       if (prefix == null && 
namespaceURI.equals(NS_URI_XMLNS)) {
+                               prefix = "xmlns";
+                       }
+                       // if a prefix exists, qualify the name with it
+                       if (prefix != null && !"".equals(prefix)) {
+                               nodeName = prefix + ":" + nodeName;
+                       }
+                       // create the appropriate type of attribute
+                       if (prefix != null) {
+                               clonedNode = 
document.createAttributeNS(namespaceURI, nodeName);
+                       } else {
+                               clonedNode = document.createAttribute(nodeName);
+                       }
+               }
                        break;
        case Node.CDATA_SECTION_NODE:
                clonedNode = document.createCDATASection(((CDATASection) 
sourceNode).getData());
@@ -1193,16 +1190,13 @@ public class DOMUtils {
        NodeList sourceChildren = sourceNode.getChildNodes();
        if (sourceChildren != null) {
                for (int i = 0; i < sourceChildren.getLength(); i++) {
-                   if (sourceNode.getNodeType() != Node.ATTRIBUTE_NODE) {
-                       Node sourceChild = sourceChildren.item(i);
-                       Node clonedChild = cloneNode(document, sourceChild);
-                       clonedNode.appendChild(clonedChild);
-                   }
-                       
+                       Node sourceChild = sourceChildren.item(i);
+                       Node clonedChild = cloneNode(document, sourceChild);
+                       clonedNode.appendChild(clonedChild);
                        // if the child has a textual value, parse it for any 
embedded prefixes
-                       if (sourceChildren.item(i).getNodeType() == 
Node.TEXT_NODE || 
-                                       sourceChildren.item(i).getNodeType() == 
Node.CDATA_SECTION_NODE) {
-                               parseEmbeddedPrefixes(sourceNode, clonedNode, 
sourceChildren.item(i));
+                       if (clonedChild.getNodeType() == Node.TEXT_NODE || 
+                                       clonedChild.getNodeType() == 
Node.CDATA_SECTION_NODE) {
+                               parseEmbeddedPrefixes(sourceNode, clonedNode, 
clonedChild);
                        }
                }
        }

Modified: 
ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/DOMUtilsTest.java
URL: 
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/DOMUtilsTest.java?rev=945471&r1=945470&r2=945471&view=diff
==============================================================================
--- 
ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/DOMUtilsTest.java
 (original)
+++ 
ode/branches/APACHE_ODE_1.X/utils/src/test/java/org/apache/ode/utils/DOMUtilsTest.java
 Tue May 18 03:24:09 2010
@@ -18,24 +18,9 @@
  */
 package org.apache.ode.utils;
 
-import net.sf.saxon.dom.DocumentBuilderFactoryImpl;
-import net.sf.saxon.xqj.SaxonXQDataSource;
-
 import org.apache.ode.utils.TestResources;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.io.InputStream;
-import java.util.Map;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xquery.XQConnection;
-import javax.xml.xquery.XQDataSource;
-import javax.xml.xquery.XQItem;
-import javax.xml.xquery.XQPreparedExpression;
-import javax.xml.xquery.XQResultSequence;
 
 import junit.framework.TestCase;
 
@@ -43,29 +28,12 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
 
 /**
  * Test the {...@link DOMUtils} class.
  */
 public class DOMUtilsTest extends TestCase {
-    private static final String SAXON_DOM_DOCUMENT_BUILDER_FACTORY = 
"net.sf.saxon.dom.DocumentBuilderFactoryImpl";
-    private static final String DOCUMENT_BUILDER_FACTORY = 
"javax.xml.parsers.DocumentBuilderFactory";
-    String defaultBuilderFactory = null;
-
-  @Override
-  protected void setUp() throws Exception {
-        super.setUp();
-        defaultBuilderFactory = System.getProperty(DOCUMENT_BUILDER_FACTORY, 
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
-  }
-  
-  @Override
-  protected void tearDown() throws Exception {
-        super.tearDown();
-        
-        System.setProperty(DOCUMENT_BUILDER_FACTORY, defaultBuilderFactory);
-  }
-  
+
   public void testParseInputStream() throws Exception {
     Document doc = 
DOMUtils.parse(TestResources.getLoanApprovalProcess().openStream());
     assertEquals("process", doc.getDocumentElement().getLocalName());
@@ -142,117 +110,5 @@ public class DOMUtilsTest extends TestCa
       }
     }
   }
-  
-  public void testCloneNode() throws Exception {
-    String testString = "<ns1:parent xmlns:ns1=\"abc\">\n" +
-   "  <ns1:child xmlns=\"def\">\n" +
-   "     <ns2:nestedChild xmlns:ns2=\"def\"/>\n" +
-   "  </ns1:child>\n" +
-   "</ns1:parent>";
-    
-    Document doc = DOMUtils.parse(new 
ByteArrayInputStream(testString.getBytes()));
-    Node node = doc.getFirstChild();
-    Node clonedNode = DOMUtils.cloneNode(doc, node);
-    String actualString = DOMUtils.domToString(clonedNode).replace("<?xml 
version=\"1.0\" encoding=\"UTF-8\"?>\n", "");
-    assertEquals("XML Result", testString, actualString);
-  }
-  
-  public void testCloneNodeNewDocument() throws Exception {
-      String testString = "<ns1:parent xmlns:ns1=\"abc\">\n" +
-     "  <ns1:child xmlns=\"def\">\n" +
-     "     <ns2:nestedChild xmlns:ns2=\"def\"/>\n" +
-     "  </ns1:child>\n" +
-     "</ns1:parent>";
-      
-      Document doc = DOMUtils.parse(new 
ByteArrayInputStream(testString.getBytes()));
-      Document doc2 = 
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-      Node node = doc.getFirstChild();
-      Node clonedNode = DOMUtils.cloneNode(doc2, node);
-      
-      assertNotSame("DOM's are the same", doc, doc2);
-      String actualString = DOMUtils.domToString(clonedNode).replace("<?xml 
version=\"1.0\" encoding=\"UTF-8\"?>\n", "");
-      assertEquals("XML Result", testString, actualString);
-          
-  }
-  
-  /**
-   * A Saxon's DOM is read only. cloneNode should throw an 
UnsupportedOperationException.
-   * 
-   * @throws Exception
-   */
-  public void testCloneNodeSaxon() throws Exception {
-      String testString = "<ns1:parent xmlns:ns1=\"abc\">\n" +
-     "  <ns1:child xmlns=\"def\">\n" +
-     "     <ns2:nestedChild xmlns:ns2=\"def\"/>\n" +
-     "  </ns1:child>\n" +
-     "</ns1:parent>";
-      
-      Document doc = createSaxonDOM(testString);
-      
-      Node node = doc.getFirstChild();
-      try {
-          Node clonedNode = DOMUtils.cloneNode(doc, node);
-      } catch (UnsupportedOperationException ex) {
-          
-      }
-      
-    }
-    
-    public void testCloneNodeNewDocumentSaxon() throws Exception {
-        String testString = "<ns1:parent xmlns:ns1=\"abc\">\n" +
-       "  <ns1:child xmlns=\"def\">\n" +
-       "     <ns2:nestedChild xmlns:ns2=\"def\"/>\n" +
-       "  </ns1:child>\n" +
-       "</ns1:parent>";
-
-        String saxonString = "<ns1:parent xmlns:ns1=\"abc\">\n" +
-        "  <ns1:child xmlns=\"def\">\n" +
-        "     <nestedChild xmlns:ns2=\"def\"/>\n" +
-        "  </ns1:child>\n" +
-        "</ns1:parent>";
-        
-        Document doc = createSaxonDOM(testString);
-        Document doc2 = DOMUtils.newDocument();
-        Node node = doc.getFirstChild();
-        Node clonedNode = DOMUtils.cloneNode(doc2, node);
-        
-        assertNotSame("DOM's are the same", doc, doc2);
-        String actualString = DOMUtils.domToString(clonedNode).replace("<?xml 
version=\"1.0\" encoding=\"UTF-8\"?>\n", "");
-        assertEquals("XML Result", saxonString, actualString);
-            
-    }
-    
-    public void testSaxonXQueryResultValueClone() throws Exception {
-       String testString = "<test:test1 xmlns:test=\"http://test.org\";>\n" +
-      "  <test:test2>asdf</test:test2>\n" +
-      "</test:test1>";
-       
-       Document doc = DOMUtils.parse(new 
ByteArrayInputStream(testString.getBytes()));
-       
-       XQDataSource ds = new SaxonXQDataSource();
-       XQConnection conn = ds.getConnection();
-       XQPreparedExpression exp = conn.prepareExpression(testString);
-       
-       XQResultSequence rs = exp.executeQuery();
-       rs.next();
-
-       XQItem xqitem = rs.getItem();
-       Node node = xqitem.getNode();
-       Node clonedNode = DOMUtils.cloneNode(DOMUtils.newDocument(), node);
-       assertNotNull(clonedNode);
-       
-    }
-    
-    
 
-    private Document createSaxonDOM(String testString)
-            throws ParserConfigurationException, SAXException, IOException {
-        System.setProperty(DOCUMENT_BUILDER_FACTORY, 
SAXON_DOM_DOCUMENT_BUILDER_FACTORY);
-        DocumentBuilderFactory factory = 
DocumentBuilderFactoryImpl.newInstance();
-        factory.setNamespaceAware(true);
-        DocumentBuilder saxonBuilder = factory.newDocumentBuilder();
-        Document doc = saxonBuilder.parse(new 
ByteArrayInputStream(testString.getBytes()));
-        return doc;
-    }
-    
 }


Reply via email to