Search in sources :

Example 11 with Dispatch

use of com.jacob.com.Dispatch in project yyl_example by Relucent.

the class JacobWordEngine method addRow.

/**
   * 增加一行
   * 
   * @param tableIndex
   *        word文档中的第N张表(从1开始)
   */
public void addRow(int tableIndex) {
    Dispatch tables = Dispatch.get(doc, "Tables").toDispatch();
    // 要填充的表格
    Dispatch table = Dispatch.call(tables, "Item", new Variant(tableIndex)).toDispatch();
    // 表格的所有行
    Dispatch rows = Dispatch.get(table, "Rows").toDispatch();
    Dispatch.call(rows, "Add");
}
Also used : Variant(com.jacob.com.Variant) Dispatch(com.jacob.com.Dispatch)

Example 12 with Dispatch

use of com.jacob.com.Dispatch in project janrufmonitor by tbrandt77.

the class OutlookMappingManager method setPictureAttribute.

@SuppressWarnings("deprecation")
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 = Dispatch.get(items, "Count").toInt();
                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 = Dispatch.get(item, "Type").toInt();
                    // type 1 olAttachmentType = olByValue
                    if (type == 1) {
                        try {
                            String outlookFilename = Dispatch.get(item, "FileName").toString();
                            if (outlookFilename != null && (outlookFilename.startsWith("ContactPicture") || outlookFilename.startsWith("ContactPhoto"))) {
                                Dispatch.call(item, "SaveAsFile", new String(imagepath));
                            }
                        } catch (ComFailException ex) {
                            this.m_logger.warning("Could not get FileName attribute: " + ex.getMessage() + ", " + ex.getSource());
                        }
                    }
                    if (item != null)
                        item.safeRelease();
                }
                if (items != null)
                    items.safeRelease();
            }
            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 13 with Dispatch

use of com.jacob.com.Dispatch in project janrufmonitor by tbrandt77.

the class OutlookContactProxy method countContactsByUUID.

private int countContactsByUUID(Dispatch items, String uuid) {
    int count = 0;
    Dispatch aContact = Dispatch.call(items, "Find", new Variant("[User1]='" + uuid + "'")).toDispatch();
    if (aContact != null && aContact.m_pDispatch > 0) {
        do {
            count++;
            aContact = Dispatch.call(items, "FindNext").toDispatch();
        } while (aContact != null && aContact.m_pDispatch > 0);
    }
    return count;
}
Also used : Variant(com.jacob.com.Variant) Dispatch(com.jacob.com.Dispatch)

Example 14 with Dispatch

use of com.jacob.com.Dispatch in project janrufmonitor by tbrandt77.

the class OutlookContactProxy method getModifiedContacts.

public synchronized ICallerList getModifiedContacts(long timestamp) throws OutlookContactProxyException {
    ICallerList callers = getRuntime().getCallerFactory().createCallerList();
    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;
            if (this.countContactsByLastModificationTime(items, timestamp) > 0) {
                Date d = new Date(timestamp);
                SimpleDateFormat sfd = new SimpleDateFormat("MM/dd/yyyy h:mm a");
                Dispatch aContact = Dispatch.call(items, "Find", new Variant("[LastModificationTime] >= '" + sfd.format(d) + "'")).toDispatch();
                if (aContact != null && aContact.m_pDispatch > 0) {
                    do {
                        // check UUID in User1 attribute
                        this.checkContactUUID(aContact);
                        ICallerList 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();
    }
    return callers;
}
Also used : Message(de.janrufmonitor.exception.Message) ArrayList(java.util.ArrayList) Dispatch(com.jacob.com.Dispatch) Date(java.util.Date) 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) SimpleDateFormat(java.text.SimpleDateFormat) ComFailException(com.jacob.com.ComFailException)

Example 15 with Dispatch

use of com.jacob.com.Dispatch in project janrufmonitor by tbrandt77.

the class OutlookContactProxy method updateContact.

public synchronized boolean updateContact(ICaller c) throws OutlookContactProxyException {
    boolean processed = false;
    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 oldContact = this.findContactByUUID(items, c.getUUID());
        if (oldContact != null) {
            processed = true;
            boolean business = (c.getAttribute("outlook.business") != null && c.getAttribute("outlook.business").getValue().equalsIgnoreCase("true") ? true : false);
            this.setContactData(oldContact, c, business);
            this.clearPicture(c);
            if (this.m_logger.isLoggable(Level.INFO)) {
                this.m_logger.info("Updating outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + ": " + c);
            }
        } else {
            // contact does not exist in this folder maybe somewhere other...
            List subfolders = new ArrayList();
            subfolders.add("");
            subfolders.addAll(getAllContactFolders());
            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;
                oldContact = this.findContactByUUID(items, c.getUUID());
                if (oldContact != null) {
                    processed = true;
                    boolean business = (c.getAttribute("outlook.business") != null && c.getAttribute("outlook.business").getValue().equalsIgnoreCase("true") ? true : false);
                    this.setContactData(oldContact, c, business);
                    this.moveContactToFolder(oldContact, contactsFolder, this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY)));
                    if (this.m_logger.isLoggable(Level.INFO)) {
                        this.m_logger.info("Updated outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + " and moved to folder " + this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) + ": " + c);
                    }
                    break;
                }
            }
            if (!processed) {
                // try to find upon creation and modification date
                if (this.m_logger.isLoggable(Level.INFO)) {
                    this.m_logger.info("An outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + " could not be found: " + c);
                }
                String[] name = c.getUUID().split("_");
                if (name != null && name.length > 1) {
                    folder = null;
                    processed = false;
                    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;
                        oldContact = this.findContactByName(items, name[1], name[0]);
                        if (oldContact != null) {
                            processed = true;
                            boolean business = (c.getAttribute("outlook.business") != null && c.getAttribute("outlook.business").getValue().equalsIgnoreCase("true") ? true : false);
                            this.setContactData(oldContact, c, business);
                            this.moveContactToFolder(oldContact, contactsFolder, this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY)));
                            if (this.m_logger.isLoggable(Level.INFO)) {
                                this.m_logger.info("Updated outlook contact in folder " + (folder.length() > 0 ? folder : "<root>") + " and moved to folder " + this.getAttribute(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) + " after UUID search: " + c);
                            }
                            break;
                        }
                    }
                    if (!processed) {
                        this.m_logger.warning("Contact " + c.toString() + " not found in Outlook contact list by creation and modified date. Contact is not updated.");
                    }
                } else
                    this.m_logger.warning("Contact " + c.toString() + " not found in Outlook contact list. Contact is not updated.");
            }
        }
        if (oldContact != null)
            oldContact.safeRelease();
    } catch (ComFailException ex) {
        throw new OutlookContactProxyException("Error in Application Outlook.", ex);
    } catch (Exception ex) {
        throw new OutlookContactProxyException("Error in Application Outlook.", ex);
    } finally {
        if (this.m_dbh != null) {
            try {
                this.m_dbh.delete(c.getUUID());
            } catch (SQLException e) {
                this.m_logger.log(Level.SEVERE, e.getMessage(), e);
            }
        }
        // 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 processed;
}
Also used : SQLException(java.sql.SQLException) 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) ActiveXComponent(com.jacob.activeX.ActiveXComponent) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) ComFailException(com.jacob.com.ComFailException)

Aggregations

Dispatch (com.jacob.com.Dispatch)50 Variant (com.jacob.com.Variant)45 ComFailException (com.jacob.com.ComFailException)19 ActiveXComponent (com.jacob.activeX.ActiveXComponent)18 Message (de.janrufmonitor.exception.Message)13 ICallerList (de.janrufmonitor.framework.ICallerList)13 ZipArchiveException (de.janrufmonitor.repository.zip.ZipArchiveException)13 SQLException (java.sql.SQLException)13 ArrayList (java.util.ArrayList)13 List (java.util.List)13 IAttribute (de.janrufmonitor.framework.IAttribute)8 File (java.io.File)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 ICaller (de.janrufmonitor.framework.ICaller)1 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)1 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)1 UUID (de.janrufmonitor.util.uuid.UUID)1 Properties (java.util.Properties)1