Update of 
/var/cvs/contributions/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms
In directory james.mmbase.org:/tmp/cvs-serv4220/forms

Modified Files:
        PasteAction.java 
Log Message:
CMSC-1298 Clone channel feature


See also: 
http://cvs.mmbase.org/viewcvs/contributions/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms
See also: http://www.mmbase.org/jira/browse/CMSC-1298


Index: PasteAction.java
===================================================================
RCS file: 
/var/cvs/contributions/CMSContainer/cmsc/contentrepository/src/java/com/finalist/cmsc/repository/forms/PasteAction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- PasteAction.java    26 Nov 2007 11:43:40 -0000      1.4
+++ PasteAction.java    23 Feb 2009 08:40:41 -0000      1.5
@@ -10,6 +10,7 @@
 package com.finalist.cmsc.repository.forms;
 
 import org.mmbase.bridge.Node;
+import org.mmbase.bridge.NodeList;
 
 import com.finalist.cmsc.repository.RepositoryUtil;
 import com.finalist.cmsc.security.SecurityUtil;
@@ -17,9 +18,13 @@
 
 public class PasteAction extends TreePasteAction {
 
+   private static final String NAME_FIELD = "name";
+   private static final String CHANNELSUBFIX = "-Copy";
    @Override
    protected void copy(Node sourceChannel, Node destChannel) {
-      RepositoryUtil.copyChannel(sourceChannel, destChannel);
+      Node newChannel = RepositoryUtil.copyChannel(sourceChannel, destChannel);
+      renameChannel(newChannel,destChannel);
+
    }
 
 
@@ -29,4 +34,36 @@
       SecurityUtil.clearUserRoles(sourceChannel.getCloud());
    }
 
+   private void renameChannel(Node newChannel, Node destChannel) {
+      if (newChannel != null) {
+         NodeList children = RepositoryUtil.getOrderedChildren(destChannel);
+         outer:            
+         while(true) {
+            String channelName = newChannel.getStringValue(NAME_FIELD);
+            for (int i = 0 ; i < children.size(); i++) {
+               Node childChannel = children.getNode(i);
+               if(channelName.equals(childChannel.getStringValue(NAME_FIELD)) 
&& newChannel.getNumber() != childChannel.getNumber()) {
+                  if(channelName.indexOf(CHANNELSUBFIX) > -1) {
+                     if(channelName.endsWith(CHANNELSUBFIX)) {
+                        newChannel.setStringValue(NAME_FIELD, 
channelName+"-2");
+                     }
+                     else {
+                        int subfix = 
Integer.parseInt(channelName.substring(channelName.lastIndexOf("-")+1));
+                        subfix++;
+                        newChannel.setStringValue(NAME_FIELD, 
channelName.substring(0,channelName.lastIndexOf("-"))+"-"+subfix);
+                     }
+                  }
+                  else {
+                     newChannel.setStringValue(NAME_FIELD, 
channelName+CHANNELSUBFIX); 
+                  }
+                  newChannel.commit(); 
+                  continue outer;
+               }
+               if(i == (children.size()-1)) {
+                  break outer;
+               }
+            }
+         }
+      }
+   }
 }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to