Search in sources :

Example 36 with Message

use of de.janrufmonitor.exception.Message 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;
}
Also used : Variant(com.jacob.com.Variant) Message(de.janrufmonitor.exception.Message) ActiveXComponent(com.jacob.activeX.ActiveXComponent) Dispatch(com.jacob.com.Dispatch) ComFailException(com.jacob.com.ComFailException) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException)

Example 37 with Message

use of de.janrufmonitor.exception.Message 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;
}
Also used : Variant(com.jacob.com.Variant) Message(de.janrufmonitor.exception.Message) ActiveXComponent(com.jacob.activeX.ActiveXComponent) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException)

Example 38 with Message

use of de.janrufmonitor.exception.Message 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;
}
Also used : Variant(com.jacob.com.Variant) Message(de.janrufmonitor.exception.Message) ActiveXComponent(com.jacob.activeX.ActiveXComponent) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException)

Example 39 with Message

use of de.janrufmonitor.exception.Message 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;
}
Also used : Variant(com.jacob.com.Variant) Message(de.janrufmonitor.exception.Message) ActiveXComponent(com.jacob.activeX.ActiveXComponent) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException)

Example 40 with Message

use of de.janrufmonitor.exception.Message in project janrufmonitor by tbrandt77.

the class OutlookContactProxy method getContactsByAreaCode.

public synchronized ICallerList getContactsByAreaCode(String code) throws OutlookContactProxyException {
    ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    long outlookItemsCount = 0;
    this.m_current = 0;
    this.m_total = this.countAllContact();
    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;
            ICallerList cl = null;
            Dispatch aContact = Dispatch.call(items, "Find", new Variant("[User2]='" + code + "'")).toDispatch();
            if (aContact != null && aContact.m_pDispatch > 0) {
                do {
                    outlookItemsCount++;
                    this.m_current++;
                    // check UUID in User1 attribute
                    this.checkContactUUID(aContact);
                    cl = getCallerListFromSingleContact(aContact);
                    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 (aContact != null)
                        aContact.safeRelease();
                    aContact = Dispatch.call(items, "FindNext").toDispatch();
                } while (aContact != null && aContact.m_pDispatch > 0);
            }
        }
    } 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();
    }
    this.m_logger.info(outlookItemsCount + " Outlook contacts found and " + callers.size() + " numbers available.");
    return callers;
}
Also used : Message(de.janrufmonitor.exception.Message) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) ZipArchiveException(de.janrufmonitor.repository.zip.ZipArchiveException) SQLException(java.sql.SQLException) ComFailException(com.jacob.com.ComFailException) Variant(com.jacob.com.Variant) ICallerList(de.janrufmonitor.framework.ICallerList) ActiveXComponent(com.jacob.activeX.ActiveXComponent) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException)

Aggregations

Message (de.janrufmonitor.exception.Message)64 List (java.util.List)25 ICallerList (de.janrufmonitor.framework.ICallerList)20 ArrayList (java.util.ArrayList)20 IOException (java.io.IOException)19 Shell (org.eclipse.swt.widgets.Shell)19 ComFailException (com.jacob.com.ComFailException)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)15 Properties (java.util.Properties)15 ZipArchiveException (de.janrufmonitor.repository.zip.ZipArchiveException)14 ActiveXComponent (com.jacob.activeX.ActiveXComponent)13 Dispatch (com.jacob.com.Dispatch)13 Variant (com.jacob.com.Variant)13 SQLException (java.sql.SQLException)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)12 IAttribute (de.janrufmonitor.framework.IAttribute)11 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)11 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)11 ICaller (de.janrufmonitor.framework.ICaller)9