You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2008/08/06 17:14:09 UTC

svn commit: r683292 - in /cxf/branches/2.0.x-fixes: ./ common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java

Author: dkulp
Date: Wed Aug  6 08:14:09 2008
New Revision: 683292

URL: http://svn.apache.org/viewvc?rev=683292&view=rev
Log:
Merged revisions 683290 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r683290 | dkulp | 2008-08-06 11:07:38 -0400 (Wed, 06 Aug 2008) | 2 lines
  
  [CXF-1724] Patch from Dave Leatherdale applied
........

Modified:
    cxf/branches/2.0.x-fixes/   (props changed)
    cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java

Propchange: cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Aug  6 08:14:09 2008
@@ -1 +1 @@
-/cxf/trunk:673548,674485,674547,674551,674562,674601,674649,674764,674887,675644,675653,677048,677385,678004,678009,678559,678629,678808,678852,678891,678893,679248,679597,680435,681060,681165,681813,681816,682902,682951,683089
+/cxf/trunk:673548,674485,674547,674551,674562,674601,674649,674764,674887,675644,675653,677048,677385,678004,678009,678559,678629,678808,678852,678891,678893,679248,679597,680435,681060,681165,681813,681816,682902,682951,683089,683290

Propchange: cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java?rev=683292&r1=683291&r2=683292&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java (original)
+++ cxf/branches/2.0.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java Wed Aug  6 08:14:09 2008
@@ -44,6 +44,9 @@
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
+import org.apache.cxf.common.util.StringUtils;
+
+
 /**
  * Few simple utils to read DOM. This is originally from the Jakarta Commons
  * Modeler.
@@ -53,6 +56,7 @@
 public final class DOMUtils {
     static final DocumentBuilderFactory FACTORY = DocumentBuilderFactory.newInstance();
     static DocumentBuilder builder;
+    private static final String XMLNAMESPACE = "xmlns";
 
     private DOMUtils() {
     }
@@ -348,12 +352,7 @@
             throw new RuntimeException("Couldn't find a DOM parser.", e);
         }
     }
-
-    public static String getUniquePrefix(Element el, String ns) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-    
+   
     public static String getPrefixRecursive(Element el, String ns) {
         String prefix = getPrefix(el, ns);
         if (prefix == null && el.getParentNode() instanceof Element) {
@@ -368,7 +367,7 @@
             Node node = atts.item(i);
             String name = node.getNodeName();
             if (ns.equals(node.getNodeValue()) 
-                && (name != null && ("xmlns".equals(name) || name.startsWith("xmlns:")))) { 
+                && (name != null && (XMLNAMESPACE.equals(name) || name.startsWith(XMLNAMESPACE + ":")))) { 
                 return node.getPrefix();
             }
         }
@@ -382,26 +381,35 @@
             p = "ns" + i;
             i++;
         }
-        el.setAttribute("xmlns:" + p, ns);
+        el.setAttribute(XMLNAMESPACE + ":" + p, ns);
         return p;
     }
 
-    public static String getNamespace(Element el, String pre) {
+    /**
+     * Searches the given element including it's parent elements
+     * for a matching namspace decleration.
+     * @param el element to search for namespace definitions
+     * @param searchPrefix the prefix we are searching for
+     * @return the namespace if found.
+     */
+    public static String getNamespace(Element el, String searchPrefix) {
         NamedNodeMap atts = el.getAttributes();
         for (int i = 0; i < atts.getLength(); i++) {
-            Node node = atts.item(i);
-            String name = node.getLocalName();
-            String pre2 = node.getPrefix();
-            if (pre.equals(name) && "xmlns".equals(pre2)) {
-                return node.getNodeValue();
-            } else if (pre.length() == 0 && "xmlns".equals(name) && pre2.length() == 0) {
-                return node.getNodeValue();
+            Node currentAttribute = atts.item(i);
+            String currentLocalName = currentAttribute.getLocalName();
+            String currentPrefix = currentAttribute.getPrefix();
+            if (searchPrefix.equals(currentLocalName) && XMLNAMESPACE.equals(currentPrefix)) {
+                return currentAttribute.getNodeValue();
+            } else if (StringUtils.isEmpty(searchPrefix)
+                && XMLNAMESPACE.equals(currentLocalName) 
+                && StringUtils.isEmpty(currentPrefix)) {
+                return currentAttribute.getNodeValue();
             }
         }
         
         Node parent = el.getParentNode();
         if (parent instanceof Element) {
-            return getNamespace((Element) parent, pre);
+            return getNamespace((Element) parent, searchPrefix);
         }
         
         return null;