View Javadoc
1   /***************************************************************************
2    * Copyright (C) 2003-2009 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   *
17   **************************************************************************/
18  package org.exoplatform.ecm.webui.component.explorer.rightclick.manager;
19  
20  import java.util.Arrays;
21  import java.util.List;
22  
23  import javax.jcr.Node;
24  import javax.jcr.Session;
25  
26  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
27  import org.exoplatform.ecm.webui.component.explorer.UIWorkingArea;
28  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter;
29  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotTrashHomeNodeFilter;
30  import org.exoplatform.ecm.webui.component.explorer.control.listener.UIWorkingAreaActionListener;
31  import org.exoplatform.ecm.webui.utils.JCRExceptionManager;
32  import org.exoplatform.services.cms.actions.ActionServiceContainer;
33  import org.exoplatform.services.log.ExoLogger;
34  import org.exoplatform.services.log.Log;
35  import org.exoplatform.web.application.ApplicationMessage;
36  import org.exoplatform.webui.config.annotation.ComponentConfig;
37  import org.exoplatform.webui.config.annotation.EventConfig;
38  import org.exoplatform.webui.core.UIApplication;
39  import org.exoplatform.webui.core.UIComponent;
40  import org.exoplatform.webui.event.Event;
41  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
42  import org.exoplatform.webui.ext.filter.UIExtensionFilters;
43  import org.exoplatform.webui.ext.manager.UIAbstractManager;
44  import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent;
45  
46  /**
47   * Created by The eXo Platform SARL
48   * Author : Hoang Van Hung
49   *          hunghvit@gmail.com
50   * Aug 6, 2009
51   */
52  
53  @ComponentConfig(
54      events = {
55        @EventConfig(listeners = CustomManageComponent.CustomActionListener.class)
56      }
57  )
58  public class CustomManageComponent extends UIAbstractManagerComponent {
59  
60    private static final List<UIExtensionFilter> FILTERS
61        = Arrays.asList(new UIExtensionFilter[]{new IsNotInTrashFilter(),
62                                                new IsNotTrashHomeNodeFilter() });
63    private final static Log       LOG  = ExoLogger.getLogger(CustomManageComponent.class.getName());
64  
65    @UIExtensionFilters
66    public List<UIExtensionFilter> getFilters() {
67      return FILTERS;
68    }
69  
70    public static void customManage(Event<? extends UIComponent> event, UIJCRExplorer uiExplorer,
71        UIApplication uiApp) throws Exception {
72      UIWorkingArea uicomp = event.getSource().getParent();
73      String nodePath = event.getRequestContext().getRequestParameter(OBJECTID);
74      String actionName = event.getRequestContext().getRequestParameter("actionName");
75      String wsName = event.getRequestContext().getRequestParameter(UIWorkingArea.WS_NAME);
76      Session session = uiExplorer.getSessionByWorkspace(wsName);
77      ActionServiceContainer actionService =
78        uicomp.getApplicationComponent(ActionServiceContainer.class);
79      try {
80        Node node = uiExplorer.getNodeByPath(nodePath, session);
81        String userId = event.getRequestContext().getRemoteUser();
82        actionService.executeAction(userId, node, actionName);
83        Object[] arg = { actionName };
84        uiApp.addMessage(new ApplicationMessage("UIWorkingArea.msg.execute-successfully", arg));
85        
86        uiExplorer.updateAjax(event);
87      } catch (Exception e) {
88        if (LOG.isErrorEnabled()) {
89          LOG.error("an unexpected error occurs while calling custom action on the node", e);
90        }
91        JCRExceptionManager.process(uiApp, e);
92        
93        uiExplorer.updateAjax(event);
94      }
95    }
96  
97    public static class CustomActionListener extends UIWorkingAreaActionListener<CustomManageComponent> {
98      public void processEvent(Event<CustomManageComponent> event) throws Exception {
99        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
100       UIApplication uiApp = event.getSource().getAncestorOfType(UIApplication.class);
101       customManage(event, uiExplorer, uiApp);
102     }
103   }
104 
105   @Override
106   public Class<? extends UIAbstractManager> getUIAbstractManagerClass() {
107     return null;
108   }
109 
110 }