Update of /cvsroot/struts-menu/navigator/src/java/net/sf/navigator/example In directory sc8-pr-cvs1:/tmp/cvs-serv11501/src/java/net/sf/navigator/example
Added Files: DisplaySourceServlet.java Log Message: cleaned up sample application and added servlet to view source of a JSP --- NEW FILE: DisplaySourceServlet.java --- package net.sf.navigator.example; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * <p>Servlet used to display jsp source for example pages</p> * @author fgiust (from displaytag project) */ public class DisplaySourceServlet extends HttpServlet { //~ Static fields/initializers ============================================= /** * the folder containg example pages */ private static final String EXAMPLE_FOLDER = "/"; //~ Methods ================================================================ /** * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest, HttpServletResponse) */ protected final void doGet(HttpServletRequest pRequest, HttpServletResponse pResponse) throws ServletException, IOException { String lJspFile = pRequest.getRequestURI(); // lastIndexOf(".") can't be null, since the servlet is mapped to ".src" lJspFile = lJspFile.substring(0, lJspFile.lastIndexOf(".")); if (lJspFile.lastIndexOf("/") != -1) { lJspFile = lJspFile.substring(lJspFile.lastIndexOf("/") + 1); } String lFullName = EXAMPLE_FOLDER + lJspFile; InputStream lInputStream = getServletContext().getResourceAsStream(lFullName); if (lInputStream == null) { throw new ServletException("Unable to find JSP file: " + lJspFile); } pResponse.setContentType("text/html"); PrintWriter lOut = pResponse.getWriter(); lOut.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" " + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); lOut.println("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">"); lOut.println("<head>"); lOut.println("<title>"); lOut.println("source for " + lJspFile); lOut.println("</title>"); lOut.println("<meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-1\" />"); lOut.println("</head>"); lOut.println("<body>"); lOut.println("<pre>"); for (int lChar = lInputStream.read(); lChar != -1; lChar = lInputStream.read()) { if (lChar == '<') { lOut.print("<"); } else { lOut.print((char) lChar); } } lOut.println("</pre>"); lOut.println("</body>"); lOut.println("</html>"); } } ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ struts-menu-devel mailing list [EMAIL PROTECTED] https://lists.sf.net/lists/listinfo/struts-menu-devel