KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jasper > tagplugins > jstl > When


1
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the "License"). You may not use this file except
7  * in compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * glassfish/bootstrap/legal/CDDLv1.0.txt or
11  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * HEADER in each file and include the License file at
17  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18  * add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your
20  * own identifying information: Portions Copyright [yyyy]
21  * [name of copyright owner]
22  *
23  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24  *
25  * Portions Copyright Apache Software Foundation.
26  */

27
28 package org.apache.jasper.tagplugins.jstl;
29
30 import org.apache.jasper.compiler.tagplugin.*;
31
32 public final class When implements TagPlugin {
33
34     public void doTag(TagPluginContext ctxt) {
35     // Get the parent context to determine if this is the first <c:when>
36
TagPluginContext parentContext = ctxt.getParentContext();
37     if (parentContext == null) {
38         ctxt.dontUseTagPlugin();
39         return;
40     }
41
42     if ("true".equals(parentContext.getPluginAttribute("hasBeenHere"))) {
43         ctxt.generateJavaSource("} else if(");
44         // See comment below for the reason we generate the extra "}" here.
45
}
46     else {
47         ctxt.generateJavaSource("if(");
48         parentContext.setPluginAttribute("hasBeenHere", "true");
49     }
50     ctxt.generateAttribute("test");
51     ctxt.generateJavaSource("){");
52     ctxt.generateBody();
53
54     // We don't generate the closing "}" for the "if" here because there
55
// may be whitespaces in between <c:when>'s. Instead we delay
56
// generating it until the next <c:when> or <c:otherwise> or
57
// <c:choose>
58
}
59 }
60
Popular Tags