[opencms-dev] How to Escape Unicode String in Properties of Files

Ly The Thanh thanh_ly21 at yahoo.com
Tue Nov 25 04:57:29 CET 2008


Hi,

I'm using OpenCms 7.0.5, Oracle10g, OC4J10g.
content of the site is on unicode (like that: OpenCms rất tuyệt vời!) 

In my database the content of xml file is ok (as using CLOB datatype), 
but the properties is not store correctly (as VARCHAR2 encoding in my company db is US7ASCII, and not allow to change to AL32UTF8).

so to store the properties correctly, I thing there are 2 way to do this:

1. I may have to change VARCHAR2 to NVARCHAR2 (as NVARCHAR2 in my company db is AL16UTF16). I haven't do this because I have to setup OC again.

2. I need to escape unicode character and convert to NCR code when opencms save the properties. with a function like this:

// Unicode to NCM, which will convert a String like this "OpenCms rất tuyệt vời" --> "OpenCms rất tuyệt vời"
public static String escapeUnicodeString(String str, boolean escapeAscii) {
        String ostr = new String();
        for (int i = 0; i < str.length(); i++) {
            char ch = str.charAt(i);
            if (!escapeAscii && ((ch >= 0x0020) && (ch <= 0x007e)))
                ostr += ch;
            else {
                ostr += "&#";
                String hex = Integer.toString(str.charAt(i) & 0xFFFF);
                if (hex.length() == 2)
                    ostr += "00";
                ostr += hex;
                ostr += ";";
            }
        }
        return (ostr);
    }

But I don't known how to apply these change in opencms, which class I have to change.

Please help me how to do this.

Thanks you in advanced!



      



More information about the opencms-dev mailing list