View Javadoc

1   /*
2    * $Id: ELPageTag.java 471754 2006-11-06 14:55:09Z husted $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.strutsel.taglib.bean;
22  
23  import org.apache.struts.taglib.bean.PageTag;
24  import org.apache.strutsel.taglib.utils.EvalHelper;
25  
26  import javax.servlet.jsp.JspException;
27  
28  /**
29   * Define a scripting variable that exposes the requested page context item as
30   * a scripting variable and a page scope bean. <p> This class is a subclass of
31   * the class <code>org.apache.struts.taglib.bean.PageTag</code> which provides
32   * most of the described functionality.  This subclass allows all attribute
33   * values to be specified as expressions utilizing the JavaServer Pages
34   * Standard Library expression language.
35   *
36   * @version $Rev: 471754 $
37   */
38  public class ELPageTag extends PageTag {
39      /**
40       * Instance variable mapped to "id" tag attribute. (Mapping set in
41       * associated BeanInfo class.)
42       */
43      private String idExpr;
44  
45      /**
46       * Instance variable mapped to "property" tag attribute. (Mapping set in
47       * associated BeanInfo class.)
48       */
49      private String propertyExpr;
50  
51      /**
52       * Getter method for "id" tag attribute. (Mapping set in associated
53       * BeanInfo class.)
54       */
55      public String getIdExpr() {
56          return (idExpr);
57      }
58  
59      /**
60       * Getter method for "property" tag attribute. (Mapping set in associated
61       * BeanInfo class.)
62       */
63      public String getPropertyExpr() {
64          return (propertyExpr);
65      }
66  
67      /**
68       * Setter method for "id" tag attribute. (Mapping set in associated
69       * BeanInfo class.)
70       */
71      public void setIdExpr(String idExpr) {
72          this.idExpr = idExpr;
73      }
74  
75      /**
76       * Setter method for "property" tag attribute. (Mapping set in associated
77       * BeanInfo class.)
78       */
79      public void setPropertyExpr(String propertyExpr) {
80          this.propertyExpr = propertyExpr;
81      }
82  
83      /**
84       * Resets attribute values for tag reuse.
85       */
86      public void release() {
87          super.release();
88          setIdExpr(null);
89          setPropertyExpr(null);
90      }
91  
92      /**
93       * Process the start tag.
94       *
95       * @throws JspException if a JSP exception has occurred
96       */
97      public int doStartTag() throws JspException {
98          evaluateExpressions();
99  
100         return (super.doStartTag());
101     }
102 
103     /**
104      * Processes all attribute values which use the JSTL expression evaluation
105      * engine to determine their values.
106      *
107      * @throws JspException if a JSP exception has occurred
108      */
109     private void evaluateExpressions()
110         throws JspException {
111         String string = null;
112 
113         if ((string =
114                 EvalHelper.evalString("id", getIdExpr(), this, pageContext)) != null) {
115             setId(string);
116         }
117 
118         if ((string =
119                 EvalHelper.evalString("property", getPropertyExpr(), this,
120                     pageContext)) != null) {
121             setProperty(string);
122         }
123     }
124 }