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.services.cms.views;
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  
23  /**
24   * Created by The eXo Platform SARL
25   * Author : Nguyen Quang Hung
26   *          nguyenkequanghung@yahoo.com
27   * Feb 27, 2006
28   */
29  public class ViewConfig {
30    private String name ;
31    private String permissions ;
32    private String template ;
33    private boolean hideExplorerPanel = false;
34    private List<Tab> tabList = new ArrayList<Tab>() ;
35  
36    public  ViewConfig() { }
37  
38    public String getName() { return this.name ; }
39    public void setName(String name) { this.name = name ; }
40  
41    public String getPermissions() { return this.permissions ; }
42    public void setPermissions(String permission) { this.permissions = permission ; }
43  
44    public String getTemplate() { return this.template ; }
45    public void setTemplate(String templ) { this.template = templ ; }
46  
47    public List<Tab> getTabList() { return this.tabList ; }
48    public void setTabList(List<Tab> tabs) { this.tabList = tabs ; }
49    
50    public boolean isHideExplorerPanel() { return hideExplorerPanel; }
51    public void setHideExplorerPanel(boolean value) { this.hideExplorerPanel = value; }  
52  
53    public List<String> getAllPermissions() {
54      String[] allPermissions = StringUtils.split(permissions, ";");
55      List<String> permissionList = new ArrayList<String>() ;
56      for(int i = 0 ; i < allPermissions.length ; i ++ ){
57        permissionList.add(allPermissions[i].trim()) ;
58      }
59      return permissionList ;
60    }
61  
62    public boolean hasPermission(String permission) {
63      List<String> allPermissions = getAllPermissions() ;
64      if(permission == null) return false ;
65      String[] array = StringUtils.split(permission , ":/") ;
66      if(array == null || array.length < 2) return false ;
67      int i = allPermissions.indexOf("*:/"+array[1]) ;
68      if( i > -1) return true ;
69      return allPermissions.contains(permission) ;
70    }
71  
72    public static class Tab {
73      
74      private String tabName ;
75      private String buttons ;
76      private String localizeButtons;
77  
78      public Tab() {}
79  
80      public String getTabName(){ return this.tabName ; }
81      public void setTabName( String name) { this.tabName = name ; }
82  
83      public String getButtons() { return this.buttons ; }
84      public void setButtons( String buttons) { this.buttons = buttons ; }
85      
86      public String getLocalizeButtons() { return this.localizeButtons ; }
87      public void setLocalizeButtons(String buttons) { this.localizeButtons = buttons ; }    
88  
89    }
90  }