View Javadoc
1   package org.exoplatform.ecm.webui.component.explorer;
2   
3   import org.apache.commons.lang.BooleanUtils;
4   import org.apache.commons.lang.StringUtils;
5   import org.exoplatform.ecm.webui.component.explorer.rightclick.manager.PasteManageComponent;
6   import org.exoplatform.ecm.webui.utils.JCRExceptionManager;
7   import org.exoplatform.services.cms.actions.ActionServiceContainer;
8   import org.exoplatform.services.cms.documents.TrashService;
9   import org.exoplatform.wcm.webui.reader.ContentReader;
10  import org.exoplatform.webui.core.UIApplication;
11  import org.exoplatform.services.cms.clipboard.jcr.model.ClipboardCommand;
12  import org.exoplatform.services.cms.documents.AutoVersionService;
13  import org.exoplatform.services.log.ExoLogger;
14  import org.exoplatform.services.log.Log;
15  import org.exoplatform.services.wcm.core.NodetypeConstant;
16  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
17  import org.exoplatform.wcm.webui.Utils;
18  import org.exoplatform.web.application.ApplicationMessage;
19  import org.exoplatform.webui.application.WebuiRequestContext;
20  import org.exoplatform.webui.config.annotation.ComponentConfig;
21  import org.exoplatform.webui.config.annotation.EventConfig;
22  import org.exoplatform.webui.core.UIPopupComponent;
23  import org.exoplatform.webui.core.UIPopupWindow;
24  import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
25  import org.exoplatform.webui.event.Event;
26  import org.exoplatform.webui.event.EventListener;
27  import org.exoplatform.webui.form.UIForm;
28  import org.exoplatform.webui.form.input.UICheckBoxInput;
29  
30  import javax.jcr.AccessDeniedException;
31  import javax.jcr.ItemExistsException;
32  import javax.jcr.LoginException;
33  import javax.jcr.Node;
34  import javax.jcr.Session;
35  import javax.jcr.Workspace;
36  import javax.jcr.lock.LockException;
37  import javax.jcr.nodetype.ConstraintViolationException;
38  import javax.jcr.version.VersionException;
39  
40  import java.util.HashMap;
41  import java.util.Map;
42  import java.util.Set;
43  import java.util.regex.Matcher;
44  
45  /**
46   * Created by The eXo Platform SEA
47   * Author : eXoPlatform
48   * toannh@exoplatform.com
49   * On 7/27/15
50   * Build popup document auto versioning
51   */
52  @ComponentConfig(
53          template = "app:/groovy/webui/component/explorer/versions/UIDocumentAutoVersionForm.gtmpl",
54          lifecycle = UIFormLifecycle.class,
55          events = {
56                  @EventConfig(listeners = UIDocumentAutoVersionForm.KeepBothActionListener.class),
57                  @EventConfig(listeners = UIDocumentAutoVersionForm.CreateNewVersionActionListener.class),
58                  @EventConfig(listeners = UIDocumentAutoVersionForm.ReplaceActionListener.class),
59                  @EventConfig(listeners = UIDocumentAutoVersionForm.OnChangeActionListener.class),
60                  @EventConfig(listeners = UIDocumentAutoVersionForm.CancelActionListener.class, phase = Event.Phase.DECODE)
61          }
62  )
63  public class UIDocumentAutoVersionForm extends UIForm implements UIPopupComponent {
64  
65    private static final Log    LOG           = ExoLogger.getLogger(UIDocumentAutoVersionForm.class.getName());
66    public static final String KEEP_BOTH = "KeepBoth";
67    public static final String CREATE_VERSION = "CreateNewVersion";
68    public static final String REPLACE = "Replace";
69    public static final String CREATE_OR_REPLACE = "CreateVersionOrReplace";
70    public static final String CANCEL = "Cancel";
71    public static final String REMEMBER_VERSIONED_COMPONENT = "UIDocumentAutoVersionForm.UIChkRememberVersioned";
72    public static final String REMEMBER_NONVERSIONED_COMPONENT = "UIDocumentAutoVersionForm.UIChkRememberNonVersioned";
73  
74    private boolean isVersioned, isSingleProcess = false;
75    private String sourcePath;
76    private String destPath;
77    private String sourceWorkspace;
78    private String destWorkspace;
79    private String message_;
80    private String[] args_ = {};
81    private static String[] actions = new String[] {KEEP_BOTH, CREATE_VERSION, REPLACE, CREATE_OR_REPLACE ,CANCEL};
82    private static Set<ClipboardCommand> clipboardCommands = null;
83    private ClipboardCommand currentClipboard = null;
84  
85    private static AutoVersionService autoVersionService = WCMCoreUtils.getService(AutoVersionService.class);
86    @Override
87    public void activate() { }
88  
89    @Override
90    public void deActivate() {
91  
92    }
93  
94    public UIDocumentAutoVersionForm(){
95      UICheckBoxInput chkRememberVersioned = new UICheckBoxInput(REMEMBER_VERSIONED_COMPONENT, "", false);
96      UICheckBoxInput chkRememberNonVersioned = new UICheckBoxInput(REMEMBER_NONVERSIONED_COMPONENT, "", false);
97      chkRememberVersioned.setOnChange("OnChange");
98      chkRememberVersioned.setChecked(true);
99      chkRememberNonVersioned.setChecked(true);
100     chkRememberVersioned.setRendered(false);
101     chkRememberNonVersioned.setRendered(false);
102     this.addChild(chkRememberVersioned);
103     this.addChild(chkRememberNonVersioned);
104   }
105 
106   public void init(Node currentNode) throws Exception{
107     UICheckBoxInput chkRemVersion = this.findComponentById(REMEMBER_VERSIONED_COMPONENT);
108     UICheckBoxInput chkRemNonVersioned = this.findComponentById(REMEMBER_NONVERSIONED_COMPONENT);
109     if(currentNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE)){
110       setActions(new String[]{KEEP_BOTH, CREATE_VERSION, CANCEL});
111       chkRemVersion.setRendered(true);
112       chkRemNonVersioned.setRendered(false);
113     }else{
114       setActions(new String[]{KEEP_BOTH, REPLACE, CANCEL});
115       chkRemVersion.setRendered(false);
116       chkRemNonVersioned.setRendered(true);
117     }
118     if(isSingleProcess) {
119       chkRemVersion.setRendered(false);
120       chkRemNonVersioned.setRendered(false);
121     }
122   }
123 
124   public String[] getActions() { return actions; }
125 
126   public static class KeepBothActionListener extends EventListener<UIDocumentAutoVersionForm> {
127     @Override
128     public void execute(Event<UIDocumentAutoVersionForm> event) throws Exception {
129       UIDocumentAutoVersionForm autoVersionComponent = event.getSource();
130       UIJCRExplorer uiExplorer = autoVersionComponent.getAncestorOfType(UIJCRExplorer.class);
131       UIApplication uiApp = uiExplorer.getAncestorOfType(UIApplication.class);
132       UICheckBoxInput chkRemVersion = autoVersionComponent.findComponentById(REMEMBER_VERSIONED_COMPONENT);
133       UICheckBoxInput chkRemNonVersioned = autoVersionComponent.findComponentById(REMEMBER_NONVERSIONED_COMPONENT);
134       boolean chkRem = chkRemVersion.isChecked() && chkRemVersion.isRendered();
135       boolean chkRemNon = chkRemNonVersioned.isChecked() && chkRemNonVersioned.isRendered();
136       Session destSession = uiExplorer.getSessionByWorkspace(autoVersionComponent.getDestWorkspace());
137       Session srcSession = uiExplorer.getSessionByWorkspace(autoVersionComponent.getSourceWorkspace());
138       Node sourceNode = uiExplorer.getNodeByPath(autoVersionComponent.getSourcePath(), srcSession);
139       String destPath = autoVersionComponent.getDestPath();
140 
141       if (destPath != null) {
142         Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(destPath);
143         if (matcher.find()) {
144           destPath = matcher.group(2);
145         }
146       }
147       if (!"/".equals(destPath)) destPath = destPath.concat("/");
148       destPath = destPath.concat(sourceNode.getName());
149 
150       if(autoVersionComponent.isSingleProcess) {
151         try {
152           if(ClipboardCommand.CUT.equals(autoVersionComponent.getCurrentClipboard().getType())){
153             //cut process
154             PasteManageComponent.pasteByCut(autoVersionComponent.getCurrentClipboard(), uiExplorer, destSession, autoVersionComponent.getCurrentClipboard().getWorkspace(),
155                     sourceNode.getPath(), destPath, WCMCoreUtils.getService(ActionServiceContainer.class), false,false, false);
156           }else {
157             copyNode(destSession, autoVersionComponent.getSourceWorkspace(),
158                     autoVersionComponent.getSourcePath(), destPath, uiApp, uiExplorer, event, ClipboardCommand.COPY);
159           }
160         } catch (ItemExistsException iee) {
161           uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.paste-node-same-name", null,
162                   ApplicationMessage.WARNING));
163 
164           uiExplorer.updateAjax(event);
165           return;
166         }
167       }
168       Node destNode = (Node)destSession.getItem(destPath);
169       Map<String, Boolean> remember = new HashMap<>();
170       if(destNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE) && chkRem){
171         remember.put("keepboth", true);
172         PasteManageComponent.setVersionedRemember(remember);
173       }else if(!destNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE) && chkRemNon){
174         remember.put("keepboth", true);
175         PasteManageComponent.setNonVersionedRemember(remember);
176       }
177 
178       Set<ClipboardCommand> _clipboardCommands = autoVersionComponent.getClipboardCommands();
179       if(!autoVersionComponent.isSingleProcess && _clipboardCommands!=null && _clipboardCommands.size()>0){
180         if (ClipboardCommand.CUT.equals(autoVersionComponent.getCurrentClipboard().getType())) {
181           //cut process
182           PasteManageComponent.pasteByCut(autoVersionComponent.getCurrentClipboard(), uiExplorer, destSession, autoVersionComponent.getCurrentClipboard().getWorkspace(),
183                   sourceNode.getPath(), destPath, WCMCoreUtils.getService(ActionServiceContainer.class), false, false, false);
184         } else {
185           copyNode(destSession, autoVersionComponent.getSourceWorkspace(),
186                   autoVersionComponent.getSourcePath(), destPath, uiApp, uiExplorer, event, ClipboardCommand.COPY);
187         }
188         _clipboardCommands.remove(autoVersionComponent.getCurrentClipboard());
189         if(_clipboardCommands.isEmpty()){
190           closePopup(autoVersionComponent, uiExplorer, event);
191           return;
192         }
193         PasteManageComponent.processPasteMultiple(destNode.getParent(), event, uiExplorer, _clipboardCommands, KEEP_BOTH);
194       }else {
195         closePopup(autoVersionComponent, uiExplorer, event);
196       }
197 
198       if((chkRem && chkRemNon)) closePopup(autoVersionComponent, uiExplorer, event);
199     }
200   }
201 
202   public static class CreateNewVersionActionListener extends EventListener<UIDocumentAutoVersionForm> {
203     @Override
204     public void execute(Event<UIDocumentAutoVersionForm> event) throws Exception {
205       UIDocumentAutoVersionForm autoVersionComponent = event.getSource();
206       UIJCRExplorer uijcrExplorer = autoVersionComponent.getAncestorOfType(UIJCRExplorer.class);
207 
208       UICheckBoxInput chkRemVersion = autoVersionComponent.findComponentById(REMEMBER_VERSIONED_COMPONENT);
209       UICheckBoxInput chkRemNonVersioned = autoVersionComponent.findComponentById(REMEMBER_NONVERSIONED_COMPONENT);
210       boolean chkRem = chkRemVersion.isChecked() && chkRemVersion.isRendered();
211       boolean chkRemNon = chkRemNonVersioned.isChecked() && chkRemNonVersioned.isRendered();
212       Session destSession = uijcrExplorer.getSessionByWorkspace(autoVersionComponent.getDestWorkspace());
213       Session srcSession = uijcrExplorer.getSessionByWorkspace(autoVersionComponent.getSourceWorkspace());
214       Node sourceNode = uijcrExplorer.getNodeByPath(autoVersionComponent.getSourcePath(), srcSession);
215       String destPath = autoVersionComponent.getDestPath();
216       if (destPath != null) {
217         Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(destPath);
218         if(matcher.find()) destPath = matcher.group(2);
219       }
220       if (!"/".equals(destPath)) destPath = destPath.concat("/");
221       destPath = destPath.concat(sourceNode.getName());
222 
223       Node destNode = (Node)destSession.getItem(destPath);
224       if(autoVersionComponent.isSingleProcess || autoVersionComponent.clipboardCommands.size()==1){
225         if(ClipboardCommand.CUT.equals(autoVersionComponent.getCurrentClipboard().getType())){
226           PasteManageComponent.pasteByCut(autoVersionComponent.getCurrentClipboard(), uijcrExplorer, destSession, autoVersionComponent.getCurrentClipboard().getWorkspace(),
227                   sourceNode.getPath(), destNode.getParent().getPath(),
228                   WCMCoreUtils.getService(ActionServiceContainer.class), false,false, true);
229         }else {
230           autoVersionService.autoVersion(destNode, sourceNode);
231         }
232         closePopup(autoVersionComponent, uijcrExplorer, event);
233         String msg = event.getRequestContext().getApplicationResourceBundle().getString("DocumentAuto.message");
234         msg = msg.replace("{0}", ContentReader.simpleEscapeHtml(
235             new StringBuilder("<span style='font-weight:bold;'>").append(destNode.getName()).append("</span>").toString()));
236         event.getRequestContext().getJavascriptManager().require("SHARED/wcm-utils", "wcm_utils")
237                 .addScripts("eXo.ecm.WCMUtils.showNotice(\" "+msg+"\", 'true'); ");
238         return;
239       }
240       Map<String, Boolean> remember = new HashMap<>();
241       if(destNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE) && chkRem){
242         remember.put("createVersion", true);
243         PasteManageComponent.setVersionedRemember(remember);
244       }else if(destNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE) && chkRemNon){
245         remember.put("createVersion", true);
246         PasteManageComponent.setNonVersionedRemember(remember);
247       }
248 
249       Set<ClipboardCommand> _clipboardCommands = autoVersionComponent.getClipboardCommands();
250       if(!autoVersionComponent.isSingleProcess && _clipboardCommands!=null && _clipboardCommands.size()>0){
251         if (ClipboardCommand.COPY.equals(autoVersionComponent.getCurrentClipboard().getType())) {
252           _clipboardCommands.remove(autoVersionComponent.getCurrentClipboard());
253           AutoVersionService autoVersionService = WCMCoreUtils.getService(AutoVersionService.class);
254           autoVersionService.autoVersion(destNode, sourceNode);
255         }else if (ClipboardCommand.CUT.equals(autoVersionComponent.getCurrentClipboard().getType())) {
256           PasteManageComponent.pasteByCut(autoVersionComponent.getCurrentClipboard(), uijcrExplorer, destSession, autoVersionComponent.getCurrentClipboard().getWorkspace(),
257                   sourceNode.getPath(), destNode.getParent().getPath(),
258               WCMCoreUtils.getService(ActionServiceContainer.class), false,false, true);
259           _clipboardCommands.remove(autoVersionComponent.getCurrentClipboard());
260         }
261         if(_clipboardCommands.isEmpty()){
262           closePopup(autoVersionComponent, uijcrExplorer, event);
263           return;
264         }
265         Map<String, Boolean> versionedRemember = PasteManageComponent.getVersionedRemember();
266         if(versionedRemember!=null && BooleanUtils.isTrue(versionedRemember.get("createVersion"))
267                 && !_clipboardCommands.isEmpty() ){
268           String msg = event.getRequestContext().getApplicationResourceBundle().getString("DocumentAuto.messageMultiFile");
269           event.getRequestContext().getJavascriptManager().require("SHARED/wcm-utils", "wcm_utils")
270                   .addScripts("eXo.ecm.WCMUtils.showNotice(\" "+msg+"\", 'true'); ");
271         }else {
272           String msg = event.getRequestContext().getApplicationResourceBundle().getString("DocumentAuto.message");
273           msg = msg.replace("{0}", ContentReader.simpleEscapeHtml(
274               new StringBuilder("<span style='font-weight:bold;'>").append(destNode.getName()).append("</span>").toString()));
275           event.getRequestContext().getJavascriptManager().require("SHARED/wcm-utils", "wcm_utils")
276                   .addScripts("eXo.ecm.WCMUtils.showNotice(\" "+msg+"\", 'true'); ");
277         }
278         PasteManageComponent.processPasteMultiple(destNode.getParent(), event, uijcrExplorer, _clipboardCommands, CREATE_VERSION);
279       }else {
280         closePopup(autoVersionComponent, uijcrExplorer, event);
281       }
282 
283       if(chkRem && chkRemNon) closePopup(autoVersionComponent, uijcrExplorer, event);
284     }
285   }
286 
287 
288   public static class ReplaceActionListener extends EventListener<UIDocumentAutoVersionForm> {
289     @Override
290     public void execute(Event<UIDocumentAutoVersionForm> event) throws Exception {
291       UIDocumentAutoVersionForm autoVersionComponent = event.getSource();
292       UIJCRExplorer uijcrExplorer = autoVersionComponent.getAncestorOfType(UIJCRExplorer.class);
293       UIApplication uiApp = uijcrExplorer.getAncestorOfType(UIApplication.class);
294       UICheckBoxInput chkRemVersion = autoVersionComponent.findComponentById(REMEMBER_VERSIONED_COMPONENT);
295       UICheckBoxInput chkRemNonVersioned = autoVersionComponent.findComponentById(REMEMBER_NONVERSIONED_COMPONENT);
296       boolean chkRem = chkRemVersion.isChecked() && chkRemVersion.isRendered();
297       boolean chkRemNon = chkRemNonVersioned.isChecked() && chkRemNonVersioned.isRendered();
298       Session destSession = uijcrExplorer.getSessionByWorkspace(autoVersionComponent.getDestWorkspace());
299       Session srcSession = uijcrExplorer.getSessionByWorkspace(autoVersionComponent.getSourceWorkspace());
300       Node sourceNode = uijcrExplorer.getNodeByPath(autoVersionComponent.getSourcePath(), srcSession);
301       String destPath = autoVersionComponent.getDestPath();
302       Set<ClipboardCommand> _clipboardCommands = autoVersionComponent.getClipboardCommands();
303       ClipboardCommand currentCliboard = autoVersionComponent.getCurrentClipboard();
304       if (destPath != null) {
305         Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(destPath);
306         if(matcher.find()) destPath = matcher.group(2);
307       }
308       Node _destNode = (Node)destSession.getItem(destPath);
309 
310       //If replace in same location, do nothing
311       if(destPath.equals(sourceNode.getParent().getPath()) && autoVersionComponent.isSingleProcess) {
312         closePopup(autoVersionComponent, uijcrExplorer, event);
313         return;
314       }
315 
316       Node destNode = _destNode.getNode(sourceNode.getName());
317       Map<String, Boolean> remember = new HashMap<>();
318       if(destNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE) && chkRem){
319         remember.put("replace", true);
320         PasteManageComponent.setVersionedRemember(remember);
321       }else if(!destNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE) && chkRemNon){
322         remember.put("replace", true);
323         PasteManageComponent.setNonVersionedRemember(remember);
324       }
325       TrashService trashService = WCMCoreUtils.getService(TrashService.class);
326       String trashID=null;
327       destPath = destNode.getPath();
328       if(ClipboardCommand.CUT.equals(currentCliboard.getType())
329               && _destNode.hasNode(sourceNode.getName())) {
330         if(_clipboardCommands!=null && _clipboardCommands.size()>0){
331           if(!StringUtils.equals(destNode.getPath(), sourceNode.getPath())){
332             trashID = trashService.moveToTrash(destNode, WCMCoreUtils.getUserSessionProvider());
333             try {
334               PasteManageComponent.pasteByCut(autoVersionComponent.getCurrentClipboard(), uijcrExplorer, destSession, autoVersionComponent.getCurrentClipboard().getWorkspace(),
335                       sourceNode.getPath(), destPath, WCMCoreUtils.getService(ActionServiceContainer.class), false, false, false);
336             }catch (Exception ex){
337               if(LOG.isErrorEnabled()){
338                 LOG.error("Cannot cut files while replace", ex);
339               }
340               trashService.restoreFromTrash(trashID, WCMCoreUtils.getUserSessionProvider());
341             }
342             Node deletedNode = trashService.getNodeByTrashId(trashID);
343             deletedNode.remove();
344             deletedNode.getSession().save();
345           }
346           _clipboardCommands.remove(currentCliboard);
347           PasteManageComponent.processPasteMultiple(_destNode, event, uijcrExplorer, _clipboardCommands, REPLACE);
348         }else{
349           closePopup(autoVersionComponent, uijcrExplorer, event);
350         }
351         return;
352       }
353       Node destDriectory = destNode.getParent();
354 
355       if(autoVersionComponent.isSingleProcess){
356         trashID = trashService.moveToTrash(destNode, WCMCoreUtils.getUserSessionProvider());
357         try {
358           copyNode(destSession, autoVersionComponent.getSourceWorkspace(),
359                   autoVersionComponent.getSourcePath(), destPath, uiApp, uijcrExplorer, event, ClipboardCommand.COPY);
360         }catch (Exception ex){
361           if(LOG.isErrorEnabled()){
362             LOG.error("Cannot copy files while replace", ex);
363           }
364           trashService.restoreFromTrash(trashID, WCMCoreUtils.getUserSessionProvider());
365         }
366         Node deletedNode = trashService.getNodeByTrashId(trashID);
367         deletedNode.remove();
368         deletedNode.getSession().save();
369         closePopup(autoVersionComponent, uijcrExplorer, event);
370         return;
371       }
372 
373       if(_clipboardCommands!=null && _clipboardCommands.size()>0){
374         _clipboardCommands.remove(autoVersionComponent.getCurrentClipboard());
375         if(!StringUtils.equals(destPath, autoVersionComponent.getSourcePath())){
376           trashID = trashService.moveToTrash(destNode, WCMCoreUtils.getUserSessionProvider());
377           try {
378             copyNode(destSession, autoVersionComponent.getSourceWorkspace(),
379                     autoVersionComponent.getSourcePath(), destPath, uiApp, uijcrExplorer, event, ClipboardCommand.COPY);
380           }catch (Exception ex){
381             if(LOG.isErrorEnabled()){
382               LOG.error("Cannot copy files while replace", ex);
383             }
384             trashService.restoreFromTrash(trashID, WCMCoreUtils.getUserSessionProvider());
385           }
386           Node deletedNode = trashService.getNodeByTrashId(trashID);
387           deletedNode.remove();
388           deletedNode.getSession().save();
389           destSession.save();
390         }
391         PasteManageComponent.processPasteMultiple(destDriectory, event, uijcrExplorer, _clipboardCommands, REPLACE);
392       }else {
393         closePopup(autoVersionComponent, uijcrExplorer, event);
394       }
395 
396       if(chkRem && chkRemNon) closePopup(autoVersionComponent, uijcrExplorer, event);
397     }
398   }
399 
400   public static class CancelActionListener extends EventListener<UIDocumentAutoVersionForm> {
401     @Override
402     public void execute(Event<UIDocumentAutoVersionForm> event) throws Exception {
403       UIDocumentAutoVersionForm autoVersionComponent = event.getSource();
404       UIJCRExplorer uiExplorer = autoVersionComponent.getAncestorOfType(UIJCRExplorer.class);
405       UICheckBoxInput chkRemVersion = autoVersionComponent.findComponentById(REMEMBER_VERSIONED_COMPONENT);
406       UICheckBoxInput chkRemNonVersioned = autoVersionComponent.findComponentById(REMEMBER_NONVERSIONED_COMPONENT);
407       boolean chkRem = chkRemVersion.isChecked() && chkRemVersion.isRendered();
408       boolean chkRemNon = chkRemNonVersioned.isChecked() && chkRemNonVersioned.isRendered();
409       Session destSession = uiExplorer.getSessionByWorkspace(autoVersionComponent.getDestWorkspace());
410       Session srcSession = uiExplorer.getSessionByWorkspace(autoVersionComponent.getSourceWorkspace());
411       Node sourceNode = uiExplorer.getNodeByPath(autoVersionComponent.getSourcePath(), srcSession);
412       String destPath = autoVersionComponent.getDestPath();
413       if(autoVersionComponent.isSingleProcess) {
414         closePopup(autoVersionComponent, uiExplorer, event);
415       }
416       if (destPath != null) {
417         Matcher matcher = UIWorkingArea.FILE_EXPLORER_URL_SYNTAX.matcher(destPath);
418         if (matcher.find()) {
419           destPath = matcher.group(2);
420         }
421       }
422       if (!"/".equals(destPath)) destPath = destPath.concat("/");
423       destPath = destPath.concat(sourceNode.getName());
424 
425       Node destNode = (Node)destSession.getItem(destPath);
426       Map<String, Boolean> remember = new HashMap<>();
427       if(destNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE) && chkRem){
428         remember.put(CANCEL, true);
429         PasteManageComponent.setVersionedRemember(remember);
430       }else if(!destNode.isNodeType(NodetypeConstant.MIX_VERSIONABLE) && chkRemNon){
431         remember.put(CANCEL, true);
432         PasteManageComponent.setNonVersionedRemember(remember);
433       }
434 
435       Set<ClipboardCommand> _clipboardCommands = autoVersionComponent.getClipboardCommands();
436       if(!autoVersionComponent.isSingleProcess && _clipboardCommands!=null && _clipboardCommands.size()>0){
437         _clipboardCommands.remove(autoVersionComponent.getCurrentClipboard());
438         if(_clipboardCommands.isEmpty()){
439           closePopup(autoVersionComponent, uiExplorer, event);
440           return;
441         }
442         PasteManageComponent.processPasteMultiple(destNode.getParent(), event, uiExplorer, _clipboardCommands, CANCEL);
443       }else {
444         closePopup(autoVersionComponent, uiExplorer, event);
445       }
446 
447       if((chkRem && chkRemNon)) closePopup(autoVersionComponent, uiExplorer, event);
448     }
449   }
450 
451   public String getSourcePath() {
452     return sourcePath;
453   }
454 
455   public void setSourcePath(String sourcePath) {
456     this.sourcePath = sourcePath;
457   }
458 
459   public String getDestPath() {
460     return destPath;
461   }
462 
463   public void setDestPath(String destPath) {
464     this.destPath = destPath;
465   }
466 
467   public String getSourceWorkspace() {
468     return sourceWorkspace;
469   }
470 
471   public void setSourceWorkspace(String sourceWorkspace) {
472     this.sourceWorkspace = sourceWorkspace;
473   }
474 
475   public String getDestWorkspace() {
476     return destWorkspace;
477   }
478 
479   public void setDestWorkspace(String destWorkspace) {
480     this.destWorkspace = destWorkspace;
481   }
482 
483   public void setMessage(String message) { message_ = message; }
484 
485   public String getMessage() { return message_; }
486 
487   public void setArguments(String[] args) { args_ = args; }
488 
489   public String[] getArguments() { return args_; }
490 
491   public boolean isVersioned() {
492     return isVersioned;
493   }
494 
495   public void setVersioned(boolean isVersioned) {
496     this.isVersioned = isVersioned;
497   }
498 
499   public void setActions(String[] actions) {
500     this.actions = actions;
501   }
502 
503   public void setSingleProcess(boolean isSingleProcess) {
504     this.isSingleProcess = isSingleProcess;
505   }
506 
507   /**
508    * Copy node using workspace
509    * @param session session of dest node
510    * @param srcWorkspaceName source
511    * @param srcPath
512    * @param destPath
513    * @throws Exception
514    */
515   public static void copyNode(Session session, String srcWorkspaceName, String srcPath, String destPath,
516                               UIApplication uiApp, UIJCRExplorer uiExplorer, Event<?> event, String type) throws Exception {
517     Workspace workspace = session.getWorkspace();
518     if (workspace.getName().equals(srcWorkspaceName)) {
519       try {
520         workspace.copy(srcPath, destPath);
521         Node destNode = (Node) session.getItem(destPath);
522         Utils.removeReferences(destNode);
523       }catch (ConstraintViolationException ce) {
524       uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.current-node-not-allow-paste", null,
525               ApplicationMessage.WARNING));
526 
527       uiExplorer.updateAjax(event);
528       return;
529     } catch (VersionException ve) {
530       uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.copied-node-in-versioning", null,
531               ApplicationMessage.WARNING));
532 
533       uiExplorer.updateAjax(event);
534       return;
535     } catch (ItemExistsException iee) {
536       uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.paste-node-same-name", null,
537               ApplicationMessage.WARNING));
538 
539       uiExplorer.updateAjax(event);
540       return;
541     } catch (LoginException e) {
542       if (ClipboardCommand.CUT.equals(type)) {
543         uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.cannot-login-node", null,
544                 ApplicationMessage.WARNING));
545 
546         uiExplorer.updateAjax(event);
547         return;
548       }
549       uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.cannot-paste-nodetype", null,
550               ApplicationMessage.WARNING));
551 
552       uiExplorer.updateAjax(event);
553       return;
554     } catch (AccessDeniedException ace) {
555       uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.access-denied", null,
556               ApplicationMessage.WARNING));
557 
558       uiExplorer.updateAjax(event);
559       return;
560     } catch (LockException locke) {
561       Object[] arg = { srcPath };
562       uiApp.addMessage(new ApplicationMessage("UIPopupMenu.msg.paste-lock-exception", arg,
563               ApplicationMessage.WARNING));
564 
565     } catch (Exception e) {
566       JCRExceptionManager.process(uiApp, e);
567 
568       uiExplorer.updateAjax(event);
569       return;
570     }
571     } else {
572       try {
573         if (LOG.isDebugEnabled())
574           LOG.debug("Copy to another workspace");
575         workspace.copy(srcWorkspaceName, srcPath, destPath);
576       } catch (Exception e) {
577         if (LOG.isErrorEnabled()) {
578           LOG.error("an unexpected error occurs while pasting the node", e);
579         }
580         if (LOG.isDebugEnabled())
581           LOG.debug("Copy to other workspace by clone");
582         try {
583           workspace.clone(srcWorkspaceName, srcPath, destPath, false);
584         } catch (Exception f) {
585           if (LOG.isErrorEnabled()) {
586             LOG.error("an unexpected error occurs while pasting the node", f);
587           }
588         }
589       }
590     }
591   }
592 
593   public Set<ClipboardCommand> getClipboardCommands() {
594     return clipboardCommands;
595   }
596 
597   public void setClipboardCommands(Set<ClipboardCommand> clipboardCommands) {
598     this.clipboardCommands = clipboardCommands;
599   }
600 
601   public ClipboardCommand getCurrentClipboard() {
602     return currentClipboard;
603   }
604 
605   public void setCurrentClipboard(ClipboardCommand currentClipboard) {
606     this.currentClipboard = currentClipboard;
607   }
608 
609   public static void closePopup(UIDocumentAutoVersionForm autoVersionComponent,
610                                  UIJCRExplorer uijcrExplorer, Event<?> event) throws Exception{
611     UIPopupWindow popupAction = uijcrExplorer.findFirstComponentOfType(UIPopupWindow.class) ;
612     UICheckBoxInput chkRememberVersioned = autoVersionComponent.findComponentById(REMEMBER_VERSIONED_COMPONENT);
613     UICheckBoxInput chkRememberNonVersioned = autoVersionComponent.findComponentById(REMEMBER_NONVERSIONED_COMPONENT);
614     chkRememberVersioned.setChecked(false);
615     chkRememberNonVersioned.setChecked(false);
616     PasteManageComponent.setVersionedRemember(null);
617     PasteManageComponent.setNonVersionedRemember(null);
618     autoVersionComponent.setCurrentClipboard(null);
619     popupAction.setShow(false) ;
620     popupAction.setRendered(false);
621     uijcrExplorer.updateAjax(event);
622   }
623 
624   static public class OnChangeActionListener extends EventListener<UIDocumentAutoVersionForm> {
625     public void execute(Event<UIDocumentAutoVersionForm> event) throws Exception {
626       event.getRequestContext().addUIComponentToUpdateByAjax(event.getSource());
627     }
628   }
629 
630   @Override
631   public void processRender(WebuiRequestContext context) throws Exception {
632     super.processRender(context);
633   }
634 
635 }