cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.2/src/java/org/apache/cocoon/util/jxpath DOMFactory.java
Date Wed, 17 Mar 2004 09:35:35 GMT
cziegeler    2004/03/17 01:35:35

  Modified:    src/java/org/apache/cocoon/util/jxpath DOMFactory.java
  Log:
     <action dev="CZ" type="fix" fixes-bug="27681" due-to="Peter Brant" due-to-email="peter.brant@courts.state.wi.us">
       DOMFactory can now create a document element.
     </action>
  
  Revision  Changes    Path
  1.3       +25 -7     cocoon-2.2/src/java/org/apache/cocoon/util/jxpath/DOMFactory.java
  
  Index: DOMFactory.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/util/jxpath/DOMFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DOMFactory.java	8 Mar 2004 14:04:01 -0000	1.2
  +++ DOMFactory.java	17 Mar 2004 09:35:35 -0000	1.3
  @@ -18,6 +18,7 @@
   import org.apache.commons.jxpath.AbstractFactory;
   import org.apache.commons.jxpath.JXPathContext;
   import org.apache.commons.jxpath.Pointer;
  +import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   
  @@ -44,20 +45,18 @@
            //FIXME: JXPath automatically creates attributes if the element already exists,
            //but does not call this method if the element does not exit 
   
  -        addDOMElement((Element) parent, index, name);
  +        addDOMElement((Node) parent, index, name);
           
           return true;
       }
   
  -    private void addDOMElement(Element parent, int index, String tag) {
  +    private void addDOMElement(Node parent, int index, String tag) {
           int pos = tag.indexOf(':');
           String prefix = null;
           if (pos != -1) {
               prefix = tag.substring(0, pos);
           }
  -        String uri = getNamespaceURI(parent, prefix);
  -                
  -        //System.out.println("Found namespace '" + uri + "' for tag " + tag);
  +        String uri = null;
           
           Node child = parent.getFirstChild();
           int count = 0;
  @@ -68,9 +67,28 @@
               child = child.getNextSibling();
           }
   
  +        Document doc = parent.getOwnerDocument();
  +        
  +        if (doc != null) {
  +            uri = getNamespaceURI((Element)parent, prefix);
  +        } else {
  +            if (parent instanceof Document) {
  +                doc = (Document)parent;
  +                if (prefix != null) {
  +                    throw new RuntimeException("Cannot map non-null prefix " +
  +                        "when creating a document element");    
  +                }
  +            } else { // Shouldn't happen (must be a DocumentType object)
  +                throw new RuntimeException("Node of class " +
  +                    parent.getClass().getName() + " has null owner document " +
  +                    "but is not a Document"); 
  +            }
  +
  +        }
  +
           // Keep inserting new elements until we have index + 1 of them
           while (count <= index) {
  -            Node newElement = parent.getOwnerDocument().createElementNS(uri, tag);
  +            Node newElement = doc.createElementNS(uri, tag);
               parent.appendChild(newElement);
               count++;
           }
  
  
  

Mime
View raw message