View Javadoc

1   /*
2    * $Id: ELImportAttributeTag.java 376781 2006-02-10 18:09:48Z 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.tiles;
19  
20  import org.apache.struts.tiles.taglib.ImportAttributeTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Import attribute from component to requested scope. Attribute name and
27   * scope are optional. If not specified, all component attributes are imported
28   * in page scope. <p> This class is a subclass of the class
29   * <code>org.apache.struts.taglib.tiles.ImportAttributeTag</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: 376781 $
35   */
36  public class ELImportAttributeTag extends ImportAttributeTag {
37      /***
38       * Instance variable mapped to "scope" tag attribute. (Mapping set in
39       * associated BeanInfo class.)
40       */
41      private String scopeExpr;
42  
43      /***
44       * Instance variable mapped to "name" tag attribute. (Mapping set in
45       * associated BeanInfo class.)
46       */
47      private String nameExpr;
48  
49      /***
50       * Instance variable mapped to "ignore" tag attribute. (Mapping set in
51       * associated BeanInfo class.)
52       */
53      private String ignoreExpr;
54  
55      /***
56       * Getter method for "scope" tag attribute. (Mapping set in associated
57       * BeanInfo class.)
58       */
59      public String getScopeExpr() {
60          return (scopeExpr);
61      }
62  
63      /***
64       * Getter method for "name" tag attribute. (Mapping set in associated
65       * BeanInfo class.)
66       */
67      public String getNameExpr() {
68          return (nameExpr);
69      }
70  
71      /***
72       * Getter method for "ignore" tag attribute. (Mapping set in associated
73       * BeanInfo class.)
74       */
75      public String getIgnoreExpr() {
76          return (ignoreExpr);
77      }
78  
79      /***
80       * Setter method for "scope" tag attribute. (Mapping set in associated
81       * BeanInfo class.)
82       */
83      public void setScopeExpr(String scopeExpr) {
84          this.scopeExpr = scopeExpr;
85      }
86  
87      /***
88       * Setter method for "name" tag attribute. (Mapping set in associated
89       * BeanInfo class.)
90       */
91      public void setNameExpr(String nameExpr) {
92          this.nameExpr = nameExpr;
93      }
94  
95      /***
96       * Setter method for "ignore" tag attribute. (Mapping set in associated
97       * BeanInfo class.)
98       */
99      public void setIgnoreExpr(String ignoreExpr) {
100         this.ignoreExpr = ignoreExpr;
101     }
102 
103     /***
104      * Resets attribute values for tag reuse.
105      */
106     public void release() {
107         super.release();
108         setScopeExpr(null);
109         setNameExpr(null);
110         setIgnoreExpr(null);
111     }
112 
113     /***
114      * Process the start tag.
115      *
116      * @throws JspException if a JSP exception has occurred
117      */
118     public int doStartTag() throws JspException {
119         evaluateExpressions();
120 
121         return (super.doStartTag());
122     }
123 
124     /***
125      * Processes all attribute values which use the JSTL expression evaluation
126      * engine to determine their values.
127      *
128      * @throws JspException if a JSP exception has occurred
129      */
130     private void evaluateExpressions()
131         throws JspException {
132         String string = null;
133         Boolean bool = null;
134 
135         if ((string =
136                 EvalHelper.evalString("scope", getScopeExpr(), this, pageContext)) != null) {
137             setScope(string);
138         }
139 
140         if ((string =
141                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
142             setName(string);
143         }
144 
145         if ((bool =
146                 EvalHelper.evalBoolean("ignore", getIgnoreExpr(), this,
147                     pageContext)) != null) {
148             setIgnore(bool.booleanValue());
149         }
150     }
151 }