use of com.jacob.com.ComFailException in project janrufmonitor by tbrandt77.
the class OutlookTransformer method getCallerListFromAllContacts.
public ICallerList getCallerListFromAllContacts() {
PropagationFactory.getInstance().fire(new Message(Message.INFO, OutlookContactManager.NAMESPACE, "sync", new Exception("Sync contact folder with MS Outlook...")));
ICallerList callers = getRuntime().getCallerFactory().createCallerList();
long outlookItemsCount = 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(getConfiguredContactFolders());
String folder = null;
for (int i = 0, j = subfolders.size(); i < j; i++) {
folder = (String) subfolders.get(i);
if (folder.trim().length() == 0) {
items = Dispatch.get(contactsFolder, "Items").toDispatch();
} else {
// found subfolder
try {
contactsSubFolder = Dispatch.call(contactsFolder, "Folders", new Variant(folder)).toDispatch();
items = Dispatch.get(contactsSubFolder, "Items").toDispatch();
} catch (ComFailException ex) {
continue;
}
}
// items = Dispatch.get(contactsFolder, "Items").toDispatch();
Variant item = Dispatch.call(items, "GetFirst");
ICallerList cl = null;
while ((item != null) && (!item.isNull())) {
try {
outlookItemsCount++;
Dispatch contact = item.toDispatch();
cl = getCallerListFromSingleContact(contact);
if (cl.size() > 0) {
if (folder.trim().length() > 0) {
IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, folder);
for (int l = 0, m = cl.size(); l < m; l++) {
cl.get(l).setAttribute(category);
}
}
callers.add(cl);
}
if (contact != null)
contact.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());
}
if (item != null)
item.safeRelease();
item = Dispatch.call(items, "GetNext");
}
}
} 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();
}
this.m_logger.info(outlookItemsCount + " Outlook contacts found and " + callers.size() + " numbers available.");
return callers;
}
use of com.jacob.com.ComFailException in project janrufmonitor by tbrandt77.
the class OutlookTransformer method getContactCount.
public int getContactCount(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();
} 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.ComFailException in project janrufmonitor by tbrandt77.
the class OutlookTransformer method setPictureAttribute.
private void setPictureAttribute(ICaller outlookCaller, Dispatch contact) {
try {
if (Dispatch.get(contact, "HasPicture").getBoolean()) {
String imagepath = MSO_IMAGE_CACHE_PATH + outlookCaller.getUUID() + ".jpg";
if (!new File(imagepath).exists()) {
Dispatch items = Dispatch.get(contact, "Attachments").toDispatch();
int count = Integer.valueOf(Dispatch.get(items, "Count").toString()).intValue();
if (count > 1)
this.m_logger.info("Found " + count + " attachments for outlook contact " + outlookCaller.toString());
for (int i = 1; i <= count; i++) {
Dispatch item = Dispatch.call(items, "Item", new Integer(i)).toDispatch();
int type = Integer.valueOf(Dispatch.get(item, "Type").toString()).intValue();
// type 1 olAttachmentType = olByValue
if (type == 1) {
try {
String outlookFilename = Dispatch.get(item, "FileName").toString();
if (outlookFilename != null && (outlookFilename.startsWith("ContactPicture") || outlookFilename.startsWith("ContactPhoto"))) {
// imagepath = imagepath.substring(0, imagepath.length()-4) + (i>1? Integer.toString(i) : "") + ".jpg";
Dispatch.call(item, "SaveAsFile", new String(imagepath));
}
} catch (ComFailException ex) {
this.m_logger.warning("Could not get FileName attribute: " + ex.getMessage() + ", " + ex.getSource());
}
}
}
}
IAttribute img = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(imagepath));
outlookCaller.setAttribute(img);
}
} catch (ComFailException ex) {
this.m_logger.warning(ex.getMessage() + ", " + ex.getSource());
}
}
use of com.jacob.com.ComFailException in project janrufmonitor by tbrandt77.
the class OutlookContactProxy method createContact.
public synchronized void createContact(ICaller c) 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();
String folder = this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY));
items = this.getItemsOfFolder(contactsFolder, folder, true);
if (items == null)
throw new OutlookContactProxyException("Error in Application Outlook. Folder <" + folder + "> could not be created");
Dispatch newContact = Dispatch.call(items, "Add").toDispatch();
boolean business = (c.getAttribute("outlook.business") != null && c.getAttribute("outlook.business").getValue().equalsIgnoreCase("true") ? true : false);
this.setContactData(newContact, c, business);
if (newContact != null)
newContact.safeRelease();
if (this.m_logger.isLoggable(Level.INFO)) {
this.m_logger.info("Added new outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + ": " + c);
}
} catch (ComFailException ex) {
throw new OutlookContactProxyException("Error in Application Outlook.", ex);
} 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();
}
}
use of com.jacob.com.ComFailException 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;
}
Aggregations