In the Servlet 2.4 spec section 5.4 on i18n, the deployment descriptor
gets new stuff for mapping locale to character encoding. The spec says,

[Servlet 2.4, Section 5.4] "[...] The setLocale method also sets charset
component in Content-Type with an encoding information which can be
obtained from the locale-encoding-mapping element in the deployment
descriptor, if present. For example, to map a locale to the specific
encoding, the syntax of locale-encoding-mapping would be:

   <locale-encoding-mapping-list>
        <locale-encoding-mapping>
             <locale>ja</locale>
             <encoding>ISO-2022-JP</encoding>
        </locale-encoding-mapping>
    </locale-encoding-mapping-list>
" 

To implement this, I did this,

1. I added some lines to the digester to push the local and encoding
info into the Context 

2. I changed the Context to push the mapping into the CharsetMapper
class 

3. Changed the CharsetMapper class so it can accept new mappings 

4. changed CoyoteResponse.setLocale() so it consults CharsetMapper and
sets the mapped encoding

What do people think? (I used some long method names on Context and
CharsetMapper to make it clear that the information is coming from the
Deployment Descriptor.)  Can someone review and patch this?

Cheers,
-bob


Index: coyote/src/java/org/apache/coyote/Response.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/Response.java,v
retrieving revision 1.12
diff -u -r1.12 Response.java
--- coyote/src/java/org/apache/coyote/Response.java	1 Aug 2002 17:20:36 -0000	1.12
+++ coyote/src/java/org/apache/coyote/Response.java	8 Aug 2002 19:13:47 -0000
@@ -455,8 +455,6 @@
         if (isCommitted())
             return;
 
-        characterEncoding = charset;
-
         String type = this.contentType;
         int start = type.indexOf("charset=");
         if ( start != -1 ) {
@@ -468,8 +466,11 @@
                 type = type.substring(0,start+8)
                     +charset;
             this.contentType = type;
-
+        } else {
+            type += "charset=" + charset;
         }
+        setContentType( type );
+        
     }
 
     public String getCharacterEncoding() {
Index: coyote/src/java/org/apache/coyote/tomcat5/CoyoteResponse.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-connectors/coyote/src/java/org/apache/coyote/tomcat5/CoyoteResponse.java,v
retrieving revision 1.2
diff -u -r1.2 CoyoteResponse.java
--- coyote/src/java/org/apache/coyote/tomcat5/CoyoteResponse.java	8 Aug 2002 04:08:41 -0000	1.2
+++ coyote/src/java/org/apache/coyote/tomcat5/CoyoteResponse.java	8 Aug 2002 19:13:49 -0000
@@ -753,6 +753,12 @@
 
         coyoteResponse.setLocale(locale);
 
+        CharsetMapper cm = context.getCharsetMapper();
+        String charset = cm.getCharset( locale );
+
+        if ( charset != null )
+            setCharacterEncoding( charset);
+
     }
 
 
Index: catalina/src/share/org/apache/catalina/Context.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/Context.java,v
retrieving revision 1.2
diff -u -r1.2 Context.java
--- catalina/src/share/org/apache/catalina/Context.java	2 Aug 2002 01:37:42 -0000	1.2
+++ catalina/src/share/org/apache/catalina/Context.java	8 Aug 2002 21:22:46 -0000
@@ -481,6 +481,15 @@
 
 
     /**
+     * Add a Locale Encoding Mapping (see Sec 5.4 of Servlet spec 2.4)
+     *
+     * @param locale locale to map an encoding for
+     * @param encoding encoding to be used for a give locale
+     */
+    public void addLocaleEncodingMappingParameter(String locale, String encoding);
+
+
+    /**
      * Add a local EJB resource reference for this web application.
      *
      * @param ejb New local EJB resource reference
Index: catalina/src/share/org/apache/catalina/core/StandardContext.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
retrieving revision 1.2
diff -u -r1.2 StandardContext.java
--- catalina/src/share/org/apache/catalina/core/StandardContext.java	2 Aug 2002 01:37:43 -0000	1.2
+++ catalina/src/share/org/apache/catalina/core/StandardContext.java	8 Aug 2002 21:22:53 -0000
@@ -1508,6 +1508,17 @@
 
 
     /**
+     * Add a Locale Encoding Mapping (see Sec 5.4 of Servlet spec 2.4)
+     *
+     * @param locale locale to map an encoding for
+     * @param encoding encoding to be used for a give locale
+     */
+    public void addLocaleEncodingMappingParameter(String locale, String encoding){
+        getCharsetMapper().addCharsetMappingFromDeploymentDescriptor(locale, encoding);
+    }
+
+
+    /**
      * Add a local EJB resource reference for this web application.
      *
      * @param ejb New EJB resource reference
Index: catalina/src/share/org/apache/catalina/startup/WebRuleSet.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/WebRuleSet.java,v
retrieving revision 1.3
diff -u -r1.3 WebRuleSet.java
--- catalina/src/share/org/apache/catalina/startup/WebRuleSet.java	8 Aug 2002 18:33:19 -0000	1.3
+++ catalina/src/share/org/apache/catalina/startup/WebRuleSet.java	8 Aug 2002 21:22:56 -0000
@@ -385,6 +385,11 @@
         digester.addCallMethod(prefix + "web-app/welcome-file-list/welcome-file",
                                "addWelcomeFile", 0);
 
+        digester.addCallMethod(prefix + "web-app/locale-encoding-mapping-list/locale-encoding-mapping",
+                              "addLocaleEncodingMappingParameter", 2);
+        digester.addCallParam(prefix + "web-app/locale-encoding-mapping-list/locale-encoding-mapping/locale", 0);
+        digester.addCallParam(prefix + "web-app/locale-encoding-mapping-list/locale-encoding-mapping/encoding", 1);
+
     }
 
 
Index: catalina/src/share/org/apache/catalina/util/CharsetMapper.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/util/CharsetMapper.java,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 CharsetMapper.java
--- catalina/src/share/org/apache/catalina/util/CharsetMapper.java	18 Jul 2002 16:47:45 -0000	1.1.1.1
+++ catalina/src/share/org/apache/catalina/util/CharsetMapper.java	8 Aug 2002 21:22:56 -0000
@@ -171,5 +171,18 @@
 
     }
 
+    /**
+     * The deployment descriptor can have a
+     * locale-encoding-mapping-list element which describes the
+     * webapp's desired mapping from locale to charset.  This method
+     * gets called when processing the web.xml file for a context
+     *
+     * @param locale The locale for a character set
+     * @param charset The charset to be associated with the locale
+     */
+    public void addCharsetMappingFromDeploymentDescriptor(String locale,String charset) {
+        map.put( locale, charset );
+    }
+
 
 }

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to