Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/struts/taglib/logic/ConditionalTagBase.java


1   /*
2    * $Id: ConditionalTagBase.java 54929 2004-10-16 16:38:42Z germuska $ 
3    *
4    * Copyright 1999-2004 The Apache Software Foundation.
5    * 
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * 
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  
20  package org.apache.struts.taglib.logic;
21  
22  
23  import javax.servlet.jsp.JspException;
24  import javax.servlet.jsp.tagext.TagSupport;
25  import org.apache.struts.util.MessageResources;
26  
27  
28  /**
29   * Abstract base class for the various conditional evaluation tags.
30   *
31   * @version $Rev: 54929 $ $Date: 2004-10-16 09:38:42 -0700 (Sat, 16 Oct 2004) $
32   */
33  
34  public abstract class ConditionalTagBase extends TagSupport {
35  
36  
37      // ------------------------------------------------------------- Properties
38  
39  
40      /**
41       * The name of the cookie to be used as a variable.
42       */
43      protected String cookie = null;
44  
45      public String getCookie() {
46          return (this.cookie);
47      }
48  
49      public void setCookie(String cookie) {
50          this.cookie = cookie;
51      }
52  
53  
54      /**
55       * The name of the HTTP request header to be used as a variable.
56       */
57      protected String header = null;
58  
59      public String getHeader() {
60          return (this.header);
61      }
62  
63      public void setHeader(String header) {
64          this.header = header;
65      }
66  
67  
68      /**
69       * The message resources for this package.
70       */
71      protected static MessageResources messages =
72       MessageResources.getMessageResources
73          ("org.apache.struts.taglib.logic.LocalStrings");
74  
75  
76      /**
77       * The name of the JSP bean to be used as a variable (if
78       * <code>property</code> is not specified), or whose property is to be
79       * accessed (if <code>property</code> is specified).
80       */
81      protected String name = null;
82  
83      public String getName() {
84          return (this.name);
85      }
86  
87      public void setName(String name) {
88          this.name = name;
89      }
90  
91  
92      /**
93       * The name of the HTTP request parameter to be used as a variable.
94       */
95      protected String parameter = null;
96  
97      public String getParameter() {
98          return (this.parameter);
99      }
100 
101     public void setParameter(String parameter) {
102         this.parameter = parameter;
103     }
104 
105 
106     /**
107      * The name of the bean property to be used as a variable.
108      */
109     protected String property = null;
110 
111     public String getProperty() {
112         return (this.property);
113     }
114 
115     public void setProperty(String property) {
116         this.property = property;
117     }
118 
119 
120     /**
121      * The name of the security role to be checked for.
122      */
123     protected String role = null;
124 
125     public String getRole() {
126         return (this.role);
127     }
128 
129     public void setRole(String role) {
130         this.role = role;
131     }
132 
133 
134     /**
135      * The scope to search for the bean named by the name property, or
136      * "any scope" if null.
137      */
138     protected String scope = null;
139 
140     public String getScope() {
141         return (this.scope);
142     }
143 
144     public void setScope(String scope) {
145         this.scope = scope;
146     }
147 
148 
149     /**
150      * The user principal name to be checked for.
151      */
152     protected String user = null;
153 
154     public String getUser() {
155         return (this.user);
156     }
157 
158     public void setUser(String user) {
159         this.user = user;
160     }
161 
162 
163     // --------------------------------------------------------- Public Methods
164 
165 
166     /**
167      * Perform the test required for this particular tag, and either evaluate
168      * or skip the body of this tag.
169      *
170      * @exception JspException if a JSP exception occurs
171      */
172     public int doStartTag() throws JspException {
173 
174         if (condition())
175             return (EVAL_BODY_INCLUDE);
176         else
177             return (SKIP_BODY);
178 
179     }
180 
181 
182     /**
183      * Evaluate the remainder of the current page normally.
184      *
185      * @exception JspException if a JSP exception occurs
186      */
187     public int doEndTag() throws JspException {
188 
189         return (EVAL_PAGE);
190 
191     }
192 
193 
194     /**
195      * Release all allocated resources.
196      */
197     public void release() {
198 
199         super.release();
200         cookie = null;
201         header = null;
202         name = null;
203         parameter = null;
204         property = null;
205         role = null;
206         scope = null;
207         user = null;
208 
209     }
210 
211 
212     // ------------------------------------------------------ Protected Methods
213 
214 
215     /**
216      * Evaluate the condition that is being tested by this particular tag,
217      * and return <code>true</code> if the nested body content of this tag
218      * should be evaluated, or <code>false</code> if it should be skipped.
219      * This method must be implemented by concrete subclasses.
220      *
221      * @exception JspException if a JSP exception occurs
222      */
223     protected abstract boolean condition() throws JspException;
224 
225 
226 }