cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject cvs commit: cocoon-2.0/src/java/org/apache/cocoon/components/jsp JSPEngineImpl.java JSPEngineImplNamedDispatcherInclude.java JSPEngineImplWLS.java
Date Sat, 12 Jul 2003 14:57:33 GMT
joerg       2003/07/12 07:57:33

  Modified:    src/java/org/apache/cocoon/components/jsp JSPEngineImpl.java
                        JSPEngineImplNamedDispatcherInclude.java
                        JSPEngineImplWLS.java
  Log:
  applied latest changes from 2.1:
  revert encoding changes in JSPEngineImpl (bug 14327)
  made JSPs working in Resin not ending on .jsp (bug 4934, thanks to Ryder Rishel)
  avoid NPE in JSPEngineImplNamedDispatcherInclude if no RequestDispatcher was found
  deprecation messages added
  
  Revision  Changes    Path
  1.5       +41 -56    cocoon-2.0/src/java/org/apache/cocoon/components/jsp/JSPEngineImpl.java
  
  Index: JSPEngineImpl.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.0/src/java/org/apache/cocoon/components/jsp/JSPEngineImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JSPEngineImpl.java	30 May 2003 15:28:43 -0000	1.4
  +++ JSPEngineImpl.java	12 Jul 2003 14:57:33 -0000	1.5
  @@ -50,40 +50,47 @@
   */
   package org.apache.cocoon.components.jsp;
   
  -import org.apache.avalon.framework.logger.AbstractLoggable;
  -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.PrintWriter;
   import java.io.UnsupportedEncodingException;
   import java.security.Principal;
   import java.util.Enumeration;
   import java.util.Locale;
  -import java.util.StringTokenizer;
  +
  +import javax.servlet.RequestDispatcher;
  +import javax.servlet.Servlet;
  +import javax.servlet.ServletConfig;
  +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.AbstractLoggable;
  +import org.apache.avalon.framework.parameters.Parameterizable;
  +import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.thread.ThreadSafe;
   
   /**
    * 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>
  - * @author <a href="mailto:miyabe@jzf.co.jp">MIYABE Tatsuhiko</a>
    * @version CVS $Id$
    */
   public class JSPEngineImpl extends AbstractLoggable
       implements JSPEngine, Parameterizable, ThreadSafe {
   
  -    /** The Servlet Include Path */
  +    /** 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*/
       public static final String DEFAULT_SERVLET_CLASS = "org.apache.jasper.servlet.JspServlet";
  @@ -92,9 +99,7 @@
       public String jspServletClass = DEFAULT_SERVLET_CLASS;
   
       /**
  -     * Set the sitemap-provided configuration.
  -     * @param conf The configuration information
  -     * @exception ConfigurationException
  +     * @param params The configuration information
        */
       public void parameterize(Parameters params)  {
           this.jspServletClass = params.getParameter("servlet-class", DEFAULT_SERVLET_CLASS);
  @@ -106,7 +111,6 @@
        * @param context The Servlet Context
        * @exception IOException
        * @exception ServletException
  -     * @exception SAXException
        * @exception Exception
        */
       public byte[] executeJSP(String url, HttpServletRequest httpRequest, HttpServletResponse
httpResponse, ServletContext context)
  @@ -180,10 +184,12 @@
           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))
  +            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(); }
  @@ -208,6 +214,7 @@
           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; }
  @@ -218,57 +225,37 @@
        * Stub implementation of HttpServletResponse
        */
       class MyServletResponse implements HttpServletResponse {
  -        HttpServletResponse response;
  +        HttpServletResponse response = null;
           MyServletOutputStream output = null;
  -        String encoding = "iso-8859-1";
   
           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.output == null) {
  -                this.output = new MyServletOutputStream(this.encoding);
  -            }
               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) {
  -            StringTokenizer st = new StringTokenizer(type, ";,");
  -            st.nextToken();
  -            while (st.hasMoreTokens())  {
  -                String param = st.nextToken();
  -                int equal = param.indexOf("=");
  -                if (equal != -1) {
  -                    String name = param.substring(0, equal);
  -                    if (name.trim().equalsIgnoreCase("charset")) {
  -                        this.encoding = param.substring(equal + 1).trim();
  -                        break;
  -                    }
  -                    continue;
  -                }
  -                break;
  -            }
  -        }
  +        public void setContentType(java.lang.String type) {}
           public void setLocale(java.util.Locale loc) {}
           public ServletOutputStream getOutputStream() {
  -            if (this.output == null) {
  -                this.output = new MyServletOutputStream(this.encoding);
  -            }
               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);
}
  +        /** @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)
  @@ -282,16 +269,12 @@
           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() {
  -            if (this.output != null) {
  -                return output.toByteArray();
  -            }
  -            else {
  -                return new byte[0];
  -            }
  +            return output.toByteArray();
           }
       }
   
  @@ -302,12 +285,14 @@
           ByteArrayOutputStream output;
           PrintWriter writer;
   
  -        public MyServletOutputStream(String encoding) {
  +        public MyServletOutputStream() {
               this.output = new ByteArrayOutputStream();
               try {
  -                this.writer = new PrintWriter(new OutputStreamWriter(output, encoding));
  +                this.writer = new PrintWriter(new OutputStreamWriter(output, "uft-8"));
               } catch (UnsupportedEncodingException e) {
  -                getLogger().error("Unsupported encoding: " + encoding + ", using platform
default instead.");
  +                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));
               }
           }
  
  
  
  1.2       +41 -23    cocoon-2.0/src/java/org/apache/cocoon/components/jsp/JSPEngineImplNamedDispatcherInclude.java
  
  Index: JSPEngineImplNamedDispatcherInclude.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.0/src/java/org/apache/cocoon/components/jsp/JSPEngineImplNamedDispatcherInclude.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JSPEngineImplNamedDispatcherInclude.java	9 Mar 2003 00:01:50 -0000	1.1
  +++ JSPEngineImplNamedDispatcherInclude.java	12 Jul 2003 14:57:33 -0000	1.2
  @@ -50,21 +50,32 @@
   */
   package org.apache.cocoon.components.jsp;
   
  -import org.apache.avalon.framework.logger.AbstractLoggable;
  -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 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.*;
  +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 java.io.*;
  -import java.security.Principal;
  -import java.util.Enumeration;
  -import java.util.Locale;
  +
  +import org.apache.avalon.framework.logger.AbstractLoggable;
  +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
  @@ -79,8 +90,10 @@
   public class JSPEngineImplNamedDispatcherInclude extends AbstractLoggable
       implements JSPEngine, Parameterizable, ThreadSafe {
   
  -    /** The Servlet Include Path */
  +    /** 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
  @@ -95,9 +108,7 @@
       String servletName = DEFAULT_SERVLET_NAME;
   
       /**
  -     * Set the sitemap-provided configuration.
  -     * @param conf The configuration information
  -     * @exception ConfigurationException
  +     * @param params The configuration information
        */
       public void parameterize(Parameters params)  {
           this.servletName = params.getParameter(CONFIG_SERVLET_NAME, DEFAULT_SERVLET_NAME);
  @@ -123,12 +134,13 @@
           // 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 );
  +            rd.include( request, response );
  +            response.flushBuffer();
  +            bytes = response.toByteArray();
           } else {
  -          getLogger().error( "Specify a correct " + CONFIG_SERVLET_NAME + " " + servletName
);
  +            // 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);
           }
           return bytes;
       }
  @@ -168,10 +180,12 @@
           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))
  +            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(); }
  @@ -196,6 +210,7 @@
           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; }
  @@ -231,10 +246,12 @@
           }
           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);
}
  +        /** @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)
  @@ -248,6 +265,7 @@
           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(){}
   
  
  
  
  1.2       +17 -14    cocoon-2.0/src/java/org/apache/cocoon/components/jsp/JSPEngineImplWLS.java
  
  Index: JSPEngineImplWLS.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.0/src/java/org/apache/cocoon/components/jsp/JSPEngineImplWLS.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JSPEngineImplWLS.java	9 Mar 2003 00:01:50 -0000	1.1
  +++ JSPEngineImplWLS.java	12 Jul 2003 14:57:33 -0000	1.2
  @@ -50,20 +50,22 @@
   */
   package org.apache.cocoon.components.jsp;
   
  -import org.apache.avalon.framework.logger.AbstractLoggable;
  -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 java.io.ByteArrayOutputStream;
  +import java.io.IOException;
  +import java.util.Locale;
   
   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;
  +
  +import org.apache.avalon.framework.logger.AbstractLoggable;
  +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 WLS JSP to be used as a generator.  Builds upon the JSP servlet
  @@ -95,9 +97,7 @@
       String servletName = DEFAULT_SERVLET_NAME;
   
       /**
  -     * Set the sitemap-provided configuration.
  -     * @param conf The configuration information
  -     * @exception ConfigurationException
  +     * @param params The configuration information
        */
       public void parameterize(Parameters params) {
           this.servletName = params.getParameter( CONFIG_SERVLET_NAME, DEFAULT_SERVLET_NAME);
  @@ -248,10 +248,12 @@
         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);
}
  +      /** @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)
  @@ -265,6 +267,7 @@
         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); }
       }
   }
  
  
  

Mime
View raw message