use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class LastOpenEditorAction method getLastopenedRepositories.
private List getLastopenedRepositories() {
List cms = new ArrayList();
Properties config = getRuntime().getConfigManagerFactory().getConfigManager().getProperties(NAMESPACE);
String lastOpen = config.getProperty(EditorConfigConst.CFG_LASTOPEN, "");
if (lastOpen.length() > 0) {
String[] locm = lastOpen.split(";");
if (locm != null && locm.length > 0) {
String l = null;
for (int i = 0; i < locm.length; i++) {
l = locm[i];
if (l.split("%").length == 1) {
ICallerManager mgr = getRuntime().getCallerManagerFactory().getCallerManager(l.split("%")[0]);
if (mgr != null && mgr.isActive() && mgr.isSupported(IRemoteRepository.class)) {
cms.add(new RemoteAction((IRemoteRepository) mgr));
}
continue;
}
if (l.split("%").length == 2) {
ICallerManager mgr = getRuntime().getCallerManagerFactory().getCallerManager(l.split("%")[0]);
if (mgr != null && mgr.isActive() && mgr.isSupported(ILocalRepository.class)) {
if (new File(l.split("%")[1]).exists())
cms.add(new LocalAction((ILocalRepository) mgr, l.split("%")[1]));
}
}
}
}
}
return cms;
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class UpdateCallerList method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
ICallerManager mgr = null;
String manager = null;
try {
manager = req.getParameter(UpdateCallerList.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(IWriteCallerRepository.class)) {
throw new HandlerException("Requested Callermanager does not exist or is not active.", 404);
}
ICallerList l;
try {
l = XMLSerializer.toCallerList(this.getPostData(req));
if (l != null) {
this.m_logger.info("Updating caller list with " + l.size() + " entries.");
for (int i = 0, j = l.size(); i < j; i++) ((IWriteCallerRepository) mgr).updateCaller(l.get(i));
resp.getContentStreamForWrite().close();
} else {
this.m_logger.severe("Invalid caller list transfered from client.");
throw new HandlerException("Invalid caller list transfered from client.", 500);
}
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.repository.ICallerManager 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.repository.ICallerManager 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);
}
}
use of de.janrufmonitor.repository.ICallerManager in project janrufmonitor by tbrandt77.
the class Identifier method identify.
/**
* Identifies a caller with all active caller managers specified in the configuration.
*
* @param r the current runtime
* @param pn a valid number, should not be a clired number or null
* @param activeCallerManagers a list of active caller managers
* @return an identified ICaller object or null, if not identified by any caller manager
*/
public static ICaller identify(IRuntime r, IPhonenumber pn, List activeCallerManagers) {
if (activeCallerManagers == null || activeCallerManagers.size() == 0)
return null;
long start = System.currentTimeMillis();
Identifier.logger.info("<---- Begin caller identification ---->");
Identifier.logger.info("Order of identification: " + activeCallerManagers.toString());
ICaller identifiedCaller = null;
int i = 0;
Object obj = null;
ICallerManager cm = null;
while (identifiedCaller == null && i < activeCallerManagers.size()) {
obj = activeCallerManagers.get(i);
i++;
if (obj != null && obj instanceof ICallerManager) {
cm = (ICallerManager) obj;
try {
if (cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
identifiedCaller = ((IIdentifyCallerRepository) cm).getCaller(pn);
Identifier.logger.info("Caller identified by [" + cm.getManagerID() + "]: " + identifiedCaller);
}
} catch (CallerNotFoundException e) {
Identifier.logger.info("Caller was not identified by [" + cm.getManagerID() + "]: " + e.getMessage());
}
} else {
Identifier.logger.severe("Invalid caller manager object: " + obj);
}
}
Identifier.logger.info("<---- Finished caller identification (" + (System.currentTimeMillis() - start) + " msec.) ---->");
return identifiedCaller;
}
Aggregations