KickJava   Java API By Example, From Geeks To Geeks.

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


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>isNew</b>, used to test whether the HTTPSession is new.
27  * <p>
28  * Includes the body of the tag if the session is new.
29  * <p>
30  * You can set the optional tag attribute <b>value</b> to <i>true</i> or
31  * <i>false</i>. The body of the tag is included if isNew matches
32  * the value.
33  * <p>
34  * JSP Tag Lib Descriptor
35  * <p><pre>
36  * &lt;name&gt;isNew&lt;/name&gt;
37  * &lt;tagclass&gt;org.apache.taglibs.session.IsNewTag&lt;/tagclass&gt;
38  * &lt;bodycontent&gt;JSP&lt;/bodycontent&gt;
39  * &lt;info&gt;Used to determine if a session is new.&lt;/info&gt;
40  * &lt;attribute&gt;
41  * &lt;name&gt;value&lt;/name&gt;
42  * &lt;required&gt;false&lt;/required&gt;
43  * &lt;rtexprvalue&gt;false&lt;/rtexprvalue&gt;
44  * &lt;/attribute&gt;
45  * </pre>
46  *
47  * @author Glenn Nielsen
48  */

49
50 public class IsNewTag extends TagSupport
51 {
52     private boolean value = true;
53
54     /**
55      * Used to test whether the HTTP session is new.
56      *
57      * @return SKIP_BODY if isNew doesn't match value, EVAL_BODY_include if isNew matches value
58      */

59     public final int doStartTag() throws JspException
60     {
61     boolean result = pageContext.getSession().isNew();
62     if( value == result )
63         return EVAL_BODY_INCLUDE;
64     return SKIP_BODY;
65     }
66
67     /**
68      * Set the isNew tag optional attribute value to true
69      * or false.
70      *
71      * @param boolean true or false
72      */

73     public final void setValue(boolean value)
74     {
75     this.value = value;
76     }
77 }
78
Popular Tags