KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > strutsel > taglib > logic > ELMessagesPresentTag


1 /*
2  * $Id: ELMessagesPresentTag.java 54933 2004-10-16 17:04:52Z germuska $
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
19 package org.apache.strutsel.taglib.logic;
20
21 import org.apache.struts.taglib.logic.MessagesPresentTag;
22 import javax.servlet.jsp.JspException JavaDoc;
23 import org.apache.strutsel.taglib.utils.EvalHelper;
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.
30  *<p>
31  * This class is a subclass of the class
32  * <code>org.apache.struts.taglib.logic.MessagesPresentTag</code> which
33  * provides most of the described functionality. This subclass allows all
34  * attribute values to be specified as expressions utilizing the JavaServer
35  * Pages Standard Library expression language.
36  *
37  * @version $Rev: 54933 $
38  */

39 public class ELMessagesPresentTag extends MessagesPresentTag {
40
41     /**
42      * Instance variable mapped to "name" tag attribute.
43      * (Mapping set in associated BeanInfo class.)
44      */

45     private String JavaDoc nameExpr;
46     /**
47      * Instance variable mapped to "property" tag attribute.
48      * (Mapping set in associated BeanInfo class.)
49      */

50     private String JavaDoc propertyExpr;
51     /**
52      * Instance variable mapped to "message" tag attribute.
53      * (Mapping set in associated BeanInfo class.)
54      */

55     private String JavaDoc messageExpr;
56
57     /**
58      * Getter method for "name" tag attribute.
59      * (Mapping set in associated BeanInfo class.)
60      */

61     public String JavaDoc getNameExpr() { return (nameExpr); }
62     /**
63      * Getter method for "property" tag attribute.
64      * (Mapping set in associated BeanInfo class.)
65      */

66     public String JavaDoc getPropertyExpr() { return (propertyExpr); }
67     /**
68      * Getter method for "message" tag attribute.
69      * (Mapping set in associated BeanInfo class.)
70      */

71     public String JavaDoc getMessageExpr() { return (messageExpr); }
72
73     /**
74      * Setter method for "name" tag attribute.
75      * (Mapping set in associated BeanInfo class.)
76      */

77     public void setNameExpr(String JavaDoc nameExpr) { this.nameExpr = nameExpr; }
78     /**
79      * Setter method for "property" tag attribute.
80      * (Mapping set in associated BeanInfo class.)
81      */

82     public void setPropertyExpr(String JavaDoc propertyExpr) { this.propertyExpr = propertyExpr; }
83     /**
84      * Setter method for "message" tag attribute.
85      * (Mapping set in associated BeanInfo class.)
86      */

87     public void setMessageExpr(String JavaDoc messageExpr) { this.messageExpr = messageExpr; }
88
89     /**
90      * Releases state of custom tag so this instance can be reused.
91      */

92     public void release()
93     {
94         super.release();
95         setNameExpr(null);
96         setPropertyExpr(null);
97         setMessageExpr(null);
98     }
99     
100     /**
101      * Process the start tag.
102      *
103      * @exception JspException if a JSP exception has occurred
104      */

105     public int doStartTag() throws JspException JavaDoc {
106         evaluateExpressions();
107         return (super.doStartTag());
108     }
109     
110     /**
111      * Processes all attribute values which use the JSTL expression evaluation
112      * engine to determine their values.
113      *
114      * @exception JspException if a JSP exception has occurred
115      */

116     private void evaluateExpressions() throws JspException JavaDoc {
117         String JavaDoc string = null;
118
119         if ((string = EvalHelper.evalString("name", getNameExpr(),
120                                             this, pageContext)) != null)
121             setName(string);
122
123         if ((string = EvalHelper.evalString("property", getPropertyExpr(),
124                                             this, pageContext)) != null)
125             setProperty(string);
126
127         if ((string = EvalHelper.evalString("message", getMessageExpr(),
128                                             this, pageContext)) != null)
129             setMessage(string);
130     }
131 }
132
Popular Tags