Search in sources :

Example 6 with ActiveXComponent

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

Example 7 with ActiveXComponent

use of com.jacob.activeX.ActiveXComponent 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 8 with ActiveXComponent

use of com.jacob.activeX.ActiveXComponent 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 9 with ActiveXComponent

use of com.jacob.activeX.ActiveXComponent in project yyl_example by Relucent.

the class ExcelInvokeDemo method main.

public static void main(String[] s) {
    ComThread.InitSTA();
    // 获取ACTIVEX组件实例
    ActiveXComponent xl = new ActiveXComponent("Excel.Application");
    try {
        System.out.println("version=" + xl.getProperty("Version"));
        // 获取X1对象中version属性的值
        System.out.println("version=" + Dispatch.get(xl, "Version"));
        // 将true值赋给x1对象中的Visible属性
        Dispatch.put(xl, "Visible", new Variant(true));
        // 获得x1对象中的Workbooks属性,并将转为对象
        Dispatch workbooks = xl.getProperty("Workbooks").toDispatch();
        // 获得workbooks对象的add属性
        Dispatch workbook = Dispatch.get(workbooks, "Add").toDispatch();
        // 获得workbooks对象的ActiveSheet属性
        Dispatch sheet = Dispatch.get(workbook, "ActiveSheet").toDispatch();
        // 对sheet对象的Range属性执行其GET方法,再将Range属性的值设为A1
        Dispatch a1 = Dispatch.invoke(sheet, "Range", Dispatch.Get, new Object[] { "A1" }, new int[1]).toDispatch();
        // 同上
        Dispatch a2 = Dispatch.invoke(sheet, "Range", Dispatch.Get, new Object[] { "A2" }, new int[1]).toDispatch();
        // 将a1对象中的Value属性设为"123.456"
        Dispatch.put(a1, "Value", "123.456");
        Dispatch.put(a2, "Formula", "=A1*2");
        System.out.println("a1 from excel:" + Dispatch.get(a1, "Value"));
        System.out.println("a2 from excel:" + Dispatch.get(a2, "Value"));
        Variant f = new Variant(false);
        System.out.println(f);
    // Dispatch.call(workbook, "Close", f);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        xl.invoke("Quit", new Variant[] {});
        ComThread.Release();
    }
}
Also used : Variant(com.jacob.com.Variant) ActiveXComponent(com.jacob.activeX.ActiveXComponent) Dispatch(com.jacob.com.Dispatch)

Example 10 with ActiveXComponent

use of com.jacob.activeX.ActiveXComponent in project yyl_example by Relucent.

the class ActiveXComponentDemo method main.

public static void main(String[] s) {
    ActiveXComponent sC = new ActiveXComponent("ScriptControl");
    Dispatch sControl = sC.getObject();
    Dispatch.put(sControl, "Language", "VBScript");
    // use COM component in same thread
    Variant v = Dispatch.call(sControl, "Eval", "1+2*3");
    System.out.println(v.toString());
}
Also used : Variant(com.jacob.com.Variant) ActiveXComponent(com.jacob.activeX.ActiveXComponent) Dispatch(com.jacob.com.Dispatch)

Aggregations

ActiveXComponent (com.jacob.activeX.ActiveXComponent)18 Dispatch (com.jacob.com.Dispatch)18 Variant (com.jacob.com.Variant)18 ComFailException (com.jacob.com.ComFailException)16 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)6 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 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Properties (java.util.Properties)1