|
/*
This example is adapted from Microsoft Knowledge Base Article - 186753
HOWTO: Check Someone Else's Schedule for Free/Busy Information
http://support.microsoft.com/?id=186753
*/
import com.intrinsyc.cdo.*;
import com.linar.jintegra.Cleaner;
public class GetFreeBusy{
// Modify the following variables based on your specific Exchange setup
static final String domain = "DOMAIN"; //make sure it's all capitalized
static final String user = "username"; //username of Exchange super user
static final String password = "password"; //password of Exchange super user
static final String mailbox = "mailbox"; //mailbox name of Exchange super user
static final String CDOmachine = "000.000.000.000"; //IP address of the CDO machine
static final String server = "000.000.000.000"; // IP address of Exchange server
static final String recipient1 = "joedoe"; // alias/login name of recipient
public static void main (String[] arg ){
try{
// authenticate to Windows
com.linar.jintegra.AuthInfo.setDefault(domain, user, password);
// create a Session in the CDOmachine
Session session = new Session(CDOmachine);
// logon to the Exchange Server
session.logon(null, null, new Boolean(false), new Boolean(true),
new Boolean(false), new Boolean(false),
server + "\n" + mailbox);
// Create a message in Inbox
Folder inbox = new FolderProxy(session.getInbox());
Messages messages = new MessagesProxy(inbox.getMessages());
Message message = new MessageProxy(messages.add("Subject", "text", null, null));
// Set the recipient(s) of the message
Recipients recipients = new RecipientsProxy(message.getRecipients());
Recipient oneRecipient = new RecipientProxy(
recipients.add(recipient1, null, null, null));
oneRecipient.resolve(null);
AddressEntry address = new AddressEntryProxy(oneRecipient.getAddressEntry());
//Specify the date/time of the beginning of the first time slot.
String startTime="2006/05/25 8:00:00 AM";
//Specify the date/time of the end of the last time slot.
String endTime="2006/05/25 10:00:00 AM";
// Specify the length of each time slot in minutes.
// If Interval parameter is less than 1, GetFreeBusy returns
// CdoE_INVALID_PARAMETER.
int interval = 60;
// Interval parameter determines the number of time slots.
// For this example, Interval is set to 60 minutes. Therefore,
// here will be 2 time slots between the StartTime and the EndTime.
// the first time slot is between 8:00:00-9:00:00 AM.
// The second time slot is between 9:00:00-10:00:00 AM.
// Get the free/busy status of recipient at that specified time
String freeBusy = address.getFreeBusy(
startTime, endTime, new Integer(interval)).toString();
int freeBusyValue = (new Integer(freeBusy)).intValue();
// Since there are two time slots, the GetFreeBusy method returns a
// string with length 2. For example, FreeBusy = "21" indicates that
// there is a tentative commitment during the time slot 1. Also,
// there is a confirmed commitment during the time slot 2.
System.out.println("FreeBusy = " + freeBusy);
String msg= "";
String tempMsg;
Integer j;
for (int i = 0; i < freeBusy.length(); i++){
j = new Integer(String.valueOf(freeBusy.charAt(i)));
switch(j.intValue()){
case 0:
tempMsg = "Available for meetings/appointments " +
"during the time slot " + i + "\n";
msg = msg + tempMsg;
break;
case 1:
tempMsg = "At least one tentative commitment " +
"during the time slot " + i + "\n";
msg = msg + tempMsg;
break;
case 2:
tempMsg = "At least one confirmed commitment " +
"during the time slot " + i + "\n";
msg = msg + tempMsg;
break;
case 3:
tempMsg = "Out-of-office (OOF) for at least part " +
"of the time slot " + i + "\n";
msg = msg + tempMsg;
break;
}
}
System.out.println(recipient1 + "'s availability : \n" + msg);
// logoff from the session
session.logoff();
} catch (Exception ex) {
ex.printStackTrace();
}finally{
// release all COM references
Cleaner.releaseAll();
}
}
}
|
|