cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kelly Campbell <c...@merlot.channelpoint.com>
Subject Re: 3/1/2001 FOP0.17 Change for OutputStream vs. Writer Fudged Unicode
Date Sun, 25 Mar 2001 01:01:42 GMT
Looks like the encoding for AbstractFormatters comes from a Configurations object's
"encoding" property. I'm not familiar enough with cocoon to tell how to set that
though. Look at the init method on AbstractFormatter.

My patch was a pretty straightforward refactoring. But I now see my mistake.
I wasn't sure how the encoding on the writers got set before. I saw the
getEncoding() method on Formatter, and figured that was what to use.

My mistake was that the original code just used the platform's default encoding:

-                        StringWriter writer = new StringWriter();
-                        formatter.format(document, writer, environment);

Just using 
page.setContent(new String(outputStream.toByteArray()).getBytes())
should be an equivalent operation to what it was doing before any of my changes.

What I still don't understand is once the byte array is converted to a String in the
default encoding, how does that encoding get propagated to the web client? If the
formatter.getEncoding() is null, then it still sets the Content-Type without a charset
around line 405 of Engine.java.

One way that should fix this with the current code would be to figure out if the
mime-type is text or binary, and if it's text, and the encoding property is null, use the
platform's default encoding, except I can't find a way to get the platform default.

Code:

			if (encoding != null) {
                            page.setContentType(formatter.getMIMEType() + "; charset=" +
encoding);
                        } else {
			    // use default character encoding for text mimetypes
			    if (formatter.getMIMEType() != null && 
				formatter.getMIMEType().startsWith("text")) {
				// can't find a way to get the platform default encoding
:-(
				page.setContentType(formatter.getMIMEType() +
"; charset=UTF-8" );
			    }
			    else {
				page.setContentType(formatter.getMIMEType());
			    }
			    
                        }

Let me know if I'm way off here.

-Kelly


On Sat, Mar 24, 2001 at 06:02:01PM -0600, Jay Freeman saurik" wrote:
> Kelly:
> 
> OK, turns out this wouldn't work anyway, as getEncoding() is returning null.
> If you pass a null encoding to String it kind of loses it.  Maybe there were
> further changes from your patch that caused this to be a problem.  This _is_
> what is causing the problem, however... I finally got it to work with the
> following (ugly) patch:
> 
> Index: src/org/apache/cocoon/Engine.java
> ===================================================================
> RCS file: /home/cvspublic/xml-cocoon/src/org/apache/cocoon/Engine.java,v
> retrieving revision 1.54
> diff -u -r1.54 Engine.java
> --- src/org/apache/cocoon/Engine.java   2001/03/01 16:24:20     1.54
> +++ src/org/apache/cocoon/Engine.java   2001/03/24 23:59:45
> @@ -397,7 +397,10 @@
> 
>                          // fill the page bean with content
>                          if (PROFILE) profiler.startEvent (requestMarker,
> OUTPUTTING);
> -                        page.setContent(outputStream.toByteArray());
> +
> +                        encoding = formatter.getEncoding();
> +                        if (encoding == null) encoding = "UTF-8";
> +                        page.setContent(new
> String(outputStream.toByteArray(), encoding).getBytes());
> 
>                          // set content type together with encoding if
> appropriate
>                          encoding = formatter.getEncoding();
> 
> Not sure what I could to do make it more efficient....
> 
> Sincerely,
> Jay Freeman (saurik)
> saurik@saurik.com
> 
> -----Original Message-----
> From: Kelly Campbell [mailto:camk@merlot.channelpoint.com]
> Sent: Saturday, March 24, 2001 2:34 PM
> To: cocoon-dev@xml.apache.org
> Subject: Re: 3/1/2001 FOP0.17 Change for OutputStream vs. Writer Fudged
> Unicode
> 
> ...
> 
> <<<<<<< Engine.java
>                         page.setContent(new String(stream.toByteArray(),
> formatter.getEncoding()));
> =======
>                         page.setContent(outputStream.toByteArray());
> >>>>>>> 1.54
> 
> ...
> 
> -Kelly
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org

-- 
Kelly A. Campbell              Software Engineer
<camk@merlotxml.org>           ChannelPoint, Inc.
<camk@channelpoint.com>        Colorado Springs, Co.

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message