KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > common > core > WhenTagSupport


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.common.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 import javax.servlet.jsp.tagext.Tag JavaDoc;
23
24 import org.apache.taglibs.standard.resources.Resources;
25
26 /**
27  * <p>WhenTagSupport is an abstract class that facilitates
28  * implementation of &lt;when&gt;-style tags in both the rtexprvalue
29  * and expression-evaluating libraries. It also supports
30  * &lt;otherwise&gt;.</p>
31  *
32  * <p>In particular, this base class does the following:</p>
33  *
34  * <ul>
35  * <li> overrides ConditionalTagSupport.doStartTag() to implement the
36  * appropriate semantics of subtags of &lt;choose&gt; </li>
37  * </ul>
38  *
39  * @author Shawn Bayern
40  */

41 public abstract class WhenTagSupport extends ConditionalTagSupport
42 {
43     //*********************************************************************
44
// Implementation of exclusive-conditional behavior
45

46     /*
47      * Includes its body if condition() evalutes to true AND its parent
48      * ChooseTag wants it to do so. The condition will not even be
49      * evaluated if ChooseTag instructs us not to run.
50      */

51     public int doStartTag() throws JspException JavaDoc {
52
53         Tag JavaDoc parent;
54
55         // make sure we're contained properly
56
if (!((parent = getParent()) instanceof ChooseTag))
57             throw new JspTagException JavaDoc(
58         Resources.getMessage("WHEN_OUTSIDE_CHOOSE"));
59
60         // make sure our parent wants us to continue
61
if (!((ChooseTag) parent).gainPermission())
62             return SKIP_BODY; // we've been reeled in
63

64         // handle conditional behavior
65
if (condition()) {
66             ((ChooseTag) parent).subtagSucceeded();
67             return EVAL_BODY_INCLUDE;
68         } else
69             return SKIP_BODY;
70     }
71 }
72
Popular Tags