use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class OutlookTransformer method getAllContactFolders.
public 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
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();
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 de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class OutlookTransformer method getCallerListFromSingleContact.
private ICallerList getCallerListFromSingleContact(Dispatch contact) throws ComFailException {
ICallerList callers = getRuntime().getCallerFactory().createCallerList();
try {
Properties config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperties(NAMESPACE);
if (config.getProperty("split", "true").equalsIgnoreCase("true")) {
callers.add(createPrivateCallerList(contact));
callers.add(createBusinessCallerList(contact));
} else {
ICaller c = null;
ICallerList cl = createPrivateCallerList(contact);
if (cl.size() > 0) {
if (cl.size() > 1) {
c = cl.get(0);
for (int i = 0; i < cl.size(); i++) {
((IMultiPhoneCaller) c).getPhonenumbers().addAll(((IMultiPhoneCaller) cl.get(i)).getPhonenumbers());
}
} else {
c = cl.get(0);
}
}
cl = createBusinessCallerList(contact);
if (cl.size() > 0) {
if (cl.size() > 1) {
if (c != null) {
for (int i = 0; i < cl.size(); i++) {
((IMultiPhoneCaller) c).getPhonenumbers().addAll(((IMultiPhoneCaller) cl.get(i)).getPhonenumbers());
}
} else {
c = cl.get(0);
for (int i = 0; i < cl.size(); i++) {
((IMultiPhoneCaller) c).getPhonenumbers().addAll(((IMultiPhoneCaller) cl.get(i)).getPhonenumbers());
}
}
} else {
if (c != null) {
for (int i = 0; i < cl.size(); i++) {
((IMultiPhoneCaller) c).getPhonenumbers().addAll(((IMultiPhoneCaller) cl.get(i)).getPhonenumbers());
}
} else {
c = cl.get(0);
}
}
}
if (c != null)
callers.add(c);
}
} 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.toString() + ", " + ex.getMessage());
} catch (Exception ex) {
this.m_logger.warning(ex.getMessage() + ", " + ex.toString());
} finally {
// added 2006/02/05: clean outlook references
if (contact != null)
contact.safeRelease();
}
return callers;
}
use of de.janrufmonitor.exception.Message 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 de.janrufmonitor.exception.Message 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 de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.
the class ConfigurationCommand method asyncExecute.
private void asyncExecute() {
this.m_pages = new ArrayList();
try {
Display display = DisplayManager.getDefaultDisplay();
// create a PreferenceManager
PreferenceManager mgr = new PreferenceManager();
// assign nodes to PreferenceManager
this.createPreferenceNodes(mgr);
// create a PreferenceDialog
Shell s = new Shell(display);
PreferenceDialog.setDefaultImage(SWTImageManager.getInstance(this.getRuntime()).get(IJAMConst.IMAGE_KEY_PIM_ICON));
PreferenceDialog dlg = new PreferenceDialog(s, mgr);
dlg.setPreferenceStore(new PreferenceConfigManagerStore());
DisplayManager.forceForeground(s);
dlg.open();
} catch (Throwable t) {
t.printStackTrace();
this.m_logger.log(Level.SEVERE, t.getMessage(), t);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, this.getNamespace(), t.toString().toLowerCase(), t));
} finally {
this.isExecuting = false;
this.m_pages.clear();
}
}
Aggregations