craigmcc    01/08/14 16:28:55

  Modified:    jasper/src/share/org/apache/jasper/compiler
                        IncludeGenerator.java
               jasper/src/share/org/apache/jasper/runtime
                        JspRuntimeLibrary.java PageContextImpl.java
  Log:
  Fix a spec-compliance bug in the implementation of PageContext.include(),
  which was not flushing the output stream even though this is explicitly
  required in the Javadocs.
  
  A side effect of this is that the code generated for a JSP servlet cannot
  use pageContext.include() to implement the correct behavior for:
  
    <jsp:include ... flush="false"/>
  
  so modify the code generator to call a private method in the runtime
  library that does the right thing.
  
  PR: Bugzilla #3121
  Submitted by: Eduardo Pelegri-Llopart <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.8       +15 -3     
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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- IncludeGenerator.java     2000/12/15 12:29:24     1.7
  +++ IncludeGenerator.java     2001/08/14 23:28:55     1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java,v
 1.7 2000/12/15 12:29:24 pierred Exp $
  - * $Revision: 1.7 $
  - * $Date: 2000/12/15 12:29:24 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/compiler/IncludeGenerator.java,v
 1.8 2001/08/14 23:28:55 craigmcc Exp $
  + * $Revision: 1.8 $
  + * $Date: 2001/08/14 23:28:55 $
    *
    * ====================================================================
    * 
  @@ -132,9 +132,11 @@
        writer.println("{");
        writer.pushIndent();
        writer.println("String _jspx_qStr = \"\";");
  +        /*
        if (flush) {
            writer.println("out.flush();");
        }
  +        */
        if (params != null && params.size() > 0) {
            Enumeration en = params.keys();
            while (en.hasMoreElements()) {
  @@ -168,12 +170,22 @@
                }
            }
        }
  +        /*
        if (!isExpression) 
            writer.println("pageContext.include(" +
                           writer.quoteString(page) + " + _jspx_qStr);");
        else
            writer.println ("pageContext.include(" + 
                            JspUtil.getExpr(page, isXml) + " + _jspx_qStr);");
  +        */
  +        if (!isExpression)
  +            writer.println("JspRuntimeLibrary.include(request, response, " +
  +                           writer.quoteString(page) + " + _jspx_qStr, " +
  +                           "out, " + flush + ");");
  +        else
  +            writer.println("JspRuntimeLibrary.include(request, response, " +
  +                           JspUtil.getExpr(page, isXml) + " + _jspx_qStr, " +
  +                           "out, " + flush + ");");
   
        writer.popIndent();
        writer.println("}");
  
  
  
  1.8       +73 -4     
jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java
  
  Index: JspRuntimeLibrary.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JspRuntimeLibrary.java    2001/07/18 23:16:20     1.7
  +++ JspRuntimeLibrary.java    2001/08/14 23:28:55     1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
 1.7 2001/07/18 23:16:20 horwat Exp $
  - * $Revision: 1.7 $
  - * $Date: 2001/07/18 23:16:20 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
 1.8 2001/08/14 23:28:55 craigmcc Exp $
  + * $Revision: 1.8 $
  + * $Date: 2001/08/14 23:28:55 $
    *
    * ====================================================================
    * 
  @@ -81,11 +81,14 @@
   import java.security.PrivilegedExceptionAction;
   import java.security.PrivilegedActionException;
   
  +import javax.servlet.RequestDispatcher;
   import javax.servlet.ServletException;
   import javax.servlet.ServletRequest;
   import javax.servlet.ServletContext;
   import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
   import javax.servlet.http.HttpSession;
  +import javax.servlet.jsp.JspWriter;
   
   import org.apache.jasper.JasperException;
   import org.apache.jasper.Constants;
  @@ -748,8 +751,74 @@
                ": " + ex);
        }
       }
  -}
   
   
  +    // ************************************************************************
  +    // General Purpose Runtime Methods
  +    // ************************************************************************
  +
  +
  +    /**
  +     * Convert a possibly relative resource path into a context-relative
  +     * resource path that starts with a '/'.
  +     *
  +     * @param request The servlet request we are processing
  +     * @param relativePath The possibly relative resource path
  +     */
  +    public static String getContextRelativePath(ServletRequest request,
  +                                                String relativePath) {
  +
  +        if (relativePath.startsWith("/"))
  +            return (relativePath);
  +        if (!(request instanceof HttpServletRequest))
  +            return (relativePath);
  +        HttpServletRequest hrequest = (HttpServletRequest) request;
  +        String uri = (String)
  +            request.getAttribute("javax.servlet.include.servlet_path");
  +        if (uri == null)
  +            uri = hrequest.getServletPath();
  +        return (uri.substring(0, uri.lastIndexOf('/')) + '/' + relativePath);
  +        
  +
  +    }
   
   
  +    /**
  +     * Perform a RequestDispatcher.include() operation, with optional flushing
  +     * of the response beforehand.
  +     *
  +     * @param request The servlet request we are processing
  +     * @param response The servlet response we are processing
  +     * @param relativePath The relative path of the resource to be included
  +     * @param out The JspWriter to whom we are currently writing
  +     * @param flush Should we flush before the include is processed?
  +     *
  +     * @exception IOException if thrown by the included servlet
  +     * @exception ServletException if thrown by the included servlet
  +     */
  +    public static void include(HttpServletRequest request,
  +                               HttpServletResponse response,
  +                               String relativePath,
  +                               JspWriter out,
  +                               boolean flush)
  +        throws IOException, ServletException {
  +
  +        if (flush)
  +            out.flush();
  +
  +        // FIXME - It is tempting to use request.getRequestDispatcher() to
  +        // resolve a relative path directly, but Catalina currently does not
  +        // take into account whether the caller is inside a RequestDispatcher
  +        // include or not.  Whether Catalina *should* take that into account
  +        // is a spec issue currently under review.  In the mean time,
  +        // replicate Jasper's previous behavior
  +
  +        String resourcePath = getContextRelativePath(request, relativePath);
  +        RequestDispatcher rd = request.getRequestDispatcher(resourcePath);
  +        rd.include(request,
  +                   new ServletResponseWrapperInclude(response, out));
  +
  +    }
  +
  +
  +}
  
  
  
  1.13      +8 -3      
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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PageContextImpl.java      2001/07/11 22:51:40     1.12
  +++ PageContextImpl.java      2001/08/14 23:28:55     1.13
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java,v
 1.12 2001/07/11 22:51:40 remm Exp $
  - * $Revision: 1.12 $
  - * $Date: 2001/07/11 22:51:40 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/runtime/PageContextImpl.java,v
 1.13 2001/08/14 23:28:55 craigmcc Exp $
  + * $Revision: 1.13 $
  + * $Date: 2001/08/14 23:28:55 $
    *
    * ====================================================================
    *
  @@ -387,9 +387,14 @@
       public void include(String relativeUrlPath)
           throws ServletException, IOException
       {
  +        JspRuntimeLibrary.include((HttpServletRequest) request,
  +                                  (HttpServletResponse) response,
  +                                  relativeUrlPath, out, true);
  +        /*
           String path = getAbsolutePathRelativeToContext(relativeUrlPath);
           context.getRequestDispatcher(path).include(
            request, new ServletResponseWrapperInclude(response, out));
  +        */
       }
   
       public void forward(String relativeUrlPath)
  
  
  

Reply via email to