KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.NullAttributeException;
22 import org.apache.taglibs.standard.tag.common.xml.ParseSupport;
23 import org.apache.taglibs.standard.tag.el.core.ExpressionUtil;
24 import org.xml.sax.XMLFilter JavaDoc;
25
26 /**
27  * <p>A handler for &lt;parse&gt; that accepts attributes as Strings
28  * and evaluates them as expressions at runtime.</p>
29  *
30  * @author Shawn Bayern
31  */

32 public class ParseTag extends ParseSupport {
33
34     //*********************************************************************
35
// 'Private' state (implementation details)
36

37     private String JavaDoc xml_; // stores EL-based property
38
private String JavaDoc systemId_; // stores EL-based property
39
private String JavaDoc filter_; // stores EL-based property
40

41
42     //*********************************************************************
43
// Constructor
44

45     /**
46      * Constructs a new ParseTag. As with TagSupport, subclasses
47      * should not provide other constructors and are expected to call
48      * the superclass constructor
49      */

50     public ParseTag() {
51         super();
52         init();
53     }
54
55
56     //*********************************************************************
57
// Tag logic
58

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

80     // for EL-based attribute
81
public void setFilter(String JavaDoc filter_) {
82         this.filter_ = filter_;
83     }
84
85     public void setXml(String JavaDoc xml_) {
86         this.xml_ = xml_;
87     }
88
89     public void setSystemId(String JavaDoc systemId_) {
90         this.systemId_ = systemId_;
91     }
92
93
94     //*********************************************************************
95
// Private (utility) methods
96

97     // (re)initializes state (during release() or construction)
98
private void init() {
99         // null implies "no expression"
100
filter_ = xml_ = systemId_ = null;
101     }
102
103     /* Evaluates expressions as necessary */
104     private void evaluateExpressions() throws JspException JavaDoc {
105         /*
106          * Note: we don't check for type mismatches here; we assume
107          * the expression evaluator will return the expected type
108          * (by virtue of knowledge we give it about what that type is).
109          * A ClassCastException here is truly unexpected, so we let it
110          * propagate up.
111          */

112
113     xml = ExpressionUtil.evalNotNull(
114         "parse", "xml", xml_, Object JavaDoc.class, this, pageContext);
115     systemId = (String JavaDoc) ExpressionUtil.evalNotNull(
116         "parse", "systemId", systemId_, String JavaDoc.class, this, pageContext);
117
118     try {
119         filter = (XMLFilter JavaDoc) ExpressionUtil.evalNotNull(
120             "parse", "filter", filter_, XMLFilter JavaDoc.class, this, pageContext);
121     } catch (NullAttributeException ex) {
122         // explicitly let 'filter' be null
123
filter = null;
124     }
125     }
126 }
127
Popular Tags