You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Magnus Haraldsen Amundsen <Ma...@computas.com> on 2008/02/27 17:20:28 UTC

Cocoon, JX Temaplte and UTF-8

Hello,

 

I use Jena to read a RDF Model fra a PostgreSQL database, the Model has
a method write() that writes to an OutputStream. 

 

I want to pass the content of that Model (what comes out of the write())
to the pipeline and display it in a template, jx.xml, using <jx:out
value="#{result-list}" xmlize="true"
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"/>.

 

Now to the problem;

 

How do I keep that UTF-8 encoded output from Model.write() and pass it
on to the pipeline without getting:

 

"org.xml.sax.SAXParseException: Content is not allowed in prolog" when
trying to use a ByteArrayOutPutstream.toByteArray()

 

and 

 

"org.xml.sax.SAXParseException: Invalid byte 2 of 3-byte UTF-8 sequence"
when using ByteArrayOutPutStream.toString()

 

It's vital that the UTF-8 encoding is kept, and Java String doesn't
support that.

 

Any ideas?

 

- Magnus


IMPORTANT NOTICE:
This message may contain confidential information. 
If you have received this e-mail in error, do not use, copy or 
distribute it. Do not open any attachments. Delete it immediately from
your system and notify the sender promptly by e-mail that you 
have done so. Thank you.


Re: Cocoon, JX Temaplte and UTF-8

Posted by Joerg Heinicke <jo...@gmx.de>.
On 27.02.2008 16:06, Magnus Haraldsen Amundsen wrote:
> Yes, I tried the .toString("UTF-8), but that gave the same result. I've also tried to create the String using:
> String myUTF8String = new String(byteArrayOutputStream.toByteArray(), "UTF-8");
> 
> Maybe this could be solved by using some other Output/InputStream or something?

Could it be that the Model.write() already does some conversion? You can 
try to write it directly into an FileOutputStream and try to figure out 
in which encoding it is (put some special characters into the RDF). Can 
you show a few more details like the Javascript code?

Joerg

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


RE: Cocoon, JX Temaplte and UTF-8

Posted by Magnus Haraldsen Amundsen <Ma...@computas.com>.
Yes, I tried the .toString("UTF-8), but that gave the same result. I've also tried to create the String using:
String myUTF8String = new String(byteArrayOutputStream.toByteArray(), "UTF-8");

Maybe this could be solved by using some other Output/InputStream or something?


-----Opprinnelig melding-----
Fra: Kjetil Kjernsmo [mailto:Kjetil.Kjernsmo@computas.com]
Sendt: on 27.02.2008 21:29
Til: users@cocoon.apache.org
Emne: Re: Cocoon, JX Temaplte and UTF-8
 
On Wednesday 27 February 2008 21:21:09 Martin Heiden wrote:
> MHA> It's vital that the UTF-8 encoding is kept, and Java String doesn't
> MHA> support that.
>
> AFAIK Java Strings are UTF-8 too. If you deal with different
> character sets, you've got to convert the data when constructing or
> outputting a string. Java assumes the platform standard encoding, if
> you don't specify another one.
>
> Did you try:
>
> byteArrayOutputStream.toString("UTF-8")?

Magnus is my colleague, sitting just beside me, and I'm not sure, but I think 
he did just that. The funny thing is that it works well on my Linux box, but 
not on his Windows box. I think he did investigate the standard encoding too, 
are there other possible points of failure that might be windows-specific?

Kind regards 

Kjetil Kjernsmo
-- 
Senior Knowledge Engineer
Direct: +47 6783 1136 | Mobile: +47 986 48 234
Email: kjetil.kjernsmo@computas.com   
Web: http://www.computas.com/

|  SHARE YOUR KNOWLEDGE  |

Computas AS  Vollsveien 9, PO Box 482, N-1327 Lysaker | Phone:+47 6783 1000 | 
Fax:+47 6783 1001


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



IMPORTANT NOTICE:
This message may contain confidential information. 
If you have received this e-mail in error, do not use, copy or 
distribute it. Do not open any attachments. Delete it immediately from
your system and notify the sender promptly by e-mail that you 
have done so. Thank you.


Re: Cocoon, JX Temaplte and UTF-8

Posted by Kjetil Kjernsmo <Kj...@computas.com>.
On Wednesday 27 February 2008 21:21:09 Martin Heiden wrote:
> MHA> It's vital that the UTF-8 encoding is kept, and Java String doesn't
> MHA> support that.
>
> AFAIK Java Strings are UTF-8 too. If you deal with different
> character sets, you've got to convert the data when constructing or
> outputting a string. Java assumes the platform standard encoding, if
> you don't specify another one.
>
> Did you try:
>
> byteArrayOutputStream.toString("UTF-8")?

Magnus is my colleague, sitting just beside me, and I'm not sure, but I think 
he did just that. The funny thing is that it works well on my Linux box, but 
not on his Windows box. I think he did investigate the standard encoding too, 
are there other possible points of failure that might be windows-specific?

Kind regards 

Kjetil Kjernsmo
-- 
Senior Knowledge Engineer
Direct: +47 6783 1136 | Mobile: +47 986 48 234
Email: kjetil.kjernsmo@computas.com   
Web: http://www.computas.com/

|  SHARE YOUR KNOWLEDGE  |

Computas AS  Vollsveien 9, PO Box 482, N-1327 Lysaker | Phone:+47 6783 1000 | 
Fax:+47 6783 1001


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


Re: Cocoon, JX Temaplte and UTF-8

Posted by Martin Heiden <ma...@netcologne.de>.
Hi!

Wednesday, February 27, 2008, 5:20:28 PM, you wrote:

MHA> I want to pass the content of that Model (what comes out of the write())
MHA> to the pipeline and display it in a template, jx.xml, using <jx:out
MHA> value="#{result-list}" xmlize="true"
MHA> xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"/>.


MHA> "org.xml.sax.SAXParseException: Invalid byte 2 of 3-byte UTF-8 sequence"
MHA> when using ByteArrayOutPutStream.toString()


MHA> It's vital that the UTF-8 encoding is kept, and Java String doesn't
MHA> support that.

AFAIK Java Strings are UTF-8 too. If you deal with different
character sets, you've got to convert the data when constructing or
outputting a string. Java assumes the platform standard encoding, if
you don't specify another one.

Did you try:

byteArrayOutputStream.toString("UTF-8")?

regards,

  Martin


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