roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r535942 - in /roller/trunk/src/org/apache/roller: business/hibernate/HibernateBookmarkManagerImpl.java pojos/FolderData.java
Date Mon, 07 May 2007 18:21:16 GMT
Author: agilliland
Date: Mon May  7 11:21:15 2007
New Revision: 535942

URL: http://svn.apache.org/viewvc?view=rev&rev=535942
Log:
pulling method updatePathTree(folder) out of bookmark manager impl and putting it in the FolderData
pojo where it can be appropriately reused, and adding a new updateName() method to FolderData
pojo which handles all the path updates which happen when you change a folder name.


Modified:
    roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
    roller/trunk/src/org/apache/roller/pojos/FolderData.java

Modified: roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java?view=diff&rev=535942&r1=535941&r2=535942
==============================================================================
--- roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
(original)
+++ roller/trunk/src/org/apache/roller/business/hibernate/HibernateBookmarkManagerImpl.java
Mon May  7 11:21:15 2007
@@ -134,35 +134,7 @@
         
         // the main work to be done for a category move is to update the 
         // path attribute of the category and all descendent categories
-        updatePathTree(srcFolder);
-    }
-    
-    
-    // updates the paths of all descendents of the given folder
-    private void updatePathTree(FolderData folder) throws RollerException {
-        
-        log.debug("Updating path tree for folder "+folder.getPath());
-        
-        FolderData childFolder = null;
-        Iterator childFolders = folder.getFolders().iterator();
-        while(childFolders.hasNext()) {
-            childFolder = (FolderData) childFolders.next();
-            
-            log.debug("OLD child folder path was "+childFolder.getPath());
-            
-            // update path and save
-            if("/".equals(folder.getPath())) {
-                childFolder.setPath("/" + childFolder.getName());
-            } else {
-                childFolder.setPath(folder.getPath() + "/" + childFolder.getName());
-            }
-            saveFolder(childFolder);
-            
-            log.debug("NEW child folder path is "+ childFolder.getPath());
-            
-            // then make recursive call to update this folders children
-            updatePathTree(childFolder);
-        }
+        FolderData.updatePathTree(srcFolder);
     }
     
     

Modified: roller/trunk/src/org/apache/roller/pojos/FolderData.java
URL: http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/pojos/FolderData.java?view=diff&rev=535942&r1=535941&r2=535942
==============================================================================
--- roller/trunk/src/org/apache/roller/pojos/FolderData.java (original)
+++ roller/trunk/src/org/apache/roller/pojos/FolderData.java Mon May  7 11:21:15 2007
@@ -25,6 +25,8 @@
 import java.util.TreeSet;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import org.apache.roller.RollerException;
 import org.apache.roller.business.BookmarkManager;
@@ -48,6 +50,9 @@
     
     public static final long serialVersionUID = -6272468884763861944L;
     
+    private static Log log = LogFactory.getLog(FolderData.class);
+    
+    
     // attributes
     private String id = null;
     private String name = null;
@@ -359,6 +364,55 @@
         } else {
             // if our path starts with our parents path then we are a descendent
             return this.path.startsWith(ancestor.getPath());
+        }
+    }
+    
+    
+    // convenience method for updating the folder name, which triggers a path tree rebuild
+    public void updateName(String newName) throws RollerException {
+        
+        // update name
+        setName(newName);
+        
+        // calculate path
+        if(getParent() == null) {
+            setPath("/");
+        } else if("/".equals(getParent().getPath())) {
+            setPath("/"+getName());
+        } else {
+            setPath(getParent().getPath() + "/" + getName());
+        }
+        
+        // update path tree for all children
+        updatePathTree(this);
+    }
+    
+    
+    // update the path tree for a given folder
+    public static void updatePathTree(FolderData folder) 
+            throws RollerException {
+        
+        log.debug("Updating path tree for folder "+folder.getPath());
+        
+        FolderData childFolder = null;
+        Iterator childFolders = folder.getFolders().iterator();
+        while(childFolders.hasNext()) {
+            childFolder = (FolderData) childFolders.next();
+            
+            log.debug("OLD child folder path was "+childFolder.getPath());
+            
+            // update path and save
+            if("/".equals(folder.getPath())) {
+                childFolder.setPath("/" + childFolder.getName());
+            } else {
+                childFolder.setPath(folder.getPath() + "/" + childFolder.getName());
+            }
+            RollerFactory.getRoller().getBookmarkManager().saveFolder(childFolder);
+            
+            log.debug("NEW child folder path is "+ childFolder.getPath());
+            
+            // then make recursive call to update this folders children
+            updatePathTree(childFolder);
         }
     }
     



Mime
View raw message