Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Localized content in Browser widget
Localized content in Browser widget [message #20290] Thu, 26 April 2007 06:25 Go to next message
Eclipse UserFriend
Originally posted by: roberto.sanchez.autonomind.com

This is a multi-part message in MIME format.
--------------060805050406010104090504
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi all, I'm having problems with "Spanish characters" when I try to
display them in Browser control.

I attach a html example file (test-locale.html) with these characters,
and a screenshot of my app with the result in a Browser control.

I'm using Windows XP (in Spanish language) and in Both tipical browsers,
Firefox and IExplorer, I can see this file without problems.

I set "charset" in file and in code when I read this file to convert to
String.
My code to pass it to Browser content is:

public static String resource2text(String resource) {
// I've used StringBuffer too, to store the file, with the same result
StringWriter sw = new StringWriter();

if (Util.class.getResource(resource) != null) {
BufferedInputStream reader = null;
try {
reader = new
BufferedInputStream(Util.class.getResourceAsStream(resource) );
byte[] buf = new byte[1024];
int bytes = 0;
do {
bytes = reader.read(buf);
// I've used to ways to instantiate String object, setting charset and
without set charset. My default charset in JVM is correctly setted.
sw.write(new String(buf, 0, bytes));
// sw.write(new String(buf, 0, bytes, "iso-8859-1"));
} while(bytes == buf.length);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null)
try {reader.close(); } catch (IOException e) { e.printStackTrace(); }
}
}

return sw.toString();
}


--------------060805050406010104090504
Content-Type: text/html; charset=ISO-8859-1;
name="test-locale.html"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="test-locale.html"

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>TEST</title>
</head>
<body>
<H2>Spanish characters:</h2>
<H3>&aacute; ==
Re: Localized content in Browser widget [message #20315 is a reply to message #20290] Thu, 26 April 2007 09:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: roberto.sanchez.autonomind.com

Hello again, I think that my problem is in BrowserLCA.registerHtml in
this method It is hardcoded "UTF-8" as charset for html content, I
wonder If could be possible customize content charset from Browser widget.

I don't know if this is planned or not, In any case I could create an
Enhancenment/Bug entry in Eclipse-Bugzilla for Browser widget.

Let me know what do you think about.

Regards.
Roberto.

//PD: The method where I think my problem is located (BrowserLCA):

private static String registerHtml( final String html ) throws
IOException {
String name = createUrlFromHtml( html );
byte[] bytes = html.getBytes( "UTF-8" );
InputStream inputStream = new ByteArrayInputStream( bytes );
try {
// TODO [rh] ResourceManager should be alble to deregister a
resource,
// thus we could cleanup the here registered resource when text
// is changed and in renderDispose
ResourceManager.getInstance().register( name, inputStream );
} finally {
inputStream.close();
}
return ResourceManager.getInstance().getLocation( name );
}


Roberto Sánchez wrote:
> Hi all, I'm having problems with "Spanish characters" when I try to
> display them in Browser control.
>
> I attach a html example file (test-locale.html) with these characters,
> and a screenshot of my app with the result in a Browser control.
>
> I'm using Windows XP (in Spanish language) and in Both tipical browsers,
> Firefox and IExplorer, I can see this file without problems.
>
> I set "charset" in file and in code when I read this file to convert to
> String.
> My code to pass it to Browser content is:
>
> public static String resource2text(String resource) {
> // I've used StringBuffer too, to store the file, with the same result
> StringWriter sw = new StringWriter();
>
> if (Util.class.getResource(resource) != null) {
> BufferedInputStream reader = null;
> try {
> reader = new
> BufferedInputStream(Util.class.getResourceAsStream(resource) );
> byte[] buf = new byte[1024];
> int bytes = 0;
> do {
> bytes = reader.read(buf);
> // I've used to ways to instantiate String object, setting charset and
> without set charset. My default charset in JVM is correctly setted.
> sw.write(new String(buf, 0, bytes));
> // sw.write(new String(buf, 0, bytes, "iso-8859-1"));
> } while(bytes == buf.length);
> } catch (IOException e) {
> e.printStackTrace();
> } finally {
> if (reader != null)
> try {reader.close(); } catch (IOException e) {
> e.printStackTrace(); }
> }
> }
>
> return sw.toString();
> }
>
>
> ------------------------------------------------------------ ------------
>
>
> Spanish characters:
>
>
> á == á
>
>
> é == é
>
>
> í == í
>
>
> ó == ó
>
>
> ú == ú
>
>
> ñ == ñ
>
>
> ------------------------------------------------------------ ------------
>
Re: Localized content in Browser widget [message #20405 is a reply to message #20290] Fri, 27 April 2007 13:35 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rherrmann.innoopract.com

Hi Roberto,

from what I understand You need to specify the charset when You read the
resource. You may use an InputStreamReader( stream, "iso-8859-1" ) to
read the content and then use Browser.setText.

If that doesn't do the trick, feel free to open a bug report with a
test-case or code snippet attached.

Cheers,
Rüdiger

Roberto Sánchez wrote:
> Hi all, I'm having problems with "Spanish characters" when I try to
> display them in Browser control.
>
> I attach a html example file (test-locale.html) with these characters,
> and a screenshot of my app with the result in a Browser control.
>
> I'm using Windows XP (in Spanish language) and in Both tipical browsers,
> Firefox and IExplorer, I can see this file without problems.
>
> I set "charset" in file and in code when I read this file to convert to
> String.
> My code to pass it to Browser content is:
>
> public static String resource2text(String resource) {
> // I've used StringBuffer too, to store the file, with the same result
> StringWriter sw = new StringWriter();
>
> if (Util.class.getResource(resource) != null) {
> BufferedInputStream reader = null;
> try {
> reader = new
> BufferedInputStream(Util.class.getResourceAsStream(resource) );
> byte[] buf = new byte[1024];
> int bytes = 0;
> do {
> bytes = reader.read(buf);
> // I've used to ways to instantiate String object, setting charset and
> without set charset. My default charset in JVM is correctly setted.
> sw.write(new String(buf, 0, bytes));
> // sw.write(new String(buf, 0, bytes, "iso-8859-1"));
> } while(bytes == buf.length);
> } catch (IOException e) {
> e.printStackTrace();
> } finally {
> if (reader != null)
> try {reader.close(); } catch (IOException e) {
> e.printStackTrace(); }
> }
> }
>
> return sw.toString();
> }
>
>
> ------------------------------------------------------------ ------------
>
>
> Spanish characters:
>
>
> á == á
>
>
> é == é
>
>
> í == í
>
>
> ó == ó
>
>
> ú == ú
>
>
> ñ == ñ
>
>
> ------------------------------------------------------------ ------------
>
Re: Localized content in Browser widget [message #20414 is a reply to message #20405] Fri, 27 April 2007 14:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: roberto.sanchez.autonomind.com

Hi Rüdiger, I've tested it but It doesn't work, my code (with your
recomendations):

StringWriter sw = new StringWriter();

if (Util.class.getResource(resource) != null) {
InputStreamReader reader = null;
try {
reader = new
InputStreamReader(Util.class.getResourceAsStream(resource), "iso-8859-1");
char[] buf = new char[2048];
int chars = 0;
do {
chars = reader.read(buf);
sw.write(new String(buf));
} while(chars == buf.length);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null)
try {reader.close(); } catch (IOException e) { e.printStackTrace(); }
}
}

mybrowser.setText(sw.toString());


Besides, in debug mode, In Watch View the expression "sw.toString()"
shows the correct characters now and before, so I think that It's a
Browser charset problem

I'm going to create a new Entry in bugzilla. Thanks for your help.

Regards.


Rüdiger Herrmann wrote:
> Hi Roberto,
>
> from what I understand You need to specify the charset when You read the
> resource. You may use an InputStreamReader( stream, "iso-8859-1" ) to
> read the content and then use Browser.setText.
>
> If that doesn't do the trick, feel free to open a bug report with a
> test-case or code snippet attached.
>
> Cheers,
> Rüdiger
>
> Roberto Sánchez wrote:
>> Hi all, I'm having problems with "Spanish characters" when I try to
>> display them in Browser control.
>>
>> I attach a html example file (test-locale.html) with these characters,
>> and a screenshot of my app with the result in a Browser control.
>>
>> I'm using Windows XP (in Spanish language) and in Both tipical
>> browsers, Firefox and IExplorer, I can see this file without problems.
>>
>> I set "charset" in file and in code when I read this file to convert
>> to String.
>> My code to pass it to Browser content is:
>>
>> public static String resource2text(String resource) {
>> // I've used StringBuffer too, to store the file, with the same result
>> StringWriter sw = new StringWriter();
>> if (Util.class.getResource(resource) != null) {
>> BufferedInputStream reader = null;
>> try {
>> reader = new
>> BufferedInputStream(Util.class.getResourceAsStream(resource) );
>> byte[] buf = new byte[1024];
>> int bytes = 0;
>> do {
>> bytes = reader.read(buf);
>> // I've used to ways to instantiate String object, setting charset and
>> without set charset. My default charset in JVM is correctly setted.
>> sw.write(new String(buf, 0, bytes));
>> // sw.write(new String(buf, 0, bytes, "iso-8859-1"));
>> } while(bytes == buf.length); }
>> catch (IOException e) {
>> e.printStackTrace();
>> } finally {
>> if (reader != null)
>> try {reader.close(); } catch (IOException e) {
>> e.printStackTrace(); }
>> }
>> } return sw.toString();
>> }
>>
>>
>> ------------------------------------------------------------ ------------
>>
>>
>> Spanish characters:
>>
>>
>> á == á
>>
>>
>> é == é
>>
>>
>> í == í
>>
>>
>> ó == ó
>>
>>
>> ú == ú
>>
>>
>> ñ == ñ
>>
>>
>> ------------------------------------------------------------ ------------
>>
Re: Localized content in Browser widget [message #21029 is a reply to message #20405] Mon, 30 April 2007 09:24 Go to previous message
Eclipse UserFriend
Originally posted by: roberto.sanchez.autonomind.com

I've created a new bug entry:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=184670

Regards.
Roberto.


Rüdiger Herrmann wrote:
> Hi Roberto,
>
> from what I understand You need to specify the charset when You read the
> resource. You may use an InputStreamReader( stream, "iso-8859-1" ) to
> read the content and then use Browser.setText.
>
> If that doesn't do the trick, feel free to open a bug report with a
> test-case or code snippet attached.
>
> Cheers,
> Rüdiger
>
> Roberto Sánchez wrote:
>> Hi all, I'm having problems with "Spanish characters" when I try to
>> display them in Browser control.
>>
>> I attach a html example file (test-locale.html) with these characters,
>> and a screenshot of my app with the result in a Browser control.
>>
>> I'm using Windows XP (in Spanish language) and in Both tipical
>> browsers, Firefox and IExplorer, I can see this file without problems.
>>
>> I set "charset" in file and in code when I read this file to convert
>> to String.
>> My code to pass it to Browser content is:
>>
>> public static String resource2text(String resource) {
>> // I've used StringBuffer too, to store the file, with the same result
>> StringWriter sw = new StringWriter();
>> if (Util.class.getResource(resource) != null) {
>> BufferedInputStream reader = null;
>> try {
>> reader = new
>> BufferedInputStream(Util.class.getResourceAsStream(resource) );
>> byte[] buf = new byte[1024];
>> int bytes = 0;
>> do {
>> bytes = reader.read(buf);
>> // I've used to ways to instantiate String object, setting charset and
>> without set charset. My default charset in JVM is correctly setted.
>> sw.write(new String(buf, 0, bytes));
>> // sw.write(new String(buf, 0, bytes, "iso-8859-1"));
>> } while(bytes == buf.length); }
>> catch (IOException e) {
>> e.printStackTrace();
>> } finally {
>> if (reader != null)
>> try {reader.close(); } catch (IOException e) {
>> e.printStackTrace(); }
>> }
>> } return sw.toString();
>> }
>>
>>
>> ------------------------------------------------------------ ------------
>>
>>
>> Spanish characters:
>>
>>
>> á == á
>>
>>
>> é == é
>>
>>
>> í == í
>>
>>
>> ó == ó
>>
>>
>> ú == ú
>>
>>
>> ñ == ñ
>>
>>
>> ------------------------------------------------------------ ------------
>>
Previous Topic:RAP in WAP
Next Topic:Enhancement for Browser widget
Goto Forum:
  


Current Time: Sat Apr 27 04:04:25 GMT 2024

Powered by FUDForum. Page generated in 0.02786 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top