[displaytag-cvs] displaytag/src/test/java/org/apache/jasper/servlet JspServletWrapper.java,1.1,1.2
Brought to you by:
fgiust
|
From: fabrizio g. <fg...@us...> - 2005-10-16 20:35:02
|
Update of /cvsroot/displaytag/displaytag/src/test/java/org/apache/jasper/servlet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18315/src/test/java/org/apache/jasper/servlet Modified Files: JspServletWrapper.java Log Message: committing DISPL-245 WYSIWYG Exports - from Jorge L. Barroso + some changes and fixes Index: JspServletWrapper.java =================================================================== RCS file: /cvsroot/displaytag/displaytag/src/test/java/org/apache/jasper/servlet/JspServletWrapper.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JspServletWrapper.java 3 Sep 2005 17:53:29 -0000 1.1 --- JspServletWrapper.java 16 Oct 2005 20:34:38 -0000 1.2 *************** *** 40,43 **** --- 40,44 ---- import org.apache.jasper.runtime.JspSourceDependent; + /** * <p> *************** *** 47,60 **** * <code>JasperException</code>s</strong>. (fgiust) * </p> ! * ! * The JSP engine (a.k.a Jasper). ! * ! * The servlet container is responsible for providing a ! * URLClassLoader for the web application context Jasper ! * is being used in. Jasper will try get the Tomcat ! * ServletContext attribute for its ServletContext class ! * loader, if that fails, it uses the parent class loader. ! * In either case, it must be a URLClassLoader. ! * * @author Anil K. Vijendran * @author Harish Prabandham --- 48,55 ---- * <code>JasperException</code>s</strong>. (fgiust) * </p> ! * The JSP engine (a.k.a Jasper). The servlet container is responsible for providing a URLClassLoader for the web ! * application context Jasper is being used in. Jasper will try get the Tomcat ServletContext attribute for its ! * ServletContext class loader, if that fails, it uses the parent class loader. In either case, it must be a ! * URLClassLoader. * @author Anil K. Vijendran * @author Harish Prabandham *************** *** 64,68 **** */ ! public class JspServletWrapper { // Logger --- 59,64 ---- */ ! public class JspServletWrapper ! { // Logger *************** *** 70,86 **** --- 66,96 ---- private Servlet theServlet; + private String jspUri; + private Class servletClass; + private Class tagHandlerClass; + private JspCompilationContext ctxt; + private long available = 0L; + private ServletConfig config; + private Options options; + private boolean firstTime = true; + private boolean reload = true; + private boolean isTagFile; + private int tripCount; + private JasperException compileException; + private long servletClassLastModifiedTime; + private long lastModificationTest = 0L; *************** *** 88,102 **** * JspServletWrapper for JSP pages. */ ! JspServletWrapper(ServletConfig config, Options options, String jspUri, ! boolean isErrorPage, JspRuntimeContext rctxt) ! throws JasperException { ! this.isTagFile = false; this.config = config; this.options = options; this.jspUri = jspUri; ! ctxt = new JspCompilationContext(jspUri, isErrorPage, options, ! config.getServletContext(), ! this, rctxt); } --- 98,110 ---- * JspServletWrapper for JSP pages. */ ! JspServletWrapper(ServletConfig config, Options options, String jspUri, boolean isErrorPage, JspRuntimeContext rctxt) ! throws JasperException ! { ! this.isTagFile = false; this.config = config; this.options = options; this.jspUri = jspUri; ! ctxt = new JspCompilationContext(jspUri, isErrorPage, options, config.getServletContext(), this, rctxt); } *************** *** 104,156 **** * JspServletWrapper for tag files. */ ! public JspServletWrapper(ServletContext servletContext, ! Options options, ! String tagFilePath, ! TagInfo tagInfo, ! JspRuntimeContext rctxt, ! URL tagFileJarUrl) ! throws JasperException { ! this.isTagFile = true; this.config = null; // not used this.options = options; ! this.jspUri = tagFilePath; ! this.tripCount = 0; ! ctxt = new JspCompilationContext(jspUri, tagInfo, options, ! servletContext, this, rctxt, ! tagFileJarUrl); } ! public JspCompilationContext getJspEngineContext() { return ctxt; } ! public void setReload(boolean reload) { this.reload = reload; } ! public Servlet getServlet() ! throws ServletException, IOException, FileNotFoundException { ! if (reload) { ! synchronized (this) { // Synchronizing on jsw enables simultaneous loading // of different pages, but not the same page. ! if (reload) { // This is to maintain the original protocol. destroy(); ! try { servletClass = ctxt.load(); theServlet = (Servlet) servletClass.newInstance(); ! } catch( IllegalAccessException ex1 ) { ! throw new JasperException( ex1 ); ! } catch( InstantiationException ex ) { ! throw new JasperException( ex ); } theServlet.init(config); ! if (!firstTime) { ctxt.getRuntimeContext().incrementJspReloadCount(); } --- 112,173 ---- * JspServletWrapper for tag files. */ ! public JspServletWrapper( ! ServletContext servletContext, ! Options options, ! String tagFilePath, ! TagInfo tagInfo, ! JspRuntimeContext rctxt, ! URL tagFileJarUrl) throws JasperException ! { ! this.isTagFile = true; this.config = null; // not used this.options = options; ! this.jspUri = tagFilePath; ! this.tripCount = 0; ! ctxt = new JspCompilationContext(jspUri, tagInfo, options, servletContext, this, rctxt, tagFileJarUrl); } ! public JspCompilationContext getJspEngineContext() ! { return ctxt; } ! public void setReload(boolean reload) ! { this.reload = reload; } ! public Servlet getServlet() throws ServletException, IOException, FileNotFoundException { ! if (reload) ! { ! synchronized (this) ! { // Synchronizing on jsw enables simultaneous loading // of different pages, but not the same page. ! if (reload) ! { // This is to maintain the original protocol. destroy(); ! try ! { servletClass = ctxt.load(); theServlet = (Servlet) servletClass.newInstance(); ! } ! catch (IllegalAccessException ex1) ! { ! throw new JasperException(ex1); ! } ! catch (InstantiationException ex) ! { ! throw new JasperException(ex); } theServlet.init(config); ! if (!firstTime) ! { ctxt.getRuntimeContext().incrementJspReloadCount(); } *************** *** 163,167 **** } ! public ServletContext getServletContext() { return config.getServletContext(); } --- 180,185 ---- } ! public ServletContext getServletContext() ! { return config.getServletContext(); } *************** *** 169,189 **** /** * Sets the compilation exception for this JspServletWrapper. - * * @param je The compilation exception */ ! public void setCompilationException(JasperException je) { this.compileException = je; } /** ! * Sets the last-modified time of the servlet class file associated with ! * this JspServletWrapper. ! * * @param lastModified Last-modified time of servlet class */ ! public void setServletClassLastModifiedTime(long lastModified) { ! if (this.servletClassLastModifiedTime < lastModified) { ! synchronized (this) { ! if (this.servletClassLastModifiedTime < lastModified) { this.servletClassLastModifiedTime = lastModified; reload = true; --- 187,209 ---- /** * Sets the compilation exception for this JspServletWrapper. * @param je The compilation exception */ ! public void setCompilationException(JasperException je) ! { this.compileException = je; } /** ! * Sets the last-modified time of the servlet class file associated with this JspServletWrapper. * @param lastModified Last-modified time of servlet class */ ! public void setServletClassLastModifiedTime(long lastModified) ! { ! if (this.servletClassLastModifiedTime < lastModified) ! { ! synchronized (this) ! { ! if (this.servletClassLastModifiedTime < lastModified) ! { this.servletClassLastModifiedTime = lastModified; reload = true; *************** *** 196,240 **** * Compile (if needed) and load a tag file */ ! public Class loadTagFile() throws JasperException { ! try { ! if (ctxt.isRemoved()) { throw new FileNotFoundException(jspUri); } ! if (options.getDevelopment() || firstTime ) { ! synchronized (this) { firstTime = false; ctxt.compile(); } ! } else { ! if (compileException != null) { throw compileException; } } ! if (reload) { tagHandlerClass = ctxt.load(); } ! } catch (FileNotFoundException ex) { throw new JasperException(ex); ! } ! return tagHandlerClass; } /** ! * Compile and load a prototype for the Tag file. This is needed ! * when compiling tag files with circular dependencies. A prototpe ! * (skeleton) with no dependencies on other other tag files is ! * generated and compiled. */ ! public Class loadTagFilePrototype() throws JasperException { ! ctxt.setPrototypeMode(true); ! try { ! return loadTagFile(); ! } finally { ! ctxt.setPrototypeMode(false); ! } } --- 216,273 ---- * Compile (if needed) and load a tag file */ ! public Class loadTagFile() throws JasperException ! { ! try ! { ! if (ctxt.isRemoved()) ! { throw new FileNotFoundException(jspUri); } ! if (options.getDevelopment() || firstTime) ! { ! synchronized (this) ! { firstTime = false; ctxt.compile(); } ! } ! else ! { ! if (compileException != null) ! { throw compileException; } } ! if (reload) ! { tagHandlerClass = ctxt.load(); } ! } ! catch (FileNotFoundException ex) ! { throw new JasperException(ex); ! } ! return tagHandlerClass; } /** ! * Compile and load a prototype for the Tag file. This is needed when compiling tag files with circular ! * dependencies. A prototpe (skeleton) with no dependencies on other other tag files is generated and compiled. */ ! public Class loadTagFilePrototype() throws JasperException ! { ! ctxt.setPrototypeMode(true); ! try ! { ! return loadTagFile(); ! } ! finally ! { ! ctxt.setPrototypeMode(false); ! } } *************** *** 242,291 **** * Get a list of files that the current page has source dependency on. */ ! public java.util.List getDependants() { ! try { ! Object target; ! if (isTagFile) { ! if (reload) { tagHandlerClass = ctxt.load(); } ! target = tagHandlerClass.newInstance(); ! } else { ! target = getServlet(); } ! if (target != null && target instanceof JspSourceDependent) { ! return ((JspSourceDependent) target).getDependants(); } ! } catch (Throwable ex) { ! } ! return null; } ! public boolean isTagFile() { ! return this.isTagFile; } ! public int incTripCount() { ! return tripCount++; } ! public int decTripCount() { ! return tripCount--; } ! public void service(HttpServletRequest request, ! HttpServletResponse response, ! boolean precompile) ! throws ServletException, IOException, FileNotFoundException { ! try { ! if (ctxt.isRemoved()) { throw new FileNotFoundException(jspUri); } ! if ((available > 0L) && (available < Long.MAX_VALUE)) { response.setDateHeader("Retry-After", available); ! response.sendError ! (HttpServletResponse.SC_SERVICE_UNAVAILABLE, ! Localizer.getMessage("jsp.error.unavailable")); } --- 275,337 ---- * Get a list of files that the current page has source dependency on. */ ! public java.util.List getDependants() ! { ! try ! { ! Object target; ! if (isTagFile) ! { ! if (reload) ! { tagHandlerClass = ctxt.load(); } ! target = tagHandlerClass.newInstance(); ! } ! else ! { ! target = getServlet(); ! } ! if (target != null && target instanceof JspSourceDependent) ! { ! return ((JspSourceDependent) target).getDependants(); ! } } ! catch (Throwable ex) ! { } ! return null; } ! public boolean isTagFile() ! { ! return this.isTagFile; } ! public int incTripCount() ! { ! return tripCount++; } ! public int decTripCount() ! { ! return tripCount--; } ! public void service(HttpServletRequest request, HttpServletResponse response, boolean precompile) ! throws ServletException, IOException, FileNotFoundException ! { ! try ! { ! if (ctxt.isRemoved()) ! { throw new FileNotFoundException(jspUri); } ! if ((available > 0L) && (available < Long.MAX_VALUE)) ! { response.setDateHeader("Retry-After", available); ! response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, Localizer ! .getMessage("jsp.error.unavailable")); } *************** *** 293,298 **** * (1) Compile */ ! if (options.getDevelopment() || firstTime ) { ! synchronized (this) { firstTime = false; --- 339,346 ---- * (1) Compile */ ! if (options.getDevelopment() || firstTime) ! { ! synchronized (this) ! { firstTime = false; *************** *** 300,305 **** ctxt.compile(); } ! } else { ! if (compileException != null) { // Throw cached compilation exception throw compileException; --- 348,356 ---- ctxt.compile(); } ! } ! else ! { ! if (compileException != null) ! { // Throw cached compilation exception throw compileException; *************** *** 313,317 **** // If a page is to be precompiled only, return. ! if (precompile) { return; } --- 364,369 ---- // If a page is to be precompiled only, return. ! if (precompile) ! { return; } *************** *** 320,388 **** * (3) Service request */ ! if (theServlet instanceof SingleThreadModel) { ! // sync on the wrapper so that the freshness ! // of the page is determined right before servicing ! synchronized (this) { ! theServlet.service(request, response); } ! } else { theServlet.service(request, response); } ! } catch (UnavailableException ex) { ! String includeRequestUri = (String) ! request.getAttribute("javax.servlet.include.request_uri"); ! if (includeRequestUri != null) { // This file was included. Throw an exception as // a response.sendError() will be ignored by the // servlet engine. throw ex; ! } else { int unavailableSeconds = ex.getUnavailableSeconds(); ! if (unavailableSeconds <= 0) { ! unavailableSeconds = 60; // Arbitrary default } ! available = System.currentTimeMillis() + ! (unavailableSeconds * 1000L); ! response.sendError ! (HttpServletResponse.SC_SERVICE_UNAVAILABLE, ! ex.getMessage()); } ! } catch (FileNotFoundException ex) { ctxt.incrementRemoved(); ! String includeRequestUri = (String) ! request.getAttribute("javax.servlet.include.request_uri"); ! if (includeRequestUri != null) { // This file was included. Throw an exception as // a response.sendError() will be ignored by the // servlet engine. throw new ServletException(ex); ! } else { ! try { ! response.sendError(HttpServletResponse.SC_NOT_FOUND, ! ex.getMessage()); ! } catch (IllegalStateException ise) { ! log.error(Localizer.getMessage("jsp.error.file.not.found", ! ex.getMessage()), ! ex); } } ! } catch (ServletException ex) { ! throw ex; ! } catch (IOException ex) { throw ex; ! } catch (IllegalStateException ex) { throw ex; } ! // CHANGED by fgiust ! // } catch (Exception ex) { ! // log.error(ex.getClass().getName(), ex); ! // throw new JasperException(ex); ! // } ! // END CHANGED by fgiust } ! public void destroy() { ! if (theServlet != null) { theServlet.destroy(); } --- 372,458 ---- * (3) Service request */ ! if (theServlet instanceof SingleThreadModel) ! { ! // sync on the wrapper so that the freshness ! // of the page is determined right before servicing ! synchronized (this) ! { ! theServlet.service(request, response); } ! } ! else ! { theServlet.service(request, response); } ! } ! catch (UnavailableException ex) ! { ! String includeRequestUri = (String) request.getAttribute("javax.servlet.include.request_uri"); ! if (includeRequestUri != null) ! { // This file was included. Throw an exception as // a response.sendError() will be ignored by the // servlet engine. throw ex; ! } ! else ! { int unavailableSeconds = ex.getUnavailableSeconds(); ! if (unavailableSeconds <= 0) ! { ! unavailableSeconds = 60; // Arbitrary default } ! available = System.currentTimeMillis() + (unavailableSeconds * 1000L); ! response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, ex.getMessage()); } ! } ! catch (FileNotFoundException ex) ! { ctxt.incrementRemoved(); ! String includeRequestUri = (String) request.getAttribute("javax.servlet.include.request_uri"); ! if (includeRequestUri != null) ! { // This file was included. Throw an exception as // a response.sendError() will be ignored by the // servlet engine. throw new ServletException(ex); ! } ! else ! { ! try ! { ! response.sendError(HttpServletResponse.SC_NOT_FOUND, ex.getMessage()); ! } ! catch (IllegalStateException ise) ! { ! log.error(Localizer.getMessage("jsp.error.file.not.found", ex.getMessage()), ex); } } ! } ! catch (ServletException ex) ! { throw ex; ! } ! catch (IOException ex) ! { throw ex; } ! catch (IllegalStateException ex) ! { ! throw ex; ! } ! // CHANGED by fgiust ! // } catch (Exception ex) { ! // log.error(ex.getClass().getName(), ex); ! // throw new JasperException(ex); ! // } ! // END CHANGED by fgiust } ! public void destroy() ! { ! if (theServlet != null) ! { theServlet.destroy(); } *************** *** 392,402 **** * @return Returns the lastModificationTest. */ ! public long getLastModificationTest() { return lastModificationTest; } /** * @param lastModificationTest The lastModificationTest to set. */ ! public void setLastModificationTest(long lastModificationTest) { this.lastModificationTest = lastModificationTest; } --- 462,475 ---- * @return Returns the lastModificationTest. */ ! public long getLastModificationTest() ! { return lastModificationTest; } + /** * @param lastModificationTest The lastModificationTest to set. */ ! public void setLastModificationTest(long lastModificationTest) ! { this.lastModificationTest = lastModificationTest; } |