10.07.2015 Views

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

Lotus Instant Messaging/ Web Conferencing ... - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 3-8 imReceived method()public void imReceived(ImEvent event){System.out.println("imReceived()");Im im = event.getIm();String name = im.getPartner().getDisplayName();boolean imExist = false;Im currentIm = null;for (int i = 0; i < m_imOpened.size(); i++){currentIm = (Im) m_imOpened.elementAt(i);if (currentIm.getPartner().getId().equals(im.getPartner().getId())){imExist = true;im = currentIm;break;}}if (!imExist){m_imOpened.addElement(im);im.addImListener(this);if (name.indexOf(" ") > 0){name = name.substring(0, name.indexOf(" "));}String returnText = "Hello " + name + " - " + getWELCOME_TEXT();im.sendText(true, returnText);}}The textReceived() method (Example 3-9) is where the bot-specific applicationcode is called. The ImEvent object passed into the method and the text sent bythe user is passed into the abstract doTextReceived() method, which isoverridden in each bot subclass. The result of any processing is sent back to theuser (in this case, any matches to the question posed by the user).Example 3-9 textReceived() methodpublic void textReceived(ImEvent event){Im im = event.getIm();String partnerName = im.getPartner().getDisplayName();String receivedText = event.getText().trim();// ignore no commandif(receivedText.length() == 0)64 <strong>Lotus</strong> <strong>Instant</strong> <strong>Messaging</strong>/<strong>Web</strong> <strong>Conferencing</strong> (Sametime): Building Sametime-Enabled Applications

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!