RemoveFileActivityAction.java

  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. import javax.jcr.Node;

  19. import org.apache.commons.chain.Context;
  20. import org.exoplatform.services.command.action.Action;
  21. import org.exoplatform.services.listener.ListenerService;
  22. import org.exoplatform.services.wcm.utils.WCMCoreUtils;

  23. /**
  24.  * Created by The eXo Platform SAS
  25.  * Author : Nguyen The Vinh From ECM Of eXoPlatform
  26.  *          vinh_nguyen@exoplatform.com
  27.  * 14 Jan 2013  
  28.  */
  29. public class RemoveFileActivityAction implements Action{
  30.   private ListenerService listenerService=null;
  31.   private ActivityCommonService activityService = null;
  32.   public RemoveFileActivityAction() {
  33.     listenerService =  WCMCoreUtils.getService(ListenerService.class);
  34.     activityService = WCMCoreUtils.getService(ActivityCommonService.class);
  35.   }
  36.   public boolean execute(Context context) throws Exception {
  37.     if (listenerService ==null) return false;
  38.     Object item = context.get("currentItem");
  39.     if (item instanceof Node) {
  40.       Node node = (Node)item;
  41.       Node parent = node.getParent();
  42.       if (node.getPrimaryNodeType().isNodeType(ActivityCommonService.NT_FILE)) {        
  43.         if (activityService.isAcceptedNode(node) && activityService.isBroadcastNTFileEvents(node)) {
  44.           listenerService.broadcast(ActivityCommonService.FILE_REMOVE_ACTIVITY, parent, node);
  45.         }
  46.       }
  47.     }
  48.     return false;
  49.   }  
  50. }