Friday, October 30, 2009

Chinese characters in resource bundles

I had a difficult time to implement Chinese characters for my SWT application. I was using resource bundle for internationalizing the application. While creating resource bundles for Chinese characters I noticed that resource bundles will accept only ASCII and Java is not able to read UTF-8 resource bundles.I was using eclipse as my development IDE.

The following work around helped me to overcome the situation.

Open an existing file outside eclipse using notepad. Enter Chinese characters for the translation you want and save the file in UTF-8 format. You can use google translation for getting the chinese characters.

Use the tool 'native2ascii' to convert the chinese charcters to unicode characters.

The syntax is like this:

C:\temp>native2ascii -encoding utf-8

The file will contain Unicode characters for your Chinese letters in Then copy the content in file and copy it to any file created in eclipse.

The program will work fine displaying Chinese characters without any modification to source code.

Tuesday, October 27, 2009

ini file which helps you to preserve comments while updating

I have faced a difficult situation where one of the scenario require to write and preserve comments in configuration file. I tried using properties file and ini file concept using java. But when we write back to the file for storing configuration information, the entire comments in the proprieties or ini file get lost.

At last after a frantic search, I got the following free library which will help you to store configuration in an ini file where you can read and write and it will preserve any comments wrtitten at the top of the file.

Format date in Lotus script

Below post helped me to format date in Lotus script

I made changes to the code and below code will format the date value in a field of document.

Dim session As New NotesSession
Dim dateTime As NotesDateTime
Set dateTime = session.CreateDateTime ( deliveredDate )
print " : " & Cstr(dateTime.LocalTime ) & " GMT Time :" & Cstr(dateTime.GMTTime)

Dim dtGMT As NotesDateTime
Dim strRSSDate As String

Set dtGMT = New NotesDateTime( Left$(dateTime.LocalTime , 22) )
strRSSDate = Format$(dtGMT.LSLocalTime, "dd-mmm-yyyy hh:mm:ss AM/PM")

ReplaceAll function in lotus script

Code snippet to stimulate replaceAll function in lotus script

Function StringReplaceAll(Byval strArg As String, Byval strSrc As String,Byval strDst As String) As String

Dim iPos As Integer
iPos = Instr(strArg, strSrc)

While iPos > 0
strArg = Left$(strArg, iPos - 1) + strDst + Mid$(strArg, iPos + Len(strSrc))
iPos = Instr(iPos + Len(strDst), strArg, strSrc)

StringReplaceAll= strArg

End Function

The function call
StringReplaceAll("hello","l", "g") will give the result as 'heggo'

Dynamically moving scroll bar when dragging an object over an SWT Tree.

Dynamically moving scroll bar when dragging an object over an SWT Tree.

In the dragOver() event write the following statements: |= DND.FEEDBACK_SCROLL;

For expanding a tree, when mouse hover over it during dragging an object: |= DND.FEEDBACK_EXPAND;

The more details can be found at the below link