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  package org.exoplatform.wcm.extensions.ui;
18  
19  import java.util.Arrays;
20  import java.util.HashMap;
21  import java.util.List;
22  
23  import javax.jcr.Node;
24  
25  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
26  import org.exoplatform.ecm.webui.component.explorer.control.filter.CanAddNodeFilter;
27  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsCheckedOutFilter;
28  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotEditingDocumentFilter;
29  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotLockedFilter;
30  import org.exoplatform.ecm.webui.component.explorer.control.listener.UIActionBarActionListener;
31  import org.exoplatform.ecm.utils.lock.LockUtil;
32  import org.exoplatform.services.ecm.publication.PublicationService;
33  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
34  import org.exoplatform.webui.config.annotation.ComponentConfig;
35  import org.exoplatform.webui.config.annotation.EventConfig;
36  import org.exoplatform.webui.core.UIComponent;
37  import org.exoplatform.webui.core.UIPopupContainer;
38  import org.exoplatform.webui.event.Event;
39  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
40  import org.exoplatform.webui.ext.filter.UIExtensionFilters;
41  
42  /**
43   * Created by The eXo Platform SAS
44   * Author : eXoPlatform
45   *          benjamin.paillereau@exoplatform.com
46   * 27 june 2010
47   */
48  @ComponentConfig(
49      events = {
50          @EventConfig(listeners = PublicationPublishAction.PublicationPublishActionListener.class)
51      }
52  )
53  public class PublicationPublishAction extends UIComponent {
54  
55    private static final List<UIExtensionFilter> FILTERS = Arrays.asList(
56        new UIExtensionFilter[] {
57            new CanAddNodeFilter(), new IsNotLockedFilter(), new IsCheckedOutFilter(), new CanPublishFilter(), new IsNotEditingDocumentFilter()});
58  
59    @UIExtensionFilters
60    public List<UIExtensionFilter> getFilters() {
61      return FILTERS;
62    }
63    public static class PublicationPublishActionListener extends UIActionBarActionListener<PublicationPublishAction> {
64  
65      @Override
66      protected void processEvent(Event<PublicationPublishAction> event) throws Exception {
67        UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
68        PublicationService publicationService = WCMCoreUtils.getService(PublicationService.class);
69        Node node = uiExplorer.getCurrentNode();
70        if(node.isLocked()) {
71          node.getSession().addLockToken(LockUtil.getLockToken(node));
72        }
73        HashMap<String,String> context = new HashMap<String,String>();
74  
75        publicationService.changeState(node, "published", context);
76  
77        UIPopupContainer UIPopupContainer = uiExplorer.getChild(UIPopupContainer.class);
78        event.getRequestContext().addUIComponentToUpdateByAjax(UIPopupContainer);
79        event.getRequestContext().addUIComponentToUpdateByAjax(uiExplorer);
80  
81      }
82    }
83  }