You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by pi...@locus.apache.org on 2000/10/11 06:32:25 UTC

cvs commit: jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime PageContextImpl.java

pierred     00/10/10 21:32:25

  Modified:    jasper/src/share/org/apache/jasper/compiler
                        IncludeGenerator.java JspParseEventListener.java
               jasper/src/share/org/apache/jasper/resources
                        messages.properties
               jasper/src/share/org/apache/jasper/runtime
                        PageContextImpl.java
  Added:       jasper/src/share/org/apache/jasper/compiler
                        ServletResponseWrapperInclude.java
  Log:
  Modifications
  
  New JSP1.2 feature -> jsp:include can now indicate flush="false"
  
  Implementation of this new feature has brought up a few issues
  which have been submitted to the expert group. Implementation will
  be revised once we get clarifications.
  
  Specifically:
    - A forward done in an included page yields an infinite
      loop because the jsp engine has no way of knowing that the
      include request attributes should be ignored.
    - Not clear what the impact of a forward performed within an
      included page should be on the output buffers.
  
  -----
  Modifications:
  
  IncludeGenerator
  - flush is not a required parameter anymore. Default value is "false".
  - generated code now flushes the buffer or not prior to calling
    pagecontext.include() depending on the flush value
  
  PageContextImpl
  - set the value of isIncluded when the page context is initialized
  include()
  - flush in an include is not done in pageContext anymore.
    This is handled prior to calling the include() so we can flush or not
    depending on the value of the flush attribute.
  - A ServletResponseWrapperInclude object is now passed as the Response
    (the including page JspWriter is what gets returned in getWriter())
  release()
  - if isIncluded()
       flush the current jspWriter into the including
       page JspWriter
    else
       flush through (recursive) the buffer
  
  JspParseEventListener
  generateFooter()
  - do not generate the code to flush the buffer anymore
    this will be handled in pageContext.release() which will
    flush the buffer in a way that depends whether the
    page is being included or not.
  
  messages.properties
  - add jsp.error.include.flush.invalid.value
  
  New file:
  ServletResponseWrapperInclude
  
  Revision  Changes    Path
  1.3       +34 -20    jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java
  
  Index: IncludeGenerator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IncludeGenerator.java	2000/09/15 15:42:43	1.2
  +++ IncludeGenerator.java	2000/10/11 04:32:20	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java,v 1.2 2000/09/15 15:42:43 pierred Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/09/15 15:42:43 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java,v 1.3 2000/10/11 04:32:20 pierred Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/10/11 04:32:20 $
    *
    * ====================================================================
    * 
  @@ -86,29 +86,41 @@
   {
       String page;
       boolean isExpression = false;
  +    boolean flush;
       Hashtable params;
       
       public IncludeGenerator(Mark start, Hashtable attrs, Hashtable param) 
           throws JasperException 
       {
  -	if (attrs.size() != 2)
  -	    throw new CompileException(start,
  -				       Constants.getString("jsp.error.include.tag"));
  +	if (attrs.size() > 2) {
  +	    throw new CompileException(
  +                start,
  +		Constants.getString("jsp.error.include.tag"));
  +	}
   
           page = (String) attrs.get("page");
  -        if (page == null)
  -	    throw new CompileException(start,
  -				       Constants.getString("jsp.error.include.tag"));
  -
  -        String flush = (String) attrs.get("flush");
  -        if (flush == null)
  -            throw new CompileException(start,
  -				       Constants.getString("jsp.error.include.noflush"));
  -
  -        if (!flush.equals("true"))
  -            throw new CompileException(start,
  -				       Constants.getString("jsp.error.include.badflush"));
  -
  +        if (page == null) {
  +	    throw new CompileException(
  +                start,
  +		Constants.getString("jsp.error.include.tag"));
  +	}
  +
  +        String flushString = (String) attrs.get("flush");
  +	if (flushString == null && attrs.size() != 1) {
  +	    throw new CompileException(
  +               start,
  +	       Constants.getString("jsp.error.include.tag"));
  +	}
  +        if (flushString == null || flushString.equalsIgnoreCase("false")) {
  +            flush = false;
  +        } else if (flushString.equalsIgnoreCase("true")) {
  +            flush = true;
  +        } else {
  +            throw new CompileException(
  +               start,
  +	       Constants.getString("jsp.error.include.flush.invalid.value",
  +				   new Object[]{flushString}));
  +        }
   	this.params = param;
   	isExpression = JspUtil.isExpression (page);
       }
  @@ -119,7 +131,9 @@
   	writer.println("{");
   	writer.pushIndent();
   	writer.println("String _jspx_qStr = \"\";");
  -	
  +	if (flush) {
  +	    writer.println("out.flush();");
  +	}
   	if (params.size() > 0) {
   	    Enumeration en = params.keys();
   	    while (en.hasMoreElements()) {
  
  
  
  1.5       +3 -5      jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java
  
  Index: JspParseEventListener.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JspParseEventListener.java	2000/10/04 20:01:05	1.4
  +++ JspParseEventListener.java	2000/10/11 04:32:21	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v 1.4 2000/10/04 20:01:05 pierred Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/10/04 20:01:05 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/JspParseEventListener.java,v 1.5 2000/10/11 04:32:21 pierred Exp $
  + * $Revision: 1.5 $
  + * $Date: 2000/10/11 04:32:21 $
    *
    * ====================================================================
    *
  @@ -365,8 +365,6 @@
   	writer.println("} finally {");
   	writer.pushIndent();
   	/* Do stuff here for finally actions... */
  -        //writer.println("out.close();");
  -	writer.println("out.flush();");
   	writer.println("_jspxFactory.releasePageContext(pageContext);");
   	writer.popIndent();
   	writer.println("}");
  
  
  
  1.1                  jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ServletResponseWrapperInclude.java
  
  Index: ServletResponseWrapperInclude.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/ServletResponseWrapperInclude.java,v 1.1 2000/10/11 04:32:22 pierred Exp $
   * $Revision: 1.1 $
   * $Date: 2000/10/11 04:32:22 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.jasper.compiler;
  
  import java.lang.IllegalStateException;
  import java.io.PrintWriter;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  import javax.servlet.jsp.*;
  
  /**
   * ServletResponseWrapper used for the JSP 'include' action.
   *
   * This 'wrapped' response object is passed as the second argument 
   * to the internal RequestDispatcher.include(). It channels
   * all output text into the current JspWriter.
   *
   * @author Pierre Delisle
   */
  
  public class ServletResponseWrapperInclude
      extends HttpServletResponseWrapper
  {
      /**
       * The PrintWriter writes all output to the JspWriter of the 
       * including page.
       */
      PrintWriter printWriter;
  
      public ServletResponseWrapperInclude(ServletResponse response, 
  					 JspWriter jspWriter) 
      {
  	super((HttpServletResponse)response);
  	this.printWriter = new PrintWriter(jspWriter);
      }
  
      /**
       * Returns a wrapper around the JspWriter of the including page.
       */
      public java.io.PrintWriter getWriter()
  	throws java.io.IOException 
      {
  	return printWriter;
      }
  
      public ServletOutputStream getOutputStream()
  	throws java.io.IOException
      {
  	throw new IllegalStateException();
      }
  }
  
  
  
  1.5       +2 -1      jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/resources/messages.properties
  
  Index: messages.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/resources/messages.properties,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- messages.properties	2000/10/04 05:10:56	1.4
  +++ messages.properties	2000/10/11 04:32:23	1.5
  @@ -1,4 +1,4 @@
  -# $Id: messages.properties,v 1.4 2000/10/04 05:10:56 pierred Exp $
  +# $Id: messages.properties,v 1.5 2000/10/11 04:32:23 pierred Exp $
   #
   # Default localized string information
   # Localized this the Default Locale as is en_US
  @@ -222,3 +222,4 @@
   jsp.error.parse.xml.line=XML parsing error on file {0}: (line {1}, col {2}): {3}
   jsp.error.internal.filenotfound=Internal Error: File {0} not found
   jsp.error.parse.xml.invalidPublicId=Invalid PUBLIC ID: {0}
  +jsp.error.include.flush.invalid.value=Invalid value for the flush attribute: {0}
  
  
  
  1.3       +21 -6     jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java
  
  Index: PageContextImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PageContextImpl.java	2000/09/15 15:42:40	1.2
  +++ PageContextImpl.java	2000/10/11 04:32:24	1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java,v 1.2 2000/09/15 15:42:40 pierred Exp $
  - * $Revision: 1.2 $
  - * $Date: 2000/09/15 15:42:40 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java,v 1.3 2000/10/11 04:32:24 pierred Exp $
  + * $Revision: 1.3 $
  + * $Date: 2000/10/11 04:32:24 $
    *
    * ====================================================================
    *
  @@ -88,6 +88,7 @@
   
   import org.apache.jasper.Constants;
   import org.apache.jasper.logging.Logger;
  +import org.apache.jasper.compiler.ServletResponseWrapperInclude;
   
   /**
    * Implementation of the PageContext class from the JSP spec.
  @@ -100,7 +101,7 @@
    */
   public class PageContextImpl extends PageContext {
   
  -    Logger.Helper loghelper = new Logger.Helper("JASPER_LOG", "JspFactoryImpl");
  +    Logger.Helper loghelper = new Logger.Helper("JASPER_LOG", "PageContextImpl");
   
       PageContextImpl(JspFactory factory) {
           this.factory = factory;
  @@ -203,9 +204,21 @@
   	setAttribute(CONFIG,      config);
   	setAttribute(PAGECONTEXT, this);
   	setAttribute(APPLICATION,  context);
  +	
  +	isIncluded = request.getAttribute(
  +	    "javax.servlet.include.servlet_path") != null;	    
       }
   
       public void release() {
  +	try {
  +	    if (isIncluded) {
  +		((JspWriterImpl)out).flushBuffer(); // push it into the including jspWriter
  +	    } else {
  +		out.flush();
  +	    }
  +	} catch (IOException ex) {
  +	    loghelper.log("Internal error flushing the buffer in release()");
  +	}
   	servlet      = null;
   	config	     = null;
   	context	     = null;
  @@ -407,8 +420,8 @@
           throws ServletException, IOException
       {
           String path = getAbsolutePathRelativeToContext(relativeUrlPath);
  -	out.flush();
  -        context.getRequestDispatcher(path).include(request, response);
  +        context.getRequestDispatcher(path).include(
  +	    request, new ServletResponseWrapperInclude(response, out));
       }
   
       public void forward(String relativeUrlPath)
  @@ -494,6 +507,8 @@
       protected transient Object          page;
   
       protected transient HttpSession	session;
  +
  +    protected boolean isIncluded;
   
       // initial output stream