Getting started
This page presents an introduction to the Java Outlook Connector product. You'll learn the basics on how to configure and use the library with your Java application.Installation
You need three files to use the Java Outlook Connector with your application. The downloaded package contains a folder named « lib ». This folder contains the necessary files described in detail below:-
These files contains all Java classes.
You have to add the JAR files to your application's CLASSPATH. The CLASSPATH is the path that the Java runtime environment (JRE) searches for classes and other resource files.
There are multiple ways to setup the CLASSPATH depending on your development environment. For example, you can specify the path to the JAR files in the command line when launching your application using the « -cp » option:
> java -cp lib\joc-v3.0.4-eval.jar;lib\moyocore.jar ...For more information about the CLASSPATH, have a look at Sun's documentation: http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html
-
This file contains all native code necessary to access the Outlook application. This file has to be accessible by the Java runtime environment (JRE) in order to load the library. By default, native libraries are searched in locations defined by the « java.library.path » system property. You can define this property when launching your Java application like this:
> java -Djava.library.path=./lib ...You can also define the path to this DLL file at runtime using Java code: Use the static method Outlook.setLibraryPath(String path) before creating an instance of the Outlook object.
Using the library
To follow this guide, please have a look at the minimal sample application: HelloOutlook.java. The starting point is creating an Outlook object:
// Creating the Outlook application object
Outlook outlookApplication = new Outlook();
Once you created the Outlook object, you have access to Outlook's folders, items and data. As you can see in the HelloOutlook.java example, to get the information about the currently logged-on user, the method Outlook.getCurrentUser() is used.Outlook outlookApplication = new Outlook();
Look at the JavaDoc for the listing of all Outlook object's methods.
Do not forget to call the method Outlook.dispose() when you're done using all Outlook objects. This is necessary to release native resources used by the library:
// Dispose the library
outlookApplication.dispose(); |
Now, let's have a look at a more complex sample application: DisplayContacts.java. This example displays all Outlook contacts stored in the default contacts' folder.
First of all, the default contacts' folder have to be loaded using the method Outlook.getDefaultFolder(FolderType) :
// Get the default contacts folder
OutlookFolder folder = outlookApplication.getDefaultFolder(FolderType.CONTACTS);
If the folder doesn't exist or some error occurs a ComponentObjectModelException is thrown. Otherwise, we can load and iterate through all the items in the contacts folder :OutlookFolder folder = outlookApplication.getDefaultFolder(FolderType.CONTACTS);
// Get the folder's items collection
ItemsCollection items = folder.getItems();
// Display info for all contacts in the folder
for(ItemsIterator it = items.iterator(); it.hasNext();)
{
OutlookItem item = it.nextItem();
// Check the item is a contact
if(item != null && item.getType().isContact())
{
OutlookContact contact = (OutlookContact) item;
System.out.println("First name: " + contact.getFirstName());
System.out.println("Last name: " + contact.getLastName());
System.out.println("Company: " + contact.getCompanyName());
System.out.println();
}
}
Items stored in an Outlook folder are always accessed through the ItemsCollection object. The ItemsCollection object allows you to:
ItemsCollection items = folder.getItems();
// Display info for all contacts in the folder
for(ItemsIterator it = items.iterator(); it.hasNext();)
{
OutlookItem item = it.nextItem();
// Check the item is a contact
if(item != null && item.getType().isContact())
{
OutlookContact contact = (OutlookContact) item;
System.out.println("First name: " + contact.getFirstName());
System.out.println("Last name: " + contact.getLastName());
System.out.println("Company: " + contact.getCompanyName());
System.out.println();
}
}
For more information on how to perform each of these tasks, look at the example applications' source code.
As you can see when iterating through all the items in the DisplayContacts.java example, items contained in the collection can be of any type or even null in case of an unknown type. For this reason the following test is necessary for each item to ensure it is a correct Contact item:
// Check the item is a contact
if(item != null && item.getType().isContact()) |
|