use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class XMLSerializer method toXML.
private static synchronized String toXML(IAttributeMap l) {
StringBuffer c = new StringBuffer();
c.append("<attributes>");
Iterator i = l.iterator();
IAttribute a = null;
while (i.hasNext()) {
a = ((IAttribute) i.next());
c.append("<attribute name=\"" + a.getName() + "\" value=\"" + encode(a.getValue()) + "\" />");
}
c.append("</attributes>");
return c.toString();
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class GoogleMapsDialogPlugin method buildRequestParameters.
private String buildRequestParameters(ICaller c) {
StringBuffer params = new StringBuffer();
IAttribute att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET);
if (att != null) {
params.append("+");
params.append(encode(att.getValue()));
}
att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_STREET_NO);
if (att != null) {
params.append("+");
params.append(encode(att.getValue()));
}
att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE);
if (att != null) {
params.append("+");
params.append(encode(att.getValue()));
}
att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CITY);
if (att != null) {
params.append("+");
params.append(encode(att.getValue()));
}
att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY);
if (att != null) {
params.append("+");
params.append(encode(att.getValue()));
}
return params.toString();
}
use of de.janrufmonitor.framework.IAttribute in project janrufmonitor by tbrandt77.
the class EditorController method deleteElements.
public synchronized void deleteElements(Object list) {
if (list != null && list instanceof ICallerList) {
Map cms = new HashMap();
ICallerList tmplist = null;
ICaller c = null;
for (int i = 0; i < ((ICallerList) list).size(); i++) {
c = ((ICallerList) list).get(i);
IAttribute att = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_CALLERMANAGER);
String cname = (att == null ? "all" : att.getValue());
if (cms.containsKey(cname)) {
tmplist = (ICallerList) cms.get(cname);
tmplist.add(c);
} else {
tmplist = this.getRuntime().getCallerFactory().createCallerList(1);
tmplist.add(c);
cms.put(cname, tmplist);
}
}
List managers = this.getActiveCallerManagers();
ICallerManager mgr = null;
for (int i = 0; i < managers.size(); i++) {
mgr = this.getRuntime().getCallerManagerFactory().getCallerManager((String) managers.get(i));
if (mgr != null) {
if (mgr.isSupported(IWriteCallerRepository.class)) {
tmplist = (ICallerList) cms.get("all");
if (tmplist != null) {
this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
((IWriteCallerRepository) mgr).removeCaller(tmplist);
}
tmplist = (ICallerList) cms.get(mgr.getManagerID());
if (tmplist != null) {
this.m_logger.info("removing " + tmplist.size() + " callers to manager: " + mgr.getManagerID());
((IWriteCallerRepository) mgr).removeCaller(tmplist);
}
}
}
}
}
}
use of de.janrufmonitor.framework.IAttribute 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.IAttribute 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