001: package org.enhydra.server;
002:
003: import org.enhydra.util.ConfigFileInterface;
004:
005: import com.lutris.util.Config;
006: import com.lutris.util.ConfigException;
007: import com.lutris.util.KeywordValueException;
008:
009: /**
010: * <p>Title: </p>
011: * <p>Description: </p>
012: * <p>Copyright: Copyright (c) 2002</p>
013: * <p>Company: www.together.at</p>
014: * @author tufeX tufex@uns.ns.ac.yu
015: * @version 1.1
016: */
017:
018: public class SessionEdit {
019:
020: private String sessionLifetimeMax;
021: private String sessionIdleTimeMax;
022: private String sessionNoUserIdleTimeMax;
023: private String idleScanInterval;
024: private String randomizerIntervals[];
025: private String memoryPersistence;
026: private String mode;
027: private String maxSessions;
028: private String pageThreshold;
029: private String pageTimeThreshold;
030: private String pageWait;
031: private String saveOnRestart;
032: private String pageDir;
033: private String databaseName;
034: private String dBTableName;
035: private String sessionHomeClass;
036: private String sessionUserTableClass;
037:
038: private String sessionEncodeUrlState;
039: private String sessionEncodeFirstUrl;
040: //Default values
041:
042: private String sessionLifetimeMaxDefault = "0";
043: private String sessionIdleTimeMaxDefault = "30";
044: private String sessionNoUserIdleTimeMaxDefault = "30";
045: private String idleScanIntervalDefault = "30";
046: private String randomizerIntervalsDefault[] = { "301", "1001",
047: "5003" };
048: private String memoryPersistenceDefault = "false";
049: private String modeDefault = "BASIC";
050: private String maxSessionsDefault = "-1";
051: private String pageThresholdDefault = "-1";
052: // private String pageTimeThresholdDefault = "-1";
053: private String pageWaitDefault = "60000";
054: private String saveOnRestartDefault = "false";
055: private String pageDirDefault = "";
056: private String databaseNameDefault = "";
057: private String dBTableNameDefault = "PersistentSession";
058: private String sessionHomeClassDefault = "";
059: private String sessionUserTableClassDefault = "";
060:
061: private String sessionEncodeUrlStateDefault = "Auto";
062: private String sessionEncodeFirstUrlDefault = "false";
063:
064: Config config;
065:
066: private SessionEdit() {
067: }
068:
069: /**
070: * One and only constructor, fill SessionManager parameters from application
071: * config file (or set default value if parameter doesn't exist).
072: * @param appConfig application Config
073: * @throws ConfigException
074: * @throws KeywordValueException
075: */
076: public SessionEdit(Config appConfig) throws ConfigException,
077: KeywordValueException {
078: config = appConfig;
079: String temp;
080: if (config == null)
081: throw new ConfigException(
082: "Exception in SessionEdit(), config == null");
083: //SessionManager.*
084: if (config.containsKey("SessionManager.Lifetime")) { // backwards compatibility
085: setSessionLifetimeMax(config
086: .getString("SessionManager.Lifetime")); //set new parameter
087: config.remove("SessionManager.Lifetime"); //remove old parameter
088: } else
089: sessionLifetimeMax = config.getString(
090: "SessionManager.SessionLifetimeMax",
091: sessionLifetimeMaxDefault);
092:
093: if (config.containsKey("SessionManager.MaxIdleTime")) { // backwards compatibility
094: setSessionIdleTimeMax(config
095: .getString("SessionManager.MaxIdleTime")); //set new parameter
096: config.remove("SessionManager.MaxIdleTime"); //remove old parameter
097: } else
098: sessionIdleTimeMax = config.getString(
099: "SessionManager.SessionIdleTimeMax",
100: sessionIdleTimeMaxDefault);
101:
102: if (config.containsKey("SessionManager.MaxNoUserIdleTime")) { // backwards compatibility
103: setSessionNoUserIdleTimeMax(config
104: .getString("SessionManager.MaxNoUserIdleTime")); //set new parameter
105: config.remove("SessionManager.MaxNoUserIdleTime"); //remove old parameter
106: } else
107: sessionNoUserIdleTimeMax = config.getString(
108: "SessionManager.SessionNoUserIdleTimeMax",
109: sessionNoUserIdleTimeMaxDefault);
110:
111: idleScanInterval = config.getString(
112: "SessionManager.IdleScanInterval",
113: idleScanIntervalDefault);
114:
115: randomizerIntervals = config.getStrings(
116: "SessionManager.RandomizerIntervals",
117: randomizerIntervalsDefault);
118: memoryPersistence = config.getString(
119: "SessionManager.MemoryPersistence",
120: memoryPersistenceDefault);
121:
122: if (config.containsKey("SessionManager.EncodeUrlState")) { // backwards compatibility
123: setSessionEncodeUrlState(config
124: .getString("SessionManager.EncodeUrlState")); //set new parameter
125: config.remove("SessionManager.EncodeUrlState"); //remove old parameter
126: } else
127: sessionEncodeUrlState = config.getString(
128: "SessionManager.SessionEncodeUrlState",
129: sessionEncodeUrlStateDefault);
130:
131: sessionEncodeFirstUrl = config.getString(
132: "SessionManager.SessionEncodeFirstUrl",
133: sessionEncodeFirstUrlDefault);
134:
135: //SessionManager.SessionHome.*
136: mode = config.getString("SessionManager.SessionHome.Mode",
137: modeDefault);
138: maxSessions = config.getString(
139: "SessionManager.SessionHome.MaxSessions",
140: maxSessionsDefault);
141: pageThreshold = config.getString(
142: "SessionManager.SessionHome.PageThreshold",
143: pageThresholdDefault);
144: pageTimeThreshold = config.getString(
145: "SessionManager.SessionHome.PageTimeThreshold",
146: pageTimeThreshold);
147: pageWait = config.getString(
148: "SessionManager.SessionHome.PageWait", pageWaitDefault);
149: saveOnRestart = config.getString(
150: "SessionManager.SessionHome.SaveOnRestart",
151: saveOnRestartDefault);
152: pageDir = config.getString(
153: "SessionManager.SessionHome.PageDir", pageDirDefault);
154: databaseName = config.getString(
155: "SessionManager.SessionHome.DatabaseName",
156: databaseNameDefault);
157: dBTableName = config.getString(
158: "SessionManager.SessionHome.DBTableName",
159: dBTableNameDefault);
160:
161: sessionHomeClass = config.getString(
162: "SessionManager.SessionHome.Class",
163: sessionHomeClassDefault);
164: sessionUserTableClass = config.getString(
165: "SessionManager.SessionUserTable.Class",
166: sessionUserTableClassDefault);
167:
168: }
169:
170: public String getSessionLifetimeMax() {
171: return sessionLifetimeMax;
172: }
173:
174: public void setSessionLifetimeMax(String lifetimeMax)
175: throws KeywordValueException {
176: this .sessionLifetimeMax = lifetimeMax;
177: config.set("SessionManager.SessionLifetimeMax", lifetimeMax);
178: }
179:
180: public String getSessionIdleTimeMax() {
181: return sessionIdleTimeMax;
182: }
183:
184: public void setSessionIdleTimeMax(String idleTimeMax)
185: throws KeywordValueException {
186: this .sessionIdleTimeMax = idleTimeMax;
187: config.set("SessionManager.SessionIdleTimeMax", idleTimeMax);
188: }
189:
190: public String getSessionNoUserIdleTimeMax() {
191: return sessionNoUserIdleTimeMax;
192: }
193:
194: public void setSessionNoUserIdleTimeMax(String noUserIdleTimeMax)
195: throws KeywordValueException {
196: this .sessionNoUserIdleTimeMax = noUserIdleTimeMax;
197: config.set("SessionManager.SessionNoUserIdleTimeMax",
198: noUserIdleTimeMax);
199: }
200:
201: public String getIdleScanInterval() {
202: return idleScanInterval;
203: }
204:
205: public void setIdleScanInterval(String idleScanInterval)
206: throws KeywordValueException {
207: this .idleScanInterval = idleScanInterval;
208: config.set("SessionManager.IdleScanInterval", idleScanInterval);
209: }
210:
211: public String[] getRandomizerIntervals() {
212: return randomizerIntervals;
213: }
214:
215: public void setRandomizerIntervals(String[] randomizerIntervals)
216: throws KeywordValueException {
217: this .randomizerIntervals = randomizerIntervals;
218: config.set("SessionManager.RandomizerIntervals",
219: randomizerIntervals);
220: }
221:
222: public String getMemoryPersistence() {
223: return memoryPersistence;
224: }
225:
226: public void setMemoryPersistence(String memoryPersistence)
227: throws KeywordValueException {
228: this .memoryPersistence = memoryPersistence;
229: config.set("SessionManager.MemoryPersistence",
230: memoryPersistence);
231: }
232:
233: public String getSessionEncodeUrlState() {
234: return sessionEncodeUrlState;
235: }
236:
237: public void setSessionEncodeUrlState(String sessionEncodeUrlState)
238: throws KeywordValueException {
239: this .sessionEncodeUrlState = sessionEncodeUrlState;
240: config.set("SessionManager.SessionEncodeUrlState",
241: sessionEncodeUrlState);
242: }
243:
244: public String getSessionEncodeFirstUrl() {
245: return sessionEncodeFirstUrl;
246: }
247:
248: public void setSessionEncodeFirstUrl(String sessionEncodeFirstUrl)
249: throws KeywordValueException {
250: this .sessionEncodeFirstUrl = sessionEncodeFirstUrl;
251: config.set("SessionManager.SessionEncodeFirstUrl",
252: sessionEncodeFirstUrl);
253: }
254:
255: public String getMode() {
256: return mode;
257: }
258:
259: public void setMode(String mode) throws KeywordValueException {
260: this .mode = mode;
261: config.set("SessionManager.SessionHome.Mode", mode);
262: }
263:
264: public String getMaxSessions() {
265: return maxSessions;
266: }
267:
268: public void setMaxSessions(String maxSessions)
269: throws KeywordValueException {
270: this .maxSessions = maxSessions;
271: config.set("SessionManager.SessionHome.MaxSessions",
272: maxSessions);
273: }
274:
275: public String getPageThreshold() {
276: return pageThreshold;
277: }
278:
279: public void setPageThreshold(String pageThreshold)
280: throws KeywordValueException {
281: this .pageThreshold = pageThreshold;
282: config.set("SessionManager.SessionHome.PageThreshold",
283: pageThreshold);
284: }
285:
286: public String getPageTimeThreshold() {
287: return pageTimeThreshold;
288: }
289:
290: public void setPageTimeThreshold(String pageTimeThreshold)
291: throws KeywordValueException {
292: this .pageTimeThreshold = pageTimeThreshold;
293: config.set("SessionManager.SessionHome.PageTimeThreshold",
294: pageTimeThreshold);
295: }
296:
297: public String getPageWait() {
298: return pageWait;
299: }
300:
301: public void setPageWait(String pageWait)
302: throws KeywordValueException {
303: this .pageWait = pageWait;
304: config.set("SessionManager.SessionHome.PageWait", pageWait);
305: }
306:
307: public String getSaveOnRestart() {
308: return saveOnRestart;
309: }
310:
311: public void setSaveOnRestart(String saveOnRestart)
312: throws KeywordValueException {
313: this .saveOnRestart = saveOnRestart;
314: config.set("SessionManager.SessionHome.SaveOnRestart",
315: saveOnRestart);
316: }
317:
318: public String getPageDir() {
319: return pageDir;
320: }
321:
322: public void setPageDir(String pageDir) throws KeywordValueException {
323: this .pageDir = pageDir;
324: config.set("SessionManager.SessionHome.PageDir", pageDir);
325: }
326:
327: public String getDatabaseName() {
328: return databaseName;
329: }
330:
331: public void setDatabaseName(String databaseName)
332: throws KeywordValueException {
333: this .databaseName = databaseName;
334: config.set("SessionManager.SessionHome.DatabaseName",
335: databaseName);
336: }
337:
338: public String getDBTableName() {
339: return dBTableName;
340: }
341:
342: public void setDBTableName(String dBTableName)
343: throws KeywordValueException {
344: this .dBTableName = dBTableName;
345: config.set("SessionManager.SessionHome.DBTableName",
346: dBTableName);
347: }
348:
349: public String getSessionHomeClass() {
350: return sessionHomeClass;
351: }
352:
353: public void setSessionHomeClass(String sessionHomeClass)
354: throws KeywordValueException {
355: this .sessionHomeClass = sessionHomeClass;
356: config
357: .set("SessionManager.SessionHome.Class",
358: sessionHomeClass);
359: }
360:
361: public String getSessionUserTableClass() {
362: return sessionUserTableClass;
363: }
364:
365: public void setSessionUserTableClass(String sessionUserTableClass)
366: throws KeywordValueException {
367: this .sessionUserTableClass = sessionUserTableClass;
368: config.set("SessionManager.SessionUserTable.Class",
369: sessionUserTableClass);
370: }
371:
372: /**
373: * Save state of SessionManager configuration parameters into config file.
374: * @return TRUE if OK, else FALSE.
375: */
376:
377: public boolean saveState() {
378: try {
379: ConfigFileInterface confFile = config.getConfigFile();
380: confFile.write();
381: } catch (Exception e) { //FIXME log Exception
382: return false;
383: }
384: return true;
385: }
386: }
|