Search in sources :

Example 11 with ComFailException

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;
}
Also used : Message(de.janrufmonitor.exception.Message) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) 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)

Example 12 with ComFailException

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;
}
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) ComFailException(com.jacob.com.ComFailException)

Example 13 with ComFailException

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());
    }
}
Also used : IAttribute(de.janrufmonitor.framework.IAttribute) Dispatch(com.jacob.com.Dispatch) File(java.io.File) ComFailException(com.jacob.com.ComFailException)

Example 14 with ComFailException

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();
    }
}
Also used : Variant(com.jacob.com.Variant) 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 15 with ComFailException

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;
}
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)

Aggregations

ComFailException (com.jacob.com.ComFailException)22 Dispatch (com.jacob.com.Dispatch)19 Variant (com.jacob.com.Variant)17 ActiveXComponent (com.jacob.activeX.ActiveXComponent)16 Message (de.janrufmonitor.exception.Message)15 ICallerList (de.janrufmonitor.framework.ICallerList)15 ZipArchiveException (de.janrufmonitor.repository.zip.ZipArchiveException)14 SQLException (java.sql.SQLException)14 ArrayList (java.util.ArrayList)14 List (java.util.List)14 IAttribute (de.janrufmonitor.framework.IAttribute)10 ICaller (de.janrufmonitor.framework.ICaller)3 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)3 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)3 Properties (java.util.Properties)3 File (java.io.File)2 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)1 DefaultOutlookMapping (de.janrufmonitor.repository.mapping.DefaultOutlookMapping)1 UUID (de.janrufmonitor.util.uuid.UUID)1 SimpleDateFormat (java.text.SimpleDateFormat)1