KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > session > MaxInactiveIntervalTag


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.session;
18
19 import java.util.*;
20 import javax.servlet.*;
21 import javax.servlet.http.*;
22 import javax.servlet.jsp.*;
23 import javax.servlet.jsp.tagext.*;
24
25 /**
26  * JSP Tag <b>maxInactiveInterval</b>, used to set an HttpSession
27  * max inactive interval in seconds from the body of the tag.
28  * <p>
29  * JSP Tag Lib Descriptor
30  * <p><pre>
31  * &lt;name&gt;maxInactiveInterval&lt;/name&gt;
32  * &lt;tagclass&gt;org.apache.taglibs.session.MaxInactiveIntervalTag&lt;/tagclass&gt;
33  * &lt;bodycontent&gt;JSP&lt;/bodycontent&gt;
34  * &lt;info&gt;Sets the max inactive interval in seconds using the content of the tag body.&lt;/info&gt;
35  * </pre>
36  *
37  * @author Glenn Nielsen
38  */

39
40 public class MaxInactiveIntervalTag extends BodyTagSupport
41 {
42     /**
43      * Returns EVAL_BODY_TAG so the body of the tag can be evaluated.
44      *
45      * @return EVAL_BODY_TAG
46      */

47     public final int doStartTag() throws JspException
48     {
49     return EVAL_BODY_TAG;
50     }
51
52     /**
53      * Read the body of the maxInactiveInterval tag to obtain the
54      * number of seconds to set the max inactive session interval to.
55      *
56      * @return SKIP_BODY
57      */

58     public final int doAfterBody() throws JspException
59     {
60     // Use the body of the tag as number of seconds
61
BodyContent body = getBodyContent();
62     String JavaDoc s = body.getString().trim();
63     // Clear the body since we only used it as input for the seconds
64
// value
65
body.clearBody();
66
67     int interval;
68     try {
69         interval = Integer.valueOf(s).intValue();
70         // set the interval
71
pageContext.getSession().setMaxInactiveInterval(interval);
72     } catch(NumberFormatException JavaDoc e) {
73         throw new JspException(
74         "session tag maxInactiveInterval, bad number format: " + s);
75     }
76
77     return SKIP_BODY;
78     }
79 }
80
Popular Tags