You are viewing a plain text version of this content. The canonical link for it is here.
Posted to crimson-cvs@xml.apache.org by ed...@apache.org on 2001/04/30 23:28:27 UTC
cvs commit: xml-crimson/src/org/apache/crimson/tree ParentNode.java
edwingo 01/04/30 14:28:27
Modified: src/org/apache/crimson/tree ParentNode.java
Log:
Fix DOM Node.insertBefore(newChild, refChild) should remove newChild first
if. DOM Node.replaceChild(newChild, refChild) should remove newChild first
if. DOM Element.normalize() normalizes whitespace when it should not
Revision Changes Path
1.3 +30 -12 xml-crimson/src/org/apache/crimson/tree/ParentNode.java
Index: ParentNode.java
===================================================================
RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/tree/ParentNode.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ParentNode.java 2001/03/14 21:41:41 1.2
+++ ParentNode.java 2001/04/30 21:28:25 1.3
@@ -1,5 +1,5 @@
/*
- * $Id: ParentNode.java,v 1.2 2001/03/14 21:41:41 edwingo Exp $
+ * $Id: ParentNode.java,v 1.3 2001/04/30 21:28:25 edwingo Exp $
*
* The Apache Software License, Version 1.1
*
@@ -79,7 +79,7 @@
* changes made by other threads.
*
* @author David Brownell
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
// not public ... javadoc looks a bit odd (hidden base class)
// but it's only subclassable within this package anyway
@@ -359,10 +359,10 @@
/**
- * <b>DOM:</b> Inserts the new child before the specified child,
- * which if null indicates appending the new child to the
- * current set of children. The new child must belong to
- * this particular document.
+ * <b>DOM:</b> Inserts the new child before the specified child, which
+ * if null indicates appending the new child to the current set of
+ * children. The new child must belong to this particular document.
+ * If the newChild is already in the tree, it is first removed.
*
* @param newChild the new child to be inserted
* @param refChild node before which newChild is to be inserted
@@ -389,6 +389,14 @@
checkNotAncestor (newChild);
checkChildType (newChild.getNodeType ());
+ // If the newChild is already in the tree, it is first removed
+ for (int i = 0; i < length; i++) {
+ if (children[i] == newChild) {
+ removeChild(newChild);
+ break;
+ }
+ }
+
// grow array if needed
if (children.length == length) {
NodeBase temp [] = new NodeBase [length * 2];
@@ -411,9 +419,10 @@
}
/**
- * <b>DOM:</b> Replaces the specified child with the new node,
- * returning the original child or throwing an exception.
- * The new child must belong to this particular document.
+ * <b>DOM:</b> Replaces the specified child with the new node,
+ * returning the original child or throwing an exception. The new
+ * child must belong to this particular document. If the newChild is
+ * already in the tree, it is first removed.
*
* @param newChild the new child to be inserted
* @param refChild node which is to be replaced
@@ -440,6 +449,14 @@
checkNotAncestor (newChild);
checkChildType (newChild.getNodeType ());
+ // If the newChild is already in the tree, it is first removed
+ for (int i = 0; i < length; i++) {
+ if (children[i] == newChild) {
+ removeChild(newChild);
+ break;
+ }
+ }
+
for (int i = 0; i < length; i++) {
if (children [i] != refChild)
continue;
@@ -682,7 +699,8 @@
* then reread (and normalized) retains the same content. </P>
*/
public void normalize() {
- boolean preserve = false;
+ boolean preserve = true;
+// boolean preserve = false;
boolean knowPreserve = false;
if (readonly) {
@@ -704,8 +722,8 @@
if (node2 == null || node2.getNodeType() != TEXT_NODE) {
// See if xml:space='preserve' is set...
if (!knowPreserve) {
- preserve = "preserve".equals(
- getInheritedAttribute("xml:space"));
+// preserve = "preserve".equals(
+// getInheritedAttribute("xml:space"));
knowPreserve = true;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: crimson-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: crimson-cvs-help@xml.apache.org