View Javadoc

1   /*
2    * $Id: ELResourceTag.java 376778 2006-02-10 18:08:07Z 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.bean;
19  
20  import org.apache.struts.taglib.bean.ResourceTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Define a scripting variable based on the contents of the specified web
27   * application resource. <p> This class is a subclass of the class
28   * <code>org.apache.struts.taglib.bean.ResourceTag</code> which provides most
29   * of the described functionality.  This subclass allows all attribute values
30   * to be specified as expressions utilizing the JavaServer Pages Standard
31   * Library expression language.
32   *
33   * @version $Rev: 376778 $
34   */
35  public class ELResourceTag extends ResourceTag {
36      /***
37       * Instance variable mapped to "id" tag attribute. (Mapping set in
38       * associated BeanInfo class.)
39       */
40      private String idExpr;
41  
42      /***
43       * Instance variable mapped to "input" tag attribute. (Mapping set in
44       * associated BeanInfo class.)
45       */
46      private String inputExpr;
47  
48      /***
49       * Instance variable mapped to "name" tag attribute. (Mapping set in
50       * associated BeanInfo class.)
51       */
52      private String nameExpr;
53  
54      /***
55       * Getter method for "id" tag attribute. (Mapping set in associated
56       * BeanInfo class.)
57       */
58      public String getIdExpr() {
59          return (idExpr);
60      }
61  
62      /***
63       * Getter method for "input" tag attribute. (Mapping set in associated
64       * BeanInfo class.)
65       */
66      public String getInputExpr() {
67          return (inputExpr);
68      }
69  
70      /***
71       * Getter method for "name" tag attribute. (Mapping set in associated
72       * BeanInfo class.)
73       */
74      public String getNameExpr() {
75          return (nameExpr);
76      }
77  
78      /***
79       * Setter method for "id" tag attribute. (Mapping set in associated
80       * BeanInfo class.)
81       */
82      public void setIdExpr(String idExpr) {
83          this.idExpr = idExpr;
84      }
85  
86      /***
87       * Setter method for "input" tag attribute. (Mapping set in associated
88       * BeanInfo class.)
89       */
90      public void setInputExpr(String inputExpr) {
91          this.inputExpr = inputExpr;
92      }
93  
94      /***
95       * Setter method for "name" tag attribute. (Mapping set in associated
96       * BeanInfo class.)
97       */
98      public void setNameExpr(String nameExpr) {
99          this.nameExpr = nameExpr;
100     }
101 
102     /***
103      * Resets attribute values for tag reuse.
104      */
105     public void release() {
106         super.release();
107         setIdExpr(null);
108         setInputExpr(null);
109         setNameExpr(null);
110     }
111 
112     /***
113      * Process the start tag.
114      *
115      * @throws JspException if a JSP exception has occurred
116      */
117     public int doStartTag() throws JspException {
118         evaluateExpressions();
119 
120         return (super.doStartTag());
121     }
122 
123     /***
124      * Processes all attribute values which use the JSTL expression evaluation
125      * engine to determine their values.
126      *
127      * @throws JspException if a JSP exception has occurred
128      */
129     private void evaluateExpressions()
130         throws JspException {
131         String string = null;
132 
133         if ((string =
134                 EvalHelper.evalString("id", getIdExpr(), this, pageContext)) != null) {
135             setId(string);
136         }
137 
138         if ((string =
139                 EvalHelper.evalString("input", getInputExpr(), this, pageContext)) != null) {
140             setInput(string);
141         }
142 
143         if ((string =
144                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
145             setName(string);
146         }
147     }
148 }