use of com.jacob.com.Variant in project janrufmonitor by tbrandt77.
the class OutlookContactProxy method countContacts.
public synchronized int countContacts(String folder) {
int count = 0;
ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
Dispatch mapiNS = null;
Dispatch contactsFolder = null;
Dispatch contactsSubFolder = null;
Dispatch items = null;
try {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("created Outlook.Application dispatch");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook version: " + Dispatch.get(outlook.getObject(), "Version"));
mapiNS = outlook.getProperty("Session").toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook namespace: " + mapiNS);
Variant contactsVariant = new Variant(10);
contactsFolder = Dispatch.call(mapiNS, "GetDefaultFolder", contactsVariant).toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook folder: " + contactsFolder);
// searching subfolders
this.m_logger.info("Includig outlook contact subfolders");
contactsSubFolder = Dispatch.call(contactsFolder, "Folders", new Variant(folder)).toDispatch();
items = Dispatch.get(contactsSubFolder, "Items").toDispatch();
count = Dispatch.get(items, "Count").getInt();
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("There are " + count + " outlook contacts in folder " + (folder.length() > 0 ? folder : "<root>"));
}
} catch (ComFailException ex) {
this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
this.m_logger.log(Level.SEVERE, ex.toString(), ex);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
} else
this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
} catch (Exception ex) {
this.m_logger.warning(ex.getMessage() + ", " + ex.toString());
} finally {
// added 2006/02/05: clean outlook references
if (items != null)
items.safeRelease();
if (contactsFolder != null)
contactsFolder.safeRelease();
if (contactsSubFolder != null)
contactsSubFolder.safeRelease();
if (mapiNS != null)
mapiNS.safeRelease();
if (outlook != null)
outlook.safeRelease();
}
return count;
}
use of com.jacob.com.Variant in project janrufmonitor by tbrandt77.
the class OutlookContactProxy method countAllContact.
private int countAllContact() throws OutlookContactProxyException {
int count = 0;
ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
Dispatch mapiNS = null;
Dispatch contactsFolder = null;
Dispatch contactsSubFolder = null;
Dispatch items = null;
try {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("created Outlook.Application dispatch");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook version: " + Dispatch.get(outlook.getObject(), "Version"));
mapiNS = outlook.getProperty("Session").toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook namespace: " + mapiNS);
Variant contactsVariant = new Variant(10);
contactsFolder = Dispatch.call(mapiNS, "GetDefaultFolder", contactsVariant).toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook folder: " + contactsFolder);
contactsVariant.safeRelease();
// getting configured subfolders
List subfolders = new ArrayList();
subfolders.add("");
subfolders.addAll(getAllContactFolders());
String folder = null;
for (int i = 0, j = subfolders.size(); i < j; i++) {
folder = (String) subfolders.get(i);
items = this.getItemsOfFolder(contactsFolder, folder, false);
if (items == null)
continue;
count += Dispatch.get(items, "Count").getInt();
}
} catch (ComFailException ex) {
this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
this.m_logger.log(Level.SEVERE, ex.toString(), ex);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
} else
this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
} catch (Exception ex) {
throw new OutlookContactProxyException("Error in Application Outlook.", ex);
} finally {
// added 2006/02/05: clean outlook references
if (items != null)
items.safeRelease();
if (contactsFolder != null)
contactsFolder.safeRelease();
if (contactsSubFolder != null)
contactsSubFolder.safeRelease();
if (mapiNS != null)
mapiNS.safeRelease();
if (outlook != null)
outlook.safeRelease();
}
return count;
}
use of com.jacob.com.Variant in project janrufmonitor by tbrandt77.
the class OutlookContactProxy method getAllContactFolders.
public synchronized List getAllContactFolders() {
List subfolders = new ArrayList();
ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
Dispatch mapiNS = null;
Dispatch contactsFolder = null;
Dispatch contactsSubFolder = null;
Dispatch items = null;
try {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("created Outlook.Application dispatch");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook version: " + Dispatch.get(outlook.getObject(), "Version"));
mapiNS = outlook.getProperty("Session").toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook namespace: " + mapiNS);
Variant contactsVariant = new Variant(10);
contactsFolder = Dispatch.call(mapiNS, "GetDefaultFolder", contactsVariant).toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook folder: " + contactsFolder);
// searching subfolders
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Includig outlook contact subfolders");
items = Dispatch.get(contactsFolder, "Folders").toDispatch();
Variant itemf = Dispatch.call(items, "GetFirst");
Dispatch f = null;
while ((itemf != null) && (!itemf.isNull())) {
f = itemf.toDispatch();
subfolders.add(Dispatch.get(f, "Name").toString());
itemf = Dispatch.call(items, "GetNext");
}
if (f != null)
f.safeRelease();
if (itemf != null)
itemf.safeRelease();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("List of including outlook contact subfolders: " + subfolders);
contactsVariant.safeRelease();
} catch (ComFailException ex) {
this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
this.m_logger.log(Level.SEVERE, ex.toString(), ex);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
} else
this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
} catch (Exception ex) {
this.m_logger.warning(ex.getMessage() + ", " + ex.toString());
} finally {
// added 2006/02/05: clean outlook references
if (items != null)
items.safeRelease();
if (contactsFolder != null)
contactsFolder.safeRelease();
if (contactsSubFolder != null)
contactsSubFolder.safeRelease();
if (mapiNS != null)
mapiNS.safeRelease();
if (outlook != null)
outlook.safeRelease();
}
return subfolders;
}
use of com.jacob.com.Variant in project janrufmonitor by tbrandt77.
the class OutlookContactProxy method getItemsOfFolder.
private Dispatch getItemsOfFolder(Dispatch rootContactFolder, String folder, boolean doCreate) {
Dispatch items = null;
Dispatch subFolder = null;
if (folder.trim().length() == 0) {
items = Dispatch.get(rootContactFolder, "Items").toDispatch();
} else {
// check subfolder
try {
subFolder = Dispatch.call(rootContactFolder, "Folders", new Variant(folder)).toDispatch();
items = Dispatch.get(subFolder, "Items").toDispatch();
} catch (ComFailException ex) {
if (doCreate) {
// sub-folder does not exist, create one
try {
subFolder = Dispatch.call(rootContactFolder, "Folders").toDispatch();
subFolder = Dispatch.call(subFolder, "Add", new Variant(folder)).toDispatch();
items = Dispatch.get(subFolder, "Items").toDispatch();
} catch (ComFailException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
}
return items;
}
use of com.jacob.com.Variant in project janrufmonitor by tbrandt77.
the class OutlookContactProxy method existsContact.
public synchronized boolean existsContact(String uuid) throws OutlookContactProxyException {
ActiveXComponent outlook = new ActiveXComponent("Outlook.Application");
Dispatch mapiNS = null;
Dispatch contactsFolder = null;
Dispatch contactsSubFolder = null;
Dispatch items = null;
try {
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("created Outlook.Application dispatch");
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook version: " + Dispatch.get(outlook.getObject(), "Version"));
mapiNS = outlook.getProperty("Session").toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook namespace: " + mapiNS);
Variant contactsVariant = new Variant(10);
contactsFolder = Dispatch.call(mapiNS, "GetDefaultFolder", contactsVariant).toDispatch();
if (this.m_logger.isLoggable(Level.INFO))
this.m_logger.info("Microsoft Outlook folder: " + contactsFolder);
contactsVariant.safeRelease();
// getting configured subfolders
List subfolders = new ArrayList();
subfolders.add("");
subfolders.addAll(getAllContactFolders());
String folder = null;
for (int i = 0, j = subfolders.size(); i < j; i++) {
folder = (String) subfolders.get(i);
items = this.getItemsOfFolder(contactsFolder, folder, false);
if (items == null)
continue;
Dispatch aContact = Dispatch.call(items, "Find", new Variant("[User1]='" + uuid + "'")).toDispatch();
if (aContact != null && aContact.m_pDispatch > 0) {
return true;
}
}
} catch (ComFailException ex) {
this.m_logger.warning("1 item (e.g. distribution list) was ignored on loading.");
if (ex.toString().indexOf("Can't get object clsid from progid") > -1) {
this.m_logger.log(Level.SEVERE, ex.toString(), ex);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "olstarterror", ex));
} else
this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
} catch (Exception ex) {
throw new OutlookContactProxyException("Error in Application Outlook.", ex);
} finally {
// added 2006/02/05: clean outlook references
if (items != null)
items.safeRelease();
if (contactsFolder != null)
contactsFolder.safeRelease();
if (contactsSubFolder != null)
contactsSubFolder.safeRelease();
if (mapiNS != null)
mapiNS.safeRelease();
if (outlook != null)
outlook.safeRelease();
}
return false;
}
Aggregations