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