View Javadoc
1   /*
2    * Copyright (C) 2003-2013 eXo Platform SAS.
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU Affero General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (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 Affero General Public License for more details.
13   *
14   * You should have received a copy of the GNU Affero General Public License
15   * along with this program. If not, see <http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.cms.jcrext.activity;
18  
19  import javax.jcr.Node;
20  
21  import org.apache.commons.chain.Context;
22  import org.exoplatform.services.command.action.Action;
23  import org.exoplatform.services.listener.ListenerService;
24  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
25  
26  /**
27   * Created by The eXo Platform SAS
28   * Author : Nguyen The Vinh From ECM Of eXoPlatform
29   *          vinh_nguyen@exoplatform.com
30   * 14 Jan 2013  
31   */
32  public class RemoveFileActivityAction implements Action{
33    private ListenerService listenerService=null;
34    private ActivityCommonService activityService = null;
35    public RemoveFileActivityAction() {
36      listenerService =  WCMCoreUtils.getService(ListenerService.class);
37      activityService = WCMCoreUtils.getService(ActivityCommonService.class);
38    }
39    public boolean execute(Context context) throws Exception {
40      if (listenerService ==null) return false;
41      Object item = context.get("currentItem");
42      if (item instanceof Node) {
43        Node node = (Node)item;
44        Node parent = node.getParent();
45        if (node.getPrimaryNodeType().isNodeType(ActivityCommonService.NT_FILE)) {        
46          if (activityService.isAcceptedNode(node) && activityService.isBroadcastNTFileEvents(node)) {
47            listenerService.broadcast(ActivityCommonService.FILE_REMOVE_ACTIVITY, parent, node);
48          }
49        }
50      }
51      return false;
52    }  
53  }