KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.taglibs.xsl;
17
18
19 import javax.servlet.*;
20 import javax.servlet.jsp.*;
21 import javax.servlet.jsp.tagext.*;
22
23 import java.io.*;
24
25 /**
26  * Display the sources of the JSP file.
27  *
28  * Author Anil Vijendran.
29  */

30
31 public class ShowSource
32     extends TagSupport
33 {
34     String JavaDoc jspFile;
35     
36     public void setJspFile(String JavaDoc jspFile) {
37         this.jspFile = jspFile;
38     }
39
40     public int doEndTag() throws JspException {
41         InputStream in
42             = pageContext.getServletContext().getResourceAsStream(jspFile);
43
44         if (in == null)
45             throw new JspTagException("Unable to find JSP file: "+jspFile);
46         InputStreamReader reader = new InputStreamReader(in);
47         
48         JspWriter out = pageContext.getOut();
49
50         try {
51             out.println("<body>");
52             out.println("<pre>");
53             for(int ch = in.read(); ch != -1; ch = in.read())
54                 if (ch == '<')
55                     out.print("&lt;");
56                 else
57                     out.print((char) ch);
58             out.println("</pre>");
59             out.println("</body>");
60         } catch (IOException ex) {
61             throw new JspTagException("IOException: "+ex.toString());
62         }
63         return super.doEndTag();
64     }
65 }
66
67     
68         
69     
70
Popular Tags