KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > el > core > IfTag


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.standard.tag.el.core;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.JspTagException JavaDoc;
21 import javax.servlet.jsp.jstl.core.ConditionalTagSupport;
22
23 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
24 import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
25
26 /**
27  * <p>Tag handler for &lt;if&gt; in JSTL's expression-evaluating library.
28  * Because of the support provided by the ConditionalTagSupport class,
29  * thistag is trivial enough not to require a separate base supporting
30  * class common to both libraries.</p>
31  *
32  * @author Shawn Bayern
33  */

34
35 public class IfTag extends ConditionalTagSupport {
36
37     //*********************************************************************
38
// Constructor and lifecycle management
39

40     // initialize inherited and local state
41
public IfTag() {
42         super();
43         init();
44     }
45
46     // Releases any resources we may have (or inherit)
47
public void release() {
48         super.release();
49         init();
50     }
51
52
53     //*********************************************************************
54
// Supplied conditional logic
55

56     protected boolean condition() throws JspTagException JavaDoc {
57     try {
58             Object JavaDoc r = ExpressionEvaluatorManager.evaluate(
59                 "test", test, Boolean JavaDoc.class, this, pageContext);
60             if (r == null)
61                 throw new NullAttributeException("if", "test");
62         else
63             return (((Boolean JavaDoc) r).booleanValue());
64         } catch (JspException JavaDoc ex) {
65         throw new JspTagException JavaDoc(ex.toString(), ex);
66     }
67     }
68
69
70     //*********************************************************************
71
// Private state
72

73     private String JavaDoc test; // the value of the 'test' attribute
74

75
76     //*********************************************************************
77
// Accessors
78

79     // receives the tag's 'test' attribute
80
public void setTest(String JavaDoc test) {
81         this.test = test;
82     }
83
84
85     //*********************************************************************
86
// Private utility methods
87

88     // resets internal state
89
private void init() {
90         test = null;
91     }
92 }
93
Popular Tags