View Javadoc
1   /*
2    * Copyright (C) 2003-2010 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  package org.exoplatform.services.wcm.symlink;
18  
19  import javax.jcr.Node;
20  import javax.jcr.Property;
21  
22  import org.apache.commons.chain.Context;
23  import org.exoplatform.container.xml.PortalContainerInfo;
24  import org.exoplatform.services.cms.CmsService;
25  import org.exoplatform.services.cms.link.LinkManager;
26  import org.exoplatform.services.command.action.Action;
27  import org.exoplatform.services.listener.ListenerService;
28  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
29  
30  /**
31   * Created by The eXo Platform SAS
32   * Author : Phan Le Thanh Chuong
33   *          chuong.phan@exoplatform.com, phan.le.thanh.chuong@gmail.com
34   * Jun 8, 2010
35   */
36  public class CreateLinkAction implements Action{
37  
38    public static final String UPDATE_EVENT = "WCMPublicationService.event.updateState";
39    public static  final String  EXO_SORTABLE = "exo:sortable";
40  
41    public boolean execute(Context context) throws Exception {
42      Property property = (Property)context.get("currentItem");
43      if (!"exo:uuid".equals(property.getName())) return false;
44  
45      Node linkNode = property.getParent();
46      if (!linkNode.isNodeType(EXO_SORTABLE) && !linkNode.canAddMixin(EXO_SORTABLE))
47        return false;
48  
49      PortalContainerInfo containerInfo = WCMCoreUtils.getService(PortalContainerInfo.class);
50      String containerName = containerInfo.getContainerName();
51      LinkManager linkManager = WCMCoreUtils.getService(LinkManager.class, containerName);
52      Node targetNode = linkManager.getTarget(linkNode, true);
53  
54      ListenerService listenerService = WCMCoreUtils.getService(ListenerService.class, containerName);
55      CmsService cmsService = WCMCoreUtils.getService(CmsService.class, containerName);
56  
57      listenerService.broadcast(UPDATE_EVENT, cmsService, targetNode);
58  
59      return true;
60    }
61  
62  }