use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class MacAddressBookProxy method getContactsByAreaCode.
@SuppressWarnings("unchecked")
public synchronized ICallerList getContactsByAreaCode(String countrycode, String areacode) throws MacAddressBookProxyException {
this.m_total = 0;
this.m_current = 0;
final ICallerList callers = getRuntime().getCallerFactory().createCallerList();
if (this.m_dbh != null) {
try {
List uuids = this.m_dbh.select(countrycode, areacode);
if (uuids.size() > 0) {
List contacts = getRecordsByUIDs(uuids);
if (contacts.size() > 0) {
this.m_total = contacts.size();
ICaller businessCaller, privateCaller = null;
for (Object contact : contacts) {
if (contact instanceof Map<?, ?>) {
this.m_current++;
privateCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new PrivateMacAddressBookMapping());
businessCaller = MacAddressBookMappingManager.getInstance().mapToJamCaller((Map<?, ?>) contact, new BusinessMacAddressBookMapping());
if (privateCaller == null && businessCaller != null && this.containsCountryAndAreaCode(businessCaller, countrycode, areacode)) {
callers.add(businessCaller);
}
if (privateCaller != null && businessCaller == null && this.containsCountryAndAreaCode(privateCaller, countrycode, areacode)) {
callers.add(privateCaller);
}
if (privateCaller != null && businessCaller != null) {
if (((IMultiPhoneCaller) businessCaller).getPhonenumbers().size() == 1) {
// only one entry available
IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) businessCaller).getPhonenumbers().get(0);
IAttribute numbertype = businessCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
this.m_logger.info("Bussiness caller will be dropped. Only mobile number available, but still in private contact: " + businessCaller);
businessCaller = null;
}
}
if (((IMultiPhoneCaller) privateCaller).getPhonenumbers().size() == 1 && businessCaller != null) {
// only one entry available
IPhonenumber pn = (IPhonenumber) ((IMultiPhoneCaller) privateCaller).getPhonenumbers().get(0);
IAttribute numbertype = privateCaller.getAttribute(IMacAddressBookNumberMapping.MAPPING_ATTTRIBUTE_ID + pn.getTelephoneNumber());
if (numbertype != null && numbertype.getValue().equalsIgnoreCase(IMacAddressBookConst.MOBILE)) {
this.m_logger.info("Private caller will be dropped. Only mobile number available, but still in business contact: " + privateCaller);
privateCaller = null;
}
}
if (privateCaller != null && this.containsCountryAndAreaCode(privateCaller, countrycode, areacode)) {
callers.add(privateCaller);
}
if (businessCaller != null && this.containsCountryAndAreaCode(businessCaller, countrycode, areacode)) {
callers.add(businessCaller);
}
}
}
}
}
}
} catch (SQLException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
if (callers.size() > 0) {
Thread updateDbhThread = new Thread() {
public void run() {
updateProxyDatabase(callers);
}
};
updateDbhThread.setName("JAM-MacAddressBookSync-Thread-(deamon)");
updateDbhThread.start();
}
return callers;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class Callto method generateHtml.
private StringBuffer generateHtml(Object o, String dial, String ext) {
StringBuffer html = new StringBuffer();
html.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" + IJAMConst.CRLF);
html.append("<html>" + IJAMConst.CRLF);
html.append("<head>" + IJAMConst.CRLF);
html.append("<title>");
html.append("Callto");
html.append("</title>" + IJAMConst.CRLF);
html.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">" + IJAMConst.CRLF);
html.append("<link rel=\"stylesheet\" href=\"/config/web-config/styles/jam-styles.css\" type=\"text/css\">" + IJAMConst.CRLF);
html.append("<link rel=\"SHORTCUT ICON\" href=\"/config/web-config/images/favicon.ico\" type=\"image/ico\" />");
html.append("</head>" + IJAMConst.CRLF);
html.append("<body>" + IJAMConst.CRLF);
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 });
html.append("Call to 0");
html.append(pn.getTelephoneNumber());
html.append(" successfully established" + (ext != null ? " on line " + ext : "") + ". Take the head phone...");
html.append(IJAMConst.CRLF);
} catch (Exception ex) {
html.append(ex.getMessage());
html.append(IJAMConst.CRLF);
}
} else {
html.append("Wrong callto syntax: http://<server>:<port>/callto?dial=<number>[&ext=<extension>]");
html.append(IJAMConst.CRLF);
}
html.append("</body>" + IJAMConst.CRLF);
html.append("</html>" + IJAMConst.CRLF);
return html;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class XMLSerializer method toXML.
private static synchronized String toXML(List phones) {
StringBuffer c = new StringBuffer();
c.append("<phonenumbers>");
Iterator i = phones.iterator();
IPhonenumber a = null;
while (i.hasNext()) {
a = ((IPhonenumber) i.next());
c.append("<phonenumber intarea=\"" + encode(a.getIntAreaCode()) + "\" area=\"" + encode(a.getAreaCode()) + "\" callnumber=\"" + encode(a.getCallNumber()) + "\" telephonenumber=\"" + encode(a.getTelephoneNumber()) + "\" />");
}
c.append("</phonenumbers>");
return c.toString();
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class GetCaller method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(GetCaller.PARAMETER_CALLERMANAGER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IIdentifyCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
String number = null;
try {
number = req.getParameter(GetCaller.PARAMETER_NUMBER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (number == null || number.length() == 0) {
this.m_logger.severe("Parameter &number= was empty or not set.");
throw new HandlerException("Parameter &number= was empty or not set.", 404);
}
IPhonenumber pn = null;
StringTokenizer st = new StringTokenizer(number, ";");
if (st.countTokens() == 3) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), st.nextToken().trim(), st.nextToken().trim());
}
if (st.countTokens() == 2) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), "", st.nextToken().trim());
}
if (st.countTokens() == 1) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim());
}
try {
ICaller caller = ((IIdentifyCallerRepository) mgr).getCaller(pn);
String xml = XMLSerializer.toXML(caller, false);
resp.setParameter("Content-Type", "text/xml");
resp.setParameter("Content-Length", Long.toString(xml.length()));
OutputStream ps = resp.getContentStreamForWrite();
ps.write(xml.getBytes());
ps.flush();
ps.close();
} catch (CallerNotFoundException e) {
throw new HandlerException(e.getMessage(), 404);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class Image method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(Image.PARAMETER_CALLERMANAGER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (manager == null)
mgr = this.getRuntime().getCallerManagerFactory().getDefaultCallerManager();
if (manager != null && manager.length() > 0)
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager(manager);
if (mgr == null || !mgr.isActive() || !mgr.isSupported(IIdentifyCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
String number = null;
try {
number = req.getParameter(Image.PARAMETER_NUMBER);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
if (number == null || number.length() == 0) {
this.m_logger.severe("Parameter &number= was empty or not set.");
throw new HandlerException("Parameter &number= was empty or not set.", 404);
}
IPhonenumber pn = null;
StringTokenizer st = new StringTokenizer(number, ";");
if (st.countTokens() == 3) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), st.nextToken().trim(), st.nextToken().trim());
}
if (st.countTokens() == 2) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim(), "", st.nextToken().trim());
}
if (st.countTokens() == 1) {
pn = this.getRuntime().getCallerFactory().createPhonenumber(st.nextToken().trim());
}
try {
ICaller caller = ((IIdentifyCallerRepository) mgr).getCaller(pn);
IAttribute imageAtt = caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH);
if (ImageHandler.getInstance().hasImage(caller)) {
InputStream in = ImageHandler.getInstance().getImageStream(caller);
if (in != null) {
resp.setParameter("Content-Type", this.getMimetype("jpg"));
OutputStream ps = resp.getContentStreamForWrite();
byte[] buffer = new byte[8092];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
ps.write(buffer, 0, bytesRead);
}
in.close();
ps.flush();
ps.close();
}
} else if (imageAtt != null) {
String pathToImage = PathResolver.getInstance(getRuntime()).resolve(imageAtt.getValue());
File image = new File(pathToImage);
if (image.exists()) {
resp.setParameter("Content-Type", this.getMimetype(pathToImage));
resp.setParameter("Content-Length", Long.toString(image.length()));
OutputStream ps = resp.getContentStreamForWrite();
FileInputStream in = new FileInputStream(image);
byte[] buffer = new byte[8092];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
ps.write(buffer, 0, bytesRead);
}
in.close();
ps.flush();
ps.close();
} else {
throw new CallerNotFoundException("Image " + pathToImage + " not found");
}
} else {
throw new CallerNotFoundException("No image assigned for caller " + caller);
}
} catch (CallerNotFoundException e) {
throw new HandlerException(e.getMessage(), 404);
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
Aggregations