cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp JSPEngineServletOutputStream.java JSPEngineServletRequest.java JSPEngineServletResponse.java JSPEngineServletConfig.java JSPEngineImplNamedDispatcherInclude.java JSPEngineImplWLS.java JSPEngineImpl.java
Date Fri, 16 Jan 2004 13:49:33 GMT
unico       2004/01/16 05:49:33

  Modified:    src/blocks/jsp/java/org/apache/cocoon/components/jsp
                        JSPEngineImplNamedDispatcherInclude.java
                        JSPEngineImplWLS.java JSPEngineImpl.java
  Added:       src/blocks/jsp/java/org/apache/cocoon/components/jsp
                        JSPEngineServletOutputStream.java
                        JSPEngineServletRequest.java
                        JSPEngineServletResponse.java
                        JSPEngineServletConfig.java
  Log:
  factor out common code into separate classes; allow named dispatcher to also use forward method; documentation improvments
  
  Revision  Changes    Path
  1.7       +74 -225   cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImplNamedDispatcherInclude.java
  
  Index: JSPEngineImplNamedDispatcherInclude.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImplNamedDispatcherInclude.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JSPEngineImplNamedDispatcherInclude.java	5 Jan 2004 14:54:27 -0000	1.6
  +++ JSPEngineImplNamedDispatcherInclude.java	16 Jan 2004 13:49:32 -0000	1.7
  @@ -50,38 +50,26 @@
   */
   package org.apache.cocoon.components.jsp;
   
  -import java.io.BufferedReader;
  -import java.io.ByteArrayOutputStream;
   import java.io.IOException;
  -import java.io.OutputStreamWriter;
  -import java.io.PrintWriter;
  -import java.io.UnsupportedEncodingException;
  -import java.security.Principal;
  -import java.util.Enumeration;
  -import java.util.Locale;
   
   import javax.servlet.RequestDispatcher;
   import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
  -import javax.servlet.ServletInputStream;
  -import javax.servlet.ServletOutputStream;
  -import javax.servlet.http.Cookie;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;
  -import javax.servlet.http.HttpSession;
   
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
  -import org.apache.avalon.framework.parameters.ParameterException;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.thread.ThreadSafe;
  -import org.xml.sax.SAXException;
   
   /**
  - * Allows JSP to be used as a generator.  Builds upon the JSP servlet
  - * functionality - overrides the output method and returns the byte(s).
  - * This implementation includes via ServletContext.getNamedDispatcher() the
  - * jsp-response. This a generic implementation.
  + * Allows a Servlet or JSP to be used as a generator.
  + * 
  + * <p>
  + * This implementation includes the servlet response using the 
  + * RequestDispatcher from ServletContext.getNamedDispatcher().
  + * </p>
    *
    * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
    * @author <a href="mailto:bh22351@i-one.at">Bernhard Huber</a>
  @@ -90,229 +78,90 @@
   public class JSPEngineImplNamedDispatcherInclude extends AbstractLogEnabled
       implements JSPEngine, Parameterizable, ThreadSafe {
   
  -    /** The servlet include path. */
  -    public static final String INC_SERVLET_PATH = "javax.servlet.include.servlet_path";
  -    /** The servlet request uri, needed for Resin. */
  -    public static final String INC_REQUEST_URI = "javax.servlet.include.request_uri";
  -
  -    /** config-parameter name for specifying the jsp servlet-name.
  -      ie. servlet-name
  -    */
  +    /**
  +     * 'servlet-name' configuration parameter name for specifying 
  +     * the servlet name to dispatch to.
  +     */
       public static final String CONFIG_SERVLET_NAME = "servlet-name";
  -    /** default value of CONFIG_SERVLET_NAME.
  -      ie. *jsp, this is the WLS JSP servlet default name
  -    */
  +    
  +    /**
  +     * 'forward' configuration parameter name for specifying
  +     * whether or not the dispather should use forward 
  +     * instead of include.
  +     */
  +    public static final String CONFIG_FORWARD = "forward";
  +    
  +    /** 
  +     * Default value of CONFIG_SERVLET_NAME.
  +     * The value is <code>*.jsp</code>, 
  +     * this is the WLS JSP servlet default name.
  +     */
       public static final String DEFAULT_SERVLET_NAME = "*.jsp";
  -    /** the configured name of the jsp servlet
  -    */
  -    String servletName = DEFAULT_SERVLET_NAME;
  +    
  +    /**
  +     * Default value of CONFIG_FORWARD.
  +     * The value is <code>false</code>.
  +     */
  +    public static final boolean DEFAULT_FORWARD = false;
  +    
  +    /** 
  +     * the configured name of the jsp servlet
  +     */
  +    private String servletName = DEFAULT_SERVLET_NAME;
  +    
  +    /**
  +     * Whether or not to use forward instead of include
  +     * when dispatching to the Servlet.
  +     */
  +    private boolean forward = DEFAULT_FORWARD;
   
       /**
  -     * parameterize
  -     * @param params Parameters
  -     * @exception ParameterException
  +     * <p>
  +     * The <code>forward</code> configuration parameter allows you to
  +     * control whether to use the forward dispatch method instead of 
  +     * the include method which is used by default.
  +     * </p>
  +     * <p>
  +     * Using the <code>servlet-name</code> configuration parameter
  +     * you can specify the name of the Servlet to dispatch to.
  +     * </p>
        */
  -    public void parameterize(Parameters params) throws ParameterException {
  +    public void parameterize(Parameters params) {
           this.servletName = params.getParameter(CONFIG_SERVLET_NAME, DEFAULT_SERVLET_NAME);
  +        this.forward = params.getParameterAsBoolean(CONFIG_FORWARD, DEFAULT_FORWARD);
       }
   
       /**
  -     * execute the JSP and return the output
  -     *
  -     * @param context The Servlet Context
  -     * @exception IOException
  -     * @exception ServletException
  -     * @exception SAXException
  -     * @exception Exception
  +     * Execute the Servlet and return the output.
        */
  -    public byte[] executeJSP(String url, HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletContext context)
  -        throws IOException, ServletException, SAXException, Exception {
  -
  +    public byte[] executeJSP(String url,
  +                             HttpServletRequest servletRequest,
  +                             HttpServletResponse servletResponse,
  +                             ServletContext servletContext)
  +        throws IOException, ServletException, Exception {
  +        
  +        JSPEngineServletOutputStream output = new JSPEngineServletOutputStream();
  +        JSPEngineServletRequest request = new JSPEngineServletRequest(servletRequest,url);
  +        JSPEngineServletResponse response = new JSPEngineServletResponse(servletResponse,output);
  +        
           byte[] bytes = null;
  -
  -        MyServletRequest request = new MyServletRequest(httpRequest, url);
  -        MyServletResponse response = new MyServletResponse(httpResponse);
  -
  -        // start JSPServlet.
  -        javax.servlet.RequestDispatcher rd = context.getNamedDispatcher( servletName );
  +        
  +        // dispatch to the named servlet
  +        RequestDispatcher rd = servletContext.getNamedDispatcher(servletName);
           if (rd != null) {
  -            rd.include( request, response );
  +            if (forward) {
  +                rd.forward(request,response);
  +            }
  +            else {
  +                rd.include(request,response);
  +            }
               response.flushBuffer();
  -            bytes = response.toByteArray();
  +            bytes = output.toByteArray();
           } else {
  -            // FIXME: I guess it's better to throw a more specific exception.
               throw new Exception("No RequestDispatcher found. Specify a correct '"
  -                                + CONFIG_SERVLET_NAME + "': " + servletName);
  +                                 + CONFIG_SERVLET_NAME + "': " + servletName);
           }
           return bytes;
  -    }
  -
  -
  -    /**
  -     * Stub implementation of HttpServletRequest
  -     */
  -    class MyServletRequest implements HttpServletRequest {
  -        HttpServletRequest request;
  -        String jspFile;
  -
  -        public MyServletRequest(HttpServletRequest request, String jspFile) {
  -            this.request = request;
  -            this.jspFile = jspFile;
  -        }
  -        public String getAuthType(){ return request.getAuthType(); }
  -        public Cookie[] getCookies(){ return request.getCookies(); }
  -        public long getDateHeader(String s){ return request.getDateHeader(s); }
  -        public String getHeader(String s){ return request.getHeader(s); }
  -        public Enumeration getHeaders(String s){ return request.getHeaders(s); }
  -        public Enumeration getHeaderNames(){ return request.getHeaderNames(); }
  -        public int getIntHeader(String s){ return request.getIntHeader(s); }
  -        public String getMethod(){ return request.getMethod(); }
  -        public String getPathInfo(){ return request.getPathInfo(); }
  -        public String getPathTranslated(){ return request.getPathTranslated(); }
  -        public String getContextPath(){ return request.getContextPath(); }
  -        public String getQueryString(){ return request.getQueryString(); }
  -        public String getRemoteUser(){ return request.getRemoteUser(); }
  -        public boolean isUserInRole(String s){ return request.isUserInRole(s); }
  -        public Principal getUserPrincipal(){ return request.getUserPrincipal(); }
  -        public String getRequestedSessionId(){ return request.getRequestedSessionId(); }
  -        public String getRequestURI(){ return request.getRequestURI(); }
  -        public String getServletPath(){ return request.getServletPath(); }
  -        public HttpSession getSession(boolean flag){ return request.getSession(flag); }
  -        public HttpSession getSession(){ return request.getSession(); }
  -        public boolean isRequestedSessionIdValid(){ return request.isRequestedSessionIdValid(); }
  -        public boolean isRequestedSessionIdFromCookie(){ return request.isRequestedSessionIdFromCookie(); }
  -        public boolean isRequestedSessionIdFromURL(){ return request.isRequestedSessionIdFromURL(); }
  -        /** @deprecated use isRequestedSessionIdFromURL instead. */
  -        public boolean isRequestedSessionIdFromUrl(){ return request.isRequestedSessionIdFromUrl(); }
  -        public Object getAttribute(String s){
  -            if (s != null && (s.equals(INC_SERVLET_PATH) || s.equals(INC_REQUEST_URI))) {
  -                return jspFile;
  -            }
  -            return request.getAttribute(s);
  -        }
  -        public Enumeration getAttributeNames(){ return request.getAttributeNames(); }
  -        public String getCharacterEncoding(){ return request.getCharacterEncoding(); }
  -        public int getContentLength(){ return request.getContentLength(); }
  -        public String getContentType(){ return request.getContentType(); }
  -        public ServletInputStream getInputStream() throws IOException{ return request.getInputStream(); }
  -        public String getParameter(String s){ return request.getParameter(s); }
  -        public Enumeration getParameterNames(){ return request.getParameterNames(); }
  -        public String[] getParameterValues(String s){ return request.getParameterValues(s); }
  -        public String getProtocol(){ return request.getProtocol(); }
  -        public String getScheme(){ return request.getScheme(); }
  -        public String getServerName(){ return request.getServerName(); }
  -        public int getServerPort(){ return request.getServerPort(); }
  -        public BufferedReader getReader()
  -            throws IOException{ return request.getReader(); }
  -        public String getRemoteAddr(){ return request.getRemoteAddr(); }
  -        public String getRemoteHost(){ return request.getRemoteHost(); }
  -        public void setAttribute(String s, Object obj){ request.setAttribute(s,obj); }
  -        public void removeAttribute(String s){ request.removeAttribute(s); }
  -        public Locale getLocale(){ return request.getLocale(); }
  -        public Enumeration getLocales(){ return request.getLocales(); }
  -        public boolean isSecure(){ return request.isSecure(); }
  -        public RequestDispatcher getRequestDispatcher(String s){ return request.getRequestDispatcher(s); }
  -        /** @deprecated use ServletContext.getRealPath(java.lang.String) instead. */
  -        public String getRealPath(String s){ return request.getRealPath(s); }
  -        public java.lang.StringBuffer getRequestURL() { return null; }
  -        public java.util.Map getParameterMap() { return null; }
  -        public void setCharacterEncoding(java.lang.String s) { }
  -    }
  -
  -    /**
  -     * Stub implementation of HttpServletResponse
  -     */
  -    class MyServletResponse implements HttpServletResponse {
  -        HttpServletResponse response;
  -        MyServletOutputStream output;
  -        boolean hasOutputStream = false;
  -        boolean hasWriter = false;
  -
  -        public MyServletResponse(HttpServletResponse response){
  -            this.response = response;
  -            this.output = new MyServletOutputStream();
  -        }
  -        public void flushBuffer() throws IOException { }
  -        public int getBufferSize() { return 1024; }
  -        public String getCharacterEncoding() { return this.response.getCharacterEncoding();}
  -        public Locale getLocale(){ return this.response.getLocale();}
  -        public PrintWriter getWriter() {
  -            if (this.hasOutputStream) {
  -                throw new IllegalStateException("getOutputStream was already called.");
  -            }
  -            this.hasWriter = true;
  -            return this.output.getWriter();
  -        }
  -        public boolean isCommitted() { return false; }
  -        public void reset() {}
  -        public void setBufferSize(int size) {}
  -        public void setContentLength(int len) {}
  -        public void setContentType(java.lang.String type) {}
  -        public void setLocale(java.util.Locale loc) {}
  -        public ServletOutputStream getOutputStream() {
  -            if (this.hasWriter) {
  -                throw new IllegalStateException("getWriter was already called.");
  -            }
  -            this.hasOutputStream = true;
  -            return this.output;
  -        }
  -        public void addCookie(Cookie cookie){ response.addCookie(cookie); }
  -        public boolean containsHeader(String s){ return response.containsHeader(s); }
  -        /** @deprecated use encodeURL(String url) instead. */
  -        public String encodeUrl(String s){ return response.encodeUrl(s); }
  -        public String encodeURL(String s){ return response.encodeURL(s); }
  -        /** @deprecated use encodeRedirectURL(String url) instead. */
  -        public String encodeRedirectUrl(String s){ return response.encodeRedirectUrl(s); }
  -        public String encodeRedirectURL(String s){ return response.encodeRedirectURL(s); }
  -        public void sendError(int i, String s)
  -            throws IOException{response.sendError(i,s); }
  -        public void sendError(int i)
  -            throws IOException{response.sendError(i); }
  -        public void sendRedirect(String s)
  -            throws IOException{response.sendRedirect(s); }
  -        public void setDateHeader(String s, long l){response.setDateHeader(s, l); }
  -        public void addDateHeader(String s, long l){response.addDateHeader(s, l); }
  -        public void setHeader(String s, String s1){response.setHeader(s, s1); }
  -        public void addHeader(String s, String s1){response.addHeader(s, s1); }
  -        public void setIntHeader(String s, int i){response.setIntHeader(s, i); }
  -        public void addIntHeader(String s, int i){response.addIntHeader(s, i); }
  -        public void setStatus(int i){response.setStatus(i); }
  -        /** @deprecated use sendError(int, String) instead */
  -        public void setStatus(int i, String s){response.setStatus(i, s); }
  -        public void resetBuffer(){}
  -
  -        public byte[] toByteArray() {
  -            return output.toByteArray();
  -        }
  -    }
  -
  -    /**
  -     * Stub implementation of ServletOutputStream
  -     */
  -    class MyServletOutputStream extends ServletOutputStream {
  -        ByteArrayOutputStream output;
  -        PrintWriter writer;
  -
  -        public MyServletOutputStream() {
  -            this.output = new ByteArrayOutputStream();
  -            try {
  -                this.writer = new PrintWriter(new OutputStreamWriter(output, "utf-8"));
  -            } catch (UnsupportedEncodingException e) {
  -                // This can't be true: JVM must support UTF-8 encoding.
  -                this.writer = new PrintWriter(new OutputStreamWriter(output));
  -            }
  -        }
  -        public PrintWriter getWriter() {
  -            return this.writer;
  -        }
  -        public void write(int b) throws java.io.IOException {
  -            this.output.write(b);
  -        }
  -        public byte[] toByteArray() {
  -            this.writer.flush();
  -            byte[] bytes = output.toByteArray();
  -            return bytes;
  -        }
       }
   }
   
  
  
  
  1.4       +24 -17    cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImplWLS.java
  
  Index: JSPEngineImplWLS.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImplWLS.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JSPEngineImplWLS.java	15 Nov 2003 04:21:28 -0000	1.3
  +++ JSPEngineImplWLS.java	16 Jan 2004 13:49:32 -0000	1.4
  @@ -55,8 +55,8 @@
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.thread.ThreadSafe;
  -import org.xml.sax.SAXException;
   
  +import javax.servlet.RequestDispatcher;
   import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   import javax.servlet.http.Cookie;
  @@ -67,8 +67,8 @@
   import java.util.Locale;
   
   /**
  - * Allows WLS JSP to be used as a generator.  Builds upon the JSP servlet
  - * functionality - overrides the output method and returns the byte(s).
  + * Allows WLS JSP to be used as a generator. 
  + * 
    * This implementation includes via ServletContext.getNamedDispatcher() the
    * jsp-response. This a WLS-specific implementation.
    * This code contain WLS 5.1 specific classes, and uses WLS internal classes.
  @@ -93,6 +93,7 @@
       public static final String DEFAULT_SERVLET_NAME = "*.jsp";
       /** the configured name of the jsp servlet
       */
  +    
       String servletName = DEFAULT_SERVLET_NAME;
   
       /**
  @@ -113,28 +114,34 @@
        * @exception SAXException
        * @exception Exception
        */
  -    public byte[] executeJSP(String url, HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletContext context)
  -        throws IOException, ServletException, SAXException, Exception {
  +    public byte[] executeJSP(String url,
  +                             HttpServletRequest servletRequest,
  +                             HttpServletResponse servletResponse,
  +                             ServletContext servletContext)
  +        throws IOException, ServletException, Exception {
   
           byte[] bytes = null;
   
  -        HttpServletRequest request = httpRequest;
  -        String inc_servlet_path_was = (String)httpRequest.getAttribute( INC_SERVLET_PATH );
  -        request.setAttribute( INC_SERVLET_PATH, url );
  -        MyWLSResponse response = new MyWLSResponse( httpResponse,
  -          (weblogic.servlet.internal.ServletContextImpl)context );
  +        HttpServletRequest request = servletRequest;
  +        String inc_servlet_path_was = (String) servletRequest.getAttribute(INC_SERVLET_PATH);
  +        request.setAttribute(INC_SERVLET_PATH, url);
  +        MyWLSResponse response = new MyWLSResponse( servletResponse,
  +          (weblogic.servlet.internal.ServletContextImpl) servletContext);
   
  -        // start JSPServlet.
  -        javax.servlet.RequestDispatcher rd = context.getNamedDispatcher( servletName );
  +        // dispatch to the named servlet
  +        RequestDispatcher rd = servletContext.getNamedDispatcher(servletName);
           if (rd != null) {
  -          rd.include( request, response );
  +          rd.include(request,response);
             response.flushBuffer();
  -
  -          getLogger().debug( "JSP response: " + response.getResponseContentAsString() );
  +          
  +          if (getLogger().isDebugEnabled()) {
  +              getLogger().debug("JSP response: " + response.getResponseContentAsString());
  +          }
  +          
             bytes = response.getResponseContentAsByteArray();
   
             if (inc_servlet_path_was != null) {
  -            httpRequest.setAttribute( INC_SERVLET_PATH, inc_servlet_path_was );
  +            servletRequest.setAttribute( INC_SERVLET_PATH, inc_servlet_path_was );
             }
           } else {
             getLogger().error( "Specify a correct " + CONFIG_SERVLET_NAME + " " + servletName );
  
  
  
  1.9       +32 -230   cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImpl.java
  
  Index: JSPEngineImpl.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JSPEngineImpl.java	5 Jan 2004 14:54:27 -0000	1.8
  +++ JSPEngineImpl.java	16 Jan 2004 13:49:32 -0000	1.9
  @@ -50,29 +50,21 @@
   */
   package org.apache.cocoon.components.jsp;
   
  +import java.io.IOException;
  +
  +import javax.servlet.Servlet;
  +import javax.servlet.ServletContext;
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +
   import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.thread.ThreadSafe;
   
  -import javax.servlet.*;
  -import javax.servlet.http.Cookie;
  -import javax.servlet.http.HttpServletRequest;
  -import javax.servlet.http.HttpServletResponse;
  -import javax.servlet.http.HttpSession;
  -import java.io.BufferedReader;
  -import java.io.ByteArrayOutputStream;
  -import java.io.IOException;
  -import java.io.PrintWriter;
  -import java.io.OutputStreamWriter;
  -import java.io.UnsupportedEncodingException;
  -import java.security.Principal;
  -import java.util.Enumeration;
  -import java.util.Locale;
  -
   /**
  - * Allows JSP to be used as a generator.  Builds upon the JSP servlet
  - * functionality - overrides the output method and returns the byte(s).
  + * Allows Servlets and JSPs to be used as a generator.
    *
    * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
    * @version CVS $Id$
  @@ -80,236 +72,46 @@
   public class JSPEngineImpl extends AbstractLogEnabled
       implements JSPEngine, Parameterizable, ThreadSafe {
   
  -    /** The servlet include path. */
  -    public static final String INC_SERVLET_PATH = "javax.servlet.include.servlet_path";
  -    /** The servlet request uri, needed for Resin. */
  -    public static final String INC_REQUEST_URI = "javax.servlet.include.request_uri";
  -
  -    /** The Default Servlet Class Name for Tomcat 3.X and 4.X*/
  +    /** The Default Servlet Class Name for Tomcat 3.X and 4.X */
       public static final String DEFAULT_SERVLET_CLASS = "org.apache.jasper.servlet.JspServlet";
   
       /** Servlet Class Name */
       public String jspServletClass = DEFAULT_SERVLET_CLASS;
  -
  +    
       /**
  -     * Set the sitemap-provided configuration.
        * @param params The configuration parameters
        */
  -    public void parameterize(Parameters params)  {
  +    public void parameterize(Parameters params) {
           this.jspServletClass = params.getParameter("servlet-class", DEFAULT_SERVLET_CLASS);
       }
  -
  +    
       /**
  -     * execute the JSP and return the output in UTF8 encoding
  -     *
  -     * @param context The Servlet Context
  -     * @exception IOException
  -     * @exception ServletException
  -     * @exception Exception
  +     * Execute the Servlet/JSP and return the output in UTF8 encoding.
        */
  -    public byte[] executeJSP(String url, HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletContext context)
  +    public byte[] executeJSP(String url, 
  +                             HttpServletRequest servletRequest, 
  +                             HttpServletResponse servletResponse,
  +                             ServletContext context)
           throws IOException, ServletException, Exception {
  -
  +        
  +        JSPEngineServletOutputStream output = new JSPEngineServletOutputStream();
  +        JSPEngineServletRequest request = new JSPEngineServletRequest(servletRequest, url);
  +        JSPEngineServletResponse response = new JSPEngineServletResponse(servletResponse,output);
  +        
           byte[] bytes = null;
   
  -        MyServletRequest request = new MyServletRequest(httpRequest, url);
  -        MyServletResponse response = new MyServletResponse(httpResponse);
  -
  -        // start JSPServlet.
  +        // start the servlet
           Class clazz = Thread.currentThread().getContextClassLoader().loadClass(this.jspServletClass);
  -        Servlet jsp = (Servlet) clazz.newInstance();
  -        jsp.init(new config(context));
  -        jsp.service(request, response);
  -
  -        bytes = response.toByteArray();
  -
  +        Servlet servlet = (Servlet) clazz.newInstance();
  +        servlet.init(new JSPEngineServletConfig(context,"JSPEngineImpl"));
  +        servlet.service(request, response);
  +        
  +        bytes = output.toByteArray();
  +        
           // clean up
  -        jsp.destroy();
  +        servlet.destroy();
   
           return bytes;
       }
   
  -
  -    /**
  -     * Stub implementation of Servlet Config
  -     */
  -    class config implements ServletConfig {
  -        ServletContext c = null;
  -        public config(ServletContext c) {this.c = c; }
  -
  -        public String getServletName() { return "JSPEngineImpl"; }
  -        public Enumeration getInitParameterNames()
  -               { return c.getInitParameterNames(); }
  -        public ServletContext getServletContext() { return c; }
  -        public String getInitParameter(String name) { return c.getInitParameter(name); }
  -    }
  -
  -    /**
  -     * Stub implementation of HttpServletRequest
  -     */
  -    class MyServletRequest implements HttpServletRequest {
  -        HttpServletRequest request = null;
  -        String jspFile = null;
  -
  -        public MyServletRequest(HttpServletRequest request, String jspFile) {
  -            this.request = request;
  -            this.jspFile = jspFile;
  -        }
  -        public String getAuthType(){ return request.getAuthType(); }
  -        public Cookie[] getCookies(){ return request.getCookies(); }
  -        public long getDateHeader(String s){ return request.getDateHeader(s); }
  -        public String getHeader(String s){ return request.getHeader(s); }
  -        public Enumeration getHeaders(String s){ return request.getHeaders(s); }
  -        public Enumeration getHeaderNames(){ return request.getHeaderNames(); }
  -        public int getIntHeader(String s){ return request.getIntHeader(s); }
  -        public String getMethod(){ return request.getMethod(); }
  -        public String getPathInfo(){ return request.getPathInfo(); }
  -        public String getPathTranslated(){ return request.getPathTranslated(); }
  -        public String getContextPath(){ return request.getContextPath(); }
  -        public String getQueryString(){ return request.getQueryString(); }
  -        public String getRemoteUser(){ return request.getRemoteUser(); }
  -        public boolean isUserInRole(String s){ return request.isUserInRole(s); }
  -        public Principal getUserPrincipal(){ return request.getUserPrincipal(); }
  -        public String getRequestedSessionId(){ return request.getRequestedSessionId(); }
  -        public String getRequestURI(){ return request.getRequestURI(); }
  -        public String getServletPath(){ return request.getServletPath(); }
  -        public HttpSession getSession(boolean flag){ return request.getSession(flag); }
  -        public HttpSession getSession(){ return request.getSession(); }
  -        public boolean isRequestedSessionIdValid(){ return request.isRequestedSessionIdValid(); }
  -        public boolean isRequestedSessionIdFromCookie(){ return request.isRequestedSessionIdFromCookie(); }
  -        public boolean isRequestedSessionIdFromURL(){ return request.isRequestedSessionIdFromURL(); }
  -        /** @deprecated use isRequestedSessionIdFromURL instead. */
  -        public boolean isRequestedSessionIdFromUrl(){ return request.isRequestedSessionIdFromUrl(); }
  -        public Object getAttribute(String s){
  -            if (s != null && (s.equals(INC_SERVLET_PATH) || s.equals(INC_REQUEST_URI))) {
  -                return jspFile;
  -            }
  -            return request.getAttribute(s);
  -        }
  -        public Enumeration getAttributeNames(){ return request.getAttributeNames(); }
  -        public String getCharacterEncoding(){ return request.getCharacterEncoding(); }
  -        public int getContentLength(){ return request.getContentLength(); }
  -        public String getContentType(){ return request.getContentType(); }
  -        public ServletInputStream getInputStream() throws IOException{ return request.getInputStream(); }
  -        public String getParameter(String s){ return request.getParameter(s); }
  -        public Enumeration getParameterNames(){ return request.getParameterNames(); }
  -        public String[] getParameterValues(String s){ return request.getParameterValues(s); }
  -        public String getProtocol(){ return request.getProtocol(); }
  -        public String getScheme(){ return request.getScheme(); }
  -        public String getServerName(){ return request.getServerName(); }
  -        public int getServerPort(){ return request.getServerPort(); }
  -        public BufferedReader getReader()
  -            throws IOException{ return request.getReader(); }
  -        public String getRemoteAddr(){ return request.getRemoteAddr(); }
  -        public String getRemoteHost(){ return request.getRemoteHost(); }
  -        public void setAttribute(String s, Object obj){ request.setAttribute(s,obj); }
  -        public void removeAttribute(String s){ request.removeAttribute(s); }
  -        public Locale getLocale(){ return request.getLocale(); }
  -        public Enumeration getLocales(){ return request.getLocales(); }
  -        public boolean isSecure(){ return request.isSecure(); }
  -        public RequestDispatcher getRequestDispatcher(String s){ return request.getRequestDispatcher(s); }
  -        /** @deprecated use ServletContext.getRealPath(java.lang.String) instead. */
  -        public String getRealPath(String s){ return request.getRealPath(s); }
  -        public java.lang.StringBuffer getRequestURL() { return null; }
  -        public java.util.Map getParameterMap() { return null; }
  -        public void setCharacterEncoding(java.lang.String s) { }
  -    }
  -
  -    /**
  -     * Stub implementation of HttpServletResponse
  -     */
  -    class MyServletResponse implements HttpServletResponse {
  -        HttpServletResponse response = null;
  -        MyServletOutputStream output = null;
  -        boolean hasWriter = false;
  -        boolean hasOutputStream = false;
  -
  -        public MyServletResponse(HttpServletResponse response){
  -            this.response = response;
  -            this.output = new MyServletOutputStream();
  -        }
  -        public void flushBuffer() throws IOException { }
  -        public int getBufferSize() { return 1024; }
  -        public String getCharacterEncoding() { return this.response.getCharacterEncoding();}
  -        public Locale getLocale(){ return this.response.getLocale();}
  -        public PrintWriter getWriter() {
  -            if (this.hasOutputStream) {
  -                throw new IllegalStateException("getOutputStream was already called.");
  -            }
  -            this.hasWriter = true;
  -            return this.output.getWriter();
  -        }
  -        public boolean isCommitted() { return false; }
  -        public void reset() {}
  -        public void setBufferSize(int size) {}
  -        public void setContentLength(int len) {}
  -        public void setContentType(java.lang.String type) {}
  -        public void setLocale(java.util.Locale loc) {}
  -        public ServletOutputStream getOutputStream() {
  -            if (this.hasWriter) {
  -                throw new IllegalStateException("getWriter was already called.");
  -            }
  -            this.hasOutputStream = true;
  -            return this.output;
  -        }
  -        public void addCookie(Cookie cookie){ response.addCookie(cookie); }
  -        public boolean containsHeader(String s){ return response.containsHeader(s); }
  -        /** @deprecated use encodeURL(String url) instead. */
  -        public String encodeUrl(String s){ return response.encodeUrl(s); }
  -        public String encodeURL(String s){ return response.encodeURL(s); }
  -        /** @deprecated use encodeRedirectURL(String url) instead. */
  -        public String encodeRedirectUrl(String s){ return response.encodeRedirectUrl(s); }
  -        public String encodeRedirectURL(String s){ return response.encodeRedirectURL(s); }
  -        public void sendError(int i, String s)
  -            throws IOException{response.sendError(i,s); }
  -        public void sendError(int i)
  -            throws IOException{response.sendError(i); }
  -        public void sendRedirect(String s)
  -            throws IOException{response.sendRedirect(s); }
  -        public void setDateHeader(String s, long l){response.setDateHeader(s, l); }
  -        public void addDateHeader(String s, long l){response.addDateHeader(s, l); }
  -        public void setHeader(String s, String s1){response.setHeader(s, s1); }
  -        public void addHeader(String s, String s1){response.addHeader(s, s1); }
  -        public void setIntHeader(String s, int i){response.setIntHeader(s, i); }
  -        public void addIntHeader(String s, int i){response.addIntHeader(s, i); }
  -        public void setStatus(int i){response.setStatus(i); }
  -        /** @deprecated use sendError(int, String) instead */
  -        public void setStatus(int i, String s){response.setStatus(i, s); }
  -        public void resetBuffer(){}
  -
  -        public byte[] toByteArray() {
  -            return output.toByteArray();
  -        }
  -    }
  -
  -    /**
  -     * Stub implementation of ServletOutputStream
  -     */
  -    class MyServletOutputStream extends ServletOutputStream {
  -        ByteArrayOutputStream output = null;
  -        PrintWriter writer = null;
  -
  -        public MyServletOutputStream() {
  -            this.output = new ByteArrayOutputStream();
  -            try {
  -                this.writer = new PrintWriter(new OutputStreamWriter(output, "UTF-8"));
  -            } catch (UnsupportedEncodingException e) {
  -                getLogger().error("Your JVM seems not to support UTF-8,"
  -                                  + " using platform default instead."
  -                                  + " This can cause problems as you can imagine.");
  -                this.writer = new PrintWriter(new OutputStreamWriter(output));
  -            }
  -        }
  -        public PrintWriter getWriter() {
  -            return this.writer;
  -        }
  -        public void write(int b) throws IOException  {
  -            this.output.write(b);
  -        }
  -        public byte[] toByteArray() {
  -            this.writer.flush();
  -            byte[] bytes = output.toByteArray();
  -            return bytes;
  -        }
  -    }
   }
  
  
  
  1.1                  cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineServletOutputStream.java
  
  Index: JSPEngineServletOutputStream.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.jsp;
  
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.io.UnsupportedEncodingException;
  
  import javax.servlet.ServletOutputStream;
  
  /**
   * Stub implementation of ServletOutputStream.
   */
  public final class JSPEngineServletOutputStream extends ServletOutputStream {
  
      private final ByteArrayOutputStream output;
      private final PrintWriter writer;
  
      public JSPEngineServletOutputStream() throws UnsupportedEncodingException {
          this.output = new ByteArrayOutputStream();
          this.writer = new PrintWriter(new OutputStreamWriter(output, "UTF-8"));
      }
      
      final PrintWriter getWriter() {
          return this.writer;
      }
      
      public void write(int b) throws IOException  {
          this.output.write(b);
      }
      
      final byte[] toByteArray() {
          this.writer.flush();
          byte[] bytes = output.toByteArray();
          return bytes;
      }
      
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineServletRequest.java
  
  Index: JSPEngineServletRequest.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.jsp;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.security.Principal;
  import java.util.Enumeration;
  import java.util.Locale;
  
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletInputStream;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;
  
  /**
   * Stub implementation of HttpServletRequest.
   */
  public class JSPEngineServletRequest implements HttpServletRequest {
  
      /** The servlet include path. */
      private static final String INC_SERVLET_PATH = "javax.servlet.include.servlet_path";
      /** The servlet request uri, needed for Resin. */
      private static final String INC_REQUEST_URI = "javax.servlet.include.request_uri";
      
      private final HttpServletRequest request;
      private final String jspFile;
  
      public JSPEngineServletRequest(HttpServletRequest request, String jspFile) {
          this.request = request;
          this.jspFile = jspFile;
      }
      public String getAuthType(){ return request.getAuthType(); }
      public Cookie[] getCookies(){ return request.getCookies(); }
      public long getDateHeader(String s){ return request.getDateHeader(s); }
      public String getHeader(String s){ return request.getHeader(s); }
      public Enumeration getHeaders(String s){ return request.getHeaders(s); }
      public Enumeration getHeaderNames(){ return request.getHeaderNames(); }
      public int getIntHeader(String s){ return request.getIntHeader(s); }
      public String getMethod(){ return request.getMethod(); }
      public String getPathInfo(){ return request.getPathInfo(); }
      public String getPathTranslated(){ return request.getPathTranslated(); }
      public String getContextPath(){ return request.getContextPath(); }
      public String getQueryString(){ return request.getQueryString(); }
      public String getRemoteUser(){ return request.getRemoteUser(); }
      public boolean isUserInRole(String s){ return request.isUserInRole(s); }
      public Principal getUserPrincipal(){ return request.getUserPrincipal(); }
      public String getRequestedSessionId(){ return request.getRequestedSessionId(); }
      public String getRequestURI(){ return request.getRequestURI(); }
      public String getServletPath(){ return request.getServletPath(); }
      public HttpSession getSession(boolean flag){ return request.getSession(flag); }
      public HttpSession getSession(){ return request.getSession(); }
      public boolean isRequestedSessionIdValid(){ return request.isRequestedSessionIdValid(); }
      public boolean isRequestedSessionIdFromCookie(){ return request.isRequestedSessionIdFromCookie(); }
      public boolean isRequestedSessionIdFromURL(){ return request.isRequestedSessionIdFromURL(); }
      /** @deprecated use isRequestedSessionIdFromURL instead. */
      public boolean isRequestedSessionIdFromUrl(){ return request.isRequestedSessionIdFromUrl(); }
      public Object getAttribute(String s){
          if (s != null && (s.equals(INC_SERVLET_PATH) || s.equals(INC_REQUEST_URI))) {
              return jspFile;
          }
          return request.getAttribute(s);
      }
      public Enumeration getAttributeNames(){ return request.getAttributeNames(); }
      public String getCharacterEncoding(){ return request.getCharacterEncoding(); }
      public int getContentLength(){ return request.getContentLength(); }
      public String getContentType(){ return request.getContentType(); }
      public ServletInputStream getInputStream() throws IOException{ return request.getInputStream(); }
      public String getParameter(String s){ return request.getParameter(s); }
      public Enumeration getParameterNames(){ return request.getParameterNames(); }
      public String[] getParameterValues(String s){ return request.getParameterValues(s); }
      public String getProtocol(){ return request.getProtocol(); }
      public String getScheme(){ return request.getScheme(); }
      public String getServerName(){ return request.getServerName(); }
      public int getServerPort(){ return request.getServerPort(); }
      public BufferedReader getReader()
          throws IOException{ return request.getReader(); }
      public String getRemoteAddr(){ return request.getRemoteAddr(); }
      public String getRemoteHost(){ return request.getRemoteHost(); }
      public void setAttribute(String s, Object obj){ request.setAttribute(s,obj); }
      public void removeAttribute(String s){ request.removeAttribute(s); }
      public Locale getLocale(){ return request.getLocale(); }
      public Enumeration getLocales(){ return request.getLocales(); }
      public boolean isSecure(){ return request.isSecure(); }
      public RequestDispatcher getRequestDispatcher(String s){ return request.getRequestDispatcher(s); }
      /** @deprecated use ServletContext.getRealPath(java.lang.String) instead. */
      public String getRealPath(String s){ return request.getRealPath(s); }
      public java.lang.StringBuffer getRequestURL() { return null; }
      public java.util.Map getParameterMap() { return null; }
      public void setCharacterEncoding(java.lang.String s) { }
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineServletResponse.java
  
  Index: JSPEngineServletResponse.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.jsp;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Locale;
  
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletResponse;
  
  
  /**
   * Stub implementation of HttpServletResponse.
   */
  public class JSPEngineServletResponse implements HttpServletResponse {
  
      private final HttpServletResponse servletResponse;
      private final JSPEngineServletOutputStream output;
      
      private boolean hasWriter = false;
      private boolean hasOutputStream = false;
  
      public JSPEngineServletResponse(HttpServletResponse servletResponse, JSPEngineServletOutputStream output) {
          this.servletResponse = servletResponse;
          this.output = output;
      }
      public String getCharacterEncoding() {
          return this.servletResponse.getCharacterEncoding();
      }
      public Locale getLocale(){
          return this.servletResponse.getLocale();
      }
      public PrintWriter getWriter() {
          if (this.hasOutputStream) {
              throw new IllegalStateException("getOutputStream was already called.");
          }
          this.hasWriter = true;
          return this.output.getWriter();
      }
      public void setContentLength(int len) {
          // this value can be overriden by cocoon
          servletResponse.setContentLength(len);
      }
      public void setContentType(java.lang.String type) {
          servletResponse.setContentType(type);
      }
      public void setLocale(java.util.Locale loc) {
          servletResponse.setLocale(loc);
      }
      public ServletOutputStream getOutputStream() {
          if (this.hasWriter) {
              throw new IllegalStateException("getWriter was already called.");
          }
          this.hasOutputStream = true;
          return this.output;
      }
      public void addCookie(Cookie cookie){
          servletResponse.addCookie(cookie);
      }
      public boolean containsHeader(String s){
          return servletResponse.containsHeader(s);
      }
      /** @deprecated use encodeURL(String url) instead. */
      public String encodeUrl(String s){
          return servletResponse.encodeUrl(s);
      }
      public String encodeURL(String s){
          return servletResponse.encodeURL(s);
      }
      /** @deprecated use encodeRedirectURL(String url) instead. */
      public String encodeRedirectUrl(String s){
          return servletResponse.encodeRedirectUrl(s);
      }
      public String encodeRedirectURL(String s){
          return servletResponse.encodeRedirectURL(s);
      }
      public void sendError(int i, String s) throws IOException{
          servletResponse.sendError(i,s); 
      }
      public void sendError(int i) throws IOException{
          servletResponse.sendError(i);
      }
      public void sendRedirect(String s) throws IOException{
          servletResponse.sendRedirect(s);
      }
      public void setDateHeader(String s, long l) {
          servletResponse.setDateHeader(s, l);
      }
      public void addDateHeader(String s, long l) {
          servletResponse.addDateHeader(s, l);
      }
      public void setHeader(String s, String s1) {
          servletResponse.setHeader(s, s1);
      }
      public void addHeader(String s, String s1) {
          servletResponse.addHeader(s, s1);
      }
      public void setIntHeader(String s, int i) {
          servletResponse.setIntHeader(s, i);
      }
      public void addIntHeader(String s, int i) {
          servletResponse.addIntHeader(s, i);
      }
      public void setStatus(int i){
          servletResponse.setStatus(i);
      }
      /** @deprecated use sendError(int, String) instead */
      public void setStatus(int i, String s){
          servletResponse.setStatus(i, s);
      }
      public void resetBuffer() {}
      public void reset() {}
      public int getBufferSize() { return 1024; }
      public void setBufferSize(int size) {}
      public void flushBuffer() throws IOException {}
      public boolean isCommitted() { return false; }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineServletConfig.java
  
  Index: JSPEngineServletConfig.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" 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 name,  without prior written permission  of the
      Apache Software Foundation.
  
   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 (INCLU-
   DING, 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 and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.jsp;
  
  import java.util.Enumeration;
  
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletContext;
  
  /**
   * Stub implementation of ServletConfig.
   */
  public final class JSPEngineServletConfig implements ServletConfig {
  
      private final ServletContext context;
      private final String name;
      
      public JSPEngineServletConfig(ServletContext context, String name) {
          this.context = context;
          this.name = name;
      }
      public String getServletName() { return name; }
      public Enumeration getInitParameterNames() { return context.getInitParameterNames(); }
      public ServletContext getServletContext() { return context; }
      public String getInitParameter(String name) { return context.getInitParameter(name); }
  
  }
  
  
  

Mime
View raw message