1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.util;
16  
17  import com.liferay.portal.kernel.configuration.Filter;
18  import com.liferay.portal.kernel.util.GetterUtil;
19  import com.liferay.portal.kernel.util.PropsKeys;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.kernel.util.StringUtil;
22  import com.liferay.portal.model.Layout;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  /**
28   * <a href="LayoutSettings.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Shuyang Zhou
31   * @author Brian Wing Shun Chan
32   */
33  public class LayoutSettings {
34  
35      public static LayoutSettings getInstance(Layout layout) {
36          return getInstance(layout.getType());
37      }
38  
39      public static LayoutSettings getInstance(String type) {
40          return _layoutSettingsMap.get(type);
41      }
42  
43      public String[] getConfigurationActionDelete() {
44          return _configurationActionDelete;
45      }
46  
47      public String[] getConfigurationActionUpdate() {
48          return _configurationActionUpdate;
49      }
50  
51      public String getEditPage() {
52          return _editPage;
53      }
54  
55      public String getType() {
56          return _type;
57      }
58  
59      public String getURL() {
60          return _url;
61      }
62  
63      public String getURL(Map<String, String> variables) {
64          return StringUtil.replace(
65              _url, StringPool.DOLLAR_AND_OPEN_CURLY_BRACE,
66              StringPool.CLOSE_CURLY_BRACE, variables);
67      }
68  
69      public String getViewPage() {
70          return _viewPage;
71      }
72  
73      public boolean isFirstPageable() {
74          return _firstPageable;
75      }
76  
77      public boolean isParentable() {
78          return _parentable;
79      }
80  
81      public boolean isSitemapable() {
82          return _sitemapable;
83      }
84  
85      public boolean isURLFriendliable() {
86          return _urlFriendliable;
87      }
88  
89      private LayoutSettings(String type) {
90          _type = type;
91  
92          Filter filter = new Filter(type);
93  
94          _configurationActionDelete = StringUtil.split(
95              GetterUtil.getString(
96                  PropsUtil.get(
97                      PropsKeys.LAYOUT_CONFIGURATION_ACTION_DELETE, filter)));
98          _configurationActionUpdate = StringUtil.split(
99              GetterUtil.getString(
100                 PropsUtil.get(
101                     PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, filter)));
102         _editPage = GetterUtil.getString(
103             PropsUtil.get(PropsKeys.LAYOUT_EDIT_PAGE, filter));
104         _firstPageable = GetterUtil.getBoolean(
105             PropsUtil.get(PropsKeys.LAYOUT_FIRST_PAGEABLE, filter));
106         _parentable = GetterUtil.getBoolean(
107             PropsUtil.get(PropsKeys.LAYOUT_PARENTABLE, filter), true);
108         _sitemapable = GetterUtil.getBoolean(
109             PropsUtil.get(PropsKeys.LAYOUT_SITEMAPABLE, filter), true);
110         _url = GetterUtil.getString(
111             PropsUtil.get(PropsKeys.LAYOUT_URL, filter));
112         _urlFriendliable = GetterUtil.getBoolean(
113             PropsUtil.get(PropsKeys.LAYOUT_URL_FRIENDLIABLE, filter), true);
114         _viewPage = GetterUtil.getString(
115             PropsUtil.get(PropsKeys.LAYOUT_VIEW_PAGE, filter));
116 
117         _layoutSettingsMap.put(type, this);
118     }
119 
120     private static Map<String, LayoutSettings> _layoutSettingsMap =
121         new HashMap<String, LayoutSettings>();
122 
123     static {
124         new LayoutSettings("control_panel");
125 
126         for (String type : PropsValues.LAYOUT_TYPES) {
127             new LayoutSettings(type);
128         }
129     }
130 
131     private String[] _configurationActionDelete;
132     private String[] _configurationActionUpdate;
133     private String _editPage;
134     private boolean _firstPageable;
135     private boolean _parentable;
136     private boolean _sitemapable;
137     private String _type;
138     private String _url;
139     private boolean _urlFriendliable;
140     private String _viewPage;
141 
142 }