Index: LockhartContentSource.java =================================================================== RCS file: /cvs/glassfish/admin-gui/src/java/com/sun/enterprise/tools/admingui/servlet/LockhartContentSource.java,v retrieving revision 1.1 diff -c -r1.1 LockhartContentSource.java *** LockhartContentSource.java 19 Jan 2007 03:27:15 -0000 1.1 --- LockhartContentSource.java 14 Mar 2007 19:44:06 -0000 *************** *** 24,35 **** --- 24,37 ---- import java.io.File; import java.io.FileInputStream; + import java.io.FileNotFoundException; import java.io.InputStream; import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; + import javax.servlet.ServletContext; //import java.io.*; import java.util.StringTokenizer; *************** *** 37,45 **** //import javax.servlet.*; //import javax.servlet.http.*; - import org.apache.jasper.compiler.JspUtil; - - /** * */ --- 39,44 ---- *************** *** 67,114 **** public InputStream getInputStream(DownloadServlet.Context ctx) { HttpServletRequest request = (HttpServletRequest) ctx.getServletRequest(); - if (isJSP(request)) { - serveJSPPage(ctx); - //This attribute is used to decide whether to send error code, or not. - ctx.setAttribute("JSP_PAGE_SERVED", "true"); - - return null; - } String pathInfo = request.getPathInfo(); if (pathInfo == null || pathInfo.length() == 0) { return null; } String servletPath = request.getServletPath(); int index = pathInfo.lastIndexOf('.'); // Set the extension so it can be mapped to a MIME type String extnsn = pathInfo.substring(index + 1); ctx.setAttribute(DownloadServlet.EXTENSION, extnsn); // NOI18N - InputStream is = getClass().getClassLoader().getResourceAsStream(servletPath.substring(1)+pathInfo); ctx.setAttribute("filePath", is); - ctx.setAttribute("JSP_PAGE_SERVED", "false"); // Return an InputStream to the tmpFile return is; } /** - *

This method looks at the request information and determines if it - * thinks it is a jsp. Essentially it thinks anything that ends with - * "jsp" in is a jsp (this is not fool proof).

- */ - public boolean isJSP(HttpServletRequest request) { - String uri = request.getRequestURI(); - String pathInfo = request.getPathInfo(); - if ((uri.indexOf("jsp") > -1) && pathInfo.endsWith(".jsp")) { - return true; - } - return false; - } - - /** *

This method may be used to clean up any temporary resources. It * will be invoked after the InputStream has been * completely read.

--- 66,100 ---- public InputStream getInputStream(DownloadServlet.Context ctx) { HttpServletRequest request = (HttpServletRequest) ctx.getServletRequest(); String pathInfo = request.getPathInfo(); if (pathInfo == null || pathInfo.length() == 0) { return null; } + ServletContext sc = ctx.getServletConfig().getServletContext(); String servletPath = request.getServletPath(); + String realPath = sc.getRealPath(servletPath); + File file = new File(realPath+pathInfo); + InputStream is = null; + try { + is = new FileInputStream(file); + } catch (FileNotFoundException ex) { + //try classpath + is = getClass().getClassLoader().getResourceAsStream(servletPath.substring(1)+pathInfo); + } int index = pathInfo.lastIndexOf('.'); // Set the extension so it can be mapped to a MIME type String extnsn = pathInfo.substring(index + 1); ctx.setAttribute(DownloadServlet.EXTENSION, extnsn); // NOI18N ctx.setAttribute("filePath", is); // Return an InputStream to the tmpFile return is; } /** *

This method may be used to clean up any temporary resources. It * will be invoked after the InputStream has been * completely read.

*************** *** 134,231 **** * used for caching.

*/ public long getLastModified(DownloadServlet.Context context) { - if (isJSP((HttpServletRequest) context.getServletRequest())) { - // Don't cache JSP's - return -1; - } - // This will enable caching on all files served through this code path return DEFAULT_MODIFIED_DATE; } - private void serveJSPPage(DownloadServlet.Context ctx) { - HttpServletRequest request = (HttpServletRequest)ctx.getServletRequest(); - HttpServletResponse response = (HttpServletResponse)ctx.getServletResponse(); - String pathInfo = (String)request.getAttribute(PATH_INFO_ATTRIBUTE); - String servletPath = (String)request.getAttribute(SERVLET_PATH_ATTRIBUTE); - - if(servletPath == null) { - servletPath = request.getServletPath(); - pathInfo = request.getPathInfo(); - } - String className = getClassName(servletPath, pathInfo); - - try { - Class cls = Class.forName(className); - Object obj = cls.newInstance(); - ((HttpServlet)obj).init(ctx.getServletConfig()); - ((HttpServlet)obj).service(request, response); - } catch(Exception ex) { - //throw an exception here - } - } - - /** - * This method takes the servlet path and the pathInfo (which should be - * the jspName) and generates the class name of the generated JSP. Both - * of these Strings are expected to have a leading '/'. - */ - protected String getClassName(String servletPath, String jspName) { - return getClassName(servletPath+jspName); - } - - - /** - * This method takes the full jsp name and generates the class name for - * the generated JSP. - */ - protected String getClassName(String fullPath) { - fullPath = fullPath.trim(); - int lastSlash = fullPath.lastIndexOf('/'); - if (lastSlash == -1) { - // Probably an error, but just in case we'll do this and let it - // fail later. - return JSP_CLASS_PREFIX+JspUtil.makeJavaIdentifier(fullPath); - } - - // The packageName is the full path minus everything after last '/' - String packageName = fullPath.substring(0, ++lastSlash); - - // The jspName is everything after the last '/' - String jspName = fullPath.substring(lastSlash); - - // Make sure to get rid of any double slashes "//" - //This may never happen to our application. - for (int loc=packageName.indexOf("//"); loc != -1; - loc=packageName.indexOf("//")) { - packageName = packageName.replaceAll("//", "/"); - } - - // Get rid of leading '/' - if (packageName.startsWith("/")) { - packageName = packageName.substring(1); - } - - // Iterate through each part of path and call makeJavaIdentifier - StringTokenizer tok = new StringTokenizer(packageName, "/"); - StringBuffer className = new StringBuffer(JSP_CLASS_PREFIX); - while (tok.hasMoreTokens()) { - // Convert .'s to _'s + other conversions - className.append(JspUtil.makeJavaIdentifier(tok.nextToken())); - className.append('.'); - } - - // Add on the jsp name - className.append(JspUtil.makeJavaIdentifier(jspName)); - /* Commenting out for now, log later - if (Util.isLoggableFINER()) { - Util.logFINER("CLASSNAME = "+className); - } - */ - // Return the classname - return className.toString(); - } - /** * When an include() is called the PATH_INFO is set via a Request * attribute named "javax.servlet.include.path_info". This constant is --- 120,129 ---- *************** *** 241,251 **** */ private static final String SERVLET_PATH_ATTRIBUTE = "javax.servlet.include.servlet_path"; - - /** - * The base package where compiled JSP class files are located. - */ - private static final String JSP_CLASS_PREFIX = "org.apache.jsp."; /** * This is the default "Last-Modified" Date. Its value is the --- 139,144 ----