Search in sources :

Example 51 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.

the class IdentifyAction method run.

public synchronized void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            if (selection.getFirstElement() instanceof ICaller) {
                ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                try {
                    IRunnableWithProgress r = new IRunnableWithProgress() {

                        public void run(IProgressMonitor progressMonitor) {
                            progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "identifyprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                            progressMonitor.worked(1);
                            final ICaller caller = (ICaller) selection.getFirstElement();
                            List phones = new ArrayList();
                            if (caller instanceof IMultiPhoneCaller) {
                                phones.addAll(((IMultiPhoneCaller) caller).getPhonenumbers());
                            } else {
                                phones.add(caller.getPhoneNumber());
                            }
                            String ignoreCM = "";
                            IAttribute att = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
                            if (att != null) {
                                ignoreCM = att.getValue();
                            }
                            List activeCMs = getAllActiveCallerManagers(getRuntime(), ignoreCM);
                            ICaller identifiedCaller = null;
                            // identification only makes sence if there are active CMs or if there are numbers
                            if (activeCMs.size() > 0 && phones.size() > 0) {
                                IPhonenumber pn = null;
                                for (int i = 0; i < phones.size(); i++) {
                                    pn = (IPhonenumber) phones.get(i);
                                    identifiedCaller = Identifier.identify(getRuntime(), pn, activeCMs);
                                    if (identifiedCaller != null)
                                        break;
                                }
                            }
                            progressMonitor.done();
                            if (identifiedCaller == null) {
                                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "failedidentify", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                                PropagationFactory.getInstance().fire(new Message(Message.INFO, getNamespace(), "failedidentify", new Exception("Caller with number " + caller.getPhoneNumber() + " not identified...")));
                                return;
                            }
                            // remove repository flag and set all numbers
                            if (!(identifiedCaller instanceof IMultiPhoneCaller)) {
                                identifiedCaller = getRuntime().getCallerFactory().toMultiPhoneCaller(identifiedCaller);
                            }
                            ((IMultiPhoneCaller) identifiedCaller).setPhonenumbers(phones);
                            ((IMultiPhoneCaller) identifiedCaller).setPhoneNumber((IPhonenumber) phones.get(0));
                            IAttributeMap m = getRuntime().getCallerFactory().createAttributeMap();
                            m.addAll(caller.getAttributes());
                            m.addAll(identifiedCaller.getAttributes());
                            m.remove(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
                            identifiedCaller.setAttributes(m);
                            final ICaller theIdentifiedCaller = identifiedCaller;
                            new SWTExecuter() {

                                protected void execute() {
                                    if (MessageDialog.openConfirm(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "identify", "label", getLanguage()), getI18nManager().getString(getNamespace(), "identify", "description", getLanguage()))) {
                                        ICaller newCaller = openCallerWizard(theIdentifiedCaller);
                                        if (newCaller != null) {
                                            ICallerList list = getRuntime().getCallerFactory().createCallerList(1);
                                            list.add(caller);
                                            m_app.getController().deleteElements(list);
                                            list.clear();
                                            list.add(newCaller);
                                            m_app.getController().addElements(list);
                                            m_app.updateViews(true);
                                        }
                                    }
                                }
                            }.start();
                        }
                    };
                    pmd.setBlockOnOpen(false);
                    pmd.run(true, false, r);
                // ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
                } catch (InterruptedException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                } catch (InvocationTargetException e) {
                    m_logger.log(Level.SEVERE, e.getMessage(), e);
                }
            }
        }
    }
}
Also used : Message(de.janrufmonitor.exception.Message) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICaller(de.janrufmonitor.framework.ICaller) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) ICallerList(de.janrufmonitor.framework.ICallerList) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 52 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.

the class ImportAction method run.

public void run(String[] filenames) {
    List ids = ImExportFactory.getInstance().getAllImporterIds(IImExporter.CALLER_MODE);
    String filename = null;
    for (int h = 0; h < filenames.length; h++) {
        filename = filenames[h];
        if (!filename.endsWith(this.m_app.getApplication().getConfiguration().getProperty(CFG_OLD_EDITOR, "cpnumber.dat"))) {
            String ext = "";
            for (int i = 0; i < ids.size(); i++) {
                final IImExporter imp = ImExportFactory.getInstance().getImporter((String) ids.get(i));
                ext = imp.getExtension();
                if (ext.startsWith("*"))
                    ext = ext.substring(1);
                if (filename.toLowerCase().endsWith(ext) && imp.getMode() == IImExporter.CALLER_MODE) {
                    imp.setFilename(filename);
                    // chedk for categorie filters
                    String filter = this.m_app.getApplication().getConfiguration().getProperty("filter", "");
                    EditorFilterManager efm = new EditorFilterManager();
                    final IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, "");
                    if (filter.length() > 0) {
                        String cat = null;
                        IFilter[] filters = efm.getFiltersFromString(filter);
                        for (int z = 0; z < filters.length; z++) {
                            if (filters[z].getType().equals(FilterType.ATTRIBUTE)) {
                                AttributeFilter cf = ((AttributeFilter) filters[z]);
                                IAttributeMap m = cf.getAttributeMap();
                                if (m != null && m.size() > 0) {
                                    Iterator it = m.iterator();
                                    IAttribute a = null;
                                    while (it.hasNext()) {
                                        a = (IAttribute) it.next();
                                        if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                                            cat = a.getValue();
                                        }
                                    }
                                }
                            }
                        }
                        if (cat != null) {
                            int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
                            MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
                            String text = this.getI18nManager().getString(this.getNamespace(), "assigncategoryconfirm", "label", this.getLanguage());
                            text = StringUtils.replaceString(text, "{%1}", cat);
                            messageBox.setMessage(text);
                            if (messageBox.open() == SWT.YES) {
                                category.setValue(cat);
                            }
                        }
                    }
                    final String f = filename;
                    try {
                        ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
                        IRunnableWithProgress r = new IRunnableWithProgress() {

                            public void run(IProgressMonitor progressMonitor) {
                                progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "importprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
                                ICallerList importedCallers = (ICallerList) getRuntime().getCallerFactory().createCallerList();
                                if (imp.getMode() == IImExporter.CALLER_MODE) {
                                    ImportThread ti = new ImportThread((ICallerImporter) imp, (category.getValue().length() == 0 ? null : category));
                                    Thread t = new Thread(ti);
                                    t.start();
                                    while (t.isAlive()) {
                                        if (imp instanceof ITracker) {
                                            String text = getI18nManager().getString(getNamespace(), "importprogress2", "label", getLanguage());
                                            text = StringUtils.replaceString(text, "{%1}", Integer.toString(((ITracker) imp).getCurrent()));
                                            text = StringUtils.replaceString(text, "{%2}", Integer.toString(((ITracker) imp).getTotal()));
                                            progressMonitor.beginTask(text, IProgressMonitor.UNKNOWN);
                                        }
                                        try {
                                            Thread.sleep(500);
                                        } catch (InterruptedException e) {
                                        }
                                    }
                                    if (ti != null) {
                                        importedCallers = ti.getResult();
                                        m_app.getController().addElements(importedCallers);
                                    }
                                }
                                if (importedCallers.size() > 0) {
                                    progressMonitor.done();
                                    String msg = getI18nManager().getString(getNamespace(), "success", "description", getLanguage());
                                    msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(importedCallers.size()));
                                    msg = StringUtils.replaceString(msg, "{%2}", f);
                                    PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(msg)), "Tray");
                                    new SWTExecuter() {

                                        protected void execute() {
                                            m_app.updateViews(true);
                                        }
                                    }.start();
                                } else {
                                    progressMonitor.done();
                                    PropagationFactory.getInstance().fire(new Message(Message.ERROR, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "error", "description", getLanguage()))), "Tray");
                                    new SWTExecuter() {

                                        protected void execute() {
                                            MessageDialog.openError(DisplayManager.getDefaultDisplay().getActiveShell(), getI18nManager().getString(getNamespace(), "error", "label", getLanguage()), getI18nManager().getString(getNamespace(), "error", "description", getLanguage()));
                                            m_logger.warning("Import of data failed.");
                                        }
                                    }.start();
                                }
                            }
                        };
                        pmd.setBlockOnOpen(false);
                        pmd.run(true, false, r);
                    } catch (InterruptedException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    } catch (InvocationTargetException e) {
                        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
                    }
                }
            }
        } else {
            // do cpnumber.dat migration
            int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
            MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
            messageBox.setMessage(this.getI18nManager().getString(this.getNamespace(), "migrationconfirm", "label", this.getLanguage()));
            if (messageBox.open() == SWT.YES) {
                IImExporter imp = ImExportFactory.getInstance().getImporter("OldDatFileCallerImporter");
                if (imp != null && (imp instanceof OldDatFileCallerImporter)) {
                    ((OldDatFileCallerImporter) imp).setFilename(filename);
                    ICallerList importedCallers = ((OldDatFileCallerImporter) imp).doImport();
                    if (importedCallers != null) {
                        final String f = filename;
                        this.m_app.getController().addElements(importedCallers);
                        String msg = getI18nManager().getString(getNamespace(), "success", "description", getLanguage());
                        msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(importedCallers.size()));
                        msg = StringUtils.replaceString(msg, "{%2}", f);
                        PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Editor.NAMESPACE, "title", "label", getLanguage()), new Exception(msg)), "Tray");
                        m_app.updateViews(true);
                    }
                }
            } else {
                return;
            }
        }
    }
}
Also used : Message(de.janrufmonitor.exception.Message) EditorFilterManager(de.janrufmonitor.ui.jface.application.editor.EditorFilterManager) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) IImExporter(de.janrufmonitor.repository.imexport.IImExporter) Iterator(java.util.Iterator) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter) ITracker(de.janrufmonitor.repository.imexport.ITracker) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MessageBox(org.eclipse.swt.widgets.MessageBox) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ICallerList(de.janrufmonitor.framework.ICallerList) IFilter(de.janrufmonitor.repository.filter.IFilter) IAttribute(de.janrufmonitor.framework.IAttribute) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) OldDatFileCallerImporter(de.janrufmonitor.repository.imexporter.OldDatFileCallerImporter)

Example 53 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.

the class NumberType method renderAsText.

public String renderAsText() {
    if (this.m_o != null) {
        if (this.m_o instanceof ICall) {
            this.m_o = ((ICall) this.m_o).getCaller();
        }
        if (this.m_o instanceof ICaller) {
            this.m_o = new TreeItemCallerData(((ICaller) this.m_o).getAttributes(), ((ICaller) this.m_o).getPhoneNumber());
        }
        if (this.m_o instanceof ITreeItemCallerData) {
            IAttributeMap m = ((ITreeItemCallerData) m_o).getAttributes();
            IPhonenumber pn = ((ITreeItemCallerData) m_o).getPhone();
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber())) {
                IAttribute type = m.get(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber());
                if (type != null) {
                    return PIMRuntime.getInstance().getI18nManagerFactory().getI18nManager().getString(NAMESPACE, type.getValue(), "label", getLanguage());
                }
            }
        }
    }
    return "";
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICall(de.janrufmonitor.framework.ICall) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 54 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.

the class LdapRepository method getCallers.

public ICallerList getCallers(IFilter filter) {
    try {
        if (filter != null && filter.getType().equals(FilterType.ATTRIBUTE)) {
            IAttributeMap m = ((AttributeFilter) filter).getAttributeMap();
            if (m.contains(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
                IAttribute a = m.get(IJAMConst.ATTRIBUTE_NAME_CATEGORY);
                return getProxy().getContacts(a.getValue());
            }
        }
        if (filter != null && filter.getType().equals(FilterType.PHONENUMBER)) {
            ICallerList cl = getProxy().getContacts(null);
            this.applyFilters(cl, new IFilter[] { filter });
            return cl;
        }
        if (filter != null && filter.getType().equals(FilterType.CHARACTER)) {
            ICallerList cl = getProxy().getContacts(null);
            this.applyFilters(cl, new IFilter[] { filter });
            return cl;
        }
        return getProxy().getContacts(null);
    } catch (LdapContactsException e) {
        this.m_logger.log(Level.SEVERE, e.getMessage(), e);
        PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "loginerror", e));
    }
    return getRuntime().getCallerFactory().createCallerList();
}
Also used : ICallerList(de.janrufmonitor.framework.ICallerList) Message(de.janrufmonitor.exception.Message) AttributeFilter(de.janrufmonitor.repository.filter.AttributeFilter) IAttribute(de.janrufmonitor.framework.IAttribute) IAttributeMap(de.janrufmonitor.framework.IAttributeMap)

Example 55 with IAttributeMap

use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.

the class VcfParser30 method parse.

public ICallerList parse() throws VcfParserException {
    if (this.m_buffer == null)
        this.read();
    if (this.m_buffer.length() < 64)
        throw new VcfParserException("VCF file contains only " + this.m_buffer.length() + " characters.");
    ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList();
    String[] entries = this.m_buffer.toString().split(BEGIN_VCARD);
    this.m_logger.info("Entries in generic VcfParser vcf file: " + entries.length);
    this.m_total = entries.length;
    for (int i = 0; i < entries.length; i++) {
        try {
            this.m_current++;
            IAttributeMap private_attributes = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
            IAttributeMap bussiness_attributes = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
            List private_phones = new ArrayList();
            List bussiness_phones = new ArrayList();
            String[] lines = entries[i].split(IJAMConst.CRLF);
            // parse single entry
            String line = null;
            String[] value = null;
            for (int j = 0; j < lines.length; j++) {
                line = lines[j];
                // check name
                if (line.toLowerCase().startsWith(N) || line.toLowerCase().startsWith(N2)) {
                    value = line.substring(line.indexOf(":") + 1).split(";");
                    if (value.length >= 2) {
                        this.m_logger.info("Set attribute name.");
                        private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
                        bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
                        private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, value[1]));
                        bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, value[1]));
                    }
                    if (value.length == 1) {
                        private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
                        bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
                    }
                }
                if (line.toLowerCase().startsWith(ORG) || line.toLowerCase().startsWith(ORG2)) {
                    value = line.split(":");
                    if (value.length >= 2) {
                        this.m_logger.info("Set attribute organization.");
                        private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, value[1]));
                        bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, value[1]));
                    }
                }
                if (line.toLowerCase().startsWith(ADR)) {
                    String[] tokens = line.split(":");
                    if (tokens.length == 2) {
                        boolean isBusiness = false;
                        String[] attributes = tokens[0].split(";");
                        for (int k = 0; k < attributes.length; k++) {
                            if (attributes[k].toLowerCase().startsWith(ATTRIBUTE_TYPE)) {
                                String[] values = attributes[k].toLowerCase().substring(ATTRIBUTE_TYPE.length()).split(";");
                                for (int l = 0; l < values.length; l++) {
                                    if (values[l].equalsIgnoreCase(ADR_TYPES[1])) {
                                        isBusiness = true;
                                    }
                                }
                            }
                            if (attributes[k].toLowerCase().startsWith(ADR_TYPES[1])) {
                                isBusiness = true;
                            }
                        }
                        value = tokens[1].split(";");
                        if (value.length >= 6 && (value.length > 6 ? value[6].trim().length() > 0 : true) && value[3].trim().length() > 0) {
                            if (isBusiness) {
                                this.m_logger.info("Set attribute work address.");
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, value[2]));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, value[5]));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, value[3] + (value[4].trim().length() > 0 ? ", " + value[4] : "")));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, (value.length > 6 ? value[6] : "")));
                            } else {
                                this.m_logger.info("Set attribute home address.");
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, value[2]));
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, value[5]));
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, value[3] + (value[4].trim().length() > 0 ? ", " + value[4] : "")));
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, (value.length > 6 ? value[6] : "")));
                            }
                        }
                    }
                }
                if (line.toLowerCase().startsWith(TEL)) {
                    value = line.split(":");
                    if (value.length == 2 && value[1].trim().length() > 0) {
                        boolean isBusiness = false;
                        boolean isFax = false;
                        boolean isCell = false;
                        String[] attributes = value[0].split(";");
                        for (int k = 0; k < attributes.length; k++) {
                            if (attributes[k].toLowerCase().startsWith(ATTRIBUTE_TYPE)) {
                                String[] values = attributes[k].toLowerCase().substring(ATTRIBUTE_TYPE.length()).split(",");
                                for (int l = 0; l < values.length; l++) {
                                    if (values[l].equalsIgnoreCase(TEL_TYPES[1])) {
                                        isBusiness = true;
                                    }
                                    if (values[l].equalsIgnoreCase(TEL_TYPES[3])) {
                                        isFax = true;
                                    }
                                    if (values[l].equalsIgnoreCase(TEL_TYPES[2])) {
                                        isCell = true;
                                    }
                                }
                            }
                            if (attributes[k].toLowerCase().startsWith(TEL_TYPES[1])) {
                                isBusiness = true;
                            }
                            if (attributes[k].toLowerCase().startsWith(TEL_TYPES[3])) {
                                isFax = true;
                            }
                            if (attributes[k].toLowerCase().startsWith(TEL_TYPES[2])) {
                                isCell = true;
                            }
                        }
                        try {
                            IPhonenumber pn = parsePhonenumber(value[1]);
                            if (pn != null && !bussiness_phones.contains(pn)) {
                                if (isBusiness) {
                                    this.m_logger.info("Set attribute work");
                                    bussiness_phones.add(pn);
                                    bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), (isFax ? IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE : (isCell ? IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE : IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))));
                                } else {
                                    this.m_logger.info("Set attribute home");
                                    private_phones.add(pn);
                                    private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), (isFax ? IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE : (isCell ? IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE : IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))));
                                }
                            }
                        } catch (Exception ex) {
                            this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
                        }
                    }
                }
                if (line.toLowerCase().startsWith(EMAIL)) {
                    value = line.split(":");
                    if (value.length == 2 && value[1].trim().length() > 0) {
                        boolean isBusiness = false;
                        String[] attributes = value[0].split(";");
                        for (int k = 0; k < attributes.length; k++) {
                            if (attributes[k].toLowerCase().startsWith(ATTRIBUTE_TYPE)) {
                                String[] values = attributes[k].toLowerCase().substring(ATTRIBUTE_TYPE.length()).split(",");
                                for (int l = 0; l < values.length; l++) {
                                    if (values[l].equalsIgnoreCase(EMAIL_TYPES[1])) {
                                        isBusiness = true;
                                    }
                                }
                            }
                            if (attributes[k].toLowerCase().startsWith(EMAIL_TYPES[1])) {
                                isBusiness = true;
                            }
                        }
                        if (isBusiness) {
                            this.m_logger.info("Set attribute work");
                            bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL, value[1]));
                        } else {
                            this.m_logger.info("Set attribute home");
                            private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL, value[1]));
                        }
                    }
                }
                if (line.toLowerCase().startsWith(GEO)) {
                    value = line.split(":");
                    if (value.length == 2) {
                        value = value[1].split(";");
                        if (value.length == 2) {
                            bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, value[0]));
                            bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, value[1]));
                            private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, value[0]));
                            private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, value[1]));
                        }
                    }
                }
                if (line.toLowerCase().startsWith(PHOTO) || line.toLowerCase().startsWith(MS_CARDPICTURE)) {
                    value = new String[2];
                    value[0] = line.substring(0, line.indexOf(":"));
                    value[1] = line.substring(line.indexOf(":") + 1);
                    if (value.length == 2) {
                        boolean isUrl = false;
                        boolean isEncoding = false;
                        String img_type = null;
                        String[] attributes = value[0].split(";");
                        for (int k = 0; k < attributes.length; k++) {
                            if (attributes[k].toLowerCase().startsWith(PHOTO_TYPES[0]) || attributes[k].toLowerCase().startsWith(PHOTO_TYPES[1])) {
                                isUrl = true;
                            }
                            if (attributes[k].toLowerCase().startsWith(PHOTO_TYPES[2])) {
                                isEncoding = true;
                            }
                            if (attributes[k].toLowerCase().startsWith(PHOTO_TYPES[3])) {
                                img_type = attributes[k].split("=")[1].toLowerCase();
                            }
                        }
                        if (isUrl) {
                            String img = getImageFromURL(value[1]);
                            if (img != null) {
                                this.m_logger.info("Set attribute photo.");
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
                                private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
                                bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
                            }
                        }
                        if (isEncoding) {
                            try {
                                if (img_type == null || img_type.trim().length() == 0)
                                    img_type = "jpg";
                                StringBuffer img_content = new StringBuffer();
                                img_content.append(value[1]);
                                img_content.append("\n");
                                do {
                                    j++;
                                    value[1] = lines[j];
                                    if (value[1].startsWith(" "))
                                        value[1] = value[1].substring(1);
                                    img_content.append(value[1]);
                                    img_content.append("\n");
                                } while (value[1].indexOf("=") < 0);
                                String img = getImageFromBase64(img_content.toString(), img_type);
                                if (img != null) {
                                    this.m_logger.info("Set attribute photo.");
                                    private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
                                    bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
                                    private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
                                    bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
                                }
                            } catch (Exception ex) {
                                this.m_logger.log(Level.SEVERE, "VCF parsing error: PHOTO: " + ex.getMessage(), ex);
                            }
                        }
                    }
                }
            }
            // create ICaller objects
            IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
            if (private_phones.size() > 0 && private_attributes.size() > 0) {
                ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, private_phones);
                c.setAttributes(private_attributes);
                cl.add(c);
            }
            if (bussiness_phones.size() > 0 && bussiness_attributes.size() > 0) {
                ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, bussiness_phones);
                c.setAttributes(bussiness_attributes);
                cl.add(c);
            }
        } catch (Exception e) {
            this.m_logger.log(Level.SEVERE, "VCF parsing error: " + e.getMessage(), e);
        // throw new VcfParserException("parsing error: "+e.getMessage(), e);
        }
    }
    return cl;
}
Also used : ArrayList(java.util.ArrayList) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ICaller(de.janrufmonitor.framework.ICaller) ICallerList(de.janrufmonitor.framework.ICallerList) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IName(de.janrufmonitor.framework.IName) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IAttributeMap (de.janrufmonitor.framework.IAttributeMap)64 IAttribute (de.janrufmonitor.framework.IAttribute)37 IPhonenumber (de.janrufmonitor.framework.IPhonenumber)36 ICaller (de.janrufmonitor.framework.ICaller)31 List (java.util.List)24 ICallerList (de.janrufmonitor.framework.ICallerList)23 ArrayList (java.util.ArrayList)21 Iterator (java.util.Iterator)17 IOException (java.io.IOException)14 AttributeFilter (de.janrufmonitor.repository.filter.AttributeFilter)13 Date (java.util.Date)12 IMsn (de.janrufmonitor.framework.IMsn)11 File (java.io.File)10 ICip (de.janrufmonitor.framework.ICip)8 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)8 Message (de.janrufmonitor.exception.Message)6 ICall (de.janrufmonitor.framework.ICall)6 SimpleDateFormat (java.text.SimpleDateFormat)6 StringTokenizer (java.util.StringTokenizer)6 IFilter (de.janrufmonitor.repository.filter.IFilter)5