Line | Hits | Source |
---|---|---|
1 | /* | |
2 | Chrysalis Web Framework [http://chrysalis.sourceforge.net] | |
3 | Copyright (c) 2002, 2003, 2004, Paul Strack | |
4 | ||
5 | All rights reserved. | |
6 | ||
7 | Redistribution and use in source and binary forms, with or without | |
8 | modification, are permitted provided that the following conditions are met: | |
9 | ||
10 | 1. Redistributions of source code must retain the above copyright notice, this | |
11 | list of conditions and the following disclaimer. | |
12 | ||
13 | 2. Redistributions in binary form must reproduce the above copyright notice, | |
14 | this list of conditions and the following disclaimer in the documentation | |
15 | and/or other materials provided with the distribution. | |
16 | ||
17 | 3. Neither the name of the copyright holder nor the names of its contributors | |
18 | may be used to endorse or promote products derived from this software without | |
19 | specific prior written permission. | |
20 | ||
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | |
25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
31 | */ | |
32 | ||
33 | package org.chwf.taglib.jutil; | |
34 | ||
35 | import javax.servlet.jsp.JspException; | |
36 | ||
37 | import org.chwf.servlet.ServletUtils; | |
38 | import org.chwf.taglib.base.ObjectTagSupport; | |
39 | import org.chwf.taglib.base.TagException; | |
40 | ||
41 | /** | |
42 | * Tag handler for the <code><if></code> tag. | |
43 | * | |
44 | * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a> | |
45 | */ | |
46 | 86 | public class IfTag extends ObjectTagSupport { |
47 | ||
48 | /** Constant storing the last test result. */ | |
49 | 1 | public static final String LAST_IF_RESULT = |
50 | IfTag.class.getName() + ":LAST_IF_RESULT"; | |
51 | ||
52 | /** Whether the test value is initialized. */ | |
53 | 42 | private boolean initialized = false; |
54 | ||
55 | /** The test value. */ | |
56 | 42 | private boolean testResult = false; |
57 | ||
58 | /** | |
59 | * Calls superclass method. Is present here because of a bug in some servlet | |
60 | * engines that requires tag attibute setters to be defined in the tag class | |
61 | * itself. | |
62 | * | |
63 | * @param objectName The object name. | |
64 | * @throws JspException For errors. | |
65 | */ | |
66 | public void setObject(String objectName) throws JspException { | |
67 | 39 | super.setObject(objectName); |
68 | 39 | } |
69 | ||
70 | /** | |
71 | * Calls superclass method. Is present here because of a bug in some servlet | |
72 | * engines that requires tag attibute setters to be defined in the tag class | |
73 | * itself. | |
74 | * | |
75 | * @param property The property name. | |
76 | * @throws JspException For errors. | |
77 | */ | |
78 | public void setProperty(String property) throws JspException { | |
79 | 39 | super.setProperty(property); |
80 | 39 | } |
81 | ||
82 | /** | |
83 | * Calls superclass method. Is present here because of a bug in some servlet | |
84 | * engines that requires tag attibute setters to be defined in the tag class | |
85 | * itself. | |
86 | * | |
87 | * @param el The JSTL Expression Language statement. | |
88 | */ | |
89 | public void setEl(String el) { | |
90 | 5 | super.setEl(el); |
91 | 5 | } |
92 | ||
93 | /** | |
94 | * Clean up data for tag handler reuse and pooling. Should be overridden in | |
95 | * tag handler. Subclasses should always invoke their superclass's cleanup | |
96 | * method: <code>super.cleanup()</code> | |
97 | */ | |
98 | public void cleanup() { | |
99 | 10 | super.cleanup(); |
100 | 10 | this.initialized = false; |
101 | 10 | this.testResult = false; |
102 | 10 | } |
103 | ||
104 | /** | |
105 | * Evaluates test property and conditionally executes body. | |
106 | * | |
107 | * @return EVAL_BODY_INCLUDE If the test is true | |
108 | * @throws JspException If an exception is thrown during testing. | |
109 | */ | |
110 | public int doStart() throws JspException { | |
111 | try { | |
112 | 16 | this.initialized = false; |
113 | 16 | if (getTestResult()) { |
114 | 8 | return EVAL_BODY_INCLUDE; |
115 | } | |
116 | 8 | } catch (Exception ex) { |
117 | 0 | throw new TagException(ex); |
118 | } | |
119 | 8 | return SKIP_BODY; |
120 | } | |
121 | ||
122 | /** | |
123 | * Initialize LAST_IF_RESULT. | |
124 | * | |
125 | * @return EVAL_PAGE | |
126 | * @throws JspException For expression language parse errors. | |
127 | */ | |
128 | public int doEnd() throws JspException { | |
129 | 7 | ServletUtils.setPageAttribute( |
130 | pageContext, | |
131 | LAST_IF_RESULT, | |
132 | new Boolean(getTestResult())); | |
133 | 7 | return EVAL_PAGE; |
134 | } | |
135 | ||
136 | /** | |
137 | * Get results of test. | |
138 | * | |
139 | * @return true if object property evaluates to true. | |
140 | * @throws JspException For expression language parse errors. | |
141 | */ | |
142 | public boolean getTestResult() throws JspException { | |
143 | 26 | if (!this.initialized) { |
144 | 18 | this.testResult = false; |
145 | 18 | Object value = super.getTagResult(Boolean.class); |
146 | 18 | if (value instanceof Boolean) { |
147 | 18 | this.testResult = ((Boolean) value).booleanValue(); |
148 | } | |
149 | 18 | this.initialized = true; |
150 | } | |
151 | 26 | return this.testResult; |
152 | } | |
153 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |