View Javadoc
1   /**
2    * Copyright (C) 2009 eXo Platform SAS.
3    *
4    * This is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU Lesser General Public License as
6    * published by the Free Software Foundation; either version 2.1 of
7    * the License, or (at your option) any later version.
8    *
9    * This software 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 GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this software; if not, write to the Free
16   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
18   */
19  
20  package org.exoplatform.wcm.webui.toolbar;
21  
22  import org.exoplatform.portal.mop.user.UserNavigation;
23  import org.exoplatform.wcm.webui.Utils;
24  import org.exoplatform.webui.application.WebuiApplication;
25  import org.exoplatform.webui.application.WebuiRequestContext;
26  import org.exoplatform.webui.config.annotation.ComponentConfig;
27  import org.exoplatform.webui.core.UIPortletApplication;
28  import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
29  
30  @ComponentConfig(lifecycle = UIApplicationLifecycle.class, template = "app:/groovy/Toolbar/UIAdminToolbarPortlet.gtmpl")
31  public class UIAdminToolbarPortlet extends UIPortletApplication
32  {
33     // Minh Hoang TO
34     // TODO: Add a ThreadLocal cache to avoid double invocation of editPermission
35     // check ( one in processRender method, and one in Groovy template )
36  
37     public UIAdminToolbarPortlet() throws Exception
38     {
39     }
40  
41     public UserNavigation getSelectedNavigation() throws Exception {
42       return Utils.getSelectedNavigation();
43     }
44  
45     public boolean hasEditPermissionOnPortal() throws Exception {
46       return Utils.hasEditPermissionOnPortal();
47     }
48  
49     public boolean hasEditPermissionOnNavigation() throws Exception {
50       return Utils.hasEditPermissionOnNavigation();
51     }
52  
53     public boolean hasEditPermissionOnPage() throws Exception {
54       return Utils.hasEditPermissionOnPage();
55     }
56  
57  
58     @Override
59     public void processRender(WebuiApplication app, WebuiRequestContext context) throws Exception
60     {
61        // A user could view the toolbar portlet iff he/she has edit permission
62        // either on
63        // 'active' page, 'active' portal or 'active' navigation
64        if (hasEditPermissionOnNavigation() || hasEditPermissionOnPage() || hasEditPermissionOnPortal())
65        {
66           super.processRender(app, context);
67        }
68     }
69  
70  
71  }