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:
043: import org.apache.taglibs.standard.tag.common.core.ParamSupport;
044:
045: /**
046: * <p>A handler for <param> that accepts attributes as Strings
047: * and evaluates them as expressions at runtime.</p>
048: *
049: * @author Shawn Bayern
050: */
051:
052: public class ParamTag extends ParamSupport {
053:
054: //*********************************************************************
055: // 'Private' state (implementation details)
056:
057: private String name_; // stores EL-based property
058: private String value_; // stores EL-based property
059:
060: //*********************************************************************
061: // Constructor
062:
063: /**
064: * Constructs a new ParamTag. As with TagSupport, subclasses
065: * should not provide other constructors and are expected to call
066: * the superclass constructor
067: */
068: public ParamTag() {
069: super ();
070: init();
071: }
072:
073: //*********************************************************************
074: // Tag logic
075:
076: // evaluates expression and chains to parent
077: public int doStartTag() throws JspException {
078:
079: // evaluate any expressions we were passed, once per invocation
080: evaluateExpressions();
081:
082: // chain to the parent implementation
083: return super .doStartTag();
084: }
085:
086: // Releases any resources we may have (or inherit)
087: public void release() {
088: super .release();
089: init();
090: }
091:
092: //*********************************************************************
093: // Accessor methods
094:
095: // for EL-based attribute
096: public void setName(String name_) {
097: this .name_ = name_;
098: }
099:
100: public void setValue(String value_) {
101: this .value_ = value_;
102: }
103:
104: //*********************************************************************
105: // Private (utility) methods
106:
107: // (re)initializes state (during release() or construction)
108: private void init() {
109: // null implies "no expression"
110: name_ = value_ = null;
111: }
112:
113: /* Evaluates expressions as necessary */
114: private void evaluateExpressions() throws JspException {
115: /*
116: * Note: we don't check for type mismatches here; we assume
117: * the expression evaluator will return the expected type
118: * (by virtue of knowledge we give it about what that type is).
119: * A ClassCastException here is truly unexpected, so we let it
120: * propagate up.
121: */
122:
123: name = (String) ExpressionUtil.evalNotNull("import", "name",
124: name_, String.class, this , pageContext);
125: value = (String) ExpressionUtil.evalNotNull("import", "value",
126: value_, String.class, this, pageContext);
127: }
128: }
|