You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/04/08 13:30:05 UTC

svn commit: r160543 - in lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms: ant/DeleteNodeTask.java ant/InsertCopyNode.java ant/MoveNode.java ant/SiteTreeResetTask.java publication/AbstractPublication.java publication/DefaultSiteTree.java publication/SiteTree.java publication/SiteTreeNode.java publication/SiteTreeNodeImpl.java

Author: andreas
Date: Fri Apr  8 04:30:01 2005
New Revision: 160543

URL: http://svn.apache.org/viewcvs?view=rev&rev=160543
Log:
applied patch for bug #34348, thanks to Felix Roethenbacher

Modified:
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/DeleteNodeTask.java
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/InsertCopyNode.java
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/MoveNode.java
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/SiteTreeResetTask.java
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTree.java
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNode.java
    lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNodeImpl.java

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/DeleteNodeTask.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/DeleteNodeTask.java?view=diff&r1=160542&r2=160543
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/DeleteNodeTask.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/DeleteNodeTask.java Fri Apr  8 04:30:01 2005
@@ -88,10 +88,7 @@
 
 	  	try {
 			tree = getPublication().getTree(area);
-			SiteTreeNode node = tree.removeNode(documentid);
-			if (node == null) {
-				throw new SiteTreeException("Node " + node + " couldn't be removed");
-			} 
+			tree.deleteNode(documentid);
 			tree.save();
 		} catch (Exception e) {
 			throw new SiteTreeException(e);

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/InsertCopyNode.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/InsertCopyNode.java?view=diff&r1=160542&r2=160543
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/InsertCopyNode.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/InsertCopyNode.java Fri Apr  8 04:30:01 2005
@@ -27,65 +27,59 @@
 import org.apache.lenya.cms.publication.SiteTreeNode;
 
 /**
- * Ant task that copies a node of a tree and inserts it in  tree
- **/
+ * Ant task that copies a node of a tree and inserts it in tree
+ */
 public class InsertCopyNode extends TwoNodesTask {
-	/**
-	 * Creates a new instance of InsertCopyNode
-	 */
-	public InsertCopyNode() {
-		super();
-	}
-
-	/**
-	 * copies a node corresponding to a document with id firstdocumentid and area firstarea
-	 * and inserts it like a node corresponding to a document with id secdocumentid and area secarea.
- 	 * @param firstdocumentid The document-id of the document corresponding to the source node.
-	 * @param secdocumentid  The document-id of the document corresponding to the destination node.
-	 * @param firstarea The area of the document corresponding to the source node.
-	 * @param secarea The area of the document corresponding to the destination node.
-	 * @throws SiteTreeException if there are problems with creating or saving the site tree.  
-	 */
-	public void manipulateTree(
-		String firstdocumentid,
-		String secdocumentid,
-		String firstarea,
-		String secarea)
-		throws SiteTreeException {
-
-		Publication publication = getPublication();
-		SiteTree firsttree = publication.getTree(firstarea);
-		SiteTree sectree = publication.getTree(secarea);
-
-		String parentid = "";
-		StringTokenizer st = new StringTokenizer(secdocumentid, "/");
-		int length = st.countTokens();
-
-		for (int i = 0; i < (length - 1); i++) {
-			parentid = parentid + "/" + st.nextToken();
-		}
-		String newid = st.nextToken();
-
-		SiteTreeNode node = firsttree.getNode(firstdocumentid);
-
-		if (node != null) {
-			SiteTreeNode parentNode = sectree.getNode(parentid);
-			if (parentNode != null) {
-				sectree.importSubtree(parentNode, node, newid, null);
-			} else {
-				throw new SiteTreeException(
-					"The parent node "
-						+ parentNode
-						+ " where the copied node shall be inserted not found");
-			}
-		} else {
-			throw new SiteTreeException("Node " + node + " couldn't be found");
-		}
-		if (firstarea.equals(secarea)) {
-			firsttree.save();
-		} else {
-			firsttree.save();
-			sectree.save();
-		}
-	}
-}
+    /**
+     * Creates a new instance of InsertCopyNode
+     */
+    public InsertCopyNode() {
+        super();
+    }
+
+    /**
+     * copies a node corresponding to a document with id firstdocumentid and area firstarea and
+     * inserts it like a node corresponding to a document with id secdocumentid and area secarea.
+     * @param firstdocumentid The document-id of the document corresponding to the source node.
+     * @param secdocumentid The document-id of the document corresponding to the destination node.
+     * @param firstarea The area of the document corresponding to the source node.
+     * @param secarea The area of the document corresponding to the destination node.
+     * @throws SiteTreeException if there are problems with creating or saving the site tree.
+     */
+    public void manipulateTree(String firstdocumentid, String secdocumentid, String firstarea,
+            String secarea) throws SiteTreeException {
+
+        Publication publication = getPublication();
+        SiteTree firsttree = publication.getTree(firstarea);
+        SiteTree sectree = publication.getTree(secarea);
+
+        String parentid = "";
+        StringTokenizer st = new StringTokenizer(secdocumentid, "/");
+        int length = st.countTokens();
+
+        for (int i = 0; i < (length - 1); i++) {
+            parentid = parentid + "/" + st.nextToken();
+        }
+        String newid = st.nextToken();
+
+        SiteTreeNode node = firsttree.getNode(firstdocumentid);
+
+        if (node != null) {
+            SiteTreeNode parentNode = sectree.getNode(parentid);
+            if (parentNode != null) {
+                sectree.copy(node, parentNode, newid, null);
+            } else {
+                throw new SiteTreeException("The parent node " + parentNode
+                        + " where the copied node shall be inserted not found");
+            }
+        } else {
+            throw new SiteTreeException("Node " + node + " couldn't be found");
+        }
+        if (firstarea.equals(secarea)) {
+            firsttree.save();
+        } else {
+            firsttree.save();
+            sectree.save();
+        }
+    }
+}
\ No newline at end of file

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/MoveNode.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/MoveNode.java?view=diff&r1=160542&r2=160543
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/MoveNode.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/MoveNode.java Fri Apr  8 04:30:01 2005
@@ -67,11 +67,11 @@
 		}
 		String newid = st.nextToken();
 
-		SiteTreeNode node = firsttree.removeNode(firstdocumentid);
+		SiteTreeNode node = firsttree.getNode(firstdocumentid);
 		if (node != null) {
-			SiteTreeNode parentNode = sectree.getNode(parentid);
+		    SiteTreeNode parentNode = sectree.getNode(parentid);
 			if (parentNode != null) {
-				sectree.importSubtree(parentNode, node, newid, this.getRefdocumentid());
+                sectree.move(node, parentNode, newid, this.getRefdocumentid());
 			} else {
 				throw new SiteTreeException(
 					"The parent node "

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/SiteTreeResetTask.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/SiteTreeResetTask.java?view=diff&r1=160542&r2=160543
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/SiteTreeResetTask.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/ant/SiteTreeResetTask.java Fri Apr  8 04:30:01 2005
@@ -61,7 +61,7 @@
 			SiteTree tree = publication.getTree(getArea());
            
 			SiteTreeNode node = tree.getNode("/");
-            node.removeChildren(); 			
+            node.deleteChildren(); 			
 			tree.save();
 			} catch (
 				Exception e) {

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/AbstractPublication.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/AbstractPublication.java?view=diff&r1=160542&r2=160543
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/AbstractPublication.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/AbstractPublication.java Fri Apr  8 04:30:01 2005
@@ -566,11 +566,11 @@
 
             node.removeLabel(label);
 
-            if (node.getLabels().length == 0) {
-                tree.removeNode(document.getId());
-            }
-
             try {
+                if (node.getLabels().length == 0) {
+                    tree.deleteNode(document.getId());
+                }
+
                 tree.save();
             } catch (SiteTreeException e) {
                 throw new PublicationException(e);

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java?view=diff&r1=160542&r2=160543
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/DefaultSiteTree.java Fri Apr  8 04:30:01 2005
@@ -30,7 +30,7 @@
 
 import org.apache.lenya.xml.DocumentHelper;
 import org.apache.lenya.xml.NamespaceHelper;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 import org.apache.xpath.XPathAPI;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -43,7 +43,9 @@
  * Default Sitetree implementation
  */
 public class DefaultSiteTree implements SiteTree {
-    private static Category log = Category.getInstance(DefaultSiteTree.class);
+    private static Logger log = Logger.getLogger(DefaultSiteTree.class);
+    
+    private static Object lock = new Object();
 
     public static final String SITE_TREE_FILENAME = "sitetree.xml";
 
@@ -400,9 +402,19 @@
             return null;
         }
 
-        return new SiteTreeNodeImpl(node);
+        return new SiteTreeNodeImpl(node, this);
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.lenya.cms.publication.SiteTree#deleteNode(java.lang.String)
+     */
+    public void deleteNode(String documentId) throws SiteTreeException {
+        Node node = this.getNodeInternal(documentId);
+        Node parentNode = node.getParentNode();
+        Node newNode = parentNode.removeChild(node);
     }
 
+
     /**
      * removes the node corresponding to the given document-id
      * and returns it
@@ -448,7 +460,7 @@
 
         Node node = getNodeInternal(documentId);
         if (node != null) {
-            treeNode = new SiteTreeNodeImpl(node);
+            treeNode = new SiteTreeNodeImpl(node, this);
         }
 
         return treeNode;
@@ -465,7 +477,7 @@
         Element[] elements = helper.getChildren((Element) document.getDocumentElement(), SiteTreeNodeImpl.NODE_NAME);
 
         for (int i = 0; i < elements.length; i++) {
-            SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i]);
+            SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i], this);
             childElements.add(newNode);
         }
 
@@ -606,4 +618,71 @@
         }
     }
 
+    /**
+     * @see org.apache.lenya.cms.publication.SiteTree#copy(org.apache.lenya.cms.publication.SiteTreeNode, org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String, java.lang.String)
+     */
+    public void copy(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling) throws SiteTreeException {
+        assert dst instanceof SiteTreeNodeImpl;
+        
+        SiteTreeNodeImpl dstNode = (SiteTreeNodeImpl)dst;
+        if (this.equals(dstNode.getDefaultSiteTree())) {
+            // Copy if this sitetree is the destination sitetree.
+            // Acquire global sitetree lock to establish lock hierarchy in case of copy operation
+            synchronized(DefaultSiteTree.lock) {
+                DefaultSiteTree srcSiteTree = ((SiteTreeNodeImpl)src).getDefaultSiteTree();
+                synchronized(srcSiteTree) {
+                    synchronized(this) {
+                        String parentId = dst.getAbsoluteId();
+                        String id = newId;
+            
+                        this.addNode(
+                            parentId,
+                            id,
+                            src.getLabels(),
+                            src.visibleInNav(),
+                            src.getHref(),
+                            src.getSuffix(),
+                            src.hasLink(),
+                            followingSibling);
+                        SiteTreeNode node = this.getNode(parentId + "/" + id);
+                        if (node == null) {
+                            throw new SiteTreeException("The added node was not found.");
+                        }
+                        SiteTreeNode[] children = src.getChildren();
+                        if (children == null) {
+                            log.debug("The node " + src.toString() + " has no children");
+                            return;
+                        } else {
+                            for (int i = 0; i < children.length; i++) {
+                                copy(children[i], node, children[i].getId(), null);
+                            }
+                        }
+                    }
+                }
+            }
+        } else {
+            // Delegate copy operation to destination sitetree.
+            dstNode.getDefaultSiteTree().copy(src, dst, newId, followingSibling);
+        }
+    }
+
+    /**
+     * @see org.apache.lenya.cms.publication.SiteTree#move(org.apache.lenya.cms.publication.SiteTreeNode, org.apache.lenya.cms.publication.SiteTreeNode, java.lang.String, java.lang.String)
+     */
+    public void move(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling) throws SiteTreeException {
+        assert dst != null;
+        assert src instanceof SiteTreeNodeImpl;
+        
+        // Acquire global sitetree lock to establish lock hierarchy in case of move operation
+        synchronized(DefaultSiteTree.lock) {
+            // Lock both source and destination sitetree.
+            synchronized(((SiteTreeNodeImpl)src).getDefaultSiteTree()) {
+                synchronized(((SiteTreeNodeImpl)dst).getDefaultSiteTree()) {
+                    copy(src, dst, newId, followingSibling);
+                    DefaultSiteTree sitetree = ((SiteTreeNodeImpl)src).getDefaultSiteTree();
+                    sitetree.deleteNode(src.getAbsoluteId());
+                }
+            }
+        }
+    }
 }

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTree.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTree.java?view=diff&r1=160542&r2=160543
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTree.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTree.java Fri Apr  8 04:30:01 2005
@@ -191,8 +191,17 @@
      * @param documentId the document-id of the node that is to be removed
      * 
      * @return the removed node
+     * @deprecated Use deleteNode() instead
      */
     SiteTreeNode removeNode(String documentId);
+    
+    /**
+     * Removes the node corresponding to the given document-id
+     * from the tree.
+     *
+     * @param documentId the document-id of the node that is to be removed
+     */
+    void deleteNode(String documentId) throws SiteTreeException;
 
     /**
      * Return the Node for a given document-id.
@@ -224,7 +233,29 @@
      * @throws SiteTreeException if the moving failed.
      */
     void moveDown(String documentid) throws SiteTreeException;
-
+    
+    /**
+     * Copy a node with all its child node.
+     * @param src Node to copy.
+     * @param dst Parent node where node will be inserted.
+     * @param newId The new id of the inserted node (in case when the node id exists already).
+     * @param followingSibling The sibling node that should follow this node (ordering),
+     * if null the node will be inserted at the end.
+     */
+    void copy(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling)
+        throws SiteTreeException;
+    
+    /**
+     * Move a node with all its child node.
+     * @param src Node to move.
+     * @param dst Parent node where node will be inserted.
+     * @param newId The new id of the inserted node (in case when the node id exists already).
+     * @param followingSibling The sibling node that should follow the moved node (ordering),
+     * if null the node will be inserted at the end.
+     */
+    void move(SiteTreeNode src, SiteTreeNode dst, String newId, String followingSibling)
+        throws SiteTreeException;
+    
     /**
      * Imports a subtree (from this or from another tree) at a certain position.
      * @param subtreeRoot The root of the subtree to import.
@@ -234,6 +265,7 @@
      * the subtree should be inserted. If null, the subtree is inserted at the end. 
      * in case there is already a node with the same id in the tree).
      * @throws SiteTreeException when an error occurs.
+     * @deprecated Use copy, move instead.
      */
     void importSubtree(
         SiteTreeNode subtreeRoot,

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNode.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNode.java?view=diff&r1=160542&r2=160543
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNode.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNode.java Fri Apr  8 04:30:01 2005
@@ -150,8 +150,14 @@
      * Remove the children of the node
      * 
      * @return the removed node
+     * @deprecated Use deleteChildren() instead
      */
     SiteTreeNode[] removeChildren();
+    
+    /**
+     * Remove the children of this node.
+     */
+    void deleteChildren() throws SiteTreeException;
 
 	/**
 	 * Get the sitetreenodes, which are the siblings following this node

Modified: lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNodeImpl.java
URL: http://svn.apache.org/viewcvs/lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNodeImpl.java?view=diff&r1=160542&r2=160543
==============================================================================
--- lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNodeImpl.java (original)
+++ lenya/branches/BRANCH_1_2_X/src/java/org/apache/lenya/cms/publication/SiteTreeNodeImpl.java Fri Apr  8 04:30:01 2005
@@ -24,7 +24,7 @@
 
 import org.apache.lenya.xml.DocumentHelper;
 import org.apache.lenya.xml.NamespaceHelper;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
@@ -36,7 +36,7 @@
  * @see org.apache.lenya.cms.publication.SiteTreeNode
  */
 public class SiteTreeNodeImpl implements SiteTreeNode {
-    private static Category log = Category.getInstance(SiteTreeNodeImpl.class);
+    private static Logger log = Logger.getLogger(SiteTreeNodeImpl.class);
     public static final String ID_ATTRIBUTE_NAME = "id";
     public static final String VISIBLEINNAV_ATTRIBUTE_NAME="visibleinnav";
     public static final String HREF_ATTRIBUTE_NAME = "href";
@@ -47,14 +47,16 @@
     public static final String LABEL_NAME = "label";
 
     private Node node = null;
+    private DefaultSiteTree sitetree = null;
 
     /**
      * Creates a new SiteTreeNodeImpl object.
      *
      * @param node the node which is to be wrapped by this SiteTreeNode 
      */
-    public SiteTreeNodeImpl(Node node) {
+    public SiteTreeNodeImpl(Node node, DefaultSiteTree sitetree) {
         this.node = node;
+        this.sitetree = sitetree;
     }
 
     /**
@@ -63,34 +65,43 @@
      */
     public String getParentId() {
         Node parent = node.getParentNode();
+        String parentId = null;
 
         if (parent == null) {
-            return "/";
-        }
-
-        NamedNodeMap attributes = parent.getAttributes();
-
-        if (attributes == null) {
-            return "/";
-        }
-
-        Node idAttribute = attributes.getNamedItem(ID_ATTRIBUTE_NAME);
-
-        if (idAttribute == null) {
-            return "/";
+            parentId = "/";
+        } else {
+            synchronized(sitetree) {
+                NamedNodeMap attributes = parent.getAttributes();
+                if (attributes == null) {
+                    parentId = "/";
+                } else {
+                    Node idAttribute = attributes.getNamedItem(ID_ATTRIBUTE_NAME);
+
+                    if (idAttribute == null) {
+                        parentId = "/";
+                    } else {
+                        parentId = idAttribute.getNodeValue();
+                    }
+                    
+                }
+            }
         }
-
-        return idAttribute.getNodeValue();
+        return parentId;
     }
 
     /**
      * @see org.apache.lenya.cms.publication.SiteTreeNode#getId()
      */
     public String getId() {
-        if (node == node.getOwnerDocument().getDocumentElement()) {
-            return "";
+        String id = null;
+        synchronized (sitetree) {
+            if (node == node.getOwnerDocument().getDocumentElement()) {
+                id = "";
+            } else {
+                id = node.getAttributes().getNamedItem(ID_ATTRIBUTE_NAME).getNodeValue(); 
+            }
         }
-        return node.getAttributes().getNamedItem(ID_ATTRIBUTE_NAME).getNodeValue();
+        return id;
     }
 
     /**
@@ -112,23 +123,24 @@
         NamedNodeMap attributes = null;
         Node idAttribute = null;
 
-        while (currentNode != null) {
-            attributes = currentNode.getAttributes();
-
-            if (attributes == null) {
-                break;
-            }
-
-            idAttribute = attributes.getNamedItem(ID_ATTRIBUTE_NAME);
-
-            if (idAttribute == null) {
-                break;
+        synchronized (sitetree) {
+            while (currentNode != null) {
+                attributes = currentNode.getAttributes();
+    
+                if (attributes == null) {
+                    break;
+                }
+    
+                idAttribute = attributes.getNamedItem(ID_ATTRIBUTE_NAME);
+    
+                if (idAttribute == null) {
+                    break;
+                }
+    
+                absoluteId = "/" + idAttribute.getNodeValue() + absoluteId;
+                currentNode = currentNode.getParentNode();
             }
-
-            absoluteId = "/" + idAttribute.getNodeValue() + absoluteId;
-            currentNode = currentNode.getParentNode();
         }
-
         return absoluteId;
     }
 
@@ -138,26 +150,27 @@
     public Label[] getLabels() {
         ArrayList labels = new ArrayList();
 
-        NodeList children = node.getChildNodes();
-
-        for (int i = 0; i < children.getLength(); i++) {
-            Node child = children.item(i);
-
-            if ((child.getNodeType() == Node.ELEMENT_NODE)
-                && child.getNodeName().equals(LABEL_NAME)) {
-                String labelName = DocumentHelper.getSimpleElementText((Element) child);
-                String labelLanguage = null;
-                Node languageAttribute =
-                    child.getAttributes().getNamedItem(LANGUAGE_ATTRIBUTE_NAME);
-
-                if (languageAttribute != null) {
-                    labelLanguage = languageAttribute.getNodeValue();
+        synchronized(sitetree) {
+            NodeList children = node.getChildNodes();
+    
+            for (int i = 0; i < children.getLength(); i++) {
+                Node child = children.item(i);
+    
+                if ((child.getNodeType() == Node.ELEMENT_NODE)
+                    && child.getNodeName().equals(LABEL_NAME)) {
+                    String labelName = DocumentHelper.getSimpleElementText((Element) child);
+                    String labelLanguage = null;
+                    Node languageAttribute =
+                        child.getAttributes().getNamedItem(LANGUAGE_ATTRIBUTE_NAME);
+    
+                    if (languageAttribute != null) {
+                        labelLanguage = languageAttribute.getNodeValue();
+                    }
+    
+                    labels.add(new Label(labelName, labelLanguage));
                 }
-
-                labels.add(new Label(labelName, labelLanguage));
             }
         }
-
         return (Label[]) labels.toArray(new Label[labels.size()]);
     }
 
@@ -197,8 +210,9 @@
             Element labelElem = helper.createElement(SiteTreeNodeImpl.LABEL_NAME, label.getLabel());
 
             labelElem.setAttribute(SiteTreeNodeImpl.LANGUAGE_ATTRIBUTE_NAME, label.getLanguage());
-
-            node.appendChild(labelElem);
+            synchronized (sitetree) {
+                node.appendChild(labelElem);
+            }
         }
     }
 
@@ -209,22 +223,24 @@
         if (getLabel(label.getLanguage()) != null) {
             // this node doesn't contain this label
 
-            NodeList children = node.getChildNodes();
-
-            for (int i = 0; i < children.getLength(); i++) {
-                Node child = children.item(i);
-
-                if ((child.getNodeType() == Node.ELEMENT_NODE)
-                    && child.getNodeName().equals(LABEL_NAME)
-                    && child.getFirstChild().getNodeValue().equals(label.getLabel())) {
-
-                    Node languageAttribute =
-                        child.getAttributes().getNamedItem(LANGUAGE_ATTRIBUTE_NAME);
+            synchronized (sitetree) {
+                NodeList children = node.getChildNodes();
 
-                    if (languageAttribute != null
-                        && languageAttribute.getNodeValue().equals(label.getLanguage())) {
-                        node.removeChild(child);
-                        break;
+                for (int i = 0; i < children.getLength(); i++) {
+                    Node child = children.item(i);
+    
+                    if ((child.getNodeType() == Node.ELEMENT_NODE)
+                        && child.getNodeName().equals(LABEL_NAME)
+                        && child.getFirstChild().getNodeValue().equals(label.getLabel())) {
+    
+                        Node languageAttribute =
+                            child.getAttributes().getNamedItem(LANGUAGE_ATTRIBUTE_NAME);
+    
+                        if (languageAttribute != null
+                            && languageAttribute.getNodeValue().equals(label.getLanguage())) {
+                            node.removeChild(child);
+                            break;
+                        }
                     }
                 }
             }
@@ -235,67 +251,75 @@
      * @see org.apache.lenya.cms.publication.SiteTreeNode#hasLink()
      */
     public boolean visibleInNav() {
-        Node attribute = node.getAttributes().getNamedItem(VISIBLEINNAV_ATTRIBUTE_NAME);
-
-        if (attribute != null) {
-            return attribute.getNodeValue().equals("true");
-        } else {
-        	return true;
+        boolean isVisibleInNav = true;
+        synchronized (sitetree) {
+            Node attribute = node.getAttributes().getNamedItem(VISIBLEINNAV_ATTRIBUTE_NAME);
+    
+            if (attribute != null) {
+                isVisibleInNav = attribute.getNodeValue().equals("true");
+            }
         }
+        return isVisibleInNav;
     }
  
     /**
      * @see org.apache.lenya.cms.publication.SiteTreeNode#getHref()
      */
     public String getHref() {
-        Node attribute = node.getAttributes().getNamedItem(HREF_ATTRIBUTE_NAME);
+        String href = null;
+        synchronized (sitetree) {
+            Node attribute = node.getAttributes().getNamedItem(HREF_ATTRIBUTE_NAME);
 
-        if (attribute != null) {
-            return attribute.getNodeValue();
-        } else {
-            return null;
+            if (attribute != null) {
+                href = attribute.getNodeValue();
+            }
         }
+        return href;
     }
    
     /**
      * @see org.apache.lenya.cms.publication.SiteTreeNode#getSuffix()
      */
     public String getSuffix() {
-        Node attribute = node.getAttributes().getNamedItem(SUFFIX_ATTRIBUTE_NAME);
+        String suffix = null;
+        synchronized (sitetree) {
+            Node attribute = node.getAttributes().getNamedItem(SUFFIX_ATTRIBUTE_NAME);
 
-        if (attribute != null) {
-            return attribute.getNodeValue();
-        } else {
-            return null;
+            if (attribute != null) {
+                suffix = attribute.getNodeValue();
+            }
         }
+        return suffix;
     }
 
     /**
      * @see org.apache.lenya.cms.publication.SiteTreeNode#hasLink()
      */
     public boolean hasLink() {
-        Node attribute = node.getAttributes().getNamedItem(LINK_ATTRIBUTE_NAME);
-
-        if (attribute != null) {
-            return attribute.getNodeValue().equals("true");
-        } else {
-            return false;
+        boolean hasLink = false;
+        synchronized (sitetree) {
+            Node attribute = node.getAttributes().getNamedItem(LINK_ATTRIBUTE_NAME);
+    
+            if (attribute != null) {
+                hasLink = attribute.getNodeValue().equals("true");
+            }
         }
+        return hasLink;
     }
     /**
      * @see org.apache.lenya.cms.publication.SiteTreeNode#getChildren()
      */
     public SiteTreeNode[] getChildren() {
         List childElements = new ArrayList();
-
-        NamespaceHelper helper = getNamespaceHelper();
-        Element[] elements = helper.getChildren((Element) node, SiteTreeNodeImpl.NODE_NAME);
-
-        for (int i = 0; i < elements.length; i++) {
-            SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i]);
-            childElements.add(newNode);
+        synchronized (sitetree) {
+            NamespaceHelper helper = getNamespaceHelper();
+            Element[] elements = helper.getChildren((Element) node, SiteTreeNodeImpl.NODE_NAME);
+    
+            for (int i = 0; i < elements.length; i++) {
+                SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i], sitetree);
+                childElements.add(newNode);
+            }
         }
-
         return (SiteTreeNode[]) childElements.toArray(new SiteTreeNode[childElements.size()]);
     }
 
@@ -304,28 +328,45 @@
      */
     public SiteTreeNode[] removeChildren() {
         List childElements = new ArrayList();
-        NamespaceHelper helper = getNamespaceHelper();
-        Element[] elements = helper.getChildren((Element) node, SiteTreeNodeImpl.NODE_NAME);
-        for (int i = 0; i < elements.length; i++) {
-            node.removeChild(elements[i]);
-            SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i]);
-            childElements.add(newNode);
+        synchronized (sitetree) {
+            NamespaceHelper helper = getNamespaceHelper();
+            Element[] elements = helper.getChildren((Element) node, SiteTreeNodeImpl.NODE_NAME);
+            for (int i = 0; i < elements.length; i++) {
+                node.removeChild(elements[i]);
+                SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i], sitetree);
+                childElements.add(newNode);
+            }
         }
         return (SiteTreeNode[]) childElements.toArray(new SiteTreeNode[childElements.size()]);
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.lenya.cms.publication.SiteTreeNode#deleteChildren()
+     */
+    public void deleteChildren() {
+        synchronized (sitetree) {
+            NamespaceHelper helper = getNamespaceHelper();
+            Element[] elements = helper.getChildren((Element) node, SiteTreeNodeImpl.NODE_NAME);
+            for (int i = 0; i < elements.length; i++) {
+                node.removeChild(elements[i]);
+            }
+        }
+    }
+    
     /**
      * @see org.apache.lenya.cms.publication.SiteTreeNode#getChildren()
      */
     public SiteTreeNode[] getNextSiblings() {
         List siblingElements = new ArrayList();
 
-        NamespaceHelper helper = getNamespaceHelper();
-        Element[] elements = helper.getNextSiblings((Element) node, SiteTreeNodeImpl.NODE_NAME);
-
-        for (int i = 0; i < elements.length; i++) {
-            SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i]);
-            siblingElements.add(newNode);
+        synchronized (sitetree) {
+            NamespaceHelper helper = getNamespaceHelper();
+            Element[] elements = helper.getNextSiblings((Element) node, SiteTreeNodeImpl.NODE_NAME);
+    
+            for (int i = 0; i < elements.length; i++) {
+                SiteTreeNode newNode = new SiteTreeNodeImpl(elements[i], sitetree);
+                siblingElements.add(newNode);
+            }
         }
 
         return (SiteTreeNode[]) siblingElements.toArray(new SiteTreeNode[siblingElements.size()]);
@@ -406,8 +447,10 @@
      * @see org.apache.lenya.cms.publication.SiteTreeNode#setLabel(org.apache.lenya.cms.publication.Label)
      */
     public void setNodeAttribute (String attributeName, String attributeValue) {
-        Element element = (Element) node;
-        element.setAttribute(attributeName, attributeValue);
+        synchronized (sitetree) {
+            Element element = (Element) node;
+            element.setAttribute(attributeName, attributeValue);
+        }
     }
     
     /**
@@ -432,10 +475,12 @@
     public SiteTreeNode getParent() {
         SiteTreeNode parent = null;
 
-        Node parentNode = node.getParentNode();
-        if (parentNode.getNodeType() == Node.ELEMENT_NODE
-            && parentNode.getLocalName().equals(NODE_NAME)) {
-            parent = new SiteTreeNodeImpl(parentNode);
+        synchronized (sitetree) {
+            Node parentNode = node.getParentNode();
+            if (parentNode.getNodeType() == Node.ELEMENT_NODE
+                && parentNode.getLocalName().equals(NODE_NAME)) {
+                parent = new SiteTreeNodeImpl(parentNode, sitetree);
+            }
         }
 
         return parent;
@@ -477,5 +522,9 @@
             list.addAll(orderedChildren);
         }
         return list;
+    }
+    
+    protected DefaultSiteTree getDefaultSiteTree() {
+        return this.sitetree;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org