home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-tomcat-addon-1.4.9-installer.exe / ShowSource.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-05-17  |  2.1 KB  |  52 lines

  1. package examples;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import javax.servlet.jsp.JspException;
  7. import javax.servlet.jsp.JspTagException;
  8. import javax.servlet.jsp.JspWriter;
  9. import javax.servlet.jsp.tagext.TagSupport;
  10.  
  11. public class ShowSource extends TagSupport {
  12.    String jspFile;
  13.  
  14.    public void setJspFile(String jspFile) {
  15.       this.jspFile = jspFile;
  16.    }
  17.  
  18.    public int doEndTag() throws JspException {
  19.       if (this.jspFile.indexOf("..") < 0 && this.jspFile.toUpperCase().indexOf("/WEB-INF/") == 0 && this.jspFile.toUpperCase().indexOf("/META-INF/") == 0) {
  20.          InputStream in = this.pageContext.getServletContext().getResourceAsStream(this.jspFile);
  21.          if (in == null) {
  22.             throw new JspTagException("Unable to find JSP file: " + this.jspFile);
  23.          } else {
  24.             new InputStreamReader(in);
  25.             JspWriter out = this.pageContext.getOut();
  26.  
  27.             try {
  28.                out.println("<body>");
  29.                out.println("<pre>");
  30.  
  31.                for(int ch = in.read(); ch != -1; ch = in.read()) {
  32.                   if (ch == 60) {
  33.                      out.print("<");
  34.                   } else {
  35.                      out.print((char)ch);
  36.                   }
  37.                }
  38.  
  39.                out.println("</pre>");
  40.                out.println("</body>");
  41.             } catch (IOException ex) {
  42.                throw new JspTagException("IOException: " + ex.toString());
  43.             }
  44.  
  45.             return super.doEndTag();
  46.          }
  47.       } else {
  48.          throw new JspTagException("Invalid JSP file " + this.jspFile);
  49.       }
  50.    }
  51. }
  52.