Re: Character encoding patch?

Dan Finkelstein <[email protected]> Fri, 06 Jan 2006 13:15:34 -0800
Newsgroups gmane.comp.web.maverick.general
Message-ID <[email protected]>
Hi Peter,

I had the same problem last summer and made two modifications to 
Maverick.  My app must be able to adjust to any charset based on 
locale.  I'm pasting in the changes I made below.  If someone can 
commit them to the maverick source that would be even 
better!!  Anyway, let me know how you find these changes.

Good luck,
Dan


In AbstractTransformStep.java, change to

public HttpServletResponse getResponse() throws IOException, ServletException
         {
                 log.debug("Getting fake response");

                 // Should be ok to wrap the real mccoy here.
                 if (this.fakeResponse == null) {
                         this.fakeResponse = new 
FakeHttpServletResponse(this.getTransformCtx().getRealResponse());
             // added by DF 7/26/05
             // allows propogating character encoding on to response
             fakeResponse.setContentType("text/html; charset=" + 
getTransformCtx().getRequest().getCharacterEncoding());
         }

                 return this.fakeResponse;
         }

In Dispatcher.java, change to

         public void init() throws ServletException
         {
                 // Make us available in the application attribute collection
                 this.getServletContext().setAttribute(MAVERICK_APPLICATION_KEY, 
this);

                 // Get defaultRequestCharset from init parameter, null is ok
         // CLOWN added by DF 7/26/05 -- allows pulling default char 
set from app
         defaultRequestCharset = 
(String)this.getServletContext().getAttribute(INITPARAM_DEFAULT_REQUEST_CHARSET);
         if(defaultRequestCharset == null) {
             this.defaultRequestCharset = 
this.getInitParameter(INITPARAM_DEFAULT_REQUEST_CHARSET);
         }

                 // Get limitTransformsParam from init parameter, null is ok
                 this.limitTransformsParam = 
this.getInitParameter(INITPARAM_LIMIT_TRANSFORMS_PARAM);

                 // Get reuseMaverickContext from init parameter, null is ok
                 this.reuseMaverickContext = 
"true".equals(this.getInitParameter(INITPARAM_REUSE_CONTEXT));




At 09:05 AM 1/5/2006, Peter Chase wrote:
>Is anything wrong with the following patch, to make Maverick transforms
>automatically pick up the character encoding?
>
>         public FakeHttpServletResponse(HttpServletResponse wrapMe)
>         {
>                 super(wrapMe);
>
>                 if (log.isDebugEnabled())
>                         log.debug("Creating fake response, original buffer
>size is "
>                                                 + wrapMe.getBufferSize());
>
>                 this.charset = wrapMe.getCharacterEncoding();  // THIS IS
>THE NEW LINE
>         }
>
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
>for problems?  Stop!  Download the new AJAX search engine that makes
>searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
>http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
>[INVALID FOOTER]




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
[INVALID FOOTER]