2007年6月19日火曜日

How to translate Openfire Xmpp Server in Japanese

How to translate Openfire Xmpp Server in Japanese

Reference, Translation Guide
  • http://www.igniterealtime.org/builds/openfire/docs/latest/documentation/translator-guide.html

Download Japanese Message Properties File
I put 2 Japanese translated properties file.(These files are based on Openfire Version3.3.1 properties)
One is converted to ASCII format(\uXXXX format by using native2ascii command), other is saved messages based on UTF-8 characterset without ASCII format conversion.we usually use only converted japanese messages in ASCII format. Please downlod following file.
  1. converted japanese messages in ASCII format
    http://www.box.net/shared/ou0niqzp19
  2. UTF-8 no bom file without converting
    http://www.box.net/shared/z1euxze9v3
Steps to install file
If you need to translate all messages including sidebar and tag, please try following steps.
(Please refer to following URL if you need more information
http://www.igniterealtime.org/forum/thread.jspa?threadID=27081&tstart=0)
  1. Download converted japanese messages in ASCII formt file descrived above.
  2. Change the file name from openfire_i18n_ja_JP.properties.converted to openfire_i18n_ja_JP.properties.
  3. Create a new jar file.
    jar cvf cfja.jar openfire_i18n_ja_JP.properties
  4. Put new cfja.jar file into the lib directory under your Openfire Home directory.
  5. Restart your openfire server.
Following steps are easy to use, but some messages(in sidebar and tag) are displayed in English.
  1. Download Ascii converted japanese message file.
  2. Put the file into $OpenfireHome/lib named as openfire_i18n_ja_JP.properties.
  3. Open conf/openfire.xml and change locate tag manually to ja_JP
  4. Restart openfire server.
You can translate openfire by using following steps, but it is not easy.
(Changed at 2007/06/20)
  1. Backup lib/openfire.jar
  2. Extract openfile.jar
  3. Copy Ascii converted japanese message file into the extracted directory.
  4. Create new jar file.
  5. Put created jar file into lib directory.
  6. Restart openfire server.

2007年6月8日金曜日

[JAVA>Rome, RSS/XML] When using Rome RSS Reader or Rome Fetcher(XML Reader), MalformedInputException occured

References
  1. Rome WebSite
    https://rome.dev.java.net/
Problems
When using Rome RSS Reader or Rome Fetcher to get RSS Data from any Website, sometimes sun.io.MalformedInputException error occured randomly. In case of fetching RSS from same Website, sometimes error occured, but sometimes not occured. Error stacks were as follows.

sun.io.MalformedInputException
at sun.io.ByteToCharUTF8.flush(ByteToCharUTF8.java:139)
at sun.nio.cs.StreamDecoder$ConverterSD.flushInto(StreamDecoder.java:333)
at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java:357)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:250)
at java.io.InputStreamReader.read(InputStreamReader.java:212)
at java.io.BufferedReader.fill(BufferedReader.java:157)
at java.io.BufferedReader.readLine(BufferedReader.java:320)
at java.io.BufferedReader.readLine(BufferedReader.java:383)
at com.sun.syndication.io.XmlReader.getXmlProlog(XmlReader.java:534)
at com.sun.syndication.io.XmlReader.doHttpStream(XmlReader.java:325)
at com.sun.syndication.io.XmlReader.(XmlReader.java:248)


Reason why this errr occured
While finding the Character Encoding in RSS InputStream in getXmlProlog() function In XmlReader.java(rome-0.9/src/java/com/sun/syndication/io/XmlReader.java), System tries to get first 4096 bytes characters from Stream. In case of including Japanese or not Ascii characters, System sometimes truncates the bytes at the invalid byte position(Japanese uses 3 byte for each word in UTF-8), so this problem occures.

Solution
  • Fixed file
    rome-0.9/src/java/com/sun/syndication/io/XmlReader.java
  • Fixed function
    Change as follows in getXmlProlog() function.
  • Description
    We catches the MalformedInputException exception and ignore occuring this exception because the line string this exception occures doesn't usually need. Add try and catch block when readling the line.
  • Example

    /** Changed by tatsuya anno to avoid MalformedInputException*/
    try{
    String line = br.readLine();
    while (line != null) {
    prolog.append(line).append("\n");
    line = br.readLine();
    }
    }catch(sun.io.MalformedInputException eMalformedInput){
    //skip
    }


2007年6月5日火曜日

[JAVA>JYMSG]How to use JYMSG Java Library for Yahoo Japan

How to use JYMSG Java Library for Yahoo Japan

References
  • JYMSG Homepage: http://jymsg9.sourceforge.net/

Description
Now, the messenger server for Yahoo Japan is separated from Yahoo US, and the some spec of messenger client for Yahoo Japan is different from the client for Yahoo US. While implementing messenger for Yahoo Japan,I had a character encoding problem.

Only when sending a message from Yahoo Japan client to Yahoo Japan Messenger Server, Yahoo Japan Messenger Client is sending a packet encoded by using SJIS characterset (not using UTF-8).
This problem is occured only when using Yahoo Japan Client, not Yahoo US Client. (I don't know why yahoo japan uses SJIS character encoding.) I customized the JYMSG library source code for supporting Yahoo Japan as follows.

customization steps
  1. added following in YMSG9InputStream.java to handle user defined encoding.

    private String characterEncoding="UTF-8";
    public void setCharacterEncoding(String pCharacterEncoding){
    if(pCharacterEncoding==null||pCharacterEncoding.equals("")){
    return;
    }
    characterEncoding=pCharacterEncoding;
    }
    public String getCharacterEncoding(){
    return characterEncoding;
    }

  2. at 68 in YMSG9InputStream.java, change hardcoded UTF-8 characterset to variable named characterEncoding

    for(int i=0; i<body.length-1;i++)
    { if(u2i(body[i])==0xc0 && u2i(body[i+1])==0x80)
    { // -----Create a UTF-8 string and add to array
    //changed by tatsuya anno
    Commented out ==> //String s = new String(body,start,i-start,"UTF-8");
    added new line ==> String s=new String(body,start,i-start,characterEncoding);
    //end of customization
    v.addElement(s);
    if(dbis!=null) System.out.println(">>"+s);
    // -----Skip over second byte in separator, reset string start
    i++; start=i+1;
    }
    }

  3. added following in DirectConnectionHandler.java

    //added by tatsuya anno
    public void setInputStreamCharacterEncoding(String pCharacterEncoding){
    if(ips==null){
    return;
    }

    ips.setCharacterEncoding(pCharacterEncoding);
    }

  4. example using this customization

    //create ConnectionHander object to connect to yahoo japan
    DirectConnectionHandler connectionHandler=new DirectConnectionHandler("",);
    //create Session object
    Session yahooConnection=new Session(connectionHandler);
    yahooConnection.addSessionListener(new YahooPacketListener());
    yahooConnection.login(yahooClientUsername,yahooClientPassword);
    yahooConnection.setStatus(StatusConstants.STATUS_AVAILABLE);

    //after logged in, Set InputStream Encoding Charset
    //if you use this library for Yahoo US, you don't need to this line.
    connectionHandler.setInputStreamCharacterEncoding("SJIS");