Search in sources :

Example 51 with IPhonenumber

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

the class OutlookNumberType 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(IOutlookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber())) {
                IAttribute type = m.get(IOutlookNumberMapping.MAPPING_ATTTRIBUTE_ID + 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 52 with IPhonenumber

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

the class PDFCallerListFilter method doExport.

public boolean doExport() {
    Document document = new Document(PageSize.A4.rotate());
    document.addCreationDate();
    document.addCreator("jAnrufmonitor");
    try {
        PdfWriter.getInstance(document, new FileOutputStream(this.m_filename));
        document.open();
        // get renderers
        List renderer = new ArrayList();
        String renderer_config = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "renderer");
        if (renderer_config != null && renderer_config.length() > 0) {
            StringTokenizer s = new StringTokenizer(renderer_config, ",");
            while (s.hasMoreTokens()) {
                renderer.add(RendererRegistry.getInstance().getRenderer(s.nextToken()));
            }
        }
        // get column width
        float totalWidth = 0;
        String[] cWidth = new String[renderer.size()];
        for (int i = 0, j = renderer.size(); i < j; i++) {
            cWidth[i] = getRuntime().getConfigManagerFactory().getConfigManager().getProperty("ui.jface.application.editor.Editor", "col_size_" + ((ITableCellRenderer) renderer.get(i)).getID());
            if (cWidth[i] != null && cWidth[i].length() > 0) {
                totalWidth += Float.parseFloat(cWidth[i]);
            }
            if (cWidth[i] != null && cWidth[i].length() == 0) {
                cWidth[i] = "0";
            }
        }
        float[] widths = new float[renderer.size()];
        for (int i = 0, j = renderer.size(); i < j; i++) {
            widths[i] = Float.parseFloat(cWidth[i]) / totalWidth;
        }
        PdfPTable table = new PdfPTable(widths);
        table.setHeaderRows(1);
        table.setWidthPercentage(100f);
        ITableCellRenderer t = null;
        PdfPCell cell = null;
        for (int i = 0, j = renderer.size(); i < j; i++) {
            t = (ITableCellRenderer) renderer.get(i);
            if (t == null) {
                this.m_logger.severe("No renderer found for ID: " + (String) renderer.get(i));
                this.m_logger.severe("Export to PDF format canceled...");
                return false;
            }
            cell = new PdfPCell(new Paragraph(t.getHeader()));
            cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
            table.addCell(cell);
        }
        ICaller c = null;
        String cellContent = null;
        Color iterateColor1 = new Color(0xDD, 0xDD, 0xDD);
        Color iterateColor2 = new Color(0xFF, 0xFF, 0xFF);
        cell = null;
        int type_col = -1, num_col = -1;
        for (int i = 0, j = this.m_callerList.size(); i < j; i++) {
            c = this.m_callerList.get(i);
            for (int k = 0, m = renderer.size(); k < m; k++) {
                t = (ITableCellRenderer) renderer.get(k);
                t.updateData(c);
                // find number and typ column for multiline callers
                if (t.getID().equalsIgnoreCase("NumberType"))
                    type_col = k;
                if (t.getID().equalsIgnoreCase("Number"))
                    num_col = k;
                cellContent = t.renderAsText();
                if (cellContent != null && cellContent.length() > 0) {
                    cell = new PdfPCell(new Phrase(cellContent));
                    cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                    table.addCell(cell);
                } else {
                    cellContent = t.renderAsImageID();
                    if (cellContent != null && cellContent.length() > 0) {
                        if (cellContent.startsWith("db://")) {
                            InputStream in = ImageHandler.getInstance().getImageStream(c);
                            if (in != null) {
                                ByteArrayOutputStream out = new ByteArrayOutputStream();
                                Stream.copy(in, out, true);
                                in.close();
                                out.close();
                                Image pdfImage = Image.getInstance(out.toByteArray());
                                // pdfImage.scaleAbsolute(90.0f, 45.0f);
                                table.addCell(pdfImage);
                            } else {
                                table.addCell(" ");
                            }
                        } else if (new File(cellContent).exists()) {
                            Image pdfImage = Image.getInstance(cellContent);
                            table.addCell(pdfImage);
                        } else {
                            Image pdfImage = Image.getInstance(SWTImageManager.getInstance(PIMRuntime.getInstance()).getImagePath(cellContent));
                            table.addCell(pdfImage);
                        }
                    // ((Image pdfImage = Image.getInstance(cellContent);
                    // cell = new PdfPCell(pdfImage);
                    // cell.setBackgroundColor((i%2==0 ? iterateColor1 : iterateColor2));
                    // table.addCell(pdfImage);
                    } else {
                        cell = new PdfPCell(new Phrase(" "));
                        cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                        table.addCell(cell);
                    }
                }
                // last column reached check for multiline caller
                if (k == m - 1 && (type_col > -1 || num_col > -1) && (c instanceof IMultiPhoneCaller) && (((IMultiPhoneCaller) c).getPhonenumbers().size() > 1)) {
                    List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
                    IPhonenumber pn = null;
                    for (int y = 1, z = phones.size(); y < z; y++) {
                        pn = (IPhonenumber) phones.get(y);
                        for (int w = 0, x = renderer.size(); w < x; w++) {
                            t = (ITableCellRenderer) renderer.get(w);
                            if (t.getID().equalsIgnoreCase("NumberType") || t.getID().equalsIgnoreCase("Number")) {
                                if (t.getID().equalsIgnoreCase("NumberType")) {
                                    final IPhonenumber lpn = pn;
                                    final IAttributeMap lam = c.getAttributes();
                                    t.updateData(new ITreeItemCallerData() {

                                        public IAttributeMap getAttributes() {
                                            return lam;
                                        }

                                        public IPhonenumber getPhone() {
                                            return lpn;
                                        }
                                    });
                                } else
                                    t.updateData(pn);
                                cellContent = t.renderAsText();
                                if (cellContent != null && cellContent.length() > 0) {
                                    cell = new PdfPCell(new Phrase(cellContent));
                                    cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                                    table.addCell(cell);
                                } else {
                                    cell = new PdfPCell(new Phrase(" "));
                                    cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                                    table.addCell(cell);
                                }
                            } else {
                                cell = new PdfPCell(new Phrase(" "));
                                cell.setBackgroundColor((i % 2 == 0 ? iterateColor1 : iterateColor2));
                                table.addCell(cell);
                            }
                        }
                    }
                }
            }
        }
        document.add(table);
    } catch (DocumentException de) {
        this.m_logger.severe(de.getMessage());
        return false;
    } catch (IOException ioe) {
        this.m_logger.severe(ioe.getMessage());
        return false;
    } finally {
        document.close();
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Document(com.lowagie.text.Document) Image(com.lowagie.text.Image) PdfPTable(com.lowagie.text.pdf.PdfPTable) DocumentException(com.lowagie.text.DocumentException) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IMultiPhoneCaller(de.janrufmonitor.framework.IMultiPhoneCaller) ITableCellRenderer(de.janrufmonitor.ui.jface.application.rendering.ITableCellRenderer) PdfPCell(com.lowagie.text.pdf.PdfPCell) InputStream(java.io.InputStream) Color(java.awt.Color) Phrase(com.lowagie.text.Phrase) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Paragraph(com.lowagie.text.Paragraph) ICaller(de.janrufmonitor.framework.ICaller) StringTokenizer(java.util.StringTokenizer) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ITreeItemCallerData(de.janrufmonitor.ui.jface.application.ITreeItemCallerData) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 53 with IPhonenumber

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

the class RejectAction method run.

public void run() {
    Viewer v = this.m_app.getApplication().getViewer();
    if (v != null && v instanceof Viewer) {
        final IStructuredSelection selection = (IStructuredSelection) v.getSelection();
        if (!selection.isEmpty()) {
            Iterator i = selection.iterator();
            Object o = null;
            while (i.hasNext()) {
                o = i.next();
                if (o instanceof ICall) {
                    o = ((ICall) o).getCaller();
                }
                if (o instanceof ICaller) {
                    if (this.isRejectable(((ICaller) o))) {
                        IPhonenumber pn = ((ICaller) o).getPhoneNumber();
                        setAsRejectNumber(pn);
                    }
                }
            }
            m_app.updateViews(false);
        }
    }
}
Also used : ICaller(de.janrufmonitor.framework.ICaller) ICall(de.janrufmonitor.framework.ICall) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 54 with IPhonenumber

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

the class Etiquet 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(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber())) {
                IAttribute type = m.get(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + 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 55 with IPhonenumber

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

the class NcidCallRaw method toCall.

public ICall toCall() {
    if (this.m_line == null || this.m_line.length() == 0)
        return null;
    if (this.m_call == null) {
        IRuntime r = PIMRuntime.getInstance();
        String[] call = this.m_line.split("\\*");
        if (call.length >= 8 && (call[0].trim().equalsIgnoreCase("CID:") || call[0].trim().equalsIgnoreCase("CIDLOG:"))) {
            // create MSN
            IMsn msn = r.getCallFactory().createMsn(getFestnetzAlias(call[6]), "");
            msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
            IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[8].trim());
            // if no CLIR call, check internal
            if (pn == null)
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[8].trim(), msn.getMSN());
            // if no internal call, check regular
            if (pn == null) {
                // if incoming call does not start with 0, the Provider number seems to have the wrong format
                // assume it is an international format 4971657110
                boolean onlyNumbers = call[8].matches("[+-]?[0-9]+");
                if (!call[8].startsWith("0") && onlyNumbers) {
                    call[8] = "00" + call[8];
                }
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[8].trim(), msn.getMSN());
            }
            ICaller caller = r.getCallerFactory().createCaller(pn);
            // create call data
            // added 2009/05/01
            String dateformat = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(NcidMonitor.NAMESPACE, "dateformat");
            if (dateformat == null || dateformat.trim().length() == 0)
                dateformat = "ddMMyyyyHHmm";
            if (Logger.getLogger(IJAMConst.DEFAULT_LOGGER).isLoggable(Level.INFO))
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Setting date format to #" + dateformat + "#");
            SimpleDateFormat sdf = new SimpleDateFormat(dateformat);
            Date date = new Date(0);
            try {
                date = sdf.parse(call[2] + call[4]);
            } catch (ParseException e) {
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong standard date format detected. " + call[2] + call[4] + " does not match #" + dateformat + "#");
            }
            ICip cip = r.getCallFactory().createCip(getCip("sip"), "");
            cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
            // create attributes
            IAttributeMap am = r.getCallFactory().createAttributeMap();
            am.add(r.getCallFactory().createAttribute("ncid.key", call[6]));
            if (call.length >= 12) {
                am.add(r.getCallFactory().createAttribute("ncid.msg", call[10]));
                am.add(r.getCallFactory().createAttribute("ncid.callername", call[12]));
            }
            am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
            // create UUID
            StringBuffer uuid = new StringBuffer();
            uuid.append(date.getTime());
            uuid.append("-");
            uuid.append(pn.getTelephoneNumber());
            uuid.append("-");
            uuid.append(msn.getMSN());
            // limit uuid to 32 chars
            if (uuid.length() > 31) {
                // reduce byte length to append -1 for redundant calls max -1-1 --> 3 calls
                uuid = new StringBuffer(uuid.substring(0, 31));
            }
            this.m_call = r.getCallFactory().createCall(uuid.toString(), caller, msn, cip, date);
            this.m_call.setAttributes(am);
        }
        if (call.length >= 8 && call[0].trim().equalsIgnoreCase("OUT:")) {
            // create msn
            IMsn msn = r.getCallFactory().createMsn(getFestnetzAlias(call[6]), "");
            msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
            // create caller data
            String callByCall = null;
            IPhonenumber pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toClirPhonenumber(call[8].trim());
            // if no CLIR call, check internal
            if (pn == null)
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toInternalPhonenumber(call[8].trim(), msn.getMSN());
            // if no internal call, check regular
            if (pn == null) {
                // added 2006/08/10: trim call-by-call information
                // only can occure on state CALL (out-going calls)
                callByCall = getCallByCall(call[8]);
                if (callByCall != null) {
                    call[8] = call[8].substring(callByCall.length());
                }
                // requires addition of areacode
                if (!call[8].startsWith("0")) {
                    Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Assuming number " + call[8] + " has missing areacode.");
                    call[8] = this.getGeneralAreaCode() + call[8];
                    Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Added areacode to number " + call[8]);
                }
                pn = PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).toPhonenumber(call[8].trim(), msn.getMSN());
            }
            ICaller caller = r.getCallerFactory().createCaller(pn);
            // create call data
            // added 2009/05/27
            String dateformat = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(NcidMonitor.NAMESPACE, "dateformat");
            if (dateformat == null || dateformat.trim().length() == 0)
                dateformat = "ddMMyyyyHHmm";
            if (Logger.getLogger(IJAMConst.DEFAULT_LOGGER).isLoggable(Level.INFO))
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).info("Setting date format to #" + dateformat + "#");
            SimpleDateFormat sdf = new SimpleDateFormat(dateformat);
            Date date = new Date(0);
            try {
                date = sdf.parse(call[2] + call[4]);
            } catch (ParseException e) {
                Logger.getLogger(IJAMConst.DEFAULT_LOGGER).severe("Wrong standard date format detected. " + call[2] + call[4] + " does not match #" + dateformat + "#");
            }
            ICip cip = r.getCallFactory().createCip(getCip("sip"), "");
            cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
            // create attributes
            IAttributeMap am = r.getCallFactory().createAttributeMap();
            am.add(r.getCallFactory().createAttribute("ncid.key", call[6]));
            if (call.length >= 12) {
                am.add(r.getCallFactory().createAttribute("ncid.msg", call[10]));
                am.add(r.getCallFactory().createAttribute("ncid.callername", call[12]));
            }
            am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_OUTGOING));
            if (callByCall != null)
                am.add(r.getCallFactory().createAttribute("ncid.callbycall", callByCall));
            // create UUID
            StringBuffer uuid = new StringBuffer();
            uuid.append(date.getTime());
            uuid.append("-");
            uuid.append(pn.getTelephoneNumber());
            uuid.append("-");
            uuid.append(msn.getMSN());
            // limit uuid to 32 chars
            if (uuid.length() > 31) {
                // reduce byte length to append -1 for redundant calls max -1-1 --> 3 calls
                uuid = new StringBuffer(uuid.substring(0, 31));
            }
            this.m_call = r.getCallFactory().createCall(uuid.toString(), caller, msn, cip, date);
            this.m_call.setAttributes(am);
        }
    }
    return this.m_call;
}
Also used : ICip(de.janrufmonitor.framework.ICip) Date(java.util.Date) IRuntime(de.janrufmonitor.runtime.IRuntime) ICaller(de.janrufmonitor.framework.ICaller) IAttributeMap(de.janrufmonitor.framework.IAttributeMap) ParseException(java.text.ParseException) IMsn(de.janrufmonitor.framework.IMsn) SimpleDateFormat(java.text.SimpleDateFormat) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Aggregations

IPhonenumber (de.janrufmonitor.framework.IPhonenumber)99 ICaller (de.janrufmonitor.framework.ICaller)62 List (java.util.List)49 ArrayList (java.util.ArrayList)44 IAttribute (de.janrufmonitor.framework.IAttribute)38 IAttributeMap (de.janrufmonitor.framework.IAttributeMap)37 ICallerList (de.janrufmonitor.framework.ICallerList)36 IMultiPhoneCaller (de.janrufmonitor.framework.IMultiPhoneCaller)26 ICall (de.janrufmonitor.framework.ICall)19 SQLException (java.sql.SQLException)19 IMsn (de.janrufmonitor.framework.IMsn)17 Date (java.util.Date)17 IOException (java.io.IOException)16 ICip (de.janrufmonitor.framework.ICip)13 IName (de.janrufmonitor.framework.IName)13 File (java.io.File)13 Iterator (java.util.Iterator)13 ITreeItemCallerData (de.janrufmonitor.ui.jface.application.ITreeItemCallerData)9 UUID (de.janrufmonitor.util.uuid.UUID)9 FileInputStream (java.io.FileInputStream)9