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.admin;
18  
19  import javax.jcr.RepositoryException;
20  import javax.portlet.PortletPreferences;
21  import javax.portlet.PortletRequest;
22  
23  import org.exoplatform.ecm.webui.component.admin.unlock.UIUnLockManager;
24  import org.exoplatform.ecm.webui.utils.Utils;
25  import org.exoplatform.services.cms.impl.DMSConfiguration;
26  import org.exoplatform.services.cms.impl.DMSRepositoryConfiguration;
27  import org.exoplatform.services.jcr.RepositoryService;
28  import org.exoplatform.services.jcr.core.ManageableRepository;
29  import org.exoplatform.services.log.ExoLogger;
30  import org.exoplatform.services.log.Log;
31  import org.exoplatform.services.wcm.utils.WCMCoreUtils;
32  import org.exoplatform.webui.application.WebuiApplication;
33  import org.exoplatform.webui.application.WebuiRequestContext;
34  import org.exoplatform.webui.application.portlet.PortletRequestContext;
35  import org.exoplatform.webui.config.annotation.ComponentConfig;
36  import org.exoplatform.webui.config.annotation.EventConfig;
37  import org.exoplatform.webui.core.UIPopupContainer;
38  import org.exoplatform.webui.core.UIPopupWindow;
39  import org.exoplatform.webui.core.UIPortletApplication;
40  import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
41  import org.exoplatform.webui.event.Event;
42  import org.exoplatform.webui.event.EventListener;
43  
44  /**
45   * Created by The eXo Platform SARL
46   * Author : Tran The Trong
47   *          trongtt@exoplatform.com
48   * Jul 27, 2006
49   */
50  @ComponentConfig(
51      lifecycle = UIApplicationLifecycle.class,
52      template = "app:/groovy/webui/component/admin/UIECMAdminPortlet.gtmpl",
53      events = { @EventConfig(listeners = UIECMAdminPortlet.ShowHideActionListener.class)}
54  )
55  public class UIECMAdminPortlet extends UIPortletApplication {
56  
57    /**
58     * Logger.
59     */
60    private static final Log LOG  = ExoLogger.getLogger(UIECMAdminPortlet.class.getName());
61  
62    private boolean isShowSideBar = true ;
63    private boolean isSelectedRepo_ = true ;
64    private String repoName_ = "" ;
65  
66    public UIECMAdminPortlet() throws Exception {
67      UIPopupContainer uiPopupAction = addChild(UIPopupContainer.class, null, "UIECMAdminUIPopupAction");
68      uiPopupAction.getChild(UIPopupWindow.class).setId("UIECMAdminUIPopupWindow") ;
69      try{
70        UIECMAdminControlPanel controlPanel = addChild(UIECMAdminControlPanel.class, null, null) ;
71        controlPanel.initialize();
72        UIECMAdminWorkingArea workingArea = addChild(UIECMAdminWorkingArea.class, null, null);
73        workingArea.init();
74      } catch(Exception e) {
75        if (LOG.isErrorEnabled()) {
76          LOG.error("An expected error occured while initializing the portlet", e);
77        }
78      }
79    }
80  
81    public void initChilds() throws Exception{
82      UIECMAdminControlPanel controlPanel = getChild(UIECMAdminControlPanel.class);
83      if(controlPanel == null) {
84        controlPanel = addChild(UIECMAdminControlPanel.class, null, null) ;
85        controlPanel.initialize();
86      }
87  
88      UIECMAdminWorkingArea workingArea = getChild(UIECMAdminWorkingArea.class) ;
89      if(workingArea == null){
90        workingArea = addChild(UIECMAdminWorkingArea.class, null, null) ;
91      }
92      workingArea.init() ;
93    }
94  
95    public String getUserAgent() {
96      PortletRequestContext requestContext = PortletRequestContext.getCurrentInstance();
97      PortletRequest portletRequest = requestContext.getRequest();
98      return portletRequest.getProperty("User-Agent");
99    }
100 
101   public ManageableRepository getRepository() throws Exception {
102     RepositoryService rservice = getApplicationComponent(RepositoryService.class) ;
103     return rservice.getCurrentRepository();
104   }
105 
106   public boolean isShowSideBar() { return isShowSideBar ; }
107   public void setShowSideBar(boolean bl) { this.isShowSideBar = bl ; }
108 
109   public boolean isSelectedRepo() { return isSelectedRepo_ ; }
110   public void setSelectedRepo(boolean bl) { this.isSelectedRepo_ = bl ; }
111 
112   public String getRepoName() {return repoName_ ;}
113   public void setRepoName(String name){repoName_ = name ;}
114 
115   static public class ShowHideActionListener extends EventListener<UIECMAdminPortlet> {
116     public void execute(Event<UIECMAdminPortlet> event) throws Exception {
117       UIECMAdminPortlet uiECMAdminPortlet = event.getSource() ;
118       uiECMAdminPortlet.setShowSideBar(!uiECMAdminPortlet.isShowSideBar) ;
119     }
120   }
121 
122   public String getPreferenceRepository() {
123     try {
124       return getApplicationComponent(RepositoryService.class).getCurrentRepository().getConfiguration().getName();
125     } catch (RepositoryException e) {
126       return null;
127     }
128   }
129 
130   public String getPreferenceWorkspace() {
131     PortletPreferences portletPref = getPortletPreferences() ;
132     String workspace = portletPref.getValue(Utils.WORKSPACE_NAME, "") ;
133     return workspace ;
134   }
135 
136   public PortletPreferences getPortletPreferences() {
137     PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance() ;
138     PortletRequest prequest = pcontext.getRequest() ;
139     PortletPreferences portletPref = prequest.getPreferences() ;
140     return portletPref ;
141   }
142 
143   public void  processRender(WebuiApplication app, WebuiRequestContext context) throws Exception {
144     UIECMAdminWorkingArea uiecmAdminWorkingArea = getChild(UIECMAdminWorkingArea.class);
145     UIUnLockManager uiUnLockManager = uiecmAdminWorkingArea.getChild(UIUnLockManager.class);
146     if (uiUnLockManager != null && uiUnLockManager.isRendered()) {
147       uiUnLockManager.update();
148     }
149     super.processRender(app, context);
150   }
151 
152   public String getDMSSystemWorkspace(String repository) throws Exception {
153     DMSConfiguration dmsConfiguration = WCMCoreUtils.getService(DMSConfiguration.class);
154 
155     DMSRepositoryConfiguration dmsRepoConfig = dmsConfiguration.getConfig();
156     return dmsRepoConfig.getSystemWorkspace();
157   }
158 
159 }