Author: agilliland
Date: Mon May  7 16:22:15 2007
New Revision: 536016

URL: http://svn.apache.org/viewvc?view=rev&rev=536016
Log:
moving updatePathTree() method to WeblogCategoryData and adding updateName() 
method just as we did with folders.


Modified:
    
roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
    roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java

Modified: 
roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
URL: 
http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java?view=diff&rev=536016&r1=536015&r2=536016
==============================================================================
--- 
roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
 (original)
+++ 
roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
 Mon May  7 16:22:15 2007
@@ -149,35 +149,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(srcCat);
-    }
-    
-    
-    // updates the paths of all descendents of the given category
-    private void updatePathTree(WeblogCategoryData cat) throws RollerException 
{
-        
-        log.debug("Updating path tree for category "+cat.getPath());
-        
-        WeblogCategoryData childCat = null;
-        Iterator childCats = cat.getWeblogCategories().iterator();
-        while(childCats.hasNext()) {
-            childCat = (WeblogCategoryData) childCats.next();
-            
-            log.debug("OLD child category path was "+childCat.getPath());
-            
-            // update path and save
-            if("/".equals(cat.getPath())) {
-                childCat.setPath("/" + childCat.getName());
-            } else {
-                childCat.setPath(cat.getPath() + "/" + childCat.getName());
-            }
-            saveWeblogCategory(childCat);
-            
-            log.debug("NEW child category path is "+ childCat.getPath());
-            
-            // then make recursive call to update this cats children
-            updatePathTree(childCat);
-        }
+        WeblogCategoryData.updatePathTree(srcCat);
     }
     
     

Modified: roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java
URL: 
http://svn.apache.org/viewvc/roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java?view=diff&rev=536016&r1=536015&r2=536016
==============================================================================
--- roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java (original)
+++ roller/trunk/src/org/apache/roller/pojos/WeblogCategoryData.java Mon May  7 
16:22:15 2007
@@ -25,6 +25,8 @@
 import java.util.Set;
 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.RollerFactory;
@@ -44,6 +46,9 @@
     
     public static final long serialVersionUID = 1435782148712018954L;
     
+    private static Log log = LogFactory.getLog(WeblogCategoryData.class);
+    
+    
     // attributes
     private String id = null;
     private String name = null;
@@ -361,5 +366,54 @@
     }
     /** TODO: fix form generation so this is not needed. */
     public void setInUse(boolean dummy) {}
+    
+    
+    // convenience method for updating the category 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);
+    }
+    
+    
+    // updates the paths of all descendents of the given category
+    public static void updatePathTree(WeblogCategoryData cat) 
+            throws RollerException {
+        
+        log.debug("Updating path tree for category "+cat.getPath());
+        
+        WeblogCategoryData childCat = null;
+        Iterator childCats = cat.getWeblogCategories().iterator();
+        while(childCats.hasNext()) {
+            childCat = (WeblogCategoryData) childCats.next();
+            
+            log.debug("OLD child category path was "+childCat.getPath());
+            
+            // update path and save
+            if("/".equals(cat.getPath())) {
+                childCat.setPath("/" + childCat.getName());
+            } else {
+                childCat.setPath(cat.getPath() + "/" + childCat.getName());
+            }
+            
RollerFactory.getRoller().getWeblogManager().saveWeblogCategory(childCat);
+            
+            log.debug("NEW child category path is "+ childCat.getPath());
+            
+            // then make recursive call to update this cats children
+            updatePathTree(childCat);
+        }
+    }
     
 }


Reply via email to