Re: Getting UTF-16 encoding on dynamic content regardless of output content type

gelo1234 <[email protected]> Tue, 29 Mar 2022 19:41:11 +0200
Newsgroups gmane.text.xml.cocoon.user
Message-ID <CAPJaKUrT7rCikw+5NVF0DztKFOLLAeFXS=6Txoapq2s=WZ-9sA@mail.gmail.com>
--000000000000ee7e0005db5eef46
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Chris,

Have you also tried HTMLT or XHTMLT Serializers?
Default HTMLSerializer cannot handle some unicode characters:
https://issues.apache.org/jira/browse/SLING-5973?attachmentOrder=3Dasc

Greetings,
Greg


wt., 29 mar 2022 o 19:37 gelo1234 <[email protected]> napisa=C5=82(a):

> Hello Chris,
>
> I think you will not get any icon-type character on output without using
> proper font rendering - like Emoji support? Emoji might not be supported =
by
> default in Cocoon.
> So this might be the reason why you get HTML entities instead of
> Emoji-icons.
> Also notice:
> https://www.mail-archive.com/[email protected]/msg61629.html
>
> Greetings,
> Greg
>
>
>
> wt., 29 mar 2022 o 18:36 Christopher Schultz <[email protected]=
t>
> napisa=C5=82(a):
>
>> C=C3=A9dric,
>>
>> On 3/29/22 12:06, C=C3=A9dric Damioli wrote:
>> > Could you provide more details ?
>> > How is your XML processed before outputting the wrong UTF-8 sequence ?
>>
>> It's somewhat straightforward:
>>
>> <map:match pattern=3D"/foo">
>>    <map:generate src=3D"https://source/" />
>>
>>    <map:transform src=3D"stuff-to-cincludes.xsl" />
>>
>>    <map:transform src=3D"other-stuff-to-cincludes.xsl" />
>>
>>    <map:transform type=3D"cinclude" />
>>
>>    <map:transform src=3D"my-big-transformer-to-xhtml.xsl" />
>>
>>    <map:transform type=3D"cinclude" /><!-- Yes, another one -->
>>
>>    <map:transform type=3D"i18n" />
>>
>>    <map:transform src=3D"strip-namespaces.xsl" /><!-- This is mine, not
>> Cocoons ->
>>
>>    <map:serialize type=3D"xhtml" />
>> </map:match>
>>
>> The xhtml serializer is the default, with encoding set to UTF-8. The
>> HTTP response has "Content-Type: text/html" and the document itself
>> contains:
>>
>> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
>>
>> and
>>
>> <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"content-type"=
 />
>>
>> So I think everything is configured correctly; it's just that those
>> characters are getting mangled by something. I can try to cut-out some
>> of those steps and see where it's happening.
>>
>> I seem to remember being able to give each pipeline step a "marker" or
>> something where you can say "stop after step 3" or whatever instead of
>> having to chop-out configuration. Can you remind me or what that is agai=
n?
>>
>> Thanks,
>> -chris
>>
>> > Le 29/03/2022 =C3=A0 17:48, Christopher Schultz a =C3=A9crit :
>> >> All,
>> >>
>> >> I'm still struggling with this. I have upgraded to 2.1.13 which
>> >> includes the fix for https://issues.apache.org/jira/browse/COCOON-235=
2
>> >> but I'm still getting that American flag converted into those 4 HTML
>> >> entities:
>> >>
>> >> &#55356;&#56826;&#55356;&#56824;
>> >>
>> >> I would expect there to be a single (multibyte) character in the
>> >> output with no HTML entities.
>> >>
>> >> I've double-checked, and the source XML contains the flag as a single
>> >> multi-byte character, served as UTF-8.
>> >>
>> >> Any ideas for how to get this working? I'm sure I could put together =
a
>> >> trivial test-case.
>> >>
>> >> Thanks,
>> >> -chris
>> >>
>> >> On 10/30/18 12:18, Christopher Schultz wrote:
>> >>> All,
>> >>>
>> >>> Some additional information at the end.
>> >>>
>> >>> On 10/30/18 11:58, Christopher Schultz wrote:
>> >>>> All,
>> >>>
>> >>>> I'm attempting to do everything with UTF-8 in Cocoon 2.1.11. I have
>> >>>> a servlet generating XML in UTF-8 encoding and I have a pipeline
>> >>>> with a few transforms in it, ultimately serializing to XHTML.
>> >>>
>> >>>> If I have a Unicode character in the XML which is outside of the
>> >>>> BMP, such as this one: =F0=9F=87=BA=F0=9F=87=B8  (that's an America=
n flag, in case your
>> >>>> mail reader doesn't render it correctly), then I end up getting a
>> >>>> series of bytes coming from Cocoon after the transform that look
>> >>>> like UTF-16.
>> >>>
>> >>>> Here's what's in the XML:
>> >>>
>> >>>> <first-name>Test=F0=9F=87=BA=F0=9F=87=B8</first-name>
>> >>>
>> >>>> Just like that. The bytes in the message for the flag character
>> >>>> are:
>> >>>
>> >>>> f0  9f  87  ba  f0  9f  87  b8
>> >>>
>> >>>> When rendering that into XHTML, I'm getting this in the output:
>> >>>
>> >>>> Test&#55356;&#56826;&#55356;&#56824;
>> >>>
>> >>>> The American flag in Unicode reference can be found here:
>> >>>>
>> https://apps.timwhitlock.info/unicode/inspect?s=3D%F0%9F%87%BA%F0%9F%87%
>> >>> B8
>> >>>
>> >>>>   You can see it broken down a bit better here for "Regional U":
>> >>>> http://www.fileformat.info/info/unicode/char/1f1fa/index.htm
>> >>>
>> >>>> and "Regional S":
>> >>>> http://www.fileformat.info/info/unicode/char/1f1f8/index.htm
>> >>>
>> >>>> What's happening is that some component in Cocoon has decided to
>> >>>> generate HTML entities instead of just emitting the character.
>> >>>> That's okay IMO. But what it does doesn't make sense for a UTF-8
>> >>>> output encodin g.
>> >>>
>> >>>> The first two entities "&#55356;&#56826;" are the decimal numbers
>> >>>> that represent the UTF-16 character for that "Regional Indicator
>> >>>> Symbol Letter U" and they are correct... for UTF-16. If I change
>> >>>> the output encoding from UTF-8 to UTF0-16, then the browser will
>> >>>> render these correctly. Using UTF-8, they show as four of those
>> >>>> ugly [?] characters on the screen.
>> >>>
>> >>>> I had originally just decided to throw up my hands and use UTF-16
>> >>>> encoding even though it's dumb. But it seems that MSIE cannot be
>> >>>> convinced to use UTF-16 no matter what, and I must continue to
>> >>>> support MSIE. :(
>> >>>
>> >>>> So it's back to UTF-8 for me.
>> >>>
>> >>>> How can I get Cocoon to output that character (or "those
>> >>>> characters") correctly?
>> >>>
>> >>>> It needs to be one of the following:
>> >>>
>> >>>> &#127482;&#127480; (HTML decimal entities)
>> >>>> &#x1f1fa;&#x1f1f8;             (HTML hex entities) f0 9f  87  ba
>> >>>> f0  9f  87  b8 (raw UTF-8 bytes)
>> >>>
>> >>>> Does anyone know how/where this conversion is being performed ion
>> >>>> Cocoon? Probably in a XHTML serializer (I'm using
>> >>>> org.apache.cocoon.serialization.XMLSerializer). I'm using
>> >>>> mime-type "text/html" and <encoding>UTF-8</encoding> in my sitemap
>> >>>> for that serializer (the one named "xhtml"). I believe I've mads
>> >>>> very few changes from the default, if any.
>> >>>
>> >>>> I haven't yet figured out how to get from what Java sees (\uE50C
>> >>>> for the "S" for example) to &#x1f1f8;, but knowing where the code
>> >>>> is that is making that decision would be very helpful.
>> >>>
>> >>>> Any ideas?
>> >>>
>> >>>> -chris
>> >>>
>> >>> I created a text file (UTF-8) containing only the flag and read it i=
n
>> >>> using Java and printed all of the code points. There should be 2
>> >>> "characters" in the file. It's 4 bytes per UTF-8 character so I
>> >>> assumed I'd end up with 2 'char' primitives in the file, but I ended
>> >>> up with more.
>> >>>
>> >>> Here's the loop and the output:
>> >>>
>> >>>          try(java.io.FileReader in =3D new
>> java.io.FileReader("file.txt"))
>> >>> {
>> >>>              char[] chars =3D new char[10];
>> >>>
>> >>>              int count =3D in.read(chars);
>> >>>
>> >>>              for(int i=3D0; i<count; ++i)
>> >>>                  System.out.println("Code point at " + i + " is " +
>> >>> Integer.toHexString(Character.codePointAt(chars, i)));
>> >>>
>> >>>          } catch (Exception e) {
>> >>>              e.printStackTrace();
>> >>>          }
>> >>>
>> >>> =3D=3D output =3D=3D
>> >>>
>> >>> Code point at 0 is 1f1fa
>> >>> Code point at 1 is ddfa
>> >>> Code point at 2 is 1f1f8
>> >>> Code point at 3 is ddf8
>> >>> Code point at 4 is a
>> >>>
>> >>> So Java thinks there are 4 things there, not 2. That could be a part
>> >>> of the confusion. The code points shown for indexes 0 and 2 are the
>> >>> "correct" ones. Those at indexes 1 and 3 should actually be *skipped=
*.
>> >>>
>> >>> So, to render this string as an HTML numeric entity, we'd do somethi=
ng
>> >>> like this:
>> >>>
>> >>> String str =3D // this is the input
>> >>>
>> >>> for(int i=3D0; i<str.length(); ++i) {
>> >>>    int cp =3D Character.codePointAt(chars, i);
>> >>>
>> >>>    out.print("&#x");
>> >>>    out.print(Integer.toHexString(cp));
>> >>>    out.println(';');
>> >>>
>> >>>    // Skip any trailing "characters" that are actually a part of thi=
s
>> >>> one
>> >>>    if(1 < Character.charCount(cp))
>> >>>      i +=3D Character.charCount(cp) - 1;
>> >>> }
>> >>>
>> >>> Using the above code is completely encoding-agnostic, because it's
>> >>> describing the Unicode code point and not some set of bytes in a
>> >>> particular flavor of UTF-x.
>> >>>
>> >>> -chris
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: [email protected]
>> >> For additional commands, e-mail: [email protected]
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>

--000000000000ee7e0005db5eef46
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-size:small"><br=
></div><div class=3D"gmail_default" style=3D"font-size:small">Chris, <br></=
div><div class=3D"gmail_default" style=3D"font-size:small"><br></div><div c=
lass=3D"gmail_default" style=3D"font-size:small">Have you also tried HTMLT =
or XHTMLT Serializers? <br></div><div class=3D"gmail_default" style=3D"font=
-size:small">Default HTMLSerializer cannot handle some unicode characters: =
<a href=3D"https://issues.apache.org/jira/browse/SLING-5973?attachmentOrder=
=3Dasc">https://issues.apache.org/jira/browse/SLING-5973?attachmentOrder=3D=
asc</a></div><div class=3D"gmail_default" style=3D"font-size:small"><br></d=
iv><div class=3D"gmail_default" style=3D"font-size:small">Greetings,</div><=
div class=3D"gmail_default" style=3D"font-size:small">Greg<br></div><div cl=
ass=3D"gmail_default" style=3D"font-size:small"><br></div></div><br><div cl=
ass=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">wt., 29 mar 2022 =
o 19:37=C2=A0gelo1234 &lt;<a href=3D"mailto:[email protected]">gelo1234@gm=
ail.com</a>&gt; napisa=C5=82(a):<br></div><blockquote class=3D"gmail_quote"=
 style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);p=
adding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_default" style=3D"fon=
t-size:small">Hello Chris,<br></div><div class=3D"gmail_default" style=3D"f=
ont-size:small"><br></div><div class=3D"gmail_default" style=3D"font-size:s=
mall">I think you will not get any icon-type character on output without us=
ing proper font rendering - like Emoji support? Emoji might not be supporte=
d by default in Cocoon.</div><div class=3D"gmail_default" style=3D"font-siz=
e:small">So this might be the reason why you get HTML entities instead of E=
moji-icons. <br></div><div class=3D"gmail_default" style=3D"font-size:small=
">Also notice: <a href=3D"https://www.mail-archive.com/[email protected]=
g/msg61629.html" target=3D"_blank">https://www.mail-archive.com/dev@cocoon.=
apache.org/msg61629.html</a></div><div class=3D"gmail_default" style=3D"fon=
t-size:small"><br></div><div class=3D"gmail_default" style=3D"font-size:sma=
ll">Greetings,</div><div class=3D"gmail_default" style=3D"font-size:small">=
Greg<br></div><div class=3D"gmail_default" style=3D"font-size:small"><br></=
div><div class=3D"gmail_default" style=3D"font-size:small"><br></div></div>=
<br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">wt., 2=
9 mar 2022 o 18:36=C2=A0Christopher Schultz &lt;<a href=3D"mailto:chris@chr=
istopherschultz.net" target=3D"_blank">[email protected]</a>&gt;=
 napisa=C5=82(a):<br></div><blockquote class=3D"gmail_quote" style=3D"margi=
n:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex=
">C=C3=A9dric,<br>
<br>
On 3/29/22 12:06, C=C3=A9dric Damioli wrote:<br>
&gt; Could you provide more details ?<br>
&gt; How is your XML processed before outputting the wrong UTF-8 sequence ?=
<br>
<br>
It&#39;s somewhat straightforward:<br>
<br>
&lt;map:match pattern=3D&quot;/foo&quot;&gt;<br>
=C2=A0 =C2=A0&lt;map:generate src=3D&quot;<a href=3D"https://source/" rel=
=3D"noreferrer" target=3D"_blank">https://source/</a>&quot; /&gt;<br>
<br>
=C2=A0 =C2=A0&lt;map:transform src=3D&quot;stuff-to-cincludes.xsl&quot; /&g=
t;<br>
<br>
=C2=A0 =C2=A0&lt;map:transform src=3D&quot;other-stuff-to-cincludes.xsl&quo=
t; /&gt;<br>
<br>
=C2=A0 =C2=A0&lt;map:transform type=3D&quot;cinclude&quot; /&gt;<br>
<br>
=C2=A0 =C2=A0&lt;map:transform src=3D&quot;my-big-transformer-to-xhtml.xsl&=
quot; /&gt;<br>
<br>
=C2=A0 =C2=A0&lt;map:transform type=3D&quot;cinclude&quot; /&gt;&lt;!-- Yes=
, another one --&gt;<br>
<br>
=C2=A0 =C2=A0&lt;map:transform type=3D&quot;i18n&quot; /&gt;<br>
<br>
=C2=A0 =C2=A0&lt;map:transform src=3D&quot;strip-namespaces.xsl&quot; /&gt;=
&lt;!-- This is mine, not <br>
Cocoons -&gt;<br>
<br>
=C2=A0 =C2=A0&lt;map:serialize type=3D&quot;xhtml&quot; /&gt;<br>
&lt;/map:match&gt;<br>
<br>
The xhtml serializer is the default, with encoding set to UTF-8. The <br>
HTTP response has &quot;Content-Type: text/html&quot; and the document itse=
lf <br>
contains:<br>
<br>
&lt;?xml version=3D&quot;1.0&quot; encoding=3D&quot;UTF-8&quot;?&gt;<br>
<br>
and<br>
<br>
&lt;meta content=3D&quot;text/html; charset=3Dutf-8&quot; http-equiv=3D&quo=
t;content-type&quot; /&gt;<br>
<br>
So I think everything is configured correctly; it&#39;s just that those <br=
>
characters are getting mangled by something. I can try to cut-out some <br>
of those steps and see where it&#39;s happening.<br>
<br>
I seem to remember being able to give each pipeline step a &quot;marker&quo=
t; or <br>
something where you can say &quot;stop after step 3&quot; or whatever inste=
ad of <br>
having to chop-out configuration. Can you remind me or what that is again?<=
br>
<br>
Thanks,<br>
-chris<br>
<br>
&gt; Le 29/03/2022 =C3=A0 17:48, Christopher Schultz a =C3=A9crit=C2=A0:<br=
>
&gt;&gt; All,<br>
&gt;&gt;<br>
&gt;&gt; I&#39;m still struggling with this. I have upgraded to 2.1.13 whic=
h <br>
&gt;&gt; includes the fix for <a href=3D"https://issues.apache.org/jira/bro=
wse/COCOON-2352" rel=3D"noreferrer" target=3D"_blank">https://issues.apache=
.org/jira/browse/COCOON-2352</a> <br>
&gt;&gt; but I&#39;m still getting that American flag converted into those =
4 HTML <br>
&gt;&gt; entities:<br>
&gt;&gt;<br>
&gt;&gt; &amp;#55356;&amp;#56826;&amp;#55356;&amp;#56824;<br>
&gt;&gt;<br>
&gt;&gt; I would expect there to be a single (multibyte) character in the <=
br>
&gt;&gt; output with no HTML entities.<br>
&gt;&gt;<br>
&gt;&gt; I&#39;ve double-checked, and the source XML contains the flag as a=
 single <br>
&gt;&gt; multi-byte character, served as UTF-8.<br>
&gt;&gt;<br>
&gt;&gt; Any ideas for how to get this working? I&#39;m sure I could put to=
gether a <br>
&gt;&gt; trivial test-case.<br>
&gt;&gt;<br>
&gt;&gt; Thanks,<br>
&gt;&gt; -chris<br>
&gt;&gt;<br>
&gt;&gt; On 10/30/18 12:18, Christopher Schultz wrote:<br>
&gt;&gt;&gt; All,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Some additional information at the end.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On 10/30/18 11:58, Christopher Schultz wrote:<br>
&gt;&gt;&gt;&gt; All,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I&#39;m attempting to do everything with UTF-8 in Cocoon 2=
.1.11. I have<br>
&gt;&gt;&gt;&gt; a servlet generating XML in UTF-8 encoding and I have a pi=
peline<br>
&gt;&gt;&gt;&gt; with a few transforms in it, ultimately serializing to XHT=
ML.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; If I have a Unicode character in the XML which is outside =
of the<br>
&gt;&gt;&gt;&gt; BMP, such as this one: =F0=9F=87=BA=F0=9F=87=B8=C2=A0 (tha=
t&#39;s an American flag, in case your<br>
&gt;&gt;&gt;&gt; mail reader doesn&#39;t render it correctly), then I end u=
p getting a<br>
&gt;&gt;&gt;&gt; series of bytes coming from Cocoon after the transform tha=
t look<br>
&gt;&gt;&gt;&gt; like UTF-16.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Here&#39;s what&#39;s in the XML:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &lt;first-name&gt;Test=F0=9F=87=BA=F0=9F=87=B8&lt;/first-n=
ame&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Just like that. The bytes in the message for the flag char=
acter<br>
&gt;&gt;&gt;&gt; are:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; f0=C2=A0 9f=C2=A0 87=C2=A0 ba=C2=A0 f0=C2=A0 9f=C2=A0 87=
=C2=A0 b8<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; When rendering that into XHTML, I&#39;m getting this in th=
e output:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Test&amp;#55356;&amp;#56826;&amp;#55356;&amp;#56824;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; The American flag in Unicode reference can be found here:<=
br>
&gt;&gt;&gt;&gt; <a href=3D"https://apps.timwhitlock.info/unicode/inspect?s=
=3D%F0%9F%87%BA%F0%9F%87%" rel=3D"noreferrer" target=3D"_blank">https://app=
s.timwhitlock.info/unicode/inspect?s=3D%F0%9F%87%BA%F0%9F%87%</a><br>
&gt;&gt;&gt; B8<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; =C2=A0 You can see it broken down a bit better here for &q=
uot;Regional U&quot;:<br>
&gt;&gt;&gt;&gt; <a href=3D"http://www.fileformat.info/info/unicode/char/1f=
1fa/index.htm" rel=3D"noreferrer" target=3D"_blank">http://www.fileformat.i=
nfo/info/unicode/char/1f1fa/index.htm</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; and &quot;Regional S&quot;:<br>
&gt;&gt;&gt;&gt; <a href=3D"http://www.fileformat.info/info/unicode/char/1f=
1f8/index.htm" rel=3D"noreferrer" target=3D"_blank">http://www.fileformat.i=
nfo/info/unicode/char/1f1f8/index.htm</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; What&#39;s happening is that some component in Cocoon has =
decided to<br>
&gt;&gt;&gt;&gt; generate HTML entities instead of just emitting the charac=
ter.<br>
&gt;&gt;&gt;&gt; That&#39;s okay IMO. But what it does doesn&#39;t make sen=
se for a UTF-8<br>
&gt;&gt;&gt;&gt; output encodin g.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; The first two entities &quot;&amp;#55356;&amp;#56826;&quot=
; are the decimal numbers<br>
&gt;&gt;&gt;&gt; that represent the UTF-16 character for that &quot;Regiona=
l Indicator<br>
&gt;&gt;&gt;&gt; Symbol Letter U&quot; and they are correct... for UTF-16. =
If I change<br>
&gt;&gt;&gt;&gt; the output encoding from UTF-8 to UTF0-16, then the browse=
r will<br>
&gt;&gt;&gt;&gt; render these correctly. Using UTF-8, they show as four of =
those<br>
&gt;&gt;&gt;&gt; ugly [?] characters on the screen.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I had originally just decided to throw up my hands and use=
 UTF-16<br>
&gt;&gt;&gt;&gt; encoding even though it&#39;s dumb. But it seems that MSIE=
 cannot be<br>
&gt;&gt;&gt;&gt; convinced to use UTF-16 no matter what, and I must continu=
e to<br>
&gt;&gt;&gt;&gt; support MSIE. :(<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; So it&#39;s back to UTF-8 for me.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; How can I get Cocoon to output that character (or &quot;th=
ose<br>
&gt;&gt;&gt;&gt; characters&quot;) correctly?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; It needs to be one of the following:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; &amp;#127482;&amp;#127480; (HTML decimal entities)<br>
&gt;&gt;&gt;&gt; &amp;#x1f1fa;&amp;#x1f1f8;=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (HTML hex entities) f0 9f=C2=A0 =
87=C2=A0 ba<br>
&gt;&gt;&gt;&gt; f0=C2=A0 9f=C2=A0 87=C2=A0 b8 (raw UTF-8 bytes)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Does anyone know how/where this conversion is being perfor=
med ion<br>
&gt;&gt;&gt;&gt; Cocoon? Probably in a XHTML serializer (I&#39;m using<br>
&gt;&gt;&gt;&gt; org.apache.cocoon.serialization.XMLSerializer). I&#39;m us=
ing<br>
&gt;&gt;&gt;&gt; mime-type &quot;text/html&quot; and &lt;encoding&gt;UTF-8&=
lt;/encoding&gt; in my sitemap<br>
&gt;&gt;&gt;&gt; for that serializer (the one named &quot;xhtml&quot;). I b=
elieve I&#39;ve mads<br>
&gt;&gt;&gt;&gt; very few changes from the default, if any.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I haven&#39;t yet figured out how to get from what Java se=
es (\uE50C<br>
&gt;&gt;&gt;&gt; for the &quot;S&quot; for example) to &amp;#x1f1f8;, but k=
nowing where the code<br>
&gt;&gt;&gt;&gt; is that is making that decision would be very helpful.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Any ideas?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; -chris<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I created a text file (UTF-8) containing only the flag and rea=
d it in<br>
&gt;&gt;&gt; using Java and printed all of the code points. There should be=
 2<br>
&gt;&gt;&gt; &quot;characters&quot; in the file. It&#39;s 4 bytes per UTF-8=
 character so I<br>
&gt;&gt;&gt; assumed I&#39;d end up with 2 &#39;char&#39; primitives in the=
 file, but I ended<br>
&gt;&gt;&gt; up with more.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Here&#39;s the loop and the output:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 try(java.io.F=
ileReader in =3D new java.io.FileReader(&quot;file.txt&quot;))<br>
&gt;&gt;&gt; {<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 char[] chars =3D new char[10];<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 int count =3D in.read(chars);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 for(int i=3D0; i&lt;count; ++i)<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 System.out.println(&quot;Code point at=
 &quot; + i + &quot; is &quot; +<br>
&gt;&gt;&gt; Integer.toHexString(Character.codePointAt(chars, i)));<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } catch (Exce=
ption e) {<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0 e.printStackTrace();<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =3D=3D output =3D=3D<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Code point at 0 is 1f1fa<br>
&gt;&gt;&gt; Code point at 1 is ddfa<br>
&gt;&gt;&gt; Code point at 2 is 1f1f8<br>
&gt;&gt;&gt; Code point at 3 is ddf8<br>
&gt;&gt;&gt; Code point at 4 is a<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; So Java thinks there are 4 things there, not 2. That could be =
a part<br>
&gt;&gt;&gt; of the confusion. The code points shown for indexes 0 and 2 ar=
e the<br>
&gt;&gt;&gt; &quot;correct&quot; ones. Those at indexes 1 and 3 should actu=
ally be *skipped*.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; So, to render this string as an HTML numeric entity, we&#39;d =
do something<br>
&gt;&gt;&gt; like this:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; String str =3D // this is the input<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; for(int i=3D0; i&lt;str.length(); ++i) {<br>
&gt;&gt;&gt; =C2=A0=C2=A0 int cp =3D Character.codePointAt(chars, i);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =C2=A0=C2=A0 out.print(&quot;&amp;#x&quot;);<br>
&gt;&gt;&gt; =C2=A0=C2=A0 out.print(Integer.toHexString(cp));<br>
&gt;&gt;&gt; =C2=A0=C2=A0 out.println(&#39;;&#39;);<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; =C2=A0=C2=A0 // Skip any trailing &quot;characters&quot; that =
are actually a part of this <br>
&gt;&gt;&gt; one<br>
&gt;&gt;&gt; =C2=A0=C2=A0 if(1 &lt; Character.charCount(cp))<br>
&gt;&gt;&gt; =C2=A0=C2=A0=C2=A0=C2=A0 i +=3D Character.charCount(cp) - 1;<b=
r>
&gt;&gt;&gt; }<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Using the above code is completely encoding-agnostic, because =
it&#39;s<br>
&gt;&gt;&gt; describing the Unicode code point and not some set of bytes in=
 a<br>
&gt;&gt;&gt; particular flavor of UTF-x.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; -chris<br>
&gt;&gt;<br>
&gt;&gt; ------------------------------------------------------------------=
---<br>
&gt;&gt; To unsubscribe, e-mail: <a href=3D"mailto:users-unsubscribe@cocoon=
.apache.org" target=3D"_blank">[email protected]</a><br>
&gt;&gt; For additional commands, e-mail: <a href=3D"mailto:users-help@coco=
on.apache.org" target=3D"_blank">[email protected]</a><br>
&gt;&gt;<br>
&gt; <br>
<br>
---------------------------------------------------------------------<br>
To unsubscribe, e-mail: <a href=3D"mailto:[email protected]=
rg" target=3D"_blank">[email protected]</a><br>
For additional commands, e-mail: <a href=3D"mailto:[email protected]=
.org" target=3D"_blank">[email protected]</a><br>
<br>
</blockquote></div>
</blockquote></div>

--000000000000ee7e0005db5eef46--