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.webui.viewer;
18  
19  import javax.jcr.Node;
20  import javax.jcr.PathNotFoundException;
21  
22  import org.exoplatform.ecm.resolver.JCRResourceResolver;
23  import org.exoplatform.ecm.webui.presentation.UIBaseNodePresentation;
24  import org.exoplatform.portal.webui.util.Util;
25  import org.exoplatform.resolver.ResourceResolver;
26  import org.exoplatform.services.cms.impl.DMSConfiguration;
27  import org.exoplatform.services.cms.templates.TemplateService;
28  import org.exoplatform.services.wcm.core.NodeLocation;
29  import org.exoplatform.wcm.webui.Utils;
30  import org.exoplatform.web.application.ApplicationMessage;
31  import org.exoplatform.webui.application.WebuiRequestContext;
32  import org.exoplatform.webui.config.annotation.ComponentConfig;
33  import org.exoplatform.webui.core.UIComponent;
34  import org.exoplatform.webui.core.lifecycle.Lifecycle;
35  
36  /**
37   * Created by The eXo Platform SAS
38   * Author : Phan Le Thanh Chuong
39   *          chuong.phan@exoplatform.com, phan.le.thanh.chuong@gmail.com
40   * Nov 9, 2009
41   */
42  @ComponentConfig(
43    lifecycle = Lifecycle.class
44  )
45  public class UIContentViewer extends UIBaseNodePresentation {
46  
47    public static final String TEMPLATE_NOT_SUPPORT = "UIContentViewer.msg.template-not-support";
48  
49    private NodeLocation originalNodeLocation;
50  
51    private NodeLocation viewNodeLocation;
52  
53    public Node getOriginalNode() {
54      return NodeLocation.getNodeByLocation(originalNodeLocation);
55    }
56  
57    public void setOriginalNode(Node originalNode) throws Exception{
58      originalNodeLocation = NodeLocation.getNodeLocationByNode(originalNode);
59    }
60  
61    public Node getNode() {
62      return NodeLocation.getNodeByLocation(viewNodeLocation);
63    }
64  
65    public void setNode(Node viewNode) {
66      viewNodeLocation = NodeLocation.getNodeLocationByNode(viewNode);
67    }
68  
69    public String getTemplate() {
70      TemplateService templateService = getApplicationComponent(TemplateService.class);
71      String userName = Util.getPortalRequestContext().getRemoteUser() ;
72      try {
73        String nodeType = getOriginalNode().getPrimaryNodeType().getName();
74        if(templateService.isManagedNodeType(nodeType))
75          return templateService.getTemplatePathByUser(false, nodeType, userName) ;
76      } catch (PathNotFoundException e) {
77        Utils.createPopupMessage(this, TEMPLATE_NOT_SUPPORT, null, ApplicationMessage.ERROR);
78      } catch (Exception e) {
79        Utils.createPopupMessage(this, TEMPLATE_NOT_SUPPORT, null, ApplicationMessage.ERROR);
80      }
81      return null ;
82    }
83  
84    public ResourceResolver getTemplateResourceResolver(WebuiRequestContext context, String template) {
85      try {
86        DMSConfiguration dmsConfiguration = getApplicationComponent(DMSConfiguration.class);
87        String workspace = dmsConfiguration.getConfig().getSystemWorkspace();
88        return new JCRResourceResolver(workspace);
89      } catch (Exception e) {
90        return null;
91      }
92    }
93  
94    public String getRepositoryName() {
95      try {
96        return getRepository();
97      }catch (Exception ex) {
98        return null;
99      }
100   }
101 
102   public String getTemplatePath() {
103     return null;
104   }
105 
106   public String getNodeType() {
107     return null;
108   }
109 
110   public boolean isNodeTypeSupported() {
111     return false;
112   }
113 
114   public UIComponent getCommentComponent() {
115     return null;
116   }
117 
118   public UIComponent getRemoveAttach() {
119     return null;
120   }
121 
122   public UIComponent getRemoveComment() {
123     return null;
124   }
125 
126   public UIComponent getUIComponent(String mimeType) throws Exception {
127     return org.exoplatform.ecm.webui.utils.Utils.getUIComponent(mimeType, this);
128   }
129 
130 }