View Javadoc

1   /*
2    * $Id: ConditionalTagBase.java 376842 2006-02-10 21:02:03Z husted $
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  package org.apache.struts.taglib.logic;
19  
20  import org.apache.struts.util.MessageResources;
21  
22  import javax.servlet.jsp.JspException;
23  import javax.servlet.jsp.tagext.TagSupport;
24  
25  /***
26   * Abstract base class for the various conditional evaluation tags.
27   *
28   * @version $Rev: 376842 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
29   *          $
30   */
31  public abstract class ConditionalTagBase extends TagSupport {
32      /***
33       * The message resources for this package.
34       */
35      protected static MessageResources messages =
36          MessageResources.getMessageResources(
37              "org.apache.struts.taglib.logic.LocalStrings");
38  
39      // ------------------------------------------------------------- Properties
40  
41      /***
42       * The name of the cookie to be used as a variable.
43       */
44      protected String cookie = null;
45  
46      /***
47       * The name of the HTTP request header to be used as a variable.
48       */
49      protected String header = null;
50  
51      /***
52       * The name of the JSP bean to be used as a variable (if
53       * <code>property</code> is not specified), or whose property is to be
54       * accessed (if <code>property</code> is specified).
55       */
56      protected String name = null;
57  
58      /***
59       * The name of the HTTP request parameter to be used as a variable.
60       */
61      protected String parameter = null;
62  
63      /***
64       * The name of the bean property to be used as a variable.
65       */
66      protected String property = null;
67  
68      /***
69       * The name of the security role to be checked for.
70       */
71      protected String role = null;
72  
73      /***
74       * The scope to search for the bean named by the name property, or "any
75       * scope" if null.
76       */
77      protected String scope = null;
78  
79      /***
80       * The user principal name to be checked for.
81       */
82      protected String user = null;
83  
84      public String getCookie() {
85          return (this.cookie);
86      }
87  
88      public void setCookie(String cookie) {
89          this.cookie = cookie;
90      }
91  
92      public String getHeader() {
93          return (this.header);
94      }
95  
96      public void setHeader(String header) {
97          this.header = header;
98      }
99  
100     public String getName() {
101         return (this.name);
102     }
103 
104     public void setName(String name) {
105         this.name = name;
106     }
107 
108     public String getParameter() {
109         return (this.parameter);
110     }
111 
112     public void setParameter(String parameter) {
113         this.parameter = parameter;
114     }
115 
116     public String getProperty() {
117         return (this.property);
118     }
119 
120     public void setProperty(String property) {
121         this.property = property;
122     }
123 
124     public String getRole() {
125         return (this.role);
126     }
127 
128     public void setRole(String role) {
129         this.role = role;
130     }
131 
132     public String getScope() {
133         return (this.scope);
134     }
135 
136     public void setScope(String scope) {
137         this.scope = scope;
138     }
139 
140     public String getUser() {
141         return (this.user);
142     }
143 
144     public void setUser(String user) {
145         this.user = user;
146     }
147 
148     // --------------------------------------------------------- Public Methods
149 
150     /***
151      * Perform the test required for this particular tag, and either evaluate
152      * or skip the body of this tag.
153      *
154      * @throws JspException if a JSP exception occurs
155      */
156     public int doStartTag() throws JspException {
157         if (condition()) {
158             return (EVAL_BODY_INCLUDE);
159         } else {
160             return (SKIP_BODY);
161         }
162     }
163 
164     /***
165      * Evaluate the remainder of the current page normally.
166      *
167      * @throws JspException if a JSP exception occurs
168      */
169     public int doEndTag() throws JspException {
170         return (EVAL_PAGE);
171     }
172 
173     /***
174      * Release all allocated resources.
175      */
176     public void release() {
177         super.release();
178         cookie = null;
179         header = null;
180         name = null;
181         parameter = null;
182         property = null;
183         role = null;
184         scope = null;
185         user = null;
186     }
187 
188     // ------------------------------------------------------ Protected Methods
189 
190     /***
191      * Evaluate the condition that is being tested by this particular tag, and
192      * return <code>true</code> if the nested body content of this tag should
193      * be evaluated, or <code>false</code> if it should be skipped. This
194      * method must be implemented by concrete subclasses.
195      *
196      * @throws JspException if a JSP exception occurs
197      */
198     protected abstract boolean condition()
199         throws JspException;
200 }