Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > can struts read hebrew from property files?

Reply
Thread Tools

can struts read hebrew from property files?

 
 
Elhanan
Guest
Posts: n/a
 
      12-10-2005
hi..

my jsp and property files are encoded in UTF-8:

if i use this:

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<html>
<head>

</head>

<body>*סיון
<h3><bean:message key="welcome.heading"/></h3>
</body>
</html>

i get my hebrew in gibbirsh, but changing the encoding setting in
explorer corrects this: (using meta didn't help).
however if i add
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
%>

to the jsp , i get gibbrish value from the bean tag, no matter what i
do.

 
Reply With Quote
 
 
 
 
Thomas Fritsch
Guest
Posts: n/a
 
      12-10-2005
"Elhanan" <(E-Mail Removed)> wrote:

> my jsp and property files are encoded in UTF-8:


> if i use this:


> <%@ taglib uri="/tags/struts-bean" prefix="bean" %>
> <html>
> <head>
>
> </head>
>
> <body>?????
> <h3><bean:message key="welcome.heading"/></h3>
> </body>
> </html>


> i get my hebrew in gibbirsh, but changing the encoding setting in
> explorer corrects this: (using meta didn't help).
> however if i add
> <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
> %>


> to the jsp , i get gibbrish value from the bean tag, no matter what i
> do.



I would recommend to avoid the problematic non-ASCII characters altogether
(both in HTML and in properties files) and instead use the HTML or Java
escape syntax to write the hebrew characters as hexadecimal codes.
In HTML files like this:
<body>&#x05df;&#x05d5;&#x05d9;&#x05dd;&#x05e0;
In properties files (and in Java source code) like this:
key=value\u05df\u05d5\u05d9\u05dd\u05e0
This strategy makes your HTML and properties totally independent of
encoding, thus taking you to the safe side.

(You can get the hebrew unicode chart from <http://www.unicode.org/charts/>)
--
"TFritsch$t-online:de".replace(':','.').replace('$','@')


 
Reply With Quote
 
 
 
 
Elhanan
Guest
Posts: n/a
 
      12-11-2005
actually i've just read about a utility in java called native2ascii
which converts files to such charachters, i tried, and did a simple
java application of a property class reading such a file, and altough
the get property returned a readible string, i still got gibbrish in
jsp version.

remember that if i try my page with out the page directive it defaults
to western encoding, but i can still turn it manually, if i add the
page directive, it confuses it.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-11-2005
On 10 Dec 2005 23:02:58 -0800, "Elhanan" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>actually i've just read about a utility in java called native2ascii


Let's look at your *.properties file first.

quoting from http://mindprod.com/jgloss/properties.html

In contrast to the natively generated system properties, ordinary user
Properties are usually loaded into RAM in their entirety and indexed
for rapid Hashtable access and are later saved to flat files on disk
with the *.properties extension. Properties files on disk are similar
to the old Windows 3.1 INI files, except they have no [] sections.
They are text files encoded with ISO 8859-1 keyword=value pairs. You
can get additional characters with \uxxxx escapes or with \t, \r, \n,
or \f. Comments begin with #. Lines may be continued by ending them in
a trailing \.

NOTE: you must use 8859-1 encoding for your *.properties file. I
don't know if you encode your strings left to right or right to left.

Dump your strings out on the console in hex so you can tell precisely
what you have in each slot.

/** convert a String to a hex representation of the String,
* with 4 hex chars per char of the original String.
* e.g. "1abc \uabcd" gives "0031_0061_0062_0063_0020_abcd"
* @param s String to convert to hex equivalent
*/
public static String displayHexString ( String s )
{
StringBuilder sb = new StringBuilder( s.length() * 5 - 1 );
for ( int i=0; i<s.length(); i++ )
{
char c = s.charAt(i);
if ( i != 0 )
{
sb.append( '_' );
}
// encode 16 bits as four nibbles

sb.append( hexChar [ c >>> 12 & 0xf ] );
sb.append( hexChar [ c >>> 8 & 0xf ] );
sb.append( hexChar [ c >>> 4 & 0xf ] );
sb.append( hexChar [ c & 0xf ] );
}
return sb.toString();
}

// table to convert a nibble to a hex char.
static final char[] hexChar = {
'0' , '1' , '2' , '3' ,
'4' , '5' , '6' , '7' ,
'8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f'};

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Elhanan
Guest
Posts: n/a
 
      12-11-2005
i think this program does what native2ascii program does, would like me
to send you the result from native2ascii?

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-11-2005
On 11 Dec 2005 06:22:21 -0800, "Elhanan" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>i think this program does what native2ascii program does, would like me
>to send you the result from native2ascii?


Post your properties file. If all is well it will be expressed in
7-bit ASCII so your newsreader encoding won't matter.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Elhanan
Guest
Posts: n/a
 
      12-12-2005
here it is with the \u and all

# -- validator --
bean.title=\u05f3\u00a0\u05f3\u00a1\u05f3\u2122\u0 5f3\u2022\u05f3\ufffd

bean.body= \u05f3\u2019\u05f3\u2022\u05f3\u00a3
errors.required={0} \u05f3\u201c\u05f3\u00a8\u05f3\u2022\u05f3\u00a9
# -- welcome --
welcome.title=Struts Blank Application
welcome.heading=\u05e9\u05dc\u05d5\u05dd

the one i'm aiming for is 'welcome.heading'

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-12-2005
On 11 Dec 2005 20:54:19 -0800, "Elhanan" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>here it is with the \u and all
>
># -- validator --
>bean.title=\u05f3\u00a0\u05f3\u00a1\u05f3\u2122\u 05f3\u2022\u05f3\ufffd
>
>bean.body= \u05f3\u2019\u05f3\u2022\u05f3\u00a3
>errors.required={0} \u05f3\u201c\u05f3\u00a8\u05f3\u2022\u05f3\u00a9
># -- welcome --
>welcome.title=Struts Blank Application
>welcome.heading=\u05e9\u05dc\u05d5\u05dd
>
>the one i'm aiming for is 'welcome.heading'


I wrote this little SSCCE to read your file. It seems to be reading it
correctly under Win2K with JDK 1.5.0_06.

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Hebrew
{
/**
* test harness
*
* @param args not used
*/
public static void main ( String[] args )
{

// get an ordinary property
Properties props = new Properties();
try
{
FileInputStream fis = new FileInputStream(
"hebrew.properties" );
props.load( fis );
fis.close();
}
catch ( IOException e )
{
return;
}
String desc = props.getProperty( "welcome.heading" );
System.out.println( desc );
System.out.println( displayHexString( desc ) );

}

/** convert a String to a hex representation of the String,
* with 4 hex chars per char of the original String.
* e.g. "1abc \uabcd" gives "0031_0061_0062_0063_0020_abcd"
* @param s String to convert to hex equivalent
*/
public static String displayHexString ( String s )
{
StringBuilder sb = new StringBuilder( s.length() * 5 - 1 );
for ( int i=0; i<s.length(); i++ )
{
char c = s.charAt(i);
if ( i != 0 )
{
sb.append( '_' );
}
// encode 16 bits as four nibbles

sb.append( hexChar [ c >>> 12 & 0xf ] );
sb.append( hexChar [ c >>> 8 & 0xf ] );
sb.append( hexChar [ c >>> 4 & 0xf ] );
sb.append( hexChar [ c & 0xf ] );
}
return sb.toString();
}

// table to convert a nibble to a hex char.
static final char[] hexChar = {
'0' , '1' , '2' , '3' ,
'4' , '5' , '6' , '7' ,
'8' , '9' , 'a' , 'b' ,
'c' , 'd' , 'e' , 'f'};
}
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Elhanan
Guest
Posts: n/a
 
      12-12-2005
i know it reads it correctly i also did a small application only i
simply displayed the results from the properties class on the eclipse
console, and it was correct, in the struts it doesn't work.

 
Reply With Quote
 
Richard Wheeldon
Guest
Posts: n/a
 
      12-15-2005
Elhanan wrote:
> my jsp and property files are encoded in UTF-8:


Properties files cannot be in UTF8. However, there is
a quick and dirty hack to allow this: Create a wrapper
which reads the String, gets the byte array of the
string, then re-parses the byte array as a string of
UTF8 characters,

Regards,

Richard
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
can i use struts 2 tags in a struts 1 app? John M Java 1 03-07-2008 01:17 AM
How to Install Hebrew Font? joe Firefox 2 08-23-2005 05:29 PM
hebrew output Sharon ASP .Net 0 01-22-2004 03:55 AM
sample of configuration for Hebrew Mr. x ASP .Net 5 11-05-2003 03:07 PM
Language and Direction real GURU needed! (Hebrew and maybe arabic) CR or Charset issue? Efy. ASP .Net 2 06-25-2003 03:28 PM



Advertisments