Search in sources :

Example 66 with IPhonenumber

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

the class Callto method generateXml.

private StringBuffer generateXml(Object o, String dial, String ext) throws UnsupportedEncodingException {
    StringBuffer xml = new StringBuffer();
    xml.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
    xml.append(IJAMConst.CRLF);
    xml.append("<callto>");
    xml.append(IJAMConst.CRLF);
    xml.append("<status>");
    if (dial != null && dial.length() > 1) {
        dial = PhonenumberAnalyzer.getInstance(getRuntime()).toCallable(dial);
        IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(dial);
        try {
            Method m = o.getClass().getMethod("dial", new Class[] { IPhonenumber.class, String.class });
            if (ext != null) {
                ext = URLDecoder.decode(ext, "UTF-8");
            }
            m.invoke(o, new Object[] { pn, ext });
            xml.append("OK");
        } catch (Exception ex) {
            xml.append(URLEncoder.encode("ERROR: " + ex.getCause().getMessage(), "utf-8"));
            xml.append(IJAMConst.CRLF);
        }
    } else {
        xml.append("ERROR: no valid number to call");
        xml.append(IJAMConst.CRLF);
    }
    xml.append(IJAMConst.CRLF);
    xml.append("</status>");
    xml.append(IJAMConst.CRLF);
    if (dial != null && dial.length() > 1) {
        xml.append("<number>");
        xml.append(URLEncoder.encode(dial, "utf-8"));
        xml.append("</number>");
        xml.append(IJAMConst.CRLF);
    }
    if (ext != null && ext.length() > 1) {
        xml.append("<extension>");
        xml.append(URLEncoder.encode(ext, "utf-8"));
        xml.append("</extension>");
        xml.append(IJAMConst.CRLF);
    }
    xml.append("</callto>");
    return xml;
}
Also used : Method(java.lang.reflect.Method) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 67 with IPhonenumber

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

the class Dial method handleWithException.

public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
    m_logger.info("Calling server Dial comamnd...");
    String calltoclass = null;
    if (PIMRuntime.getInstance().getMonitorListener().getMonitor("FritzBoxMonitor") != null) {
        calltoclass = "de.janrufmonitor.fritzbox.QuickDialer";
    } else if (PIMRuntime.getInstance().getMonitorListener().getMonitor("XTapiMonitor") != null) {
        calltoclass = "de.janrufmonitor.xtapi.QuickDialer";
    } else {
        throw new HandlerException("No FritzBoxMonitor or XTapiMonitor available.", 404);
    }
    try {
        Class handler = Thread.currentThread().getContextClassLoader().loadClass(calltoclass);
        Object o = handler.newInstance();
        String ext = req.getParameter(PARAMETER_EXTENSION);
        String dial = req.getParameter(PARAMETER_NUMBER);
        m_logger.info("Dial comamnd parameter dial=" + dial + ", ext=" + ext);
        if (dial != null && dial.length() > 1) {
            dial = PhonenumberAnalyzer.getInstance(getRuntime()).toCallable(dial);
            IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(dial);
            try {
                Method m = o.getClass().getMethod("dial", new Class[] { IPhonenumber.class, String.class });
                if (ext != null) {
                    ext = URLDecoder.decode(ext, "UTF-8");
                }
                m.invoke(o, new Object[] { pn, ext });
            } catch (Exception ex) {
                throw new HandlerException("Could not dial number.", 500);
            }
        }
        resp.getContentStreamForWrite().close();
    } catch (HandlerException e) {
        throw e;
    } catch (ClassNotFoundException ex) {
        throw new HandlerException("Class not found: " + calltoclass, 500);
    } catch (InstantiationException e) {
        throw new HandlerException("Cannot instantiate class: " + calltoclass, 500);
    } catch (IllegalAccessException e) {
        throw new HandlerException("Illegal access for class: " + calltoclass, 500);
    } catch (Exception e) {
        throw new HandlerException(e.getMessage(), 500);
    }
}
Also used : HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) Method(java.lang.reflect.Method) HandlerException(de.janrufmonitor.service.commons.http.handler.HandlerException) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 68 with IPhonenumber

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

the class OutgoingCallHandler method getURI.

public URI getURI() throws Exception {
    StringBuffer uri = new StringBuffer();
    uri.append("/?");
    uri.append(OutgoingCallHandler.PARAMETER_ACTION);
    uri.append("=");
    uri.append(OutgoingCallHandler.ACTION_OUTGOINGCALL);
    uri.append("&");
    uri.append(OutgoingCallHandler.PARAMETER_NUMBER);
    uri.append("=");
    IPhonenumber pn = this.m_call.getCaller().getPhoneNumber();
    uri.append(pn.getTelephoneNumber());
    uri.append("&");
    uri.append(OutgoingCallHandler.PARAMETER_MSN);
    uri.append("=");
    uri.append(this.m_call.getMSN().getMSN());
    uri.append("&");
    uri.append(OutgoingCallHandler.PARAMETER_CIP);
    uri.append("=");
    uri.append(this.m_call.getCIP().getCIP());
    uri.append("&");
    uri.append(OutgoingCallHandler.PARAMETER_DATE);
    uri.append("=");
    uri.append(this.m_call.getDate().getTime());
    return new URI(uri.toString());
}
Also used : URI(java.net.URI) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 69 with IPhonenumber

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

the class XMLCallerHandler method startElement.

public void startElement(String uri, String name, String qname, Attributes attributes) throws SAXException {
    if (this.m_multi && qname.equalsIgnoreCase(TAG_CALLERLIST)) {
        this.m_callerList = this.getRuntime().getCallerFactory().createCallerList();
    }
    if (qname.equalsIgnoreCase(TAG_CALLER)) {
        List phns = new ArrayList();
        this.m_caller = this.getRuntime().getCallerFactory().createCaller(this.getRuntime().getCallerFactory().createName("", ""), phns);
        this.m_caller.getPhonenumbers().clear();
    }
    if (qname.equalsIgnoreCase(TAG_UUID)) {
        this.m_caller.setUUID(attributes.getValue(ATTRIBUTE_VALUE));
    }
    if (qname.equalsIgnoreCase(TAG_IMAGE_CONTENT)) {
        this.m_image_content = attributes.getValue(ATTRIBUTE_VALUE);
    }
    if (qname.equalsIgnoreCase(TAG_FIRSTNAME)) {
        IName cname = this.m_caller.getName();
        cname.setFirstname(decode(attributes.getValue(ATTRIBUTE_VALUE)));
        this.m_caller.setName(cname);
    }
    if (qname.equalsIgnoreCase(TAG_LASTNAME)) {
        IName cname = this.m_caller.getName();
        cname.setLastname(decode(attributes.getValue(ATTRIBUTE_VALUE)));
        this.m_caller.setName(cname);
    }
    if (qname.equalsIgnoreCase(TAG_ADDITIONAL)) {
        IName cname = this.m_caller.getName();
        cname.setAdditional(decode(attributes.getValue(ATTRIBUTE_VALUE)));
        this.m_caller.setName(cname);
    }
    if (qname.equalsIgnoreCase(TAG_PHONENUMBER)) {
        List pns = new ArrayList(this.m_caller.getPhonenumbers());
        String iarea = attributes.getValue(TAG_INTAREA);
        String area = attributes.getValue(TAG_AREA);
        String cn = attributes.getValue(TAG_CALLNUMBER);
        String tn = attributes.getValue(TAG_TELEPHONENUMBER);
        if (iarea != null && iarea.length() > 0 && area != null && cn != null && cn.length() > 0) {
            IPhonenumber n = getRuntime().getCallerFactory().createPhonenumber(iarea, area, cn);
            n.setTelephoneNumber(tn);
            if (pns.size() == 0) {
                this.m_caller.setPhoneNumber(n);
            } else {
                pns.add(n);
                this.m_caller.setPhonenumbers(pns);
            }
        }
    }
    if (qname.equalsIgnoreCase(TAG_INTAREA)) {
        IPhonenumber pn = this.m_caller.getPhoneNumber();
        pn.setIntAreaCode(attributes.getValue(ATTRIBUTE_VALUE));
        this.m_caller.setPhoneNumber(pn);
    }
    if (qname.equalsIgnoreCase(TAG_AREA)) {
        IPhonenumber pn = this.m_caller.getPhoneNumber();
        pn.setAreaCode(attributes.getValue(ATTRIBUTE_VALUE));
        this.m_caller.setPhoneNumber(pn);
    }
    if (qname.equalsIgnoreCase(TAG_CALLNUMBER)) {
        IPhonenumber pn = this.m_caller.getPhoneNumber();
        pn.setCallNumber(attributes.getValue(ATTRIBUTE_VALUE));
        this.m_caller.setPhoneNumber(pn);
    }
    if (qname.equalsIgnoreCase(TAG_TELEPHONENUMBER)) {
        IPhonenumber pn = this.m_caller.getPhoneNumber();
        pn.setTelephoneNumber(attributes.getValue(ATTRIBUTE_VALUE));
        this.m_caller.setPhoneNumber(pn);
    }
    if (qname.equalsIgnoreCase(TAG_ATTRIBUTE)) {
        IAttribute att = this.getRuntime().getCallerFactory().createAttribute(attributes.getValue(ATTRIBUTE_NAME), decode(attributes.getValue(ATTRIBUTE_VALUE)));
        this.m_caller.setAttribute(att);
    }
}
Also used : ArrayList(java.util.ArrayList) IAttribute(de.janrufmonitor.framework.IAttribute) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IName(de.janrufmonitor.framework.IName) IPhonenumber(de.janrufmonitor.framework.IPhonenumber)

Example 70 with IPhonenumber

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

the class IncomingCallHandler method getURI.

public URI getURI() throws Exception {
    StringBuffer uri = new StringBuffer();
    uri.append("/?");
    uri.append(IncomingCallHandler.PARAMETER_ACTION);
    uri.append("=");
    uri.append(IncomingCallHandler.ACTION_INCOMINGCALL);
    uri.append("&");
    uri.append(IncomingCallHandler.PARAMETER_NUMBER);
    uri.append("=");
    IPhonenumber pn = this.m_call.getCaller().getPhoneNumber();
    uri.append(pn.getTelephoneNumber());
    uri.append("&");
    uri.append(IncomingCallHandler.PARAMETER_MSN);
    uri.append("=");
    uri.append(this.m_call.getMSN().getMSN());
    uri.append("&");
    uri.append(IncomingCallHandler.PARAMETER_CIP);
    uri.append("=");
    uri.append(this.m_call.getCIP().getCIP());
    uri.append("&");
    uri.append(IncomingCallHandler.PARAMETER_DATE);
    uri.append("=");
    uri.append(this.m_call.getDate().getTime());
    return new URI(uri.toString());
}
Also used : URI(java.net.URI) 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