001: // ServletProps.java
002: // $Id: ServletProps.java,v 1.11 2007/02/11 10:50:01 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1998.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005: package org.w3c.jigsaw.servlet;
006:
007: import org.w3c.jigsaw.http.httpd;
008:
009: import org.w3c.tools.resources.Attribute;
010: import org.w3c.tools.resources.AttributeRegistry;
011: import org.w3c.tools.resources.BooleanAttribute;
012: import org.w3c.tools.resources.FileAttribute;
013: import org.w3c.tools.resources.IntegerAttribute;
014: import org.w3c.tools.resources.LongAttribute;
015: import org.w3c.tools.resources.StringAttribute;
016:
017: import org.w3c.jigsaw.config.PropertySet;
018:
019: /**
020: * @version $Revision: 1.11 $
021: * @author Benoît Mahé (bmahe@w3.org)
022: */
023: public class ServletProps extends PropertySet {
024:
025: /**
026: * Name of the property indicating the servlet log file.
027: * This property indicates the name of the servlet log file to use.
028: * <p>This property defaults to the <code>servlets</code> file in
029: * the server log directory.
030: */
031: protected static String SERVLET_LOG_FILE_P = "org.w3c.jigsaw.servlet.servlet-log-file";
032:
033: /**
034: * Name of the property indicating the max number of session loaded
035: * in memory.
036: */
037: protected static String SERVLET_TIMEOUT = "org.w3c.jigsaw.servlet.timeout";
038:
039: /**
040: * Name of the property indicating the max number
041: * for single thread model servlet instance pool size limitation, tk, 20.10.2001
042: */
043: protected static String SERVLET_INSTANCEMAX = "org.w3c.jigsaw.servlet.instancemax";
044:
045: /**
046: * Name of the property indicating the max number of session loaded
047: * in memory.
048: */
049: protected static String SERVLET_MAX_SESSION = "org.w3c.jigsaw.servlet.max-sessions";
050:
051: /**
052: * Name of the property indicating the max idle time of session.
053: */
054: protected static String SERVLET_SESSION_IDLE = "org.w3c.jigsaw.servlet.sessions-max-idle-time";
055:
056: /**
057: * Name of the property indicating the max idle time of session.
058: */
059: protected static String SERVLET_SESSION_SWEEP = "org.w3c.jigsaw.servlet.sessions-sweep-delay";
060:
061: /**
062: * Name of the property indicating the session cookie name.
063: */
064: protected static String SERVLET_COOKIE_NAME = "org.w3c.jigsaw.servlet.session.cookie.name";
065:
066: /**
067: * The default Session Cookie name.
068: */
069: protected static String DEFAULT_COOKIE_NAME = "JIGSAW-SESSION-ID";
070:
071: /**
072: * Name of the property indicating the session cookie domain.
073: */
074: protected static String SERVLET_COOKIE_DOMAIN = "org.w3c.jigsaw.servlet.session.cookie.domain";
075:
076: /**
077: * Name of the property indicating the session cookie maxage.
078: */
079: protected static String SERVLET_COOKIE_MAXAGE = "org.w3c.jigsaw.servlet.session.cookie.maxage";
080:
081: /**
082: * Name of the property indicating the session cookie path.
083: */
084: protected static String SERVLET_COOKIE_PATH = "org.w3c.jigsaw.servlet.session.cookie.path";
085:
086: /**
087: * Name of the property indicating the session cookie comment.
088: */
089: protected static String SERVLET_COOKIE_COMMENT = "org.w3c.jigsaw.servlet.session.cookie.comment";
090:
091: /**
092: * Name of the property indicating the session cookie secure flag.
093: */
094: protected static String SERVLET_COOKIE_SECURE = "org.w3c.jigsaw.servlet.session.cookie.secure";
095:
096: /**
097: * Name of the servlet PropertySet.
098: */
099: protected static String SERVLET_PROPS_NAME = "Servlets";
100:
101: /**
102: * Attribute index - The index for our servlet log file attribute.
103: */
104: protected static int ATTR_SERVLET_LOG_FILE = -1;
105:
106: /**
107: * Attribute index - The index for our servlet session max idle time.
108: */
109: protected static int ATTR_MAX_IDLE_TIME = -1;
110:
111: /**
112: * Attribute index - The index for our servlet timeout
113: */
114: protected static int ATTR_SERVLET_TIMEOUT = -1;
115:
116: /**
117: * Attribute index - The index for for single thread model servlet instance pool size limitation, tk, 20.10.2001
118: */
119: protected static int ATTR_SERVLET_INSTANCEMAX = -1;
120:
121: /**
122: * Attribute index - The index for our servlet session max number in
123: * memory.
124: */
125: protected static int ATTR_SESSIONS_MAX = -1;
126:
127: /**
128: * Attribute index - The index for our servlet session sweep delay.
129: */
130: protected static int ATTR_SESSIONS_SWEEP = -1;
131:
132: /**
133: * Attribute index - The index for our session cookie name.
134: */
135: protected static int ATTR_SESSIONS_COOKIE_NAME = -1;
136:
137: /**
138: * Attribute index - The index for our session cookie path.
139: */
140: protected static int ATTR_SESSIONS_COOKIE_PATH = -1;
141:
142: /**
143: * Attribute index - The index for our session cookie domain.
144: */
145: protected static int ATTR_SESSIONS_COOKIE_DOMAIN = -1;
146:
147: /**
148: * Attribute index - The index for our session cookie comment.
149: */
150: protected static int ATTR_SESSIONS_COOKIE_COMMENT = -1;
151:
152: /**
153: * Attribute index - The index for our session cookie maxage.
154: */
155: protected static int ATTR_SESSIONS_COOKIE_MAXAGE = -1;
156:
157: /**
158: * Attribute index - The index for our session cookie secure.
159: */
160: protected static int ATTR_SESSIONS_COOKIE_SECURE = -1;
161:
162: static {
163: Class cls = null;
164: Attribute a = null;
165:
166: try {
167: cls = Class.forName("org.w3c.jigsaw.servlet.ServletProps");
168: } catch (Exception ex) {
169: ex.printStackTrace();
170: System.exit(1);
171: }
172: // The servlet log file:
173: a = new FileAttribute(SERVLET_LOG_FILE_P, null,
174: Attribute.EDITABLE);
175: ATTR_SERVLET_LOG_FILE = AttributeRegistry.registerAttribute(
176: cls, a);
177: // The servlet session max idle time:
178: a = new LongAttribute(SERVLET_SESSION_IDLE, new Long(1800000),
179: Attribute.EDITABLE);
180: ATTR_MAX_IDLE_TIME = AttributeRegistry
181: .registerAttribute(cls, a);
182: // The servlet timeout:
183: a = new LongAttribute(SERVLET_TIMEOUT, new Long(1800000),
184: Attribute.EDITABLE);
185: ATTR_SERVLET_TIMEOUT = AttributeRegistry.registerAttribute(cls,
186: a);
187: // The servlet instancemax, added for single thread model servlet instance pool size limitation, tk, 20.10.2001
188: a = new IntegerAttribute(SERVLET_INSTANCEMAX, new Integer(0),
189: Attribute.EDITABLE);
190: ATTR_SERVLET_INSTANCEMAX = AttributeRegistry.registerAttribute(
191: cls, a);
192: // The servlet sessions max number in memory:
193: a = new IntegerAttribute(SERVLET_MAX_SESSION,
194: new Integer(1024), Attribute.EDITABLE);
195: ATTR_SESSIONS_MAX = AttributeRegistry.registerAttribute(cls, a);
196: // The servlet sessions sweep delay:
197: a = new IntegerAttribute(SERVLET_SESSION_SWEEP, new Integer(
198: 30000), Attribute.EDITABLE);
199: ATTR_SESSIONS_SWEEP = AttributeRegistry.registerAttribute(cls,
200: a);
201: // The session cookie name
202: a = new StringAttribute(SERVLET_COOKIE_NAME,
203: DEFAULT_COOKIE_NAME, Attribute.EDITABLE);
204: ATTR_SESSIONS_COOKIE_NAME = AttributeRegistry
205: .registerAttribute(cls, a);
206: // The session cookie path
207: a = new StringAttribute(SERVLET_COOKIE_PATH, "/",
208: Attribute.EDITABLE);
209: ATTR_SESSIONS_COOKIE_PATH = AttributeRegistry
210: .registerAttribute(cls, a);
211: // The session cookie domain
212: a = new StringAttribute(SERVLET_COOKIE_DOMAIN, null,
213: Attribute.EDITABLE);
214: ATTR_SESSIONS_COOKIE_DOMAIN = AttributeRegistry
215: .registerAttribute(cls, a);
216: // The session cookie comment
217: a = new StringAttribute(SERVLET_COOKIE_COMMENT,
218: "Jigsaw Server Session Tracking Cookie",
219: Attribute.EDITABLE);
220: ATTR_SESSIONS_COOKIE_COMMENT = AttributeRegistry
221: .registerAttribute(cls, a);
222: // The session cookie maxage
223: a = new IntegerAttribute(SERVLET_COOKIE_MAXAGE,
224: new Integer(-1), Attribute.EDITABLE);
225: ATTR_SESSIONS_COOKIE_MAXAGE = AttributeRegistry
226: .registerAttribute(cls, a);
227: // The session cookie secure flag
228: a = new BooleanAttribute(SERVLET_COOKIE_SECURE, Boolean.FALSE,
229: Attribute.EDITABLE);
230: ATTR_SESSIONS_COOKIE_NAME = AttributeRegistry
231: .registerAttribute(cls, a);
232: }
233:
234: private static String title = "Servlet properties";
235:
236: private JigsawHttpSessionContext sessionContext = null;
237:
238: /**
239: * Returns the max idle time for a session.
240: * @return The max idle time in milli seconds.
241: */
242: public long getSessionsMaxIdleTime() {
243: return ((Long) getValue(ATTR_MAX_IDLE_TIME, new Long(1800000)))
244: .longValue();
245: }
246:
247: /**
248: * Returns the max number of session in memory.
249: * @return The max number of session.
250: */
251: public int getMaxSessionsNumber() {
252: return ((Integer) getValue(ATTR_SESSIONS_MAX, new Integer(1024)))
253: .intValue();
254: }
255:
256: /**
257: * Returns the delay between two sessions idle time check.
258: * @return the delay between two sessions idle time check in milli seconds.
259: */
260: public int getSessionsSweepDelay() {
261: return ((Integer) getValue(ATTR_SESSIONS_SWEEP, new Integer(
262: 30000))).intValue();
263: }
264:
265: /**
266: * Returns the session context.
267: * @return A JigsawHttpSessionContext instance.
268: */
269: public JigsawHttpSessionContext getSessionContext() {
270: if (sessionContext == null)
271: sessionContext = new JigsawHttpSessionContext(server, this );
272: return sessionContext;
273: }
274:
275: /**
276: * Get this property set title.
277: * @return A String encoded title.
278: */
279:
280: public String getTitle() {
281: return title;
282: }
283:
284: ServletProps(httpd server) {
285: super(SERVLET_PROPS_NAME, server);
286: }
287:
288: }
|