View Javadoc

1   /*
2    * $Id: ELMessagesPresentTag.java 376780 2006-02-10 18:09:22Z 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.logic;
19  
20  import org.apache.struts.taglib.logic.MessagesPresentTag;
21  import org.apache.strutsel.taglib.utils.EvalHelper;
22  
23  import javax.servlet.jsp.JspException;
24  
25  /***
26   * Evalute to <code>true</code> if an <code>ActionMessages</code> class or a
27   * class that can be converted to an <code>ActionMessages</code> class is in
28   * request scope under the specified key and there is at least one message in
29   * the class or for the property specified. <p> This class is a subclass of
30   * the class <code>org.apache.struts.taglib.logic.MessagesPresentTag</code>
31   * which provides most of the described functionality.  This subclass allows
32   * all attribute values to be specified as expressions utilizing the
33   * JavaServer Pages Standard Library expression language.
34   *
35   * @version $Rev: 376780 $
36   */
37  public class ELMessagesPresentTag extends MessagesPresentTag {
38      /***
39       * Instance variable mapped to "name" tag attribute. (Mapping set in
40       * associated BeanInfo class.)
41       */
42      private String nameExpr;
43  
44      /***
45       * Instance variable mapped to "property" tag attribute. (Mapping set in
46       * associated BeanInfo class.)
47       */
48      private String propertyExpr;
49  
50      /***
51       * Instance variable mapped to "message" tag attribute. (Mapping set in
52       * associated BeanInfo class.)
53       */
54      private String messageExpr;
55  
56      /***
57       * Getter method for "name" tag attribute. (Mapping set in associated
58       * BeanInfo class.)
59       */
60      public String getNameExpr() {
61          return (nameExpr);
62      }
63  
64      /***
65       * Getter method for "property" tag attribute. (Mapping set in associated
66       * BeanInfo class.)
67       */
68      public String getPropertyExpr() {
69          return (propertyExpr);
70      }
71  
72      /***
73       * Getter method for "message" tag attribute. (Mapping set in associated
74       * BeanInfo class.)
75       */
76      public String getMessageExpr() {
77          return (messageExpr);
78      }
79  
80      /***
81       * Setter method for "name" tag attribute. (Mapping set in associated
82       * BeanInfo class.)
83       */
84      public void setNameExpr(String nameExpr) {
85          this.nameExpr = nameExpr;
86      }
87  
88      /***
89       * Setter method for "property" tag attribute. (Mapping set in associated
90       * BeanInfo class.)
91       */
92      public void setPropertyExpr(String propertyExpr) {
93          this.propertyExpr = propertyExpr;
94      }
95  
96      /***
97       * Setter method for "message" tag attribute. (Mapping set in associated
98       * BeanInfo class.)
99       */
100     public void setMessageExpr(String messageExpr) {
101         this.messageExpr = messageExpr;
102     }
103 
104     /***
105      * Releases state of custom tag so this instance can be reused.
106      */
107     public void release() {
108         super.release();
109         setNameExpr(null);
110         setPropertyExpr(null);
111         setMessageExpr(null);
112     }
113 
114     /***
115      * Process the start tag.
116      *
117      * @throws JspException if a JSP exception has occurred
118      */
119     public int doStartTag() throws JspException {
120         evaluateExpressions();
121 
122         return (super.doStartTag());
123     }
124 
125     /***
126      * Processes all attribute values which use the JSTL expression evaluation
127      * engine to determine their values.
128      *
129      * @throws JspException if a JSP exception has occurred
130      */
131     private void evaluateExpressions()
132         throws JspException {
133         String string = null;
134 
135         if ((string =
136                 EvalHelper.evalString("name", getNameExpr(), this, pageContext)) != null) {
137             setName(string);
138         }
139 
140         if ((string =
141                 EvalHelper.evalString("property", getPropertyExpr(), this,
142                     pageContext)) != null) {
143             setProperty(string);
144         }
145 
146         if ((string =
147                 EvalHelper.evalString("message", getMessageExpr(), this,
148                     pageContext)) != null) {
149             setMessage(string);
150         }
151     }
152 }