001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Portions Copyright Apache Software Foundation.
007: *
008: * The contents of this file are subject to the terms of either the GNU
009: * General Public License Version 2 only ("GPL") or the Common Development
010: * and Distribution License("CDDL") (collectively, the "License"). You
011: * may not use this file except in compliance with the License. You can obtain
012: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
013: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
014: * language governing permissions and limitations under the License.
015: *
016: * When distributing the software, include this License Header Notice in each
017: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
018: * Sun designates this particular file as subject to the "Classpath" exception
019: * as provided by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the License
021: * Header, with the fields enclosed by brackets [] replaced by your own
022: * identifying information: "Portions Copyrighted [year]
023: * [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * If you wish your version of this file to be governed by only the CDDL or
028: * only the GPL Version 2, indicate your decision by adding "[Contributor]
029: * elects to include this software in this distribution under the [CDDL or GPL
030: * Version 2] license." If you don't indicate a single choice of license, a
031: * recipient has the option to distribute your version of this file under
032: * either the CDDL, the GPL Version 2 or to extend the choice of license to
033: * its licensees as provided above. However, if you add GPL Version 2 code
034: * and therefore, elected the GPL Version 2 license, then the option applies
035: * only if the new code is made subject to such option by the copyright
036: * holder.
037: */
038:
039: package org.apache.taglibs.standard.tag.el.core;
040:
041: import javax.servlet.jsp.JspException;
042: import javax.servlet.jsp.JspTagException;
043:
044: import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
045: import org.apache.taglibs.standard.tag.common.core.NullAttributeException;
046: import org.apache.taglibs.standard.tag.common.core.WhenTagSupport;
047:
048: /**
049: * <p>Tag handler for <when> in JSTL's expression-evaluating
050: * library.</p>
051: *
052: * @author Shawn Bayern
053: */
054:
055: public class WhenTag extends WhenTagSupport {
056:
057: //*********************************************************************
058: // Constructor and lifecycle management
059:
060: // initialize inherited and local state
061: public WhenTag() {
062: super ();
063: init();
064: }
065:
066: // Releases any resources we may have (or inherit)
067: public void release() {
068: super .release();
069: init();
070: }
071:
072: //*********************************************************************
073: // Supplied conditional logic
074:
075: protected boolean condition() throws JspTagException {
076: try {
077: Object r = ExpressionEvaluatorManager.evaluate("test",
078: test, Boolean.class, this , pageContext);
079: if (r == null)
080: throw new NullAttributeException("when", "test");
081: else
082: return (((Boolean) r).booleanValue());
083: } catch (JspException ex) {
084: throw new JspTagException(ex.toString(), ex);
085: }
086: }
087:
088: //*********************************************************************
089: // Private state
090:
091: private String test; // the value of the 'test' attribute
092:
093: //*********************************************************************
094: // Accessors
095:
096: // receives the tag's 'test' attribute
097: public void setTest(String test) {
098: this .test = test;
099: }
100:
101: //*********************************************************************
102: // Private utility methods
103:
104: // resets internal state
105: private void init() {
106: test = null;
107: }
108: }
|