KickJava   Java API By Example, From Geeks To Geeks.

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


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

31 public class TransformTag extends TransformSupport {
32
33     //*********************************************************************
34
// 'Private' state (implementation details)
35

36     private String JavaDoc xml_; // stores EL-based property
37
private String JavaDoc xmlSystemId_; // stores EL-based property
38
private String JavaDoc xslt_; // stores EL-based property
39
private String JavaDoc xsltSystemId_; // stores EL-based property
40
private String JavaDoc result_; // stores EL-based property
41

42
43     //*********************************************************************
44
// Constructor
45

46     public TransformTag() {
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 setXml(String JavaDoc xml_) {
78         this.xml_ = xml_;
79     }
80
81     // for EL-based attribute
82
public void setXmlSystemId(String JavaDoc xmlSystemId_) {
83         this.xmlSystemId_ = xmlSystemId_;
84     }
85
86     // for EL-based attribute
87
public void setXslt(String JavaDoc xslt_) {
88         this.xslt_ = xslt_;
89     }
90
91     // for EL-based attribute
92
public void setXsltSystemId(String JavaDoc xsltSystemId_) {
93         this.xsltSystemId_ = xsltSystemId_;
94     }
95
96     /* Removed for RI 0.5
97      // for EL-based attribute
98      public void setTransformer(String transformer_) {
99          this.transformer_ = transformer_;
100      }
101     */

102
103     // for EL-based attribute
104
public void setResult(String JavaDoc result_) {
105         this.result_ = result_;
106     }
107
108
109     //*********************************************************************
110
// Private (utility) methods
111

112     // (re)initializes state (during release() or construction)
113
private void init() {
114         // null implies "no expression"
115
xml_ = xmlSystemId = xslt_ = xsltSystemId_ = result_ = null;
116     }
117
118     /* Evaluates expressions as necessary */
119     private void evaluateExpressions() throws JspException JavaDoc {
120         /*
121          * Note: we don't check for type mismatches here; we assume
122          * the expression evaluator will return the expected type
123          * (by virtue of knowledge we give it about what that type is).
124          * A ClassCastException here is truly unexpected, so we let it
125          * propagate up.
126          */

127
128     xml = ExpressionUtil.evalNotNull(
129         "transform", "xml", xml_, Object JavaDoc.class, this, pageContext);
130     xmlSystemId = (String JavaDoc) ExpressionUtil.evalNotNull(
131         "transform", "xmlSystemId", xmlSystemId_, String JavaDoc.class,
132             this, pageContext);
133     xslt= ExpressionUtil.evalNotNull(
134         "transform", "xslt", xslt_, Object JavaDoc.class, this,
135         pageContext);
136     xsltSystemId = (String JavaDoc) ExpressionUtil.evalNotNull(
137         "transform", "xsltSystemId", xsltSystemId_, String JavaDoc.class,
138         this, pageContext);
139     result = (Result JavaDoc) ExpressionUtil.evalNotNull(
140         "transform", "result", result_, Result JavaDoc.class, this, pageContext);
141
142     }
143 }
144
Popular Tags