You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by rr...@apache.org on 2010/05/13 19:36:58 UTC

svn commit: r943949 - in /ode/branches/APACHE_ODE_1.X/utils/src: main/java/org/apache/ode/utils/DOMUtils.java test/java/org/apache/ode/utils/DOMUtilsTest.java

Author: rr
Date: Thu May 13 17:36:58 2010
New Revision: 943949

URL: http://svn.apache.org/viewvc?rev=943949&view=rev
Log:
V4 fix for ODE-663. Thanks to David Carver

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=943949&r1=943948&r2=943949&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 Thu May 13 17:36:58 2010
@@ -1109,7 +1109,28 @@ public class DOMUtils {
     	
     	switch (sourceNode.getNodeType()) {
     	case Node.ATTRIBUTE_NODE:
-   		    clonedNode = document.importNode(sourceNode, false);
+            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());
+            }
 			break;
     	case Node.CDATA_SECTION_NODE:
     		clonedNode = document.createCDATASection(((CDATASection) sourceNode).getData());

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=943949&r1=943948&r2=943949&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 Thu May 13 17:36:58 2010
@@ -19,6 +19,7 @@
 package org.apache.ode.utils;
 
 import net.sf.saxon.dom.DocumentBuilderFactoryImpl;
+import net.sf.saxon.xqj.SaxonXQDataSource;
 
 import org.apache.ode.utils.TestResources;
 
@@ -30,6 +31,11 @@ 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;
 
@@ -215,6 +221,29 @@ public class DOMUtilsTest extends TestCa
         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 {