KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > tag > el > xml > ExprTag


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.el.xml;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20
21 import org.apache.taglibs.standard.tag.common.xml.ExprSupport;
22 import org.apache.taglibs.standard.tag.el.core.ExpressionUtil;
23
24 /**
25  * <p>A handler for &lt;out&gt; that accepts attributes as Strings
26  * and evaluates them as expressions at runtime.</p>
27  *
28  * @author Shawn Bayern
29  */

30 public class ExprTag extends ExprSupport {
31
32     //*********************************************************************
33
// 'Private' state (implementation details)
34

35     private String JavaDoc escapeXml_; // stores EL-based property
36

37
38     //*********************************************************************
39
// Constructor
40

41     /**
42      * Constructs a new handler. As with TagSupport, subclasses
43      * should not provide other constructors and are expected to call
44      * the superclass constructor
45      */

46     public ExprTag() {
47         super();
48         init();
49     }
50
51
52     //*********************************************************************
53
// Tag logic
54

55     // evaluates expression and chains to parent
56
public int doStartTag() throws JspException JavaDoc {
57
58         // evaluate any expressions we were passed, once per invocation
59
evaluateExpressions();
60
61     // chain to the parent implementation
62
return super.doStartTag();
63     }
64
65
66     // Releases any resources we may have (or inherit)
67
public void release() {
68         super.release();
69         init();
70     }
71
72
73     //*********************************************************************
74
// Accessor methods
75

76     // for EL-based attribute
77
public void setEscapeXml(String JavaDoc escapeXml_) {
78         this.escapeXml_ = escapeXml_;
79     }
80
81
82     //*********************************************************************
83
// Private (utility) methods
84

85     // (re)initializes state (during release() or construction)
86
private void init() {
87         // null implies "no expression"
88
escapeXml_ = null;
89     }
90
91     /* Evaluates expressions as necessary */
92     private void evaluateExpressions() throws JspException JavaDoc {
93         /*
94          * Note: we don't check for type mismatches here; we assume
95          * the expression evaluator will return the expected type
96          * (by virtue of knowledge we give it about what that type is).
97          * A ClassCastException here is truly unexpected, so we let it
98          * propagate up.
99          */

100
101         if (escapeXml_ != null) {
102             Boolean JavaDoc b = (Boolean JavaDoc) ExpressionUtil.evalNotNull(
103                 "out",
104                 "escapeXml",
105                 escapeXml_,
106                 Boolean JavaDoc.class,
107                 this,
108                 pageContext);
109             if (b == null)
110                 escapeXml = false;
111             else
112                 escapeXml = b.booleanValue();
113         }
114     }
115 }
116
Popular Tags