Level: Intermediate Srinivas Varma Chitiveli (schitive@us.ibm.com), Advisory Software Engineer, IBM
13 Dec 2006
Now you can use IBM OmniFind Yahoo! Edition, a free downloadable search engine, to crawl and index up to half
a million web pages or file system documents. In this article, learn how to use Eclipse plug-ins to integrate the
IBM OmniFind Yahoo! search interface into various display areas of the IBM Lotus
Sametime Connect client.
Introduction
IBM and Yahoo! have partnered together to offer a free downloadable search engine
that is easy to set up and use. IBM's OmniFind Yahoo! Edition (referred to as just
"OmniFind" in this article) can crawl and index up to half a million web pages or
file system documents, making them available for search through an easy-to-use
web interface. You may have already downloaded OmniFind and discovered how quick and
easy it is to set up an index and start searching.
Right now, you may be investigating how to integrate the enterprise OmniFind search interface
into the desktop applications you use on daily basis. If you are an IBM Lotus Sametime connect
user, you might want a clickable Search icon in the common toolbar area or chat
area. When you click this Search icon, you would expect your enterprises search interface to be launched
in a browser, ready to service your search queries. The clickable Search icon saves you the effort of manually launching your favorite browser and typing in the URL for your search engine. For this reason, I added some flexibility to the implementation so that you can specify your favorite browser and the URL of your favorite search engine.
Scenarios
The OmniFind search interface consists of a web client hosted on the search server. The web client exposes
an edit box where the search terms are entered and results are displayed from the data indexed in the
collections. This article demonstrates the extensions to Eclipse and Sametime plug-ins for launching
the OmniFind search interface in the browser of your choice. This article highlights the development of
plug-ins that can display clickable search icons in the Toolbar, pop-up menu, and Chat view. It's up to
your discretion to deploy whichever interests you.
For ease of understanding, I'll start with the expected end results in the following
sub-sections, then walk you through the various visual areas of the Sametime GUI impacted by my plug-in
implementations. In later sections, we'll walk through the plug-in code implementation.
Configure preferences
To maintain flexibility, I am implementing a plug-in that extends the Preferences page so that you
can specify the URL of your favorite search engine and the absolute path to your favorite browser. In Figure 1,
the preference identified in red is the enhancement enabled by this plug-in:
Figure 1: IBM OmniFind Yahoo! preferences
In the URL for the search engine shown above, a substitutable must be marked to specify the search terms. In the following
example, the URL refers to the OmniFind search server, and the substitutable for the search term is identified by <SUB>:
http://mecklenburg.wma.ibm.com:8080/search/?index=Default&start=0&results=10&
preview=false&output=html&query=<SUB>
You could have this URL represent the Google or Yahoo search server with appropriate arguments set as substitutable. In
the following sections, you can see how I replace <SUB> with personal data selected in the Sametime Connect client.
Search icon in the toolbar
Figure 2 demonstrates a Search icon in the main toolbar of the Sametime Connect client:
Figure 2: Search icon in the main toolbar
Clicking the above Search icon launches a browser with your predefined URL.
Figure 3 displays the
OmniFind search interface launched in your specified browser:
Figure 3: Web-based search interface
Search icon in the Chat view
I found a search icon in the Chat view helped keep me focused on my chat sessions.
Figure 4 shows the implementation of a plug-in to display the Search icon in the Chat view:
Figure 4: Search icon in the Chat view
When you click the icon shown above, the browser displays in the tabbed area.
Figure 5 shows the browser with
the specified URL in a tabbed area, to demonstrate that the plug-in has the capability to launch a URL in an internal browser:
Figure 5: Search interface in an internal browser
Search icon in pop-up menu
Figure 6 shows Search as a pop-up menu item.
Figure 6: Search as pop-up menu item
When you select your buddies and click the pop-up menu, the search page is launched with the user email IDs as
the search term. This really helps when searching for a person's contribution in blogs, on developerWorks, or the
enterprise content indexed by IBM OmniFind Yahoo! Edition.
Getting started
To build the search plug-ins, you need to make your environment plug-in ready for Lotus Sametime.
These are the basic steps to write any plug-in for the product:
- Download Eclipse SDK 3.2 and install the J9 Java Development Tools (JDT) launch plug-in for Eclipse.
- Configure your run-time to use J9.
- Configure the Eclipse compiler settings for Java Developer Kit (JDK) 1.4
- Specify Lotus Sametime as the target platform in Eclipse.
The first four steps are explained in more detail in the Lotus Sametime Lotus Sametime Software Development Kit, so we won't cover them in this article.
Make Lotus Sametime your target platform in Eclipse
In order to use Eclipse to create plug-ins for Lotus Sametime, you must specify Lotus Sametime as the target platform.
In Eclipse, choose Window > Preferences to open the Preferences dialog box. In the left pane, select Plug-in
Development > Target Platform.
In the Location field, browse to the installation location of your Lotus Sametime Connect client, for example,
C:\Program Files\IBM\Sametime, and then click Reload. See the following figure:
Figure 7: Preferences dialog box
Create a new plug-in development project
In Eclipse, to create a plug-in you need to begin with a project. To do so, follow these steps:
- Choose File > New Project.
- In the New Project dialog box, open the Plug-in Development folder, select Plug-in Project, and then click Next.
- In the New Plug-in Project wizard, name your project com.developerworks.sametime.search, and then click Next.
- In the next wizard panel, complete the following fields:
- Plug-in ID: com.developerworks.sametime.search (or something similar)
- Plug-in Version: 1.0.0
- Plug-in Name: Search Plug-in (make the same as the plug-in ID)
- Plug-in Provider: (enter your company name)
- Select the "Generate an activator, a Java class that controls the plug-in's life cycle" and the "This plug-in will make contributions to the UI" options (see Figure 8). Click Finish when done.
Figure 8: New Plug-in Project wizard
Plug-in dependencies
The search plug-ins are dependent upon other plug-ins to integrate into the Lotus Sametime Connect user interface. Follow these
steps to add the required plug-ins:
- In Eclipse, open META-INF MANIFEST.MF in the Manifest Editor.
- Select the Dependencies tab.
- Add the following plug-ins in the Required Plug-ins section (see Figure 9):
- org.eclipse.ui
- org.eclipse.core.runtime
- com.ibm.collaboration.realtime.browser
- com.ibm.collaboration.realtime.people
- com.ibm.rcp.realtime.livenames
- com.ibm.collaboration.realtime.imhub
- com.ibm.collaboration.realtime.chatwindow
Figure 9: Eclipse dependencies
Once you finish configuring the Eclipse project, you can move to the following sections. These sections walk you through the development of the various plug-ins, as mentioned earlier.
Implement preferences through preference pages
Let's extend the Eclipse plug-in to add a preference page to the Sametime GUI client. In our preference page, we
will have preferences to describe the search engine. Specify the URL of the web interface and the absolute path of
your preferred browser:
IBM OmniFind Yahoo! preferences
Let's store your preferences in the IBM OmniFind Yahoo! preferences page, as shown in Figure 10:
Figure 10: IBM OmniFind Yahoo! preferences
To create the search preference page, open your META-INF/MANIFEST.MF file. Select the Extensions tab and click the Add
button to open the New Extension window. In the New Extension window, select the Extension Wizards tab. From the right
pane of the Extension Wizards tab, select the Preference Page extension template and click Next. See the following figure.
Figure 11. New Extension wizard
This creates a template for your preference page, which you can modify to fit your needs. Set the class name for the preference
page to SearchPreferences. Set the name for the preference page to IBM OmniFind Yahoo! preferences. Use the default package name com.developerworks.sametime.search.preferences as your Java package name and click Finish (see Figure 10).
When you create your template, Eclipse generates a class named PreferenceConstants for you. This is a convenience class that
can be used to store constant values used by your preference page. You can replace the auto-generated code with the following code:
Listing 1: Code snippet for search preferences
/**
* Constant definitions for plug-in preferences
*/
public class PreferenceConstants {
public static final String SearchEngineDescription = "Search engine description";
public static final String SearchEngineURL = "Search URL";
public static final String BrowserLocation = "Browser location";
}
|
Another class that is auto-generated for you is the PreferenceInitializer class. The InitializeDefaultPreference
method of this class is used to populate default values for your preference values. Notice in the following code how the class uses
the constants you defined in the PreferenceConstants class. By default, the browser location is set to
Microsoft Internet Explorer's default installation location (c:\Program Files\Internet Explorer\iexplore.exe).
Listing 2: Code snippet for initialize default preferences
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(PreferenceConstants.SearchEngineDescription,
"IBM OmniFind Yahoo! Edition");
store.setDefault(PreferenceConstants.SearchEngineURL,
"http://mecklenburg.wma.ibm.com:8080/search/?index=Default&start=0&results=10&
preview=false&output=html&query=<SUB>");
store.setDefault(PreferenceConstants.BrowserLocation,
"c:\\progra~1\\intern~1\\iexplore.exe");
}
|
The template generation created another class named SearchPreferences. This class defines the layout for the preference page.
You can replace the auto-generated constructor with the following constructor snippet:
Listing 3: Code snippet for search preferences
public SearchPreferences() {
super(GRID);
setPreferenceStore(Activator.getDefault().getPreferenceStore());
setDescription("IBM Omnifind Yahoo! preferences");
}
public void createFieldEditors() {
addField(new StringFieldEditor(PreferenceConstants.SearchEngineDescription,
"Search engine:", getFieldEditorParent()));
addField(new StringFieldEditor(PreferenceConstants.SearchEngineURL,
"Search URL:", getFieldEditorParent()));
addField(new StringFieldEditor(PreferenceConstants.BrowserLocation,
"My browser location:", getFieldEditorParent()));
}
|
We chose a GRID layout, which by default has one column. Each of the FieldEditor widgets that you add will have its own row.
You must provide input areas through which the client can edit the values for its preferences (more specifically, the browser
location and search URL). The graphical input facility you incorporate into your preference page is shown in
Figure 10.
To create the input areas, you replace the generated createFieldEditors method (which you must override from your parent
FieldEditorPreferencePage class) with your own code. In the above code, we programmatically add three field
editors using the StringFieldEditor Eclipse widget.
Search utilities
Before diving into the code for extending the plug-ins, let's walk through some common code for handling the
encoding of URL, parsing the URL to replace the substitutable variable with search terms and launching of the specified
URL in an external browser.
The following shows the self-explanatory utilities class:
Listing 4: Code snippet for search utilities
public class SearchUtilities {
/*
* Launch the URL in a external browser
*
* @param String search term(s)
*/
public static void showSearches(String searchTerm) {
// get location of the specified browser
String browserLocation = Activator.getDefault().getPreferenceStore()
.getString(PreferenceConstants.BrowserLocation);
try {
// launch the browser
Runtime.getRuntime().exec(browserLocation + " " + getSearchURL(searchTerm));
} catch (IOException e) {
e.printStackTrace();
}
}
/*
* Replace the substitutable variable in the search URL with search term.
* Encode the URL for special characters. The parsed URL will be returned.
*
* @param String search terms(s) @return String parser URL string
*/
public static String getSearchURL(String searchTerm) {
String searchURL = Activator.getDefault().getPreferenceStore()
.getString(PreferenceConstants.SearchEngineURL);
searchURL = searchURL.replaceAll("<SUB>", encodeSearchTerms(searchTerm));
return searchURL;
}
/*
* Encode the passed string.This function can be modifed further to address
* various URL encoded characters.
*
* @param String URL string @return String encode special characters
*/
private static String encodeSearchTerms(String urlString) {
return urlString.replace(' ', '+');
}
|
 |
Implement a search icon in the toolbar
This section walks you through the steps required to display a search icon on the toolbar. At the end of
this section, you should achieve the following change in the Sametime GUI:
Figure 12: Search icon in the toolbar
Plug-in extension to view
Use the Eclipse IDE to extend "org.eclipse.ui.viewActions". In Figure 13, the information required to create an action that contributes to the view is specified:
Figure 13: Extensions view
This is the extension populated in plugin.xml file:
Listing 5: Code snippet for plugin.xml changes
<extension point="org.eclipse.ui.viewActions">
<viewContribution id="com.developerworks.sametime.search.viewContribution1"
targetID="com.ibm.collaboration.realtime.imhub" >
<action
class="com.developerworks.sametime.search.SearchViewActionDelegate"
enablesFor="0"
icon="images/searchI.gif"
id="com.developerworks.sametime.search.action1"
label="IBM Omnifind Yahoo! search"
style="push"
toolbarPath="buddylist/additions"
tooltip="IBM Omnifind Yahoo! search"/>
</viewContribution>
</extension>
|
You should refer to the Sametime SDK for more details on the various attributes of the XML fragments shown above.
Search view action delegate
It was necessary to implement an action delegate that would be triggered when the Search icon is clicked. The action delegate
implements BuddyListDelegate, which is part of the Sametime distribution. This is the run() method that
launches an external browser with no default search term:
Listing 6: Code snippet for search view delegation
public class SearchViewActionDelegate implements BuddyListDelegate {
public void run(ISelection arg0) {
// TODO Auto-generated method stub
SearchUtilities.showSearches("");
}
}
|
This is the OmniFind search interface launched by the search action delegate:
Figure 14: IBM OmniFind Yahoo! search interface
Implement the Search icon in the Chat view
Since you spend more time in the Chat window than the in main Sametime view, it is very useful to
have the Search icon displayed on the toolbar of the Chat window, too. At the end of this section, you should
see the following change to the Chat window:
Figure 15: Search icon in Chat window
Plug-in extension to Chat window
Use the eclipse IDE to define the extension to a Sametime plug-in called "com.ibm.collaboration.realtime.chatwindow.chatArea"
and "com.ibm.collaboration.realtime.chatwindow.chatAction". The former extension addresses the implementation
required to display the Search icon in the chat windows, and the latter addresses the implementation that displays
the search interface through an internal browser. The internal browser uses the Chat view as the display area. You can display
the search interface in an external browser, but this way exploits the enchanced features of Eclipse packages.
Please refer to the sametime SDK for details on chatArea and chatAction plug-ins.
Figure 16 displays the search interface in an internal browser. Again, since we have not specified any search term, the search interface is displayed with no search term:
Figure 16: Search interface in an internal browser
Figure 17 shows the Eclipse IDE and the new plug-in definitions:
Figure 17: Extensions view
These are the additions to the plugin.xml file:
Listing 7: Code snippet for chat extensions in plugin.xml
<extension point="com.ibm.collaboration.realtime.chatwindow.chatArea">
<chatArea
class="com.developerworks.sametime.search.SearchChatWindowExtension1"
enabled="false"
id="com.developerworks.sametime.search.searchchatArea1"
label="IBM Omnifind Yahoo! search"/>
</extension>
<extension point="com.ibm.collaboration.realtime.chatwindow.chatAction">
<chatAction
class="com.developerworks.sametime.search.SearchChatActionDelegate2"
displayName="IBM Omnifind Yahoo! search"
id="com.developerworks.sametime.search.chatAction2"
image="images/searchI.gif"
path="buddy/end"
showsFor="both"
tooltipText="Click to show search interface in tabbed area"
type="buddy"/>
</extension>
|
Chat action delegates
These are the classes that implement the delegates for Chat action and Chat window:
Listing 8: Code snippet for chat action delegate
public class SearchChatActionDelegate2 extends ChatWindowAction {
public SearchChatActionDelegate2() { }
public void run() {
// Show all ChatArea extensions with getChatWindowHandler().addChatAreas()
// or just one as shown below
getChatWindowHandler().enableChatArea
("com.developerworks.sametime.search.searchchatArea1");
}
}
|
Listing 9: Code snippet for Chat window extension
public class SearchChatWindowExtension1 extends ViewPart implements ChatWindowExtension {
ChatWindowHandler handler;
public SearchChatWindowExtension1() {}
public void createPartControl(Composite parent) {
Browser browser = new Browser(parent, SWT.NONE);
browser.setUrl(SearchUtilities.getSearchURL(""));
}
public void setFocus() {}
public ChatWindowHandler getChatWindowHandler() {
return handler;
}
public void setChatWindowHandler(ChatWindowHandler handler) {
this.handler = handler;
}
}
|
Implement the Search icon in pop-up menu
With all the publications on the internet, sometimes it's very helpful to discover a person's information in a corporate index.
The index could be from blogs or developerWorks articles, or from another source. A username or an email ID are appropriate search terms to
query blog-based indexes. This section demonstrates the search action to be displayed as a pop-up menu.
This pop-up menu is launched when you select a person's entry (or several people's entries) and right-click. The demonstrated code
extracts the email IDs from the selected chat buddies and populates them as search terms in the URL launched
in a external browser.
Figure 18 displays the search action as part of the pop-up menu:
Figure 18: Search as pop-up menu item
Plug-in extension to pop-up menus
Use the Eclipse IDE to extend "org.eclipse.ui.popupMenus". In Figure 19, I specified all of the information required to create an action that is specified as an object contribution to a Sametime object, called "com.ibm.collaboration.realtime.livenames.PersonSelection". PersonSelection represents a chat buddy instance in Sametime. Please refer to the Sametime SDK for more details.
Figure 19 shows the Eclipse IDE with the plug-in extension:
Figure 19: Extensions view
Here are the suitable additions to plugin.xml:
Listing 10: Code snippet for pop-up menu items in plugin.xml
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="false"
id="com.developerworks.sametime.search.personselection"
objectClass="com.ibm.collaboration.realtime.livenames.PersonSelection">
<action
class="com.developerworks.sametime.search.SearchDelegate"
enablesFor="+"
id="com.developerworks.sametime.search.SearchDelegate"
label="IBM Omnifind Yahoo! search"
style="push"/>
</objectContribution>
</extension>
|
Action delegates to pop-up menu
Here is the class invoked when you select the Search menu:
Listing 11: Code snippet for search delegate
public class SearchDelegate extends LiveNameActionDelegate{
public void run(IAction arg0) {
Person[] persons = getSelectedPersons();
String searchTerm = "";
for(int i=0; i<persons.length; ++i){
Person p = persons[i];
searchTerm += " " + p.getContactId();
}
if (searchTerm != null) {
SearchUtilities.showSearches(searchTerm);
}
}
}
|
In the code snippet above, the email IDs are extracted from selected persons and fed to the search utility
that launches the external browser. You can modify this code to extract names instead of email IDs.
Deploy the plug-ins
Download com.developerworks.sametime.search.deploy.zip from the Downloads section and move it to the plugins directory of your Sametime installation root. For Microsoft Windows®, it should be c:\program files\IBM\sametime\plugins. If you don't intend to use all of the three plug-ins introduced in this article, you have to modify the plugin.xml file (bundled in the archive) and comment out the extensions you do not want your Sametime client to inherent. Once you modify the packaged plugin.xml file, you have to repackage the changes before moving it into the Sametime plug-ins directory.
Source code
The sample source code for the plug-ins is packaged in com.developerworks.sametime.search.source.zip in the Downloads section. Once you unzip this source code, you can use the Eclipse IDE to review and modify the sample source.
Summary
In this article, the idea is to integrate search interfaces into Eclipse-based applications. We've examined the effects of customized plug-ins on various display areas of the Sametime connect client, and learned how to make these changes to your system.
Downloads | Description | Name | Size | Download method |
|---|
| article files | com.developerworks.sametime.search.source.zip | 17805B | HTTP |
|---|
| article files | com.developerworks.sametime.search.deploy.zip | 13045B | HTTP |
|---|
Resources Learn
Get products and technologies
Discuss
About the author  | 
|  | Srinivas Varma Chitiveli is a software engineer in the IBM software group. He has been involved with IBM products that deal with technologies related to issuing digital certificates for secure e-business transactions, content management, and searching information across distributed data sources. |
Rate this page
|