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;
}
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);
}
}
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());
}
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);
}
}
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());
}
Aggregations