axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/utils DOM2Writer.java XMLUtils.java
Date Mon, 01 Dec 2003 13:46:16 GMT
dims        2003/12/01 05:46:16

  Modified:    java/src/org/apache/axis/utils DOM2Writer.java XMLUtils.java
  Log:
  Fix for Bug 23059 - DOM2Writer generates invalid XML (missing namespaces)
  from nmoyere@calendra.com (Nicolas Moy?re)
  
  Revision  Changes    Path
  1.18      +11 -8     ws-axis/java/src/org/apache/axis/utils/DOM2Writer.java
  
  Index: DOM2Writer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/DOM2Writer.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- DOM2Writer.java	18 Jul 2003 12:40:40 -0000	1.17
  +++ DOM2Writer.java	1 Dec 2003 13:46:15 -0000	1.18
  @@ -115,11 +115,12 @@
               out.println("\"?>");
           }
           NSStack namespaceStack = new NSStack();
  -        print(node, namespaceStack, out, pretty, 0);
  +        print(node, namespaceStack, node, out, pretty, 0);
           out.flush();
       }
   
       private static void print(Node node, NSStack namespaceStack,
  +    						  Node startnode,
                                 PrintWriter out, boolean pretty,
                                 int indent)
       {
  @@ -143,7 +144,7 @@
   
                       for (int i = 0; i < numChildren; i++)
                       {
  -                        print(children.item(i), namespaceStack, out,
  +                        print(children.item(i), namespaceStack, startnode, out,
                                 pretty, indent);
                       }
                   }
  @@ -185,7 +186,7 @@
   
                       if (!prefixIsDeclared)
                       {
  -                        printNamespaceDecl(node, namespaceStack, out);
  +                        printNamespaceDecl(node, namespaceStack, startnode, out);
                       }
                   }
   
  @@ -221,7 +222,7 @@
   
                           if (!prefixIsDeclared)
                           {
  -                            printNamespaceDecl(attr, namespaceStack, out);
  +                            printNamespaceDecl(attr, namespaceStack, startnode, out);
                           }
                       }
                   }
  @@ -243,7 +244,7 @@
   
                       for (int i = 0; i < numChildren; i++)
                       {
  -                        print(children.item(i), namespaceStack, out, pretty,
  +                        print(children.item(i), namespaceStack, startnode, out, pretty,
                                 indent + 1);
                       }
                   }
  @@ -332,6 +333,7 @@
   
       private static void printNamespaceDecl(Node node,
                                              NSStack namespaceStack,
  +										   Node startnode,
                                              PrintWriter out)
       {
           switch (node.getNodeType())
  @@ -339,13 +341,13 @@
           case Node.ATTRIBUTE_NODE :
               {
                   printNamespaceDecl(((Attr)node).getOwnerElement(), node,
  -                                   namespaceStack, out);
  +                                   namespaceStack, startnode, out);
                   break;
               }
   
           case Node.ELEMENT_NODE :
               {
  -                printNamespaceDecl((Element)node, node, namespaceStack, out);
  +                printNamespaceDecl((Element)node, node, namespaceStack, startnode, out);
                   break;
               }
           }
  @@ -353,6 +355,7 @@
   
       private static void printNamespaceDecl(Element owner, Node node,
                                              NSStack namespaceStack,
  +                                           Node startnode,
                                              PrintWriter out)
       {
           String namespaceURI = node.getNamespaceURI();
  @@ -361,7 +364,7 @@
           if (!(namespaceURI.equals(Constants.NS_URI_XMLNS) && prefix.equals("xmlns"))
&&
               !(namespaceURI.equals(Constants.NS_URI_XML) && prefix.equals("xml")))
           {
  -            if (XMLUtils.getNamespace(prefix, owner) == null)
  +            if (XMLUtils.getNamespace(prefix, owner, startnode) == null)
               {
                   out.print(" xmlns:" + prefix + "=\"" + namespaceURI + '\"');
               }
  
  
  
  1.89      +22 -4     ws-axis/java/src/org/apache/axis/utils/XMLUtils.java
  
  Index: XMLUtils.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/utils/XMLUtils.java,v
  retrieving revision 1.88
  retrieving revision 1.89
  diff -u -r1.88 -r1.89
  --- XMLUtils.java	1 Dec 2003 08:37:38 -0000	1.88
  +++ XMLUtils.java	1 Dec 2003 13:46:15 -0000	1.89
  @@ -507,19 +507,37 @@
           return null;
       }
   
  -    public static String getNamespace(String prefix, Node e) {
  +    /**
  +     * Searches for the namespace URI of the given prefix in the given DOM range.
  +     * 
  +     * The namespace is not searched in parent of the "greaterancestor". This is
  +     * usefull to get all the needed namespaces when you need to ouput only a
  +     * subtree of a DOM document. 
  +     * 
  +     * @param prefix the prefix to find
  +     * @param e the starting node
  +     * @param greaterancestor null to search in all the document or a parent node where
the search must stop.
  +     * @return null if no namespace is found, or the namespace URI. 
  +     */
  +    public static String getNamespace(String prefix, Node e, Node greaterancestor) {
           while (e != null && (e.getNodeType() == Node.ELEMENT_NODE)) {
               Attr attr = null;
               if (prefix == null) {
  -                attr = ((Element)e).getAttributeNode("xmlns");
  +                attr = ((Element) e).getAttributeNode("xmlns");
               } else {
  -                attr = ((Element)e).getAttributeNodeNS(Constants.NS_URI_XMLNS, 
  -                                                       prefix);
  +                attr = ((Element) e).getAttributeNodeNS(Constants.NS_URI_XMLNS,
  +                        prefix);
               }
               if (attr != null) return attr.getValue();
  +            if (e == greaterancestor)
  +                return null;
               e = e.getParentNode();
           }
           return null;
  +    }
  +
  +    public static String getNamespace(String prefix, Node e) {
  +        return getNamespace(prefix, e, null);
       }
   
       /**
  
  
  

Mime
View raw message