[opencms-dev] Re:Double-byte support

石 羽森 shi_yusen at hotmail.com
Wed Jun 2 17:03:02 CEST 2004


Yes, opencms can support double-byte languages e.g. simplified chinese, but 
you have to change some source code.

The followings are what i did for simplified chinese:
1. Encoder.java:
add the following:
    public static String changeEncoding(String input, String oldEncoding, 
String newEncoding) {
        if ((oldEncoding == null) || (newEncoding == null)) return input;
        if ((oldEncoding.trim()).equalsIgnoreCase(newEncoding.trim())) 
return input;
        String result = input;
        try {
            result = new String(input.getBytes(oldEncoding), newEncoding);
        } catch (UnsupportedEncodingException e) {
            // return value will be input value
        }
        return result;
    }
    
    public static String escapeWBlanks(String source) {
        if(source == null) {
            return null;
        }
        StringBuffer ret = new StringBuffer();

        String enc = source;
        for(int z = 0;z < enc.length();z++) {
            if(enc.charAt(z) == '+') {
                ret.append("%20");
            }
            else if(enc.charAt(z) == '\r') {
            	ret.append("\\r");
            }
            else if(enc.charAt(z) == '\n') {
            	ret.append("\\n");
            }
            else {
                ret.append(enc.charAt(z));
            }
        }
        return ret.toString();
    }

2. CmsMessages.java:
original: return m_messages.getString(keyName);
new:       return Encoder.changeEncoding(m_bundle.getString(keyName), 
"ISO-8859-1", A_OpenCms.getDefaultEncoding());
A_OpenCms.getDefaultEncoding()="GB2312". The m_bundle's string is encoding 
in ISO-8859-1 by default, it should be changed into GB2312.

3. CmsWpMain.java:
original: xmlTemplateDocument.setData("message", 
"alert(unescape('BROADCAST:" + Encoder.escape(message, 
cms.getRequestContext().getEncoding()) + "'));");
new: xmlTemplateDocument.setData("message", "alert('BROADCAST:\\n" + 
Encoder.escapeWBlanks(message) + "');");
after this change, the messagebox can support simplified chinese and 
multi-line.

4. Set GB2312 as the default encoding in opencms.properties.

5. Set MySQL's default-character-set=gb2312.

I think these changes also work for other double-byte languages. Try it.

shiys at langhua.cn

_________________________________________________________________
享用世界上最大的电子邮件系统― MSN Hotmail。  http://www.hotmail.com  




More information about the opencms-dev mailing list