home *** CD-ROM | disk | FTP | other *** search
- package examples;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import javax.servlet.jsp.JspException;
- import javax.servlet.jsp.JspTagException;
- import javax.servlet.jsp.JspWriter;
- import javax.servlet.jsp.tagext.TagSupport;
-
- public class ShowSource extends TagSupport {
- String jspFile;
-
- public void setJspFile(String jspFile) {
- this.jspFile = jspFile;
- }
-
- public int doEndTag() throws JspException {
- if (this.jspFile.indexOf("..") < 0 && this.jspFile.toUpperCase().indexOf("/WEB-INF/") == 0 && this.jspFile.toUpperCase().indexOf("/META-INF/") == 0) {
- InputStream in = this.pageContext.getServletContext().getResourceAsStream(this.jspFile);
- if (in == null) {
- throw new JspTagException("Unable to find JSP file: " + this.jspFile);
- } else {
- new InputStreamReader(in);
- JspWriter out = this.pageContext.getOut();
-
- try {
- out.println("<body>");
- out.println("<pre>");
-
- for(int ch = in.read(); ch != -1; ch = in.read()) {
- if (ch == 60) {
- out.print("<");
- } else {
- out.print((char)ch);
- }
- }
-
- out.println("</pre>");
- out.println("</body>");
- } catch (IOException ex) {
- throw new JspTagException("IOException: " + ex.toString());
- }
-
- return super.doEndTag();
- }
- } else {
- throw new JspTagException("Invalid JSP file " + this.jspFile);
- }
- }
- }
-