KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > xsl > ExportTag


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.xsl;
18
19
20 import java.io.BufferedInputStream JavaDoc;
21 import java.io.InputStreamReader JavaDoc;
22 import java.net.URL JavaDoc;
23 import java.net.URLConnection JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25 import javax.servlet.jsp.JspException JavaDoc;
26 import javax.servlet.jsp.JspWriter JavaDoc;
27 import javax.servlet.jsp.PageContext JavaDoc;
28 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
29
30
31 /**
32  * Export the content of the specified JSP bean (in the specified scope)
33  * to our output writer, presumably after modifications have been completed.
34  *
35  * @author Craig R. McClanahan
36  * @version $Revision: 1.2 $ $Date: 2004/03/08 02:41:31 $
37  */

38
39 public class ExportTag extends TagSupport JavaDoc {
40
41
42     // ------------------------------------------------------------- Properties
43

44
45     /**
46      * The name of the scripting variable to be accessed.
47      */

48     private String JavaDoc name = null;
49
50     public String JavaDoc getName() {
51     return (this.name);
52     }
53
54     public void setName(String JavaDoc name) {
55     this.name = name;
56     }
57
58
59     /**
60      * The scope in which the scripting variable should be accessed.
61      */

62     private String JavaDoc scope = "page";
63
64     public String JavaDoc getScope() {
65     return (this.scope);
66     }
67
68     public void setScope(String JavaDoc scope) {
69     this.scope = scope;
70     }
71
72
73     // --------------------------------------------------------- Public Methods
74

75
76     /**
77      * Export the contents of the specified JSP bean in the specified scope
78      * to our output writer.
79      *
80      * @exception JspException if a JSP error occurs
81      */

82     public int doStartTag() throws JspException JavaDoc {
83
84     // Validate the value of the "scope" attribute
85
int scopeId = 0;
86     if ("page".equalsIgnoreCase(scope))
87         scopeId = PageContext.PAGE_SCOPE;
88     else if ("request".equalsIgnoreCase(scope))
89         scopeId = PageContext.REQUEST_SCOPE;
90     else if ("session".equalsIgnoreCase(scope))
91         scopeId = PageContext.SESSION_SCOPE;
92     else if ("application".equalsIgnoreCase(scope))
93         scopeId = PageContext.APPLICATION_SCOPE;
94     else
95         throw new JspException JavaDoc("Invalid scope value '" + scope + "'");
96
97     // Acquire the bean we will be rendering
98
Object JavaDoc bean = pageContext.getAttribute(name, scopeId);
99     if (bean == null)
100         throw new JspException JavaDoc("Missing JSP bean '" + name + "'");
101     ; // FIXME - Special handling for DOM, InputSource, etc.?
102
if (!(bean instanceof String JavaDoc))
103         bean = bean.toString();
104
105     // Render the contents of this bean to our writer
106
try {
107         JspWriter JavaDoc out = pageContext.getOut();
108         out.print((String JavaDoc) bean);
109     } catch (Exception JavaDoc e) {
110         throw new JspException JavaDoc("Error writing output: " + e.toString());
111     }
112
113     // Skip the body of this tag (which should be empty anyway)
114
return (SKIP_BODY);
115
116     }
117
118
119 }
120
Popular Tags