View Javadoc

1   /*
2    * $Id: ELJavascriptValidatorTag.java 376779 2006-02-10 18:08:58Z 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.strutsel.taglib.html;
19  
20  import org.apache.struts.taglib.html.JavascriptValidatorTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Custom tag that generates JavaScript for client side validation based on
27   * the validation rules loaded by the <code>ValidatorPlugIn</code> defined in
28   * the struts-config.xml file. <p> This class is a subclass of the class
29   * <code>org.apache.struts.taglib.html.JavascriptValidatorTag</code> which
30   * provides most of the described functionality.  This subclass allows all
31   * attribute values to be specified as expressions utilizing the JavaServer
32   * Pages Standard Library expression language.
33   *
34   * @version $Rev: 376779 $
35   */
36  public class ELJavascriptValidatorTag extends JavascriptValidatorTag {
37      /***
38       * Instance variable mapped to "cdata" tag attribute. (Mapping set in
39       * associated BeanInfo class.)
40       */
41      private String cdataExpr;
42  
43      /***
44       * Instance variable mapped to "dynamicJavascript" tag attribute. (Mapping
45       * set in associated BeanInfo class.)
46       */
47      private String dynamicJavascriptExpr;
48  
49      /***
50       * Instance variable mapped to "formName" tag attribute. (Mapping set in
51       * associated BeanInfo class.)
52       */
53      private String formNameExpr;
54  
55      /***
56       * Instance variable mapped to "method" tag attribute. (Mapping set in
57       * associated BeanInfo class.)
58       */
59      private String methodExpr;
60  
61      /***
62       * Instance variable mapped to "page" tag attribute. (Mapping set in
63       * associated BeanInfo class.)
64       */
65      private String pageExpr;
66  
67      /***
68       * Instance variable mapped to "scriptLanguage" tag attribute. (Mapping
69       * set in associated BeanInfo class.)
70       */
71      private String scriptLanguageExpr;
72  
73      /***
74       * Instance variable mapped to "src" tag attribute. (Mapping set in
75       * associated BeanInfo class.)
76       */
77      private String srcExpr;
78  
79      /***
80       * Instance variable mapped to "staticJavascript" tag attribute. (Mapping
81       * set in associated BeanInfo class.)
82       */
83      private String staticJavascriptExpr;
84  
85      /***
86       * Instance variable mapped to "htmlComment" tag attribute. (Mapping set
87       * in associated BeanInfo class.)
88       */
89      private String htmlCommentExpr;
90  
91      /***
92       * Instance variable mapped to "bundle" tag attribute. (Mapping set in
93       * associated BeanInfo class.)
94       */
95      private String bundleExpr;
96  
97      /***
98       * Getter method for "cdata" tag attribute. (Mapping set in associated
99       * BeanInfo class.)
100      */
101     public String getCdataExpr() {
102         return (cdataExpr);
103     }
104 
105     /***
106      * Getter method for "dynamicJavascript" tag attribute. (Mapping set in
107      * associated BeanInfo class.)
108      */
109     public String getDynamicJavascriptExpr() {
110         return (dynamicJavascriptExpr);
111     }
112 
113     /***
114      * Getter method for "formName" tag attribute. (Mapping set in associated
115      * BeanInfo class.)
116      */
117     public String getFormNameExpr() {
118         return (formNameExpr);
119     }
120 
121     /***
122      * Getter method for "method" tag attribute. (Mapping set in associated
123      * BeanInfo class.)
124      */
125     public String getMethodExpr() {
126         return (methodExpr);
127     }
128 
129     /***
130      * Getter method for "page" tag attribute. (Mapping set in associated
131      * BeanInfo class.)
132      */
133     public String getPageExpr() {
134         return (pageExpr);
135     }
136 
137     /***
138      * Getter method for "scriptLanguage" tag attribute. (Mapping set in
139      * associated BeanInfo class.)
140      */
141     public String getScriptLanguageExpr() {
142         return (scriptLanguageExpr);
143     }
144 
145     /***
146      * Getter method for "src" tag attribute. (Mapping set in associated
147      * BeanInfo class.)
148      */
149     public String getSrcExpr() {
150         return (srcExpr);
151     }
152 
153     /***
154      * Getter method for "staticJavascript" tag attribute. (Mapping set in
155      * associated BeanInfo class.)
156      */
157     public String getStaticJavascriptExpr() {
158         return (staticJavascriptExpr);
159     }
160 
161     /***
162      * Getter method for "htmlComment" tag attribute. (Mapping set in
163      * associated BeanInfo class.)
164      */
165     public String getHtmlCommentExpr() {
166         return (htmlCommentExpr);
167     }
168 
169     /***
170      * Getter method for "bundle" tag attribute. (Mapping set in associated
171      * BeanInfo class.)
172      */
173     public String getBundleExpr() {
174         return (bundleExpr);
175     }
176 
177     /***
178      * Setter method for "cdata" tag attribute. (Mapping set in associated
179      * BeanInfo class.)
180      */
181     public void setCdataExpr(String cdataExpr) {
182         this.cdataExpr = cdataExpr;
183     }
184 
185     /***
186      * Setter method for "dynamicJavascript" tag attribute. (Mapping set in
187      * associated BeanInfo class.)
188      */
189     public void setDynamicJavascriptExpr(String dynamicJavascriptExpr) {
190         this.dynamicJavascriptExpr = dynamicJavascriptExpr;
191     }
192 
193     /***
194      * Setter method for "formName" tag attribute. (Mapping set in associated
195      * BeanInfo class.)
196      */
197     public void setFormNameExpr(String formNameExpr) {
198         this.formNameExpr = formNameExpr;
199     }
200 
201     /***
202      * Setter method for "method" tag attribute. (Mapping set in associated
203      * BeanInfo class.)
204      */
205     public void setMethodExpr(String methodExpr) {
206         this.methodExpr = methodExpr;
207     }
208 
209     /***
210      * Setter method for "page" tag attribute. (Mapping set in associated
211      * BeanInfo class.)
212      */
213     public void setPageExpr(String pageExpr) {
214         this.pageExpr = pageExpr;
215     }
216 
217     /***
218      * Setter method for "scriptLanguage" tag attribute. (Mapping set in
219      * associated BeanInfo class.)
220      */
221     public void setScriptLanguageExpr(String scriptLanguageExpr) {
222         this.scriptLanguageExpr = scriptLanguageExpr;
223     }
224 
225     /***
226      * Setter method for "src" tag attribute. (Mapping set in associated
227      * BeanInfo class.)
228      */
229     public void setSrcExpr(String srcExpr) {
230         this.srcExpr = srcExpr;
231     }
232 
233     /***
234      * Setter method for "staticJavascript" tag attribute. (Mapping set in
235      * associated BeanInfo class.)
236      */
237     public void setStaticJavascriptExpr(String staticJavascriptExpr) {
238         this.staticJavascriptExpr = staticJavascriptExpr;
239     }
240 
241     /***
242      * Setter method for "htmlComment" tag attribute. (Mapping set in
243      * associated BeanInfo class.)
244      */
245     public void setHtmlCommentExpr(String htmlCommentExpr) {
246         this.htmlCommentExpr = htmlCommentExpr;
247     }
248 
249     /***
250      * Setter method for "bundle" tag attribute. (Mapping set in associated
251      * BeanInfo class.)
252      */
253     public void setBundleExpr(String bundleExpr) {
254         this.bundleExpr = bundleExpr;
255     }
256 
257     /***
258      * Resets attribute values for tag reuse.
259      */
260     public void release() {
261         super.release();
262         setCdataExpr(null);
263         setDynamicJavascriptExpr(null);
264         setFormNameExpr(null);
265         setMethodExpr(null);
266         setPageExpr(null);
267         setScriptLanguageExpr(null);
268         setSrcExpr(null);
269         setStaticJavascriptExpr(null);
270         setHtmlCommentExpr(null);
271         setBundleExpr(null);
272     }
273 
274     /***
275      * Process the start tag.
276      *
277      * @throws JspException if a JSP exception has occurred
278      */
279     public int doStartTag() throws JspException {
280         evaluateExpressions();
281 
282         return (super.doStartTag());
283     }
284 
285     /***
286      * Processes all attribute values which use the JSTL expression evaluation
287      * engine to determine their values.
288      *
289      * @throws JspException if a JSP exception has occurred
290      */
291     private void evaluateExpressions()
292         throws JspException {
293         String string = null;
294         Integer integer = null;
295         Boolean bool = null;
296 
297         if ((string =
298                 EvalHelper.evalString("cdata", getCdataExpr(), this, pageContext)) != null) {
299             setCdata(string);
300         }
301 
302         if ((string =
303                 EvalHelper.evalString("dynamicJavascript",
304                     getDynamicJavascriptExpr(), this, pageContext)) != null) {
305             setDynamicJavascript(string);
306         }
307 
308         if ((string =
309                 EvalHelper.evalString("formName", getFormNameExpr(), this,
310                     pageContext)) != null) {
311             setFormName(string);
312         }
313 
314         if ((string =
315                 EvalHelper.evalString("method", getMethodExpr(), this,
316                     pageContext)) != null) {
317             setMethod(string);
318         }
319 
320         if ((integer =
321                 EvalHelper.evalInteger("page", getPageExpr(), this, pageContext)) != null) {
322             setPage(integer.intValue());
323         }
324 
325         if ((bool =
326                 EvalHelper.evalBoolean("scriptLanguage",
327                     getScriptLanguageExpr(), this, pageContext)) != null) {
328             setScriptLanguage(bool.booleanValue());
329         }
330 
331         if ((string =
332                 EvalHelper.evalString("src", getSrcExpr(), this, pageContext)) != null) {
333             setSrc(string);
334         }
335 
336         if ((string =
337                 EvalHelper.evalString("staticJavascript",
338                     getStaticJavascriptExpr(), this, pageContext)) != null) {
339             setStaticJavascript(string);
340         }
341 
342         if ((string =
343                 EvalHelper.evalString("htmlComment", getHtmlCommentExpr(),
344                     this, pageContext)) != null) {
345             setHtmlComment(string);
346         }
347 
348         if ((string =
349                 EvalHelper.evalString("bundle", getBundleExpr(), this,
350                     pageContext)) != null) {
351             setBundle(string);
352         }
353     }
354 }