Break the language barrier! This article describes how to use the Lotus Workplace Instant Messaging SPI to create real-time translation chat session, so that the two understand each other's languages can communicate with each other.
Today, instant messaging has largely ubiquitous. For some people, it is a basic e-mail as communication tools, especially in the need for timely response to the occasion. With the online in more and more aware applications (such as IBM Workplace products) in common use, instant messaging will become more and more popular.
Of course, all human means of communication, even talk face to face, must face a basic fact: We do not speak the same language. In today's multi-national composition of the world, many of us still need to take into account the language barrier. This communication is often a challenge, particularly in must be clear, when the rapid exchange of information. If you use instant messaging with others, chat functions, when each message to "immediately" be translated automatically to the receiver of the native form of presentation, this not a good idea? Just a few years ago, this feature also seems like science fiction, but now, this function is very easy to achieve together, this article describes how to implement this functionality.
This article discusses the IBM Workplace Instant Messaging Service Provider Interface (SPI) for use. Instant Messaging SPI is the IBM Workplace Products API Toolkit part, developers can use it to build instant messaging program, in a message intercepted before it reached the receiver. The most common function of this SPI is the message log. But also enables other features such as message translation. (In the annex can see the complete sample code.)
This article assumes that you are an experienced Java developer, and on the IBM Workplace Products API Toolkit have some knowledge about. On the introduction of this Toolkit, please see the developerWorks: Lotus article, "IBM Workplace portlet to add presence awareness." Can also visit the IBM Workplace resource center.
Workplace Instant Messaging SPI servlets
You can use Workplace Instant Messaging SPI application as a servlet deployed in WebSphere Portal application server instance. The servlet should be configured to start automatically when the application server instance of the load. In the init () method, servlet itself as a listener to the Instant Messaging Service in. Similarly, when the servlet destroyed, but also a listener from the Messaging Service to remove the servlet. Because this is an event listener, so servlet must implement the onMessage method passing the message to the receiver before the call. Information and records of all translation work should be dealt with in this way.
The rest of this article explains how to create a simple message handler, which extends the previously added to the Purchase Order portlet (described in this article) in the chat. The handler will use the WebSphere Translation Server in the message before they reach the receiver to translate. Our goal is to explain the development of a treatment program and its instant messaging integrated into IBM Workplace Collaborative Services solution is so simple. This example can be extended, before the implementation of the translation consider the use of configuration information, of course, is not the scope of this article series. (For example, the message handler can be translated into the receiving party stored in the LDAP server's preferred language.)
Note: The following steps assume that you are using IDE, have some understanding of J2EE applications, such as WebSphere Studio Application Developer V5.1 or IBM Rational Application Developer V6.0. It should also be installed with English and Spanish translation engine IBM WebSphere Translation Server. (In the following examples assume that you are using Rational Application Developer.)
Create instant messaging program
Open development environment such as IBM Rational Application Developer (RAD) V6.0, create a new Dynamic Web Project, will be named IMTranslatorProj (Figure 1). If you are using IBM RAD V6.0, so be sure to set Web project deployment target WebSphere Application Server V5.0.
Figure 1. Create a dynamic Web project
To use Instant Messaging SPI and the WebSphere Translation Server API, you must be able to access lwpapi25_imspi.jar and wts.jar file. These two JAR files into Web project WebContent WEB-INF lib folder (see Figure 2). (Download and unzip the toolbox, you can find in the directory lwpapi25imspilib lwpapi25_imspi.jar file. Wts.jar file to install WebSphere Translation Server is located in the directory.)
Figure 2. Lwpapi25_imspi.jar and wts.jar file
In the project to create a new servlet, name it IMTranslator. The servlet should also include a init () and destroy () method (which may need to manually input). Add the following code to the servlet code to the start position for the introduction of the correct package:
import com.ibm.workplace.services.messaging .*; import com.ibm.lt. *; to receive news of events MessagingListener servlet must implement the interfaces. The servlet class definition was revised to:
public class IMTranslator extends HttpServlet implements Servlet, MessagingListener (Now, a new servlet code should be as follows (ignore the error, because you will be in the next step to correct it):
import java.io.IOException;
import javax.servlet .*;
import javax.servlet.http .*;
import com.ibm.workplace.services.messaging .*;
import com.ibm.lt. *;
public class IMTranslator extends HttpServlet implements Servlet, MessagingListener (
public IMTranslator () (
super ();
)
protected void doGet (HttpServletRequest arg0, HttpServletResponse arg1) throws
ServletException, IOException (
)
protected void doPost (HttpServletRequest arg0, HttpServletResponse arg1) throws
ServletException, IOException (
)
public void init (ServletConfig arg0) throws ServletException (
)
public void destroy () (
)
)
To achieve MessageListener interfaces, servlet must provide the onMessage () method implementation. The method is passed to the receiver in the message before the call. Add in the servlet onMessage () method, the code is as follows (depending on the environment should change the value of translation server host name):
public byte [] onMessage (
String fromPresentityId,
String fromContactId,
java.util.Collection toPresentities,
java.util.Collection toContacts,
String sessionId,
String contentType,
byte [] data)
(
String msg = new String (data);
String convertedMsg = msg;
try
(
/ / Translation server hostname
String hostname = "portal14.dfw.ibm.com";
/ / Convert from english to spanish
String fromto = "enes";
/ / Connect to server and submit translation request
LTinterface service =
(LTinterface) LTengine.GetService (hostname, fromto);
Object handle = service.jltBeginTranslation ("* format = text");
convertedMsg = service.jltTranslate (handle, msg);
service.jltEndTranslation (handle);
)
catch (Throwable t)
(
System.out.println (t.getMessage ());
t.printStackTrace ();
)
return convertedMsg.getBytes ();
)
The servlet event notification message itself must be registered as a Messaging Service listener. In servlet's init () method to complete this operation, the method called when you first load the servlet. To the init () method to add the appropriate code, as follows:
public void init (ServletConfig arg0) throws ServletException (
MessagingService messagingService = MessagingServiceFactory.getMessagingService ();
if (messagingService == null) (
System.err.println ("IMTranslator: Messaging Service is NULL");
return;
)
messagingService.addMessagingListener (this);
)
In the unloaded servlet, you should monitor the program from the Messaging Service to delete this servlet. Can servlet's destroy () method to complete this operation, the method called before unloading the servlet. To destroy () method to add the appropriate code, as follows:
public void destroy () (
MessagingService messagingService = MessagingServiceFactory.getMessagingService ();
if (messagingService == null) (
System.err.println ("IMTranslator: Messaging Service is NULL");
return;
)
messagingService.removeMessagingListener (this);
)
By default, servlet request in the first start. The servlet will quietly deal with messages, so the application should be configured to start automatically be loaded. To this end, we should open the deployment descriptor file (web.xml) to open the Servlet tab, then select the Load On Startup options box and save the changes (see Figure 3).
Figure 3. Load on Startup option
Save the changes, will be exported to WAR files Web project. In IBM Rational Application Developer, you can right click project and select Export through to complete this operation. Then select the WAR file, click Next. In the input file name, click Finish to complete the export operation.
Web application WAR file should be deployed in WebSphere Portal IBM Workplace services application server instance. Through http://
: 9091/admin access WebSphere Application Server Administrative Console. Login navigate to the Applications Install New Application. Select the previous step to export the WAR file, enter / IMTranslator as the context root. Click Next to continue behind the operation. Follow the wizard's prompts to install the Web application. In wizard step 1 and 2, accept the default settings. Step 3 (mapping module to the application server), Web application will be mapped to WebSphere Portal application server (Figure 4):
Figure 4. Mapping modules to application servers
After the wizard finishes, you can see a message, this application has been successfully installed. Select "Save to master configuration" link and click the Save button to save your changes.
Instant messaging program running
To start IMTranslator instant messaging program, first navigate to Applications Enterprise Applications. Select IMTranslatorProj application and click the Start button. Status symbols (status symbol) of the changes that the application has been started. With the handling procedures for the WebSphere Portal information recorded in the standard output and standard error log file, the file is located in C: / WebSphere / PortalServer / log directory.
Start the message processing program, you can open a chat session with another user. English message to the receiver before the pass will be translated into Spanish and vice versa. For example Figure 5 shows the message:
Figure 5. Spanish news
Content displayed to the recipient as shown in Figure 6:
Figure 6. Translated into English news
Addressed before the application can be further expanded, according to a message recipient's preferred language (usually stored in the LDAP server) to be translated.
Conclusion
Workplace Products API Toolkit in the Instant Messaging SPI allows developers to send a message to the receiver before the acquisition and processing of the message, so you can complete the message record, monitor and translation of such features. This paper describes the use of Rational Application Developer V6.0 to create this type of development environment to achieve MessagingListener interface servlet, to instant messaging needs from English into Spanish steps. In the servlet's init () method will be added for registration as a Messaging Service servlet listener code. destroy () method contains the code to delete servlet listener. To achieve MessageListener interfaces, servlet must implement the call in a message delivered before the onMessage () method. Using IBM WebSphere Translation Server translation message needed business logic is handled in this method. Finally, we will install the servlet to the WebSphere Portal application server instance.
In short, this is a fairly easy to achieve together the application. But this is not a complex servlet in a multilingual environment may be useful, Instant Messaging SPI can be used as an example of the power.
We hope this can give you help. For clarity, keep this example simple, but you can in their own instant messaging application, creativity, achieve more.
Recommended links:
Shanghai Caohejing Property CMC Fast New Way To Communicate
Compare Reference Tools
Sun executives hefty pay Increase for 2006, six times the most high
Real to MP4
Name enterprises HR Field coaching "candidates"
Free online fax services to send fax by email
MKV to VOB
Analysis of Taobao in 2008 to adjust the CAUSES and effects of B2C strategy
3GP to FLV
Decade of embarrassing the Chinese game
Another PAIR of eyes CMMI [2]
MP4 standard expected by the end of line introduced to avoid repeating the mistakes MP3
Easy Compilers And Interpreters