Author: mbenson
Date: Mon Jul 23 14:32:41 2007
New Revision: 558866

URL: http://svn.apache.org/viewvc?view=rev&rev=558866
Log:
[JXPATH-97] implement prefix matching for undeclared XML namespaces

Added:
    
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ExternalNS.xml
   (with props)
    
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java
   (with props)
Modified:
    
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
    
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
    
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestSuite.java

Modified: 
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java?view=diff&rev=558866&r1=558865&r2=558866
==============================================================================
--- 
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
 (original)
+++ 
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMNodePointer.java
 Mon Jul 23 14:32:41 2007
@@ -101,12 +101,12 @@
             if (wildcard && testPrefix == null) {
                 return true;
             }
-
             if (wildcard
                 || testName.getName()
                         .equals(DOMNodePointer.getLocalName(node))) {
                 String nodeNS = DOMNodePointer.getNamespaceURI(node);
-                return equalStrings(namespaceURI, nodeNS);
+                return equalStrings(namespaceURI, nodeNS) || nodeNS == null
+                        && equalStrings(testPrefix, getPrefix(node));
             }
             return false;
         }

Modified: 
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java?view=diff&rev=558866&r1=558865&r2=558866
==============================================================================
--- 
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
 (original)
+++ 
jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java
 Mon Jul 23 14:32:41 2007
@@ -363,12 +363,12 @@
             if (wildcard && testPrefix == null) {
                 return true;
             }
-
             if (wildcard
                 || testName.getName()
                         .equals(JDOMNodePointer.getLocalName(node))) {
                 String nodeNS = JDOMNodePointer.getNamespaceURI(node);
-                return equalStrings(namespaceURI, nodeNS);
+                return equalStrings(namespaceURI, nodeNS) || nodeNS == null
+                        && equalStrings(testPrefix, getPrefix(node));
             }
             return false;
         }

Added: 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ExternalNS.xml
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ExternalNS.xml?view=auto&rev=558866
==============================================================================
--- 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ExternalNS.xml
 (added)
+++ 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ExternalNS.xml
 Mon Jul 23 14:32:41 2007
@@ -0,0 +1,20 @@
+<?xml version="1.0" ?>
+<!--
+   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.
+-->
+<ElementA A:myAttr="Mytype">
+  <B:ElementB>MY VALUE</B:ElementB>
+</ElementA>

Propchange: 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ExternalNS.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestSuite.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestSuite.java?view=diff&rev=558866&r1=558865&r2=558866
==============================================================================
--- 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestSuite.java
 (original)
+++ 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/JXPathTestSuite.java
 Mon Jul 23 14:32:41 2007
@@ -29,7 +29,9 @@
 import org.apache.commons.jxpath.ri.compiler.CoreOperationTest;
 import org.apache.commons.jxpath.ri.compiler.ExtensionFunctionTest;
 import org.apache.commons.jxpath.ri.compiler.VariableTest;
+import org.apache.commons.jxpath.ri.model.ExternalXMLNamespaceTest;
 import org.apache.commons.jxpath.ri.model.MixedModelTest;
+import org.apache.commons.jxpath.ri.model.XMLPreserveSpaceTest;
 import org.apache.commons.jxpath.ri.model.XMLSpaceTest;
 import org.apache.commons.jxpath.ri.model.beans.BeanModelTest;
 import org.apache.commons.jxpath.ri.model.container.ContainerModelTest;
@@ -91,6 +93,8 @@
         suite.addTestSuite(BasicTypeConverterTest.class);
         suite.addTestSuite(RecursiveAxesTest.class);
         suite.addTestSuite(XMLSpaceTest.class);
+        suite.addTestSuite(XMLPreserveSpaceTest.class);
+        suite.addTestSuite(ExternalXMLNamespaceTest.class);
         return suite;
     }
 }

Added: 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java?view=auto&rev=558866
==============================================================================
--- 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java
 (added)
+++ 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java
 Mon Jul 23 14:32:41 2007
@@ -0,0 +1,73 @@
+/*
+ * 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.commons.jxpath.ri.model;
+
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.JXPathTestCase;
+import org.apache.commons.jxpath.xml.DocumentContainer;
+
+/**
+ * Test externally registered XML namespaces; JXPATH-97.
+ *
+ * @author Matt Benson
+ * @version $Revision$ $Date$
+ */
+public class ExternalXMLNamespaceTest extends JXPathTestCase {
+    protected JXPathContext context;
+
+    /**
+     * Construct a new instance of this test case.
+     *
+     * @param name Name of the test case
+     */
+    public ExternalXMLNamespaceTest(String name) {
+        super(name);
+    }
+
+    protected DocumentContainer createDocumentContainer(String model) {
+        DocumentContainer result = new DocumentContainer(JXPathTestCase.class
+                .getResource("ExternalNS.xml"), model);
+        //this setting only works for DOM, so no JDOM tests :|
+        result.setNamespaceAware(false);
+        return result;
+    }
+
+    protected void doTest(String xpath, String model, String expected) {
+        JXPathContext context = JXPathContext
+                .newContext(createDocumentContainer(model));
+        context.registerNamespace("A", "foo");
+        context.registerNamespace("B", "bar");
+        assertXPathValue(context, xpath, expected);
+    }
+
+    protected void doTestAttribute(String model) {
+        doTest("/ElementA/@A:myAttr", model, "Mytype");
+    }
+
+    protected void doTestElement(String model) {
+         doTest("/ElementA/B:ElementB", model, "MY VALUE");
+    }
+
+    public void testAttributeDOM() {
+        doTestAttribute(DocumentContainer.MODEL_DOM);
+    }
+
+    public void testElementDOM() {
+        doTestElement(DocumentContainer.MODEL_DOM);
+    }
+
+}
\ No newline at end of file

Propchange: 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/ExternalXMLNamespaceTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to