cziegeler 2004/03/17 01:29:15
Modified: . status.xml
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="[EMAIL PROTECTED]">
DOMFactory can now create a document element.
</action>
Revision Changes Path
1.284 +4 -1 cocoon-2.1/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/cocoon-2.1/status.xml,v
retrieving revision 1.283
retrieving revision 1.284
diff -u -r1.283 -r1.284
--- status.xml 16 Mar 2004 13:19:32 -0000 1.283
+++ status.xml 17 Mar 2004 09:29:14 -0000 1.284
@@ -212,6 +212,9 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="CZ" type="fix" fixes-bug="27681" due-to="Peter Brant"
due-to-email="[EMAIL PROTECTED]">
+ DOMFactory can now create a document element.
+ </action>
<action dev="CZ" type="add">
Databases: The xml-encoding for the SQLTransformer is now configurable.
</action>
1.3 +25 -7
cocoon-2.1/src/java/org/apache/cocoon/util/jxpath/DOMFactory.java
Index: DOMFactory.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/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 5 Mar 2004 13:03:01 -0000 1.2
+++ DOMFactory.java 17 Mar 2004 09:29:15 -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++;
}