You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by ni...@apache.org on 2002/12/03 18:08:12 UTC

cvs commit: xml-cocoon2/src/blocks/jsp/java/org/apache/cocoon/reading JSPReader.java

nicolaken    2002/12/03 09:08:12

  Added:       src/blocks/jsp/java/org/apache/cocoon/components/jsp
                        JSPEngine.java JSPEngineImpl.java
                        JSPEngineImplNamedDispatcherInclude.java
                        JSPEngineImplWLS.java
               src/blocks/jsp/java/org/apache/cocoon/generation
                        JspGenerator.java
               src/blocks/jsp/java/org/apache/cocoon/reading JSPReader.java
  Log:
    <action dev="NKB" type="update">
      Moved the jsp components to the jsp block, using hand-made-to-be-cleaned
      mock objects for the weblogic specific imports.
      Had also to move some definitions from the cocoon roles and xconf file.
      This moving of the blocks is indeed cleaning the core! :-)
    </action>
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngine.java
  
  Index: JSPEngine.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.jsp;
  
  import org.apache.avalon.framework.component.Component;
  import org.xml.sax.SAXException;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.IOException;
  
  /**
   * A component for loading and running JSP.
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @version CVS $Id: JSPEngine.java,v 1.1 2002/12/03 17:08:11 nicolaken Exp $
   */
  public interface JSPEngine extends Component {
  
      String ROLE = JSPEngine.class.getName();
  
      /**
      * execute the JSP and return the output
      *
      * @param context The Servlet Context
      * @exception IOException
      * @exception ServletException
      * @exception SAXException
      * @exception Exception
      */
      byte[] executeJSP(String url,
                         HttpServletRequest request,
                         HttpServletResponse response,
                         ServletContext context)
          throws IOException, ServletException, SAXException, Exception;
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImpl.java
  
  Index: JSPEngineImpl.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.jsp;
  
  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).
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @version CVS $Id: JSPEngineImpl.java,v 1.1 2002/12/03 17:08:11 nicolaken Exp $
   */
  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 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 conf The configuration information
       * @exception ConfigurationException
       */
      public void parameterize(Parameters params)  {
          this.jspServletClass = params.getParameter("servlet-class", DEFAULT_SERVLET_CLASS);
      }
  
      /**
       * execute the JSP and return the output
       *
       * @param context The Servlet Context
       * @exception IOException
       * @exception ServletException
       * @exception SAXException
       * @exception Exception
       */
      public byte[] executeJSP(String url, HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletContext context)
          throws IOException, ServletException, Exception {
  
          byte[] bytes = null;
  
          MyServletRequest request = new MyServletRequest(httpRequest, url);
          MyServletResponse response = new MyServletResponse(httpResponse);
  
          // start JSPServlet.
          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();
  
          // clean up
          jsp.destroy();
  
          return bytes;
      }
  
  
      /**
       * Stub implementation of Servlet Config
       */
      class config implements ServletConfig {
          ServletContext c;
          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 null; }
      }
  
      /**
       * 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))
                  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;
  
          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() {
              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() {
              return this.output;
          }
          public void addCookie(Cookie cookie){ response.addCookie(cookie); }
          public boolean containsHeader(String s){ return response.containsHeader(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); }
          /** @deprecated use encodeURL(String url) instead. */
          public String encodeUrl(String s){ return response.encodeUrl(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 IOException  {
              // This method is not used but have to be implemented
              this.writer.write(b);
          }
          public byte[] toByteArray() {
              this.writer.flush();
              byte[] bytes = output.toByteArray();
              return bytes;
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImplNamedDispatcherInclude.java
  
  Index: JSPEngineImplNamedDispatcherInclude.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.jsp;
  
  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 org.xml.sax.SAXException;
  
  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.*;
  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).
   * This implementation includes via ServletContext.getNamedDispatcher() the
   * jsp-response. This a generic implementation.
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @author <a href="mailto:bh22351@i-one.at">Bernhard Huber</a>
   * @version CVS $Id: JSPEngineImplNamedDispatcherInclude.java,v 1.1 2002/12/03 17:08:11 nicolaken Exp $
   */
  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";
  
      /** config-parameter name for specifying the jsp servlet-name.
        ie. servlet-name
      */
      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
      */
      public static final String DEFAULT_SERVLET_NAME = "*.jsp";
      /** the configured name of the jsp servlet
      */
      String servletName = DEFAULT_SERVLET_NAME;
  
      /**
       * Set the sitemap-provided configuration.
       * @param conf The configuration information
       * @exception ConfigurationException
       */
      public void parameterize(Parameters params)  {
          this.servletName = params.getParameter(CONFIG_SERVLET_NAME, DEFAULT_SERVLET_NAME);
      }
  
      /**
       * execute the JSP and return the output
       *
       * @param context The Servlet Context
       * @exception IOException
       * @exception ServletException
       * @exception SAXException
       * @exception Exception
       */
      public byte[] executeJSP(String url, HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletContext context)
          throws IOException, ServletException, SAXException, Exception {
  
          byte[] bytes = null;
  
          MyServletRequest request = new MyServletRequest(httpRequest, url);
          MyServletResponse response = new MyServletResponse(httpResponse);
  
          // start JSPServlet.
          javax.servlet.RequestDispatcher rd = context.getNamedDispatcher( servletName );
          if (rd != null) {
            rd.include( request, response );
            response.flushBuffer();
            bytes = response.toByteArray();
            ByteArrayInputStream input = new ByteArrayInputStream( bytes );
          } else {
            getLogger().error( "Specify a correct " + 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(); }
          public boolean isRequestedSessionIdFromUrl(){ return request.isRequestedSessionIdFromUrl(); }
          public Object getAttribute(String s){
              if(s != null && s.equals(INC_SERVLET_PATH))
                  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); }
          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;
  
          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() {
              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() {
              return this.output;
          }
          public void addCookie(Cookie cookie){ response.addCookie(cookie); }
          public boolean containsHeader(String s){ return response.containsHeader(s); }
          public String encodeURL(String s){ return response.encodeURL(s); }
          public String encodeRedirectURL(String s){ return response.encodeRedirectURL(s); }
          public String encodeUrl(String s){ return response.encodeUrl(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); }
          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 method is not used but have to be implemented
              this.writer.write(b);
          }
          public byte[] toByteArray() {
              this.writer.flush();
              byte[] bytes = output.toByteArray();
              return bytes;
          }
      }
  }
  
  
  
  
  1.1                  xml-cocoon2/src/blocks/jsp/java/org/apache/cocoon/components/jsp/JSPEngineImplWLS.java
  
  Index: JSPEngineImplWLS.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.jsp;
  
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  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.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  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).
   * 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.
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @author <a href="mailto:bh22351@i-one.at">Bernhard Huber</a>
   * @version CVS $Id: JSPEngineImplWLS.java,v 1.1 2002/12/03 17:08:11 nicolaken Exp $
   */
  public class JSPEngineImplWLS extends AbstractLogEnabled
      implements JSPEngine, Parameterizable, ThreadSafe {
  
      /** The Servlet Include Path */
      public static final String INC_SERVLET_PATH = "javax.servlet.include.servlet_path";
  
      /** config-parameter name for specifying the jsp servlet-name.
        ie. servlet-name
      */
      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
      */
      public static final String DEFAULT_SERVLET_NAME = "*.jsp";
      /** the configured name of the jsp servlet
      */
      String servletName = DEFAULT_SERVLET_NAME;
  
      /**
       * Set the sitemap-provided configuration.
       * @param conf The configuration information
       * @exception ConfigurationException
       */
      public void parameterize(Parameters params) {
          this.servletName = params.getParameter( CONFIG_SERVLET_NAME, DEFAULT_SERVLET_NAME);
      }
  
      /**
       * execute the JSP and return the output
       *
       * @param context The Servlet Context
       * @exception IOException
       * @exception ServletException
       * @exception SAXException
       * @exception Exception
       */
      public byte[] executeJSP(String url, HttpServletRequest httpRequest, HttpServletResponse httpResponse, ServletContext context)
          throws IOException, ServletException, SAXException, 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 );
  
          // start JSPServlet.
          javax.servlet.RequestDispatcher rd = context.getNamedDispatcher( servletName );
          if (rd != null) {
            rd.include( request, response );
            response.flushBuffer();
  
            getLogger().debug( "JSP response: " + response.getResponseContentAsString() );
            bytes = response.getResponseContentAsByteArray();
  
            if (inc_servlet_path_was != null) {
              httpRequest.setAttribute( INC_SERVLET_PATH, inc_servlet_path_was );
            }
          } else {
            getLogger().error( "Specify a correct " + CONFIG_SERVLET_NAME + " " + servletName );
          }
  
          return bytes;
      }
  
      /** WLS jsp servlet hack.
        <p>
          Here WLS specific classes are used.
        </p>
        <p>
          The weblogic.servlet.JSPServlet, and
          weblogic.servlet.internal.RequesDispatcherImpl expects
          objects weblogic.servlet.internal.ServletOutputStreamImpl,
          and weblogic.servlet.internal.ServletResponseImpl.
          Thus we have to use <i>exactly</i> these classes!
        </p>
      */
      class MyWLSResponse extends weblogic.servlet.internal.ServletResponseImpl {
        /* the cocoon2 response. Let's use this response to forward headers
        , cookies, etc generated inside the jsp-response
        */
        HttpServletResponse response;
  
        ByteArrayOutputStream baos;
        weblogic.servlet.internal.ServletOutputStreamImpl wlsOutputStream;
  
        public MyWLSResponse( HttpServletResponse response,
          weblogic.servlet.internal.ServletContextImpl servlet_context ) {
  
          super( servlet_context );
          this.response = response;
  
          baos = new ByteArrayOutputStream();
  
          wlsOutputStream =
            new weblogic.servlet.internal.ServletOutputStreamImpl( baos );
          this.setOutputStream( wlsOutputStream );
          wlsOutputStream.setImpl( this );
        }
  
        /** flush response content.
        */
        public void flushBuffer() throws IOException {
          super.flushBuffer();
          baos.flush();
        }
  
        /** return response as byte array.
          <p>Note: http-headers are skipped. More exactly all chars until first
          '&lt;?xml', or '\r\n\r\n&lt; sequence. This may be a bit heuristic.
          </p>
          <p>Note: we are expecting the xml prolog, without the xml prolog http
          -headers are passed further, and the xml parser will surly complain!
          </p>
        */
        public byte[] getResponseContentAsByteArray() {
          byte[] baos_arr = baos.toByteArray();
  
          int baos_arr_length = baos_arr.length;
          int i = 0;
          boolean matched = false;
          final int I_MAX = 8192; // check only header
  
          final byte MATCH_0d = (byte)'\r';
          final byte MATCH_0a = (byte)'\n';
  
          final byte MATCH_FIRST = (byte)'<';
          final byte MATCH_SECOND = (byte)'?';
          final byte MATCH_THIRD = (byte)'x';
          final byte MATCH_FOURTH = (byte)'m';
          final byte MATCH_FIFTH = (byte)'l';
  
          final int MATCH_COUNT = 5;
  
          while (i + MATCH_COUNT < baos_arr_length && i < I_MAX && !matched) {
  
            matched = (baos_arr[i] == MATCH_FIRST && baos_arr[i+1] == MATCH_SECOND &&
               baos_arr[i+2] == MATCH_THIRD && baos_arr[i+3] == MATCH_FOURTH &&
               baos_arr[i+4] == MATCH_FIFTH);
            if (matched) break;
  
            matched = (baos_arr[i] == MATCH_0d && baos_arr[i+1] == MATCH_0a &&
              baos_arr[i+2] == MATCH_0d && baos_arr[i+3] == MATCH_0a &&
              baos_arr[i+4] == MATCH_FIRST);
            if (matched) {
              i += 4; // skip leading \r\n\r\n, too
              break;
            }
            i += 2;
          }
          if (matched && i > 0) {
            int baos_arr_new_length = baos_arr_length - i;
  
            byte []new_baos_arr = new byte[baos_arr_new_length];
            System.arraycopy( baos_arr, i, new_baos_arr, 0, baos_arr_new_length );
            baos_arr = new_baos_arr;
          }
          return baos_arr;
        }
  
        public String getResponseContentAsString() {
          String s = new String( getResponseContentAsByteArray() );
          return s;
        }
  
        // following methods forwarding from jsp-repsonse to cocoon2-repsonse
  
        public String getCharacterEncoding() { return this.response.getCharacterEncoding();}
        public Locale getLocale(){ return this.response.getLocale();}
        public void addCookie(Cookie cookie){ response.addCookie(cookie); }
        public boolean containsHeader(String s){ return response.containsHeader(s); }
        public String encodeURL(String s){ return response.encodeURL(s); }
        public String encodeRedirectURL(String s){ return response.encodeRedirectURL(s); }
        public String encodeUrl(String s){ return response.encodeUrl(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); }
        public void setStatus(int i, String s){response.setStatus(i, s); }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/jsp/java/org/apache/cocoon/generation/JspGenerator.java
  
  Index: JspGenerator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.generation;
  
  import org.apache.avalon.excalibur.xml.Parser;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.components.jsp.JSPEngine;
  import org.apache.cocoon.environment.http.HttpEnvironment;
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.ByteArrayInputStream;
  import java.io.IOException;
  
  /**
   * Allows JSP to be used as a generator.  Builds upon the JSP servlet
   * functionality - overrides the output method in order to pipe the
   * results into SAX events.
   *
   * @author <a href="mailto:dims@yahoo.com">Davanum Srinivas</a>
   * @version CVS $Id: JspGenerator.java,v 1.1 2002/12/03 17:08:12 nicolaken Exp $
   */
  public class JspGenerator extends ServletGenerator implements Configurable {
  
      public void configure(Configuration conf) throws ConfigurationException
      {
      }
  
      /**
       * Generate XML data from JSP.
       */
      public void generate() throws ProcessingException {
  
          // ensure that we are running in a servlet environment
          HttpServletResponse httpResponse =
              (HttpServletResponse)this.objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
          HttpServletRequest httpRequest =
              (HttpServletRequest)this.objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
          ServletContext httpContext =
              (ServletContext)this.objectModel.get(HttpEnvironment.HTTP_SERVLET_CONTEXT);
  
          if (httpResponse == null || httpRequest == null || httpContext == null) {
              throw new ProcessingException("HttpServletRequest or HttpServletResponse or ServletContext object not available");
          }
  
          JSPEngine engine = null;
          Parser parser = null;
          try {
              // FIXME (KP): Should we exclude not supported protocols, say 'context'?
              String url = this.source;
              // absolute path is processed as is
              if (!url.startsWith("/")) {
                  // get current request path
                  String servletPath = httpRequest.getServletPath();
                  // remove file part
                  servletPath = servletPath.substring(0, servletPath.lastIndexOf('/') + 1);
                  url = servletPath + url;
              }
  
              engine = (JSPEngine)this.manager.lookup(JSPEngine.ROLE);
  
              getLogger().debug("JspGenerator executing JSP:" + url);
  
              byte[] bytes = engine.executeJSP(url, httpRequest, httpResponse, httpContext);
  
              // explicitly specify bytestream encoding
              InputSource input = new InputSource(new ByteArrayInputStream(bytes));
              // FIXME (KP): Why do we need this?
              input.setEncoding("utf-8");
  
              // pipe the results into the parser
              parser = (Parser)this.manager.lookup(Parser.ROLE);
              parser.parse(input, this.xmlConsumer);
          } catch (ServletException e) {
              throw new ProcessingException("ServletException in JspGenerator.generate()",e.getRootCause());
          } catch (SAXException e) {
              throw new ProcessingException("SAXException JspGenerator.generate()",e.getException());
          } catch (IOException e) {
              throw new ProcessingException("IOException JspGenerator.generate()",e);
          } catch (ProcessingException e) {
              throw e;
          } catch (Exception e) {
              throw new ProcessingException("Exception JspGenerator.generate()",e);
          } finally {
              this.manager.release(parser);
              this.manager.release(engine);
          }
      }
  }
  
  
  
  1.1                  xml-cocoon2/src/blocks/jsp/java/org/apache/cocoon/reading/JSPReader.java
  
  Index: JSPReader.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 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  <st...@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.reading;
  
  import java.io.ByteArrayInputStream;
  import java.io.IOException;
  
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.components.jsp.JSPEngine;
  import org.apache.cocoon.environment.Context;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.http.HttpEnvironment;
  import org.apache.excalibur.source.Source;
  
  /**
   * The <code>JSPReader</code> component is used to serve JSP page output data
   * in a sitemap pipeline.
   *
   * @author <a href="mailto:kpiroumian@flagship.ru">Konstantin Piroumian</a>
   * @version CVS $Id: JSPReader.java,v 1.1 2002/12/03 17:08:12 nicolaken Exp $
   */
  public class JSPReader extends ComposerReader {
  
      /**
       * Generates the output from JSP page.
       */
      public void generate() throws IOException, ProcessingException {
          // ensure that we are running in a servlet environment
          if (this.source == null) {
              throw new ProcessingException("JSPReader: source JSP is not specified");
          }
  
          HttpServletResponse httpResponse =
              (HttpServletResponse)this.objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
          HttpServletRequest httpRequest =
              (HttpServletRequest)this.objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
          ServletContext httpContext =
              (ServletContext)this.objectModel.get(HttpEnvironment.HTTP_SERVLET_CONTEXT);
  
          if (httpResponse == null || httpRequest == null || httpContext == null) {
              throw new ProcessingException("JSPReader can be used only in a Servlet/JSP environment");
          }
  
          JSPEngine engine = null;
          try {
  
              // FIXME (KP): Should we exclude not supported protocols, say 'context'?
              String url = this.source;
  
              // -- debug info --
              Source src = null;
              try {
                  src = resolver.resolveURI(url);
                  System.out.println("Resolved to: " + src);
                  java.net.URL resURL = httpContext.getResource(".");
                  System.out.println(". resource is: " + resURL);
              } finally {
                  resolver.release( src );
              }
              // -- end debug --
  
  
              // absolute path is processed as is
              if (!url.startsWith("/")) {
                  // get current request path
                  String servletPath = httpRequest.getServletPath();
                  // remove file part
                  servletPath = servletPath.substring(0, servletPath.lastIndexOf('/') + 1);
                  url = servletPath + url;
              }
  
              engine = (JSPEngine)this.manager.lookup(JSPEngine.ROLE);
  
              if (this.getLogger().isDebugEnabled()) {
                  this.getLogger().debug("JSPReader executing JSP:" + url);
              }
  
              byte[] bytes = engine.executeJSP(url, httpRequest, httpResponse, httpContext);
              // FIXME (KP): Make buffer size configurable
              byte[] buffer = new byte[8192];
              int length = -1;
  
              ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
              while ((length = bais.read(buffer)) > -1) {
                  out.write(buffer, 0, length);
              }
              bais.close();
              bais = null;
              out.flush();
              //
          } catch (ServletException e) {
              throw new ProcessingException("ServletException in JSPReader.generate()",e.getRootCause());
          } catch (IOException e) {
              throw new ProcessingException("IOException JSPReader.generate()",e);
          } catch (ProcessingException e) {
              throw e;
          } catch (Exception e) {
              throw new ProcessingException("Exception JSPReader.generate()",e);
          } finally {
              if (engine != null) this.manager.release(engine);
          }
      }
  }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org