KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > common > core > RemoveTag


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.standard.tag.common.core;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.PageContext JavaDoc;
21 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
22
23 /**
24  * <p>A handler for the &lt;remove&gt; tag, which removes the variable
25  * identified by 'var' (and 'scope', if present).
26  *
27  * @author Shawn Bayern
28  */

29 public class RemoveTag extends TagSupport JavaDoc {
30
31     //*********************************************************************
32
// Constants
33

34     /* We support these 'scopes'. */
35
36     private final String JavaDoc APPLICATION = "application";
37     private final String JavaDoc SESSION = "session";
38     private final String JavaDoc REQUEST = "request";
39     private final String JavaDoc PAGE = "page";
40
41     //*********************************************************************
42
// Internal state
43

44     private int scope; // tag attribute
45
private boolean scopeSpecified; // ... by tag attribute
46
private String JavaDoc var; // tag attribute
47

48
49     //*********************************************************************
50
// Construction and initialization
51

52     /**
53      * Constructs a new handler. As with TagSupport, subclasses should
54      * not provide other constructors and are expected to call the
55      * superclass constructor.
56      */

57     public RemoveTag() {
58         super();
59         init();
60     }
61
62     // resets local state
63
private void init() {
64         var = null;
65         scope = PageContext.PAGE_SCOPE;
66         scopeSpecified = false;
67     }
68
69     // Releases any resources we may have (or inherit)
70
public void release() {
71         super.release();
72         init();
73     }
74
75
76     //*********************************************************************
77
// Tag logic
78

79     // removes the variable (from a specific scope, if specified)
80
public int doEndTag() throws JspException JavaDoc {
81         if (!scopeSpecified)
82             pageContext.removeAttribute(var);
83         else
84             pageContext.removeAttribute(var, scope);
85     return EVAL_PAGE;
86     }
87
88
89     //*********************************************************************
90
// Accessor methods
91

92     // for tag attribute
93
public void setVar(String JavaDoc var) {
94     this.var = var;
95     }
96
97     // for tag attribute
98
public void setScope(String JavaDoc scope) {
99         this.scope = Util.getScope(scope);
100     scopeSpecified = true;
101     }
102 }
103
Popular Tags