KickJava   Java API By Example, From Geeks To Geeks.

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