1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.services.webpage;
18
19 import java.io.OutputStream;
20 import java.io.FileOutputStream;
21 import java.io.FileInputStream;
22 import java.io.IOException;
23 import java.io.FileNotFoundException;
24 import java.util.Properties;
25 import javax.servlet.ServletException;
26
27 import org.apache.log4j.Logger;
28
29
30
31
32
33
34
35
36
37
38 public class Configuration
39 {
40 public static final String WPS_SERVLET = "/wps";
41
42 public static final int STATUS_NOT_CONFIGURED = 0;
43 public static final int STATUS_ONLINE = 1;
44 public static final int STATUS_OFFLINE = -1;
45
46 static Logger log = Logger.getLogger(Configuration.class);
47
48
49 public static final String KEY_WPS_SID = "wps.sid";
50 public static final String WPS_SID = "wpsid";
51 private String sid = WPS_SID;
52
53
54 public static final String KEY_WPS_PATH = "wps.path";
55 public static final String WPS_PATH = "wpspath";
56 private String path = WPS_PATH;
57
58
59 public static final String KEY_WPS_URL = "wps.url";
60 public static final String WPS_URL = "wps.url";
61 private String url = WPS_URL;
62
63
64 public static final String KEY_WPS_DEBUG = "wps.debug";
65 private boolean debug = false;
66
67
68 public static final String KEY_PARSER = "parser.default";
69 public static final String PARSER_SWING = "swing";
70 public static final String PARSER_OPENXML = "openxml";
71 private String parser = PARSER_SWING;
72
73
74 public static final String KEY_LOG_ENABLE = "log.content.enable";
75 private boolean enableContentLog = false;
76
77
78 public static final String KEY_LOG_LOCATION = "log.content.location";
79 public static final String WPS_LOG_LOCATION = "/WEB-INF/logs/wps-content.log";
80 private String logLocation = WPS_LOG_LOCATION;
81
82
83 public static final String KEY_LOG_RESET = "log.content.reset";
84 private boolean resetContentLog = false;
85
86
87 public static final String KEY_WEBAPP = "wps.webapp.name";
88 public static final String WPS_WEBAPP = "/jetspeed";
89 private String webapp = WPS_WEBAPP;
90
91
92 public static final String KEY_LOGIN = "ne.webapp.login";
93 public static final String WPS_LOGIN = "/jetspeed/loginController.php";
94 private String login = WPS_LOGIN;
95
96
97 public static final String KEY_LOGOUT = "ne.webapp.logout";
98 public static final String WPS_LOGOUT = "/jetspeed/logoutController.php";
99 private String logout = WPS_LOGOUT;
100
101
102 public static final String KEY_USER_SESSION = "user.session.key";
103 public static final String WPS_USER_SESSION = "turbine.user";
104 private String userSessionKey = WPS_USER_SESSION;
105
106
107 public static final String KEY_USER_DEFAULT = "user.default";
108 public static final String WPS_USER_DEFAULT = "joe";
109 private String userDefault = WPS_USER_DEFAULT;
110
111
112 public static final String KEY_PARAM_USER = "ne.webapp.param.username";
113 public static final String WPS_PARAM_USER = "da_username";
114 private String paramUser = WPS_PARAM_USER;
115
116
117 public static final String KEY_PARAM_PASSWORD = "webapp.param.password";
118 public static final String WPS_PARAM_PASSWORD = "da_password";
119 private String paramPassword = WPS_PARAM_PASSWORD;
120
121
122 public static final String KEY_PARAM_PERMISSIONS = "webapp.param.permissions";
123 public static final String WPS_PARAM_PERMISSIONS = "serialized_permissions";
124 private String paramPermissions = WPS_PARAM_PERMISSIONS;
125
126
127 public static final String KEY_LOGIN_FAILURE = "webapp.login.failure";
128 public static final String WPS_LOGIN_FAILURE = "LOGIN FAIL";
129 private String loginFailureString = WPS_LOGIN_FAILURE;
130
131
132 public static final String KEY_LOGIN_SUCCESS = "webapp.login.success";
133 public static final String WPS_LOGIN_SUCCESS = "LOGIN SUCCESS";
134 private String loginSuccessString = WPS_LOGIN_SUCCESS;
135
136
137
138 public static final String KEY_CONTENT_INFO = "content.info";
139 public static final String KEY_CONTENT_ERROR = "content.error";
140
141
142 public static final String TRUE_VALUE = "true";
143 public static final String FALSE_VALUE = "false";
144
145
146 private static Configuration instance = null;
147
148
149 private Properties properties;
150
151
152 private String ppath;
153
154
155 public static final String HEADER = "Jetspeed Web Page Service Configuration Properties";
156
157
158
159
160
161
162
163
164 public static Configuration getInstance()
165 {
166 return instance;
167 }
168
169
170
171
172
173
174
175
176 public static Configuration getInitialInstance(String ppath) throws ServletException
177 {
178 if (instance == null)
179 {
180 Properties properties = new Properties();
181
182 try
183 {
184 properties.load(new FileInputStream(ppath));
185 instance = new Configuration(properties, ppath);
186 instance.refresh();
187 }
188 catch (Exception e)
189 {
190 log.debug(e.toString());
191 instance = null;
192 }
193 }
194 return instance;
195 }
196
197
198
199
200
201
202
203
204 private Configuration(Properties properties, String ppath)
205 {
206 this.properties = properties;
207 this.ppath = ppath;
208 }
209
210
211
212
213
214
215
216
217 public String getProperty(String name)
218 {
219 return properties.getProperty(name);
220 }
221
222
223
224
225
226
227
228 public void setProperty(String name, String value)
229 {
230 properties.setProperty(name, value);
231 OutputStream out;
232
233 try
234 {
235 out = new FileOutputStream(ppath);
236 properties.store(out, HEADER);
237 out.close();
238 }
239 catch (FileNotFoundException e)
240 {
241 String error = "Unable to update configuration file " + ppath + e.toString();
242 log.debug(error);
243 }
244 catch (SecurityException e)
245 {
246 String error = "Unable to update configuration file " + ppath + e.toString();
247 log.debug(error);
248 }
249 catch (IOException e)
250 {
251 String error = "Error updating configuration file " + ppath + e.toString();
252 log.debug(error);
253 }
254 out = null;
255 }
256
257
258
259
260
261 public void refresh()
262 {
263 String result = getInstance().getProperty(Configuration.KEY_WPS_DEBUG);
264 if (null == result)
265 {
266 debug = false;
267 }
268 else
269 {
270 debug = (result.equalsIgnoreCase(TRUE_VALUE));
271 }
272
273 sid = getInstance().getProperty(Configuration.KEY_WPS_SID);
274 if (null == sid)
275 {
276 sid = WPS_SID;
277 }
278
279 path = getInstance().getProperty(Configuration.KEY_WPS_PATH);
280 if (null == path)
281 path = WPS_PATH;
282
283 url = getInstance().getProperty(Configuration.KEY_WPS_URL);
284 if (null == url)
285 url = WPS_URL;
286
287 parser = getInstance().getProperty(Configuration.KEY_PARSER);
288 if (null == parser)
289 parser = PARSER_SWING;
290
291 result = getInstance().getProperty(Configuration.KEY_LOG_ENABLE);
292 if (null == result)
293 enableContentLog = false;
294 else
295 enableContentLog = (result.equalsIgnoreCase(TRUE_VALUE));
296
297 logLocation = getInstance().getProperty(Configuration.KEY_LOG_LOCATION);
298 if (null == logLocation)
299 logLocation = WPS_LOG_LOCATION;
300
301 result = getInstance().getProperty(Configuration.KEY_LOG_RESET);
302 if (null == result)
303 resetContentLog = false;
304 else
305 resetContentLog = (result.equalsIgnoreCase(TRUE_VALUE));
306
307 webapp = getInstance().getProperty(Configuration.KEY_WEBAPP);
308 if (null == webapp)
309 webapp = WPS_WEBAPP;
310
311 login = getInstance().getProperty(Configuration.KEY_LOGIN);
312 if (null == login)
313 login = WPS_LOGIN;
314
315 logout = getInstance().getProperty(Configuration.KEY_LOGOUT);
316 if (null == logout)
317 login = WPS_LOGOUT;
318
319 userSessionKey = getInstance().getProperty(Configuration.KEY_USER_SESSION);
320 if (null == userSessionKey)
321 userSessionKey = WPS_USER_SESSION;
322
323 userDefault = getInstance().getProperty(Configuration.KEY_USER_DEFAULT);
324 if (null == userDefault)
325 userDefault = WPS_USER_DEFAULT;
326
327 paramUser = getInstance().getProperty(Configuration.KEY_PARAM_USER);
328 if (null == paramUser)
329 paramUser = WPS_PARAM_USER;
330
331 paramPassword = getInstance().getProperty(Configuration.KEY_PARAM_PASSWORD);
332 if (null == paramPassword)
333 paramPassword = WPS_PARAM_PASSWORD;
334
335 paramPermissions = getInstance().getProperty(Configuration.KEY_PARAM_PERMISSIONS);
336 if (null == paramPermissions)
337 paramPermissions = WPS_PARAM_PERMISSIONS;
338
339 loginFailureString = getInstance().getProperty(Configuration.KEY_LOGIN_FAILURE);
340 if (null == loginFailureString)
341 loginFailureString = WPS_LOGIN_FAILURE;
342
343 loginSuccessString = getInstance().getProperty(Configuration.KEY_LOGIN_SUCCESS);
344 if (null == loginSuccessString)
345 loginSuccessString = WPS_LOGIN_SUCCESS;
346
347 }
348
349
350
351
352
353 public boolean getDebug()
354 {
355 return debug;
356 }
357
358 public String getSID()
359 {
360 return sid;
361 }
362
363 public String getPath()
364 {
365 return path;
366 }
367
368 public String getURL()
369 {
370 return url;
371 }
372
373 public String getParser()
374 {
375 return parser;
376 }
377
378 public boolean getEnableContentLog()
379 {
380 return enableContentLog;
381 }
382
383 public String getLogLocation()
384 {
385 return logLocation;
386 }
387
388 public boolean getResetContentLog()
389 {
390 return resetContentLog;
391 }
392
393 public String getWebapp()
394 {
395 return webapp;
396 }
397
398 public String getLogin()
399 {
400 return login;
401 }
402
403 public String getLogout()
404 {
405 return logout;
406 }
407
408 public String getUserSessionKey()
409 {
410 return userSessionKey;
411 }
412
413 public String getDefaultUser()
414 {
415 return userDefault;
416 }
417
418 public String getParamUser()
419 {
420 return paramUser;
421 }
422
423 public String getParamPassword()
424 {
425 return paramPassword;
426 }
427
428 public String getParamPermissions()
429 {
430 return paramPermissions;
431 }
432
433 public String getLoginFailureString()
434 {
435 return loginFailureString;
436 }
437
438 public String getLoginSuccessString()
439 {
440 return loginSuccessString;
441 }
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457 public static String createProxyString(String proxyHost,
458 String neid,
459 String resource,
460 String relativePath)
461 {
462 String base = WebPageHelper.concatURLs(proxyHost, WPS_SERVLET);
463 StringBuffer buffer = new StringBuffer(base);
464
465
466
467
468
469
470
471 buffer.append("?");
472 buffer.append(getInstance().getSID());
473 buffer.append("=");
474 buffer.append(neid);
475 buffer.append("&");
476 buffer.append(getInstance().getPath());
477 buffer.append("=");
478
479
480
481
482
483
484
485
486 if (null != relativePath && !resource.startsWith("/"))
487 {
488
489 buffer.append(relativePath);
490 }
491
492 buffer.append(resource.replace('&', '@'));
493 String proxiedPath = buffer.toString();
494 return proxiedPath;
495 }
496 }