--- /dev/null
+// ServletProps.java\r
+// $Id: ServletProps.java,v 1.2 2010/06/15 17:52:51 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1998.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+package org.w3c.jigsaw.servlet;\r
+\r
+import org.w3c.jigsaw.http.httpd;\r
+\r
+import org.w3c.tools.resources.Attribute;\r
+import org.w3c.tools.resources.AttributeRegistry;\r
+import org.w3c.tools.resources.BooleanAttribute;\r
+import org.w3c.tools.resources.FileAttribute;\r
+import org.w3c.tools.resources.IntegerAttribute;\r
+import org.w3c.tools.resources.LongAttribute;\r
+import org.w3c.tools.resources.StringAttribute;\r
+\r
+import org.w3c.jigsaw.config.PropertySet;\r
+\r
+/**\r
+ * @version $Revision: 1.2 $\r
+ * @author Benoît Mahé (bmahe@w3.org)\r
+ */\r
+public class ServletProps extends PropertySet {\r
+ \r
+ /**\r
+ * Name of the property indicating the servlet log file.\r
+ * This property indicates the name of the servlet log file to use.\r
+ * <p>This property defaults to the <code>servlets</code> file in \r
+ * the server log directory.\r
+ */\r
+ protected static String SERVLET_LOG_FILE_P = \r
+ "org.w3c.jigsaw.servlet.servlet-log-file";\r
+\r
+ /**\r
+ * Name of the property indicating the max number of session loaded\r
+ * in memory.\r
+ */\r
+ protected static String SERVLET_TIMEOUT = \r
+ "org.w3c.jigsaw.servlet.timeout";\r
+\r
+ /**\r
+ * Name of the property indicating the max number \r
+ * for single thread model servlet instance pool size limitation, tk, 20.10.2001\r
+ */\r
+ protected static String SERVLET_INSTANCEMAX = \r
+ "org.w3c.jigsaw.servlet.instancemax"; \r
+ \r
+ /**\r
+ * Name of the property indicating the max number of session loaded\r
+ * in memory.\r
+ */\r
+ protected static String SERVLET_MAX_SESSION = \r
+ "org.w3c.jigsaw.servlet.max-sessions";\r
+\r
+ /**\r
+ * Name of the property indicating the max idle time of session.\r
+ */\r
+ protected static String SERVLET_SESSION_IDLE = \r
+ "org.w3c.jigsaw.servlet.sessions-max-idle-time";\r
+\r
+ /**\r
+ * Name of the property indicating the max idle time of session.\r
+ */\r
+ protected static String SERVLET_SESSION_SWEEP = \r
+ "org.w3c.jigsaw.servlet.sessions-sweep-delay";\r
+\r
+ /**\r
+ * Name of the property indicating the session cookie name.\r
+ */\r
+ protected static String SERVLET_COOKIE_NAME = \r
+ "org.w3c.jigsaw.servlet.session.cookie.name";\r
+\r
+ /**\r
+ * The default Session Cookie name.\r
+ */\r
+ protected static String DEFAULT_COOKIE_NAME = "JIGSAW-SESSION-ID";\r
+\r
+ /**\r
+ * Name of the property indicating the session cookie domain.\r
+ */\r
+ protected static String SERVLET_COOKIE_DOMAIN = \r
+ "org.w3c.jigsaw.servlet.session.cookie.domain";\r
+\r
+ /**\r
+ * Name of the property indicating the session cookie maxage.\r
+ */\r
+ protected static String SERVLET_COOKIE_MAXAGE = \r
+ "org.w3c.jigsaw.servlet.session.cookie.maxage";\r
+\r
+ /**\r
+ * Name of the property indicating the session cookie path.\r
+ */\r
+ protected static String SERVLET_COOKIE_PATH = \r
+ "org.w3c.jigsaw.servlet.session.cookie.path";\r
+\r
+ /**\r
+ * Name of the property indicating the session cookie comment.\r
+ */\r
+ protected static String SERVLET_COOKIE_COMMENT = \r
+ "org.w3c.jigsaw.servlet.session.cookie.comment";\r
+\r
+ /**\r
+ * Name of the property indicating the session cookie secure flag.\r
+ */\r
+ protected static String SERVLET_COOKIE_SECURE = \r
+ "org.w3c.jigsaw.servlet.session.cookie.secure";\r
+\r
+ /**\r
+ * Name of the servlet PropertySet.\r
+ */\r
+ protected static String SERVLET_PROPS_NAME = "Servlets";\r
+\r
+ /**\r
+ * Attribute index - The index for our servlet log file attribute.\r
+ */\r
+ protected static int ATTR_SERVLET_LOG_FILE = -1 ;\r
+\r
+ /**\r
+ * Attribute index - The index for our servlet session max idle time.\r
+ */\r
+ protected static int ATTR_MAX_IDLE_TIME = -1;\r
+\r
+ /**\r
+ * Attribute index - The index for our servlet timeout\r
+ */\r
+ protected static int ATTR_SERVLET_TIMEOUT = -1;\r
+\r
+ /**\r
+ * Attribute index - The index for for single thread model servlet instance pool size limitation, tk, 20.10.2001\r
+ */\r
+ protected static int ATTR_SERVLET_INSTANCEMAX = -1;\r
+ \r
+ /**\r
+ * Attribute index - The index for our servlet session max number in \r
+ * memory.\r
+ */\r
+ protected static int ATTR_SESSIONS_MAX = -1;\r
+\r
+ /**\r
+ * Attribute index - The index for our servlet session sweep delay.\r
+ */\r
+ protected static int ATTR_SESSIONS_SWEEP = -1;\r
+\r
+ /**\r
+ * Attribute index - The index for our session cookie name.\r
+ */\r
+ protected static int ATTR_SESSIONS_COOKIE_NAME = -1;\r
+\r
+ /**\r
+ * Attribute index - The index for our session cookie path.\r
+ */\r
+ protected static int ATTR_SESSIONS_COOKIE_PATH = -1;\r
+\r
+ /**\r
+ * Attribute index - The index for our session cookie domain.\r
+ */\r
+ protected static int ATTR_SESSIONS_COOKIE_DOMAIN = -1;\r
+\r
+ /**\r
+ * Attribute index - The index for our session cookie comment.\r
+ */\r
+ protected static int ATTR_SESSIONS_COOKIE_COMMENT = -1;\r
+\r
+ /**\r
+ * Attribute index - The index for our session cookie maxage.\r
+ */\r
+ protected static int ATTR_SESSIONS_COOKIE_MAXAGE = -1;\r
+\r
+ /**\r
+ * Attribute index - The index for our session cookie secure.\r
+ */\r
+ protected static int ATTR_SESSIONS_COOKIE_SECURE = -1;\r
+\r
+ \r
+\r
+ static {\r
+ Class cls = null;\r
+ Attribute a = null;\r
+\r
+ try {\r
+ cls = Class.forName("org.w3c.jigsaw.servlet.ServletProps");\r
+ //Added by Jeff Huang\r
+ //TODO: FIXIT\r
+ } catch (Exception ex) {\r
+ ex.printStackTrace();\r
+ System.exit(1);\r
+ }\r
+ // The servlet log file:\r
+ a = new FileAttribute(SERVLET_LOG_FILE_P,\r
+ null,\r
+ Attribute.EDITABLE);\r
+ ATTR_SERVLET_LOG_FILE = AttributeRegistry.registerAttribute(cls, a);\r
+ // The servlet session max idle time:\r
+ a = new LongAttribute(SERVLET_SESSION_IDLE,\r
+ new Long(1800000),\r
+ Attribute.EDITABLE);\r
+ ATTR_MAX_IDLE_TIME = AttributeRegistry.registerAttribute(cls, a);\r
+ // The servlet timeout:\r
+ a = new LongAttribute(SERVLET_TIMEOUT,\r
+ new Long(1800000),\r
+ Attribute.EDITABLE);\r
+ ATTR_SERVLET_TIMEOUT = AttributeRegistry.registerAttribute(cls, a);\r
+ // The servlet instancemax, added for single thread model servlet instance pool size limitation, tk, 20.10.2001\r
+ a = new IntegerAttribute(SERVLET_INSTANCEMAX,\r
+ new Integer(0),\r
+ Attribute.EDITABLE);\r
+ ATTR_SERVLET_INSTANCEMAX = AttributeRegistry.registerAttribute(cls, a);\r
+ // The servlet sessions max number in memory:\r
+ a = new IntegerAttribute(SERVLET_MAX_SESSION,\r
+ new Integer(1024),\r
+ Attribute.EDITABLE);\r
+ ATTR_SESSIONS_MAX = AttributeRegistry.registerAttribute(cls, a);\r
+ // The servlet sessions sweep delay:\r
+ a = new IntegerAttribute(SERVLET_SESSION_SWEEP,\r
+ new Integer(30000),\r
+ Attribute.EDITABLE);\r
+ ATTR_SESSIONS_SWEEP = AttributeRegistry.registerAttribute(cls, a);\r
+ // The session cookie name\r
+ a = new StringAttribute(SERVLET_COOKIE_NAME,\r
+ DEFAULT_COOKIE_NAME,\r
+ Attribute.EDITABLE);\r
+ ATTR_SESSIONS_COOKIE_NAME = \r
+ AttributeRegistry.registerAttribute(cls, a);\r
+ // The session cookie path\r
+ a = new StringAttribute(SERVLET_COOKIE_PATH,\r
+ "/",\r
+ Attribute.EDITABLE);\r
+ ATTR_SESSIONS_COOKIE_PATH = \r
+ AttributeRegistry.registerAttribute(cls, a);\r
+ // The session cookie domain\r
+ a = new StringAttribute(SERVLET_COOKIE_DOMAIN,\r
+ null,\r
+ Attribute.EDITABLE);\r
+ ATTR_SESSIONS_COOKIE_DOMAIN = \r
+ AttributeRegistry.registerAttribute(cls, a);\r
+ // The session cookie comment\r
+ a = new StringAttribute(SERVLET_COOKIE_COMMENT,\r
+ "Jigsaw Server Session Tracking Cookie",\r
+ Attribute.EDITABLE);\r
+ ATTR_SESSIONS_COOKIE_COMMENT = \r
+ AttributeRegistry.registerAttribute(cls, a);\r
+ // The session cookie maxage\r
+ a = new IntegerAttribute(SERVLET_COOKIE_MAXAGE,\r
+ new Integer(-1),\r
+ Attribute.EDITABLE);\r
+ ATTR_SESSIONS_COOKIE_MAXAGE = \r
+ AttributeRegistry.registerAttribute(cls, a);\r
+ // The session cookie secure flag\r
+ a = new BooleanAttribute(SERVLET_COOKIE_SECURE,\r
+ Boolean.FALSE,\r
+ Attribute.EDITABLE);\r
+ ATTR_SESSIONS_COOKIE_NAME = \r
+ AttributeRegistry.registerAttribute(cls, a);\r
+ }\r
+\r
+ private static String title = "Servlet properties";\r
+\r
+ private JigsawHttpSessionContext sessionContext = null;\r
+\r
+ /**\r
+ * Returns the max idle time for a session.\r
+ * @return The max idle time in milli seconds.\r
+ */\r
+ public long getSessionsMaxIdleTime() {\r
+ return ((Long) \r
+ getValue(ATTR_MAX_IDLE_TIME, new Long(1800000))).longValue();\r
+ }\r
+\r
+ /**\r
+ * Returns the max number of session in memory.\r
+ * @return The max number of session.\r
+ */\r
+ public int getMaxSessionsNumber() {\r
+ return ((Integer)\r
+ getValue(ATTR_SESSIONS_MAX, new Integer(1024))).intValue();\r
+ }\r
+\r
+ /**\r
+ * Returns the delay between two sessions idle time check.\r
+ * @return the delay between two sessions idle time check in milli seconds.\r
+ */\r
+ public int getSessionsSweepDelay() {\r
+ return ((Integer)\r
+ getValue(ATTR_SESSIONS_SWEEP, new Integer(30000))).intValue();\r
+ }\r
+\r
+ /**\r
+ * Returns the session context.\r
+ * @return A JigsawHttpSessionContext instance.\r
+ */\r
+ public JigsawHttpSessionContext getSessionContext() {\r
+ if (sessionContext == null)\r
+ sessionContext = new JigsawHttpSessionContext(server,this);\r
+ return sessionContext;\r
+ }\r
+\r
+ /**\r
+ * Get this property set title.\r
+ * @return A String encoded title.\r
+ */\r
+\r
+ public String getTitle() {\r
+ return title;\r
+ }\r
+\r
+ ServletProps(httpd server) {\r
+ super(SERVLET_PROPS_NAME, server);\r
+ }\r
+\r
+}\r