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 2006/11/15 01:01:14 UTC

svn commit: r475069 - in /lenya/trunk/src: impl/java/org/apache/lenya/cms/publication/ java/org/apache/lenya/cms/site/ java/org/apache/lenya/cms/site/simple/ modules/sitetree/java/src/org/apache/lenya/cms/cocoon/generation/ modules/sitetree/java/src/or...

Author: andreas
Date: Tue Nov 14 16:01:13 2006
New Revision: 475069

URL: http://svn.apache.org/viewvc?view=rev&rev=475069
Log:
Preserving node order when copying to another area

Modified:
    lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/SiteNode.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/SiteStructure.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java
    lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteNode.java
    lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java
    lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java
    lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/DefaultSiteTree.java
    lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNode.java
    lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNodeImpl.java

Modified: lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java (original)
+++ lenya/trunk/src/impl/java/org/apache/lenya/cms/publication/DocumentManagerImpl.java Tue Nov 14 16:01:13 2006
@@ -17,6 +17,7 @@
  */
 package org.apache.lenya.cms.publication;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
@@ -232,7 +233,15 @@
 
     protected void addToSiteManager(String path, Document document, String navigationTitle,
             boolean visibleInNav) throws PublicationException {
+        addToSiteManager(path, document, navigationTitle, visibleInNav, null);
+    }
+    
+    protected void addToSiteManager(String path, Document document, String navigationTitle,
+            boolean visibleInNav, String followingSiblingPath) throws PublicationException {
         SiteStructure site = document.area().getSite();
+        if (!site.contains(path) && followingSiblingPath != null) {
+            site.add(path, followingSiblingPath);
+        }
         site.add(path, document);
         document.getLink().setLabel(navigationTitle);
         document.getLink().getNode().setVisible(visibleInNav);
@@ -328,16 +337,51 @@
         } else {
             destinationDoc = addVersion(sourceDoc, destinationArea, language);
         }
+        
+        SiteStructure destSite = sourceDoc.getPublication().getArea(destinationArea).getSite();
 
-        if (SiteUtil.contains(this.manager, sourceDoc)) {
-            if (SiteUtil.contains(this.manager, destinationDoc)) {
+        if (sourceDoc.hasLink()) {
+            if (destinationDoc.hasLink()) {
                 boolean visible = sourceDoc.getLink().getNode().isVisible();
                 destinationDoc.getLink().getNode().setVisible(visible);
             } else {
                 String path = sourceDoc.getPath();
                 String label = sourceDoc.getLink().getLabel();
                 boolean visible = sourceDoc.getLink().getNode().isVisible();
-                addToSiteManager(path, destinationDoc, label, visible);
+                if (destSite.contains(sourceDoc.getLink().getNode().getPath())) {
+                    addToSiteManager(path, destinationDoc, label, visible);
+                } else {
+                    
+                    SiteStructure sourceSite = sourceDoc.area().getSite();
+                    
+                    SiteNode[] sourceSiblings;
+                    SiteNode sourceNode = sourceDoc.getLink().getNode();
+                    if (sourceNode.isTopLevel()) {
+                        sourceSiblings = sourceSite.getTopLevelNodes();
+                    }
+                    else {
+                        sourceSiblings = sourceNode.getParent().getChildren();
+                    }
+                    
+                    final int sourcePos = Arrays.asList(sourceSiblings).indexOf(sourceNode);
+                    
+                    String followingSiblingPath = null;
+                    int pos = sourcePos;
+                    while (followingSiblingPath == null && pos < sourceSiblings.length) {
+                        String siblingPath = sourceSiblings[pos].getPath();
+                        if (destSite.contains(siblingPath)) {
+                            followingSiblingPath = siblingPath;
+                        }
+                        pos++;
+                    }
+                    
+                    if (followingSiblingPath == null) {
+                        addToSiteManager(path, destinationDoc, label, visible);
+                    }
+                    else {
+                        addToSiteManager(path, destinationDoc, label, visible, followingSiblingPath);
+                    }
+                }
             }
         }
 

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/SiteManager.java Tue Nov 14 16:01:13 2006
@@ -184,5 +184,5 @@
      * @throws SiteException if the new document could not be built.
      */
     DocumentLocator getAvailableLocator(DocumentFactory factory, DocumentLocator locator) throws SiteException;
-
+    
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/SiteNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteNode.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/SiteNode.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/SiteNode.java Tue Nov 14 16:01:13 2006
@@ -88,4 +88,9 @@
      */
     void delete();
 
+    /**
+     * @return The children of this node.
+     */
+    SiteNode[] getChildren();
+
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/SiteStructure.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/site/SiteStructure.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/SiteStructure.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/SiteStructure.java Tue Nov 14 16:01:13 2006
@@ -43,7 +43,7 @@
      * @return The area.
      */
     String getArea();
-    
+
     /**
      * @return All nodes in this structure.
      */
@@ -92,8 +92,8 @@
      * @param path The path.
      * @param doc The document.
      * @return A link.
-     * @throws SiteException if the document is already contained or the node for this path already
-     *             contains a link for this language.
+     * @throws SiteException if the document is already contained or the node
+     *         for this path already contains a link for this language.
      */
     Link add(String path, Document doc) throws SiteException;
 
@@ -105,5 +105,19 @@
      */
     SiteNode add(String path) throws SiteException;
 
+    /**
+     * Adds a site node before a specific other node.
+     * @param path The path.
+     * @param followingSiblingPath The path of the node which will be the
+     *        following sibling of the node to insert.
+     * @return A site node.
+     * @throws SiteException if the path is already contained.
+     */
+    SiteNode add(String path, String followingSiblingPath) throws SiteException;
+    
+    /**
+     * @return The top level nodes.
+     */
+    SiteNode[] getTopLevelNodes();
 
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/simple/DocumentStore.java Tue Nov 14 16:01:13 2006
@@ -17,9 +17,11 @@
  */
 package org.apache.lenya.cms.site.simple;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.WeakHashMap;
@@ -283,6 +285,21 @@
     public void remove(Document document) throws DocumentException {
         super.remove(document);
         this.doc2path.remove(getKey(document.getUUID(), document.getLanguage()));
+    }
+
+    public SiteNode add(String path, String followingSiblingPath) throws SiteException {
+        return add(path);
+    }
+
+    public SiteNode[] getTopLevelNodes() {
+        SiteNode[] nodes = getNodes();
+        List topLevelNodes = new ArrayList();
+        for (int i = 0; i < nodes.length; i++) {
+            if (nodes[i].isTopLevel()) {
+                topLevelNodes.add(nodes[i]);
+            }
+        }
+        return (SiteNode[]) topLevelNodes.toArray(new SiteNode[topLevelNodes.size()]);
     }
 
 }

Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteNode.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteNode.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/simple/SimpleSiteNode.java Tue Nov 14 16:01:13 2006
@@ -26,6 +26,7 @@
 import org.apache.lenya.cms.site.AbstractSiteNode;
 import org.apache.lenya.cms.site.Link;
 import org.apache.lenya.cms.site.SiteException;
+import org.apache.lenya.cms.site.SiteNode;
 
 /**
  * Node for SimpleSiteManager.
@@ -82,6 +83,10 @@
                 throw new RuntimeException(e);
             }
         }
+    }
+
+    public SiteNode[] getChildren() {
+        return new SiteNode[0];
     }
 
 }

Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/generation/SitetreeFragmentGenerator.java Tue Nov 14 16:01:13 2006
@@ -36,6 +36,7 @@
 import org.apache.lenya.cms.site.Link;
 import org.apache.lenya.cms.site.SiteException;
 import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.site.SiteNode;
 import org.apache.lenya.cms.site.SiteStructure;
 import org.apache.lenya.cms.site.tree.SiteTree;
 import org.apache.lenya.cms.site.tree.SiteTreeNode;
@@ -235,7 +236,7 @@
             if (node == null)
                 throw new SiteException("Node with path " + this.path + " not found.");
 
-            SiteTreeNode[] children = node.getChildren();
+            SiteNode[] children = node.getChildren();
 
             addNodes(children);
         } catch (PublicationException e) {
@@ -245,13 +246,13 @@
 
     /**
      * Adds the given nodes (not recursive).
-     * @param nodes
+     * @param children
      * @throws SAXException
      */
-    protected void addNodes(SiteTreeNode[] nodes) throws SAXException, SiteException {
-        for (int i = 0; i < nodes.length; i++) {
-            startNode(NODE_NODE, nodes[i]);
-            addLabels(nodes[i]);
+    protected void addNodes(SiteNode[] children) throws SAXException, SiteException {
+        for (int i = 0; i < children.length; i++) {
+            startNode(NODE_NODE, children[i]);
+            addLabels(children[i]);
             endNode(NODE_NODE);
         }
     }
@@ -326,7 +327,7 @@
      * @throws SiteException
      * @throws SAXException
      */
-    protected void generateFragmentRecursive(SiteTreeNode[] nodes, String path)
+    protected void generateFragmentRecursive(SiteNode[] nodes, String path)
             throws SiteException, SAXException {
         String nodeid;
         String childid;
@@ -356,7 +357,7 @@
      * @throws SAXException
      * @throws SiteException
      */
-    protected void addNodeRecursive(SiteTreeNode node, String nodeid, String childid)
+    protected void addNodeRecursive(SiteNode node, String nodeid, String childid)
             throws SAXException, SiteException {
         startNode(NODE_NODE, node);
         addLabels(node);
@@ -381,7 +382,7 @@
      * @param node The attributes are taken from this node
      * @throws SAXException if an error occurs while creating the node
      */
-    protected void startNode(String nodeName, SiteTreeNode node) throws SAXException, SiteException {
+    protected void startNode(String nodeName, SiteNode node) throws SAXException, SiteException {
         setNodeAttributes(node);
         this.contentHandler.startElement(URI, nodeName, PREFIX + ':' + nodeName, this.attributes);
     }
@@ -392,14 +393,14 @@
      * @param node
      * @throws SAXException if an error occurs while setting the attributes
      */
-    protected void setNodeAttributes(SiteTreeNode node) throws SAXException, SiteException {
+    protected void setNodeAttributes(SiteNode node) throws SAXException, SiteException {
         this.attributes.clear();
 
         String id = node.getName();
         // String isVisible = Boolean.toString(node.visibleInNav());
-        String hasLink = Boolean.toString(node.hasLink());
-        String href = node.getHref();
-        String suffix = node.getSuffix();
+        String hasLink = Boolean.toString(((SiteTreeNode) node).hasLink());
+        String href = ((SiteTreeNode) node).getHref();
+        String suffix = ((SiteTreeNode) node).getSuffix();
         String isFolder = Boolean.toString(isFolder(node));
         String uuid = node.getUuid();
 
@@ -446,7 +447,7 @@
      * @param node
      * @return A boolean value.
      */
-    protected boolean isFolder(SiteTreeNode node) {
+    protected boolean isFolder(SiteNode node) {
         if (node.getChildren().length > 0)
             return true;
         return false;
@@ -466,7 +467,7 @@
      * @param node
      * @throws SAXException
      */
-    protected void addLabels(SiteTreeNode node) throws SAXException {
+    protected void addLabels(SiteNode node) throws SAXException {
         String[] languages = node.getLanguages();
 
         for (int i = 0; i < languages.length; i++) {

Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/cocoon/transformation/DocumentIndexTransformer.java Tue Nov 14 16:01:13 2006
@@ -45,8 +45,8 @@
 import org.apache.lenya.cms.repository.RepositoryUtil;
 import org.apache.lenya.cms.repository.Session;
 import org.apache.lenya.cms.site.SiteManager;
+import org.apache.lenya.cms.site.SiteNode;
 import org.apache.lenya.cms.site.tree.SiteTree;
-import org.apache.lenya.cms.site.tree.SiteTreeNode;
 import org.apache.lenya.cms.site.tree.TreeSiteManager;
 import org.apache.lenya.util.ServletHelper;
 import org.xml.sax.Attributes;
@@ -158,8 +158,8 @@
                 String path = this.document.getLink().getNode().getPath();
                 String language = this.document.getLanguage();
                 String defaultLanguage = this.publication.getDefaultLanguage();
-                SiteTreeNode node = (SiteTreeNode) this.siteTree.getNode(path);
-                SiteTreeNode[] children = node.getChildren();
+                SiteNode node = this.siteTree.getNode(path);
+                SiteNode[] children = node.getChildren();
 
                 super.startElement(uri, localName, raw, attr);
 

Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/DefaultSiteTree.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/DefaultSiteTree.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/DefaultSiteTree.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/DefaultSiteTree.java Tue Nov 14 16:01:13 2006
@@ -535,13 +535,13 @@
         if (newParent == null) {
             throw new SiteException("The added node was not found.");
         }
-        SiteTreeNode[] children = subtreeRoot.getChildren();
+        SiteNode[] children = subtreeRoot.getChildren();
         if (children == null) {
             getLogger().info("The node " + subtreeRoot.toString() + " has no children");
             return;
         }
         for (int i = 0; i < children.length; i++) {
-            importSubtree(newParent, children[i], children[i].getName(), null);
+            importSubtree(newParent, (SiteTreeNode) children[i], children[i].getName(), null);
         }
         saveDocument();
     }
@@ -701,14 +701,27 @@
     }
 
     public SiteNode[] getNodes() {
+        List nodes = getRootNode().preOrder();
+        return (SiteNode[]) nodes.toArray(new SiteNode[nodes.size()]);
+    }
+
+    public SiteNode add(String path, String followingSiblingPath) throws SiteException {
+        SiteTreeNode node = addNode(path, null, true, null, "", false, followingSiblingPath);
+        return node;
+    }
+
+    public SiteNode[] getTopLevelNodes() {
+        return getRootNode().getChildren();
+    }
+
+    protected SiteTreeNode getRootNode() {
         SiteTreeNode root;
         try {
             root = (SiteTreeNode) getNode("/");
         } catch (SiteException e) {
             throw new RuntimeException(e);
         }
-        List nodes = root.preOrder();
-        return (SiteNode[]) nodes.toArray(new SiteNode[nodes.size()]);
+        return root;
     }
 
 }

Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNode.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNode.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNode.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNode.java Tue Nov 14 16:01:13 2006
@@ -90,7 +90,7 @@
      * 
      * @return the children.
      */
-    SiteTreeNode[] getChildren();
+    SiteNode[] getChildren();
 
     /**
      * Get the sitetreenodes, which are children of this node

Modified: lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNodeImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNodeImpl.java?view=diff&rev=475069&r1=475068&r2=475069
==============================================================================
--- lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNodeImpl.java (original)
+++ lenya/trunk/src/modules/sitetree/java/src/org/apache/lenya/cms/site/tree/SiteTreeNodeImpl.java Tue Nov 14 16:01:13 2006
@@ -89,6 +89,10 @@
 
     /**
      * Creates a new SiteTreeNodeImpl object.
+     * @param factory The document factory.
+     * @param tree The tree.
+     * @param node The node.
+     * @param logger The logger.
      * 
      * @param _node the node which is to be wrapped by this SiteTreeNode
      */
@@ -190,9 +194,6 @@
         getTree().save();
     }
 
-    /**
-     * @see org.apache.lenya.cms.site.tree.SiteTreeNode#removeLabel(org.apache.lenya.cms.site.Label)
-     */
     public void removeLabel(String language) {
         if (!hasLink(language)) {
             throw new RuntimeException(this + " does not contain the language [" + language + "]");
@@ -285,7 +286,7 @@
     /**
      * @see org.apache.lenya.cms.site.tree.SiteTreeNode#getChildren()
      */
-    public SiteTreeNode[] getChildren() {
+    public SiteNode[] getChildren() {
         List childElements = new ArrayList();
 
         NamespaceHelper helper = getNamespaceHelper();
@@ -297,7 +298,7 @@
             childElements.add(newNode);
         }
 
-        return (SiteTreeNode[]) childElements.toArray(new SiteTreeNode[childElements.size()]);
+        return (SiteNode[]) childElements.toArray(new SiteNode[childElements.size()]);
     }
 
     /**
@@ -377,13 +378,13 @@
      */
     public void acceptSubtree(SiteTreeNodeVisitor visitor) throws DocumentException {
         this.accept(visitor);
-        SiteTreeNode[] children = this.getChildren();
+        SiteNode[] children = this.getChildren();
         if (children == null) {
             getLogger().info("The node " + getPath() + " has no children");
             return;
         }
         for (int i = 0; i < children.length; i++) {
-            children[i].acceptSubtree(visitor);
+            ((SiteTreeNode) children[i]).acceptSubtree(visitor);
         }
     }
 
@@ -403,9 +404,9 @@
      */
     public List postOrder() {
         List list = new ArrayList();
-        SiteTreeNode[] children = this.getChildren();
+        SiteNode[] children = this.getChildren();
         for (int i = 0; i < children.length; i++) {
-            List orderedChildren = children[i].postOrder();
+            List orderedChildren = ((SiteTreeNode) children[i]).postOrder();
             list.addAll(orderedChildren);
         }
         list.add(this);
@@ -424,7 +425,7 @@
      * @see org.apache.lenya.cms.site.tree.SiteTreeNode#getChildren(java.lang.String)
      */
     public SiteTreeNode[] getChildren(String language) {
-        SiteTreeNode[] children = getChildren();
+        SiteNode[] children = getChildren();
         List languageChildren = new ArrayList();
 
         for (int i = 0; i < children.length; i++) {
@@ -487,9 +488,9 @@
     public List preOrder() {
         List list = new ArrayList();
         list.add(this);
-        SiteTreeNode[] children = this.getChildren();
+        SiteNode[] children = this.getChildren();
         for (int i = 0; i < children.length; i++) {
-            List orderedChildren = children[i].preOrder();
+            List orderedChildren = ((SiteTreeNode) children[i]).preOrder();
             list.addAll(orderedChildren);
         }
         return list;



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