View Javadoc
1   /*
2    * Copyright (C) 2003-2007 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.ecm.webui.component.explorer.popup.admin;
18  
19  import javax.jcr.Node;
20  
21  import org.exoplatform.container.xml.PortalContainerInfo;
22  import org.exoplatform.ecm.webui.component.explorer.UIJCRExplorer;
23  import org.exoplatform.portal.webui.util.Util;
24  import org.exoplatform.resolver.ResourceResolver;
25  import org.exoplatform.services.cms.templates.TemplateService;
26  import org.exoplatform.services.wcm.core.NodeLocation;
27  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
28  import org.exoplatform.webui.application.WebuiRequestContext;
29  import org.exoplatform.webui.config.annotation.ComponentConfig;
30  import org.exoplatform.webui.core.UIContainer;
31  
32  /**
33   * Created by The eXo Platform SARL
34   * Author : Pham Tuan
35   *          phamtuanchip@yahoo.de
36   * Nov 15, 2006 10:08:29 AM
37   */
38  
39  @ComponentConfig()
40  
41  public class UIActionViewTemplate extends UIContainer {
42  
43    private String documentType_ ;
44    private NodeLocation node_ ;
45  
46    public void setTemplateNode(Node node) throws Exception {
47      node_ = NodeLocation.getNodeLocationByNode(node);
48      documentType_ = node.getPrimaryNodeType().getName() ;
49    }
50  
51    public String getViewTemplatePath(){
52      TemplateService templateService = getApplicationComponent(TemplateService.class) ;
53      String userName = Util.getPortalRequestContext().getRemoteUser() ;
54      try {
55        return templateService.getTemplatePathByUser(false, documentType_, userName) ;
56      } catch (Exception e) {
57        return null ;
58      }
59    }
60  
61    public String getPortalName() {
62      PortalContainerInfo containerInfo = WCMCoreUtils.getService(PortalContainerInfo.class) ;
63      return containerInfo.getContainerName() ;
64    }
65  
66    public String getWorkspaceName() throws Exception {
67      return NodeLocation.getNodeByLocation(node_).getSession().getWorkspace().getName() ;
68    }
69  
70    public String getTemplate() { return getViewTemplatePath() ;}
71  
72    public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) {
73      return getAncestorOfType(UIJCRExplorer.class).getJCRTemplateResourceResolver() ;
74    }
75  
76    public Node getNode() {
77      return NodeLocation.getNodeByLocation(node_);
78    }
79  }