tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Barker" <wbar...@wilshire.com>
Subject Re: cvs commit: jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5 Constants.java CoyoteResponse.java
Date Tue, 03 Dec 2002 04:35:21 GMT
I'm not really happy with having a default Locale in the o.a.c.Response.
I'd like it better if o.a.c.tc5.CoyoteResponse set the default Locale in
recycle.

----- Original Message -----
From: <jfarcand@apache.org>
To: <jakarta-tomcat-connectors-cvs@apache.org>
Sent: Monday, December 02, 2002 6:29 PM
Subject: cvs commit:
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5
Constants.java CoyoteResponse.java


> jfarcand    2002/12/02 18:29:14
>
>   Modified:    coyote/src/java/org/apache/coyote Response.java
>                coyote/src/java/org/apache/coyote/tomcat5 Constants.java
>                         CoyoteResponse.java
>   Log:
>   Servlet 2.4 section 5.4 will be modified:
>
>   A servlet should set the locale and the character encoding of a
>   response. The locale is set using the ServletResponse.setLocale method,
>   and communicated to the client using the Content-Language header. The
>   character encoding can be set explicitly using the ServletResponse
>   methods setCharacterEncoding and setContentType, or implicitly using the
>   ServletResponse.setLocale method, and is communicated to the client
>   using the charset parameter of the Content-Type header. Explicit
>   specifications take precedence over implicit specifications.
>   [...]
>   The character encoding should be specified before the getWriter method
>   of the ServletResponse interface is called; otherwise the default
>   ISO-8859-1 is used.
>
>   ---------------------
>   That means if setContentType is called, then setLocale should do reset
the content type. Same for setCharacterEncoding. If getWriter is called,
then ignore any call to setContentType, setCharacterEncoding and setLocale.
>
>   Please review.
>
>   Revision  Changes    Path
>   1.17      +10 -4
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Response.java
>
>   Index: Response.java
>   ===================================================================
>   RCS file:
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Respon
se.java,v
>   retrieving revision 1.16
>   retrieving revision 1.17
>   diff -u -r1.16 -r1.17
>   --- Response.java 9 Nov 2002 17:12:04 -0000 1.16
>   +++ Response.java 3 Dec 2002 02:29:14 -0000 1.17
>   @@ -91,8 +91,14 @@
>
>
>        // ----------------------------------------------------- Instance
Variables
>   +
>   +
>   +    /**
>   +     * Default locale
>   +     */
>   +    private static Locale DEFAULT_LOCALE = new Locale("en", "US");
>
>   -
>   +
>        /**
>         * Status code.
>         */
>   @@ -142,7 +148,7 @@
>        protected String contentLanguage = null;
>        protected String characterEncoding =
Constants.DEFAULT_CHARACTER_ENCODING;
>        protected int contentLength = -1;
>   -    private Locale locale = null;//Constants.DEFAULT_LOCALE;
>   +    private Locale locale = DEFAULT_LOCALE;
>
>        /**
>         * Holds request error exception.
>   @@ -311,7 +317,7 @@
>            // Reset the headers only if this is the main request,
>            // not for included
>            contentType = Constants.DEFAULT_CONTENT_TYPE;
>   -        locale = null;//Constants.DEFAULT_LOCALE;
>   +        locale = DEFAULT_LOCALE;
>            contentLanguage = null;
>            characterEncoding = Constants.DEFAULT_CHARACTER_ENCODING;
>            contentLength = -1;
>   @@ -525,7 +531,7 @@
>
>            contentType = Constants.DEFAULT_CONTENT_TYPE;
>            contentLanguage = null;
>   -        locale = null;//Constants.DEFAULT_LOCALE;
>   +        locale = DEFAULT_LOCALE;
>            characterEncoding = Constants.DEFAULT_CHARACTER_ENCODING;
>            contentLength = -1;
>            status = 200;
>
>
>
>   1.4       +1 -2
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/Constant
s.java
>
>   Index: Constants.java
>   ===================================================================
>   RCS file:
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat
5/Constants.java,v
>   retrieving revision 1.3
>   retrieving revision 1.4
>   diff -u -r1.3 -r1.4
>   --- Constants.java 10 Oct 2002 09:45:30 -0000 1.3
>   +++ Constants.java 3 Dec 2002 02:29:14 -0000 1.4
>   @@ -58,8 +58,6 @@
>     */
>    package org.apache.coyote.tomcat5;
>
>   -import java.util.Locale;
>   -
>    /**
>     * Constants.
>     *
>   @@ -92,5 +90,6 @@
>         */
>        protected static final boolean SECURITY =
>            (System.getSecurityManager() != null);
>   +
>
>    }
>
>
>
>   1.12      +50 -13
jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteRe
sponse.java
>
>   Index: CoyoteResponse.java
>   ===================================================================
>   RCS file:
/home/cvs/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat
5/CoyoteResponse.java,v
>   retrieving revision 1.11
>   retrieving revision 1.12
>   diff -u -r1.11 -r1.12
>   --- CoyoteResponse.java 11 Nov 2002 11:01:04 -0000 1.11
>   +++ CoyoteResponse.java 3 Dec 2002 02:29:14 -0000 1.12
>   @@ -261,7 +261,18 @@
>         */
>        protected boolean included = false;
>
>   +
>   +    /**
>   +     * The characterEncoding flag
>   +     */
>   +    private boolean isCharacterEncodingSet = false;
>   +
>   +    /**
>   +     * The contextType flag
>   +     */
>   +    private boolean isContentTypeSet = false;
>
>   +
>        /**
>         * The error flag.
>         */
>   @@ -313,6 +324,8 @@
>            appCommitted = false;
>            included = false;
>            error = false;
>   +        isContentTypeSet = false;
>   +        isCharacterEncodingSet = false;
>            cookies.clear();
>
>            if ((Constants.SECURITY) && (facade != null)) {
>   @@ -692,7 +705,10 @@
>            // Ignore any call from an included servlet
>            if (included)
>                return;
>   -
>   +
>   +        if (usingWriter)
>   +            return;
>   +
>            coyoteResponse.setContentLength(length);
>
>        }
>   @@ -713,7 +729,7 @@
>                return;
>
>            coyoteResponse.setContentType(type);
>   -
>   +        isContentTypeSet = true;
>        }
>
>
>   @@ -728,14 +744,22 @@
>
>            if (isCommitted())
>                return;
>   -
>   +
>   +        // Ignore any call from an included servlet
>            if (included)
>   -            return;     // Ignore any call from an included servlet
>   +            return;
>   +
>   +        // Ignore any call made after the getWriter has been invoked
>   +        // The default should be used
>   +        if (usingWriter)
>   +            return;
>
>            coyoteResponse.setCharacterEncoding(charset);
>   -
>   +        isCharacterEncodingSet= true;
>        }
>
>   +
>   +
>        /**
>         * Set the Locale that is appropriate for this response, including
>         * setting the appropriate character encoding.
>   @@ -750,14 +774,27 @@
>            // Ignore any call from an included servlet
>            if (included)
>                return;
>   -
>   +
>   +        // Ignore any call made after the getWriter has been invoked.
>   +        // The default should be used
>   +        if (usingWriter)
>   +            return;
>   +
>   +        if (isCharacterEncodingSet){
>   +            return;
>   +        }
>   +
>   +        if (isContentTypeSet){
>   +            return;
>   +        }
>   +
>            coyoteResponse.setLocale(locale);
>
>            CharsetMapper cm = context.getCharsetMapper();
>            String charset = cm.getCharset( locale );
>   -
>   -        if ( charset != null )
>   -            setCharacterEncoding( charset);
>   +        if ( charset != null ){
>   +            coyoteResponse.setCharacterEncoding(charset);
>   +        }
>
>        }
>
>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:tomcat-dev-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message