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  
25  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
26  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsDocumentFilter;
27  import org.exoplatform.ecm.webui.component.explorer.control.filter.IsNotInTrashFilter;
28  import org.exoplatform.portal.application.PortalRequestContext;
29  import org.exoplatform.portal.webui.util.Util;
30  import org.exoplatform.web.url.navigation.NavigationResource;
31  import org.exoplatform.web.url.navigation.NodeURL;
32  import org.exoplatform.webui.config.annotation.ComponentConfig;
33  import org.exoplatform.webui.core.lifecycle.UIContainerLifecycle;
34  import org.exoplatform.webui.ext.filter.UIExtensionFilter;
35  import org.exoplatform.webui.ext.filter.UIExtensionFilters;
36  import org.exoplatform.webui.ext.manager.UIAbstractManager;
37  import org.exoplatform.webui.ext.manager.UIAbstractManagerComponent;
38  
39  /**
40   * Created by The eXo Platform SARL Author : Hoang Van Hung hunghvit@gmail.com
41   * Aug 6, 2009
42   */
43  
44  @ComponentConfig(
45      lifecycle = UIContainerLifecycle.class
46  )
47  public class PermlinkActionComponent extends UIAbstractManagerComponent {
48  
49    private static final List<UIExtensionFilter> FILTERS = Arrays.asList(new UIExtensionFilter[] {
50        new IsNotInTrashFilter(), new IsDocumentFilter() });
51  
52    @UIExtensionFilters
53    public List<UIExtensionFilter> getFilters() {
54      return FILTERS;
55    }
56    
57    public String getPermlink(UIJCRExplorer uiExplorer, Node node) throws Exception {
58      if (uiExplorer == null) {
59        uiExplorer = getAncestorOfType(UIJCRExplorer.class);
60      }
61      if (node == null) {
62        node = uiExplorer.getCurrentNode();
63      }
64      PortalRequestContext pcontext = Util.getPortalRequestContext();
65      String portletId = pcontext.getNodePath();
66      String drivename = uiExplorer.getDriveData().getName();
67      String nodePath = node.getPath().replaceAll("/+", "/");
68      
69      String path = new StringBuilder().append(drivename)
70                                          .append(nodePath)
71                                          .toString();
72      NodeURL nodeURL = Util.getPortalRequestContext().createURL(NodeURL.TYPE);
73      NavigationResource resource = new NavigationResource(pcontext.getSiteType(), pcontext.getSiteName(), portletId);
74      nodeURL.setResource(resource);
75      nodeURL.setQueryParameterValue("path", path);
76      return nodeURL.toString();
77    }
78  
79    public String getPermlink(UIJCRExplorer uiExplorer) throws Exception {
80      return getPermlink(uiExplorer, null);
81    }
82    
83    public String getPermlink(Node node) throws Exception {
84      return getPermlink(null, node);
85    }
86  
87    public String getPermlink() throws Exception {
88      return getPermlink(null, null);
89    }
90  
91  
92    @Override
93    public Class<? extends UIAbstractManager> getUIAbstractManagerClass() {
94      return null;
95    }
96  
97  }