1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.system;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.seasar.tuigwaa.security.Action;
22 import org.seasar.tuigwaa.security.SecurityUtils;
23 import org.seasar.tuigwaa.util.MimeMappings;
24 import org.seasar.tuigwaa.util.TgwContext;
25 import org.seasar.tuigwaa.util.TgwResource;
26
27
28 /***
29 * @author nishioka
30 */
31 public class SiteConfig {
32
33 public static final int PAGEEDIT_WIKI = 0;
34
35 public static final int PAGEEDIT_HTML = 1;
36
37 private String name;
38
39 private String description;
40
41 private String stylesheet;
42
43 private String roles;
44
45 private String title;
46
47 private String initPagename;
48
49 private String menuPagename;
50
51 private String rightPagename;
52
53 private Map actionRolesMap = new HashMap();
54
55 private boolean useBaseDatabase = true;
56
57 private String dbName;
58
59 private String dbSchema;
60
61 private String logoPath = TgwResource.getProperty("system.default.logofile");
62
63 private boolean easyMode;
64
65 private int pageEditMode;
66
67 private String skin;
68
69 public String getTitle() {
70 return title;
71 }
72
73 public void setTitle(String title) {
74 this.title = title;
75 }
76
77 public String getDescription() {
78 return description;
79 }
80
81 public void setDescription(String description) {
82 this.description = description;
83 }
84
85 public String getName() {
86 return name;
87 }
88
89 public void setName(String name) {
90 this.name = name;
91 }
92
93 public String getStylesheet() {
94 return stylesheet;
95 }
96
97 public void setStylesheet(String stylesheet) {
98 this.stylesheet = stylesheet;
99 }
100
101 public String getRoles() {
102 return roles;
103 }
104
105 public void setRoles(String roles) {
106 this.roles = roles;
107 this.roleNames = SecurityUtils.splitRoleNames(roles);
108 }
109
110 public Map getActionRolesMap() {
111 return actionRolesMap;
112 }
113
114 public void putActionRoles(String actionName, String roles) {
115 actionRolesMap.put(actionName, roles);
116 }
117
118 public void putActionRoles(Action action, String roles) {
119 actionRolesMap.put(action.getActionName(), roles);
120 }
121
122 public String[] getRoleNames(Action action) {
123 String roles = (String) actionRolesMap.get(action.getActionName());
124 if (roles == null) {
125 return new String[0];
126 }
127 return roles.split(",");
128 }
129
130 private String[] roleNames;
131
132 public String[] getRoleNames() {
133 return roleNames;
134 }
135
136 public boolean isDbViewFlag() {
137 return isAccessFlag(Action.DB_VIEW);
138 }
139
140 public boolean isDbManageFlag() {
141 return isAccessFlag(Action.DB_MANAGE);
142 }
143
144 public boolean isPageViewFlag() {
145 return isAccessFlag(Action.PAGE_VIEW);
146 }
147
148 public boolean isPageManageFlag() {
149 return isAccessFlag(Action.PAGE_MANAGE);
150 }
151
152 public boolean isSiteManageFlag() {
153 return isAccessFlag(Action.SITE_MANAGE);
154 }
155
156 public boolean isLogicViewFlag() {
157 return isAccessFlag(Action.LOGIC_VIEW);
158 }
159
160 public boolean isLogicManageFlag() {
161 return isAccessFlag(Action.LOGIC_MANAGE);
162 }
163
164 private boolean isAccessFlag(Action action) {
165 String[] roleNames = getRoleNames(action);
166 if (roleNames == null || roleNames.length < 1) {
167 return true;
168 }
169 for (int i = 0; i < roleNames.length; i++) {
170 if (TgwContext.isUserInRole(roleNames[i])) {
171 return true;
172 }
173 }
174 return false;
175 }
176
177 public String getInitPagename() {
178 return initPagename;
179 }
180
181 public void setInitPagename(String initPagename) {
182 this.initPagename = initPagename;
183 }
184
185 public String getMenuPagename() {
186 return menuPagename;
187 }
188
189 public void setMenuPagename(String menuPagename) {
190 this.menuPagename = menuPagename;
191 }
192
193 public String getRightPagename() {
194 return rightPagename;
195 }
196
197 public void setRightPagename(String rightPagename) {
198 this.rightPagename = rightPagename;
199 }
200
201 public boolean isUseBaseDatabase() {
202 return useBaseDatabase;
203 }
204
205 public void setUseBaseDatabase(boolean useBaseDatabase) {
206 this.useBaseDatabase = useBaseDatabase;
207 }
208
209 public void setDbName(String dbName) {
210 this.dbName = dbName;
211 }
212
213 public void setDbSchema(String dbSchema) {
214 this.dbSchema = dbSchema;
215 }
216
217 public String getDbName() {
218 return dbName;
219 }
220
221 public String getDbSchema() {
222 return dbSchema;
223 }
224
225 public boolean isEasyMode() {
226 return easyMode;
227 }
228
229 public void setEasyMode(boolean easyMode) {
230 this.easyMode = easyMode;
231 }
232
233 public boolean isSecurity() {
234 return getRoles() != null && getRoleNames().length > 0;
235 }
236
237 public String getLogoPath() {
238 return logoPath;
239 }
240
241 public void setLogoPath(String logPath) {
242 this.logoPath = logPath;
243 }
244
245 public int getPageEditMode() {
246 return pageEditMode;
247 }
248
249 public void setPageEditMode(int pageEditMode) {
250 this.pageEditMode = pageEditMode;
251 }
252
253
254 public String defaultContentType(){
255 if (getPageEditMode() == SiteConfig.PAGEEDIT_WIKI) {
256 return MimeMappings.CONTENTTYPE_XWIKI;
257 } else {
258 return MimeMappings.CONTENTTYPE_HTML;
259 }
260 }
261
262 public void copySiteConfig(SiteConfig siteConfig) {
263 this.name = siteConfig.getName();
264 this.title = siteConfig.getTitle();
265 this.description = siteConfig.getDescription();
266 this.roles = siteConfig.getRoles();
267 this.roleNames = siteConfig.getRoleNames();
268 this.logoPath = siteConfig.getLogoPath();
269 this.stylesheet = siteConfig.getStylesheet();
270 this.actionRolesMap = siteConfig.getActionRolesMap();
271 this.easyMode = siteConfig.isEasyMode();
272 this.pageEditMode = siteConfig.getPageEditMode();
273 this.skin = siteConfig.getSkin();
274
275
276
277 }
278
279 public void setSkin(String skin) {
280 this.skin = skin;
281 }
282
283 public String getSkin() {
284 return skin;
285 }
286
287 }