use of de.janrufmonitor.repository.CallerNotFoundException 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.CallerNotFoundException 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.CallerNotFoundException 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;
}
use of de.janrufmonitor.repository.CallerNotFoundException in project janrufmonitor by tbrandt77.
the class OutlookImportAction method run.
public void run() {
String filter = this.m_app.getApplication().getConfiguration().getProperty("filter", "");
EditorFilterManager efm = new EditorFilterManager();
final IAttribute category = getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CATEGORY, "");
if (filter.length() > 0) {
String cat = null;
IFilter[] filters = efm.getFiltersFromString(filter);
for (int z = 0; z < filters.length; z++) {
if (filters[z].getType().equals(FilterType.ATTRIBUTE)) {
AttributeFilter cf = ((AttributeFilter) filters[z]);
IAttributeMap m = cf.getAttributeMap();
if (m != null && m.size() > 0) {
Iterator it = m.iterator();
IAttribute a = null;
while (it.hasNext()) {
a = (IAttribute) it.next();
if (a.getName().equalsIgnoreCase(IJAMConst.ATTRIBUTE_NAME_CATEGORY)) {
cat = a.getValue();
}
}
}
}
}
if (cat != null) {
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
String text = this.getI18nManager().getString("ui.jface.application.editor.action.ImportAction", "assigncategoryconfirm", "label", this.getLanguage());
text = StringUtils.replaceString(text, "{%1}", cat);
messageBox.setMessage(text);
if (messageBox.open() == SWT.YES) {
category.setValue(cat);
}
}
}
// determine subfolders
OutlookTransformer ot = new OutlookTransformer();
List folders = ot.getAllContactFolders();
if (folders.size() > 0) {
int itemCount = 0;
String folder = null;
for (int i = 0, j = folders.size(); i < j; i++) {
folder = (String) folders.get(i);
itemCount = ot.getContactCount(folder);
if (itemCount > 0) {
getRuntime().getConfigManagerFactory().getConfigManager().setProperty(OutlookContactManager.NAMESPACE, "subfolder_" + folder, "true");
}
}
getRuntime().getConfigManagerFactory().getConfigManager().saveConfiguration();
}
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "importprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
progressMonitor.worked(1);
OutlookTransformer otf = new OutlookTransformer();
ICallerList callers = otf.getCallerListFromAllContacts();
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "reduce", "label", getLanguage()));
otf.removeCallerManagerID(callers);
// determine duplicates
String currentCallerManagerID = m_app.getApplication().getConfiguration().getProperty(CFG_REPOSITORY);
if (currentCallerManagerID != null && currentCallerManagerID.trim().length() > 0) {
ICallerManager currentCallerManager = getRuntime().getCallerManagerFactory().getCallerManager(currentCallerManagerID);
if (currentCallerManager != null && currentCallerManager.isSupported(IWriteCallerRepository.class) && currentCallerManager.isSupported(IIdentifyCallerRepository.class)) {
ICallerList addCallers = getRuntime().getCallerFactory().createCallerList();
// ICallerList removeCallers = getRuntime().getCallerFactory().createCallerList();
ICaller currentCaller = null;
String text = null;
for (int i = 0, j = callers.size(); i < j; i++) {
// ICaller testCaller = null;
currentCaller = callers.get(i);
text = getI18nManager().getString(getNamespace(), "check", "label", getLanguage());
text = StringUtils.replaceString(text, "{%1}", Formatter.getInstance(getRuntime()).parse("%a:ln%, %a:fn%", currentCaller));
progressMonitor.setTaskName(text);
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
}
try {
// testCaller = ((IIdentifyCallerRepository)currentCallerManager).getCaller(currentCaller.getPhoneNumber());
((IIdentifyCallerRepository) currentCallerManager).getCaller(currentCaller.getPhoneNumber());
} catch (CallerNotFoundException e) {
if (category != null && category.getValue().length() > 0)
currentCaller.setAttribute(category);
addCallers.add(currentCaller);
}
// if (testCaller!=null) {
// removeCallers.add(testCaller);
// }
}
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
try {
Thread.sleep(1250);
} catch (InterruptedException e1) {
}
// if (removeCallers.size()>0)
// m_app.getController().deleteElements(removeCallers);
m_app.getController().addElements(addCallers);
}
} else {
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "add", "label", getLanguage()));
m_app.getController().addElements(callers);
}
progressMonitor.done();
}
};
pmd.setBlockOnOpen(false);
pmd.run(true, false, r);
// ModalContext.run(r, true, pmd.getProgressMonitor(), DisplayManager.getDefaultDisplay());
} catch (InterruptedException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (InvocationTargetException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
m_app.updateViews(true);
return;
}
use of de.janrufmonitor.repository.CallerNotFoundException in project janrufmonitor by tbrandt77.
the class GosPage method createControl.
public void createControl(Composite c) {
Composite co = new Composite(c, SWT.NONE);
co.setLayout(new GridLayout(2, false));
co.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
int operations = DND.DROP_MOVE;
Transfer[] types = new Transfer[] { FileTransfer.getInstance() };
DropTarget target = new DropTarget(co, operations);
target.setTransfer(types);
target.addDropListener(new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
// A drop has occurred, copy over the data
if (event.data == null) {
event.detail = DND.DROP_NONE;
return;
}
File f = new File(((String[]) event.data)[0]);
m_logger.info("Detected drag action with file: " + f.getAbsolutePath());
if (f.exists() && f.getName().toLowerCase().endsWith(".jam.zip")) {
ZipArchive zip = new ZipArchive(f, false);
try {
zip.open();
List files = zip.list(new FilenameFilter() {
public boolean accept(File f, String name) {
return name.toLowerCase().startsWith("install/repository.") && name.toLowerCase().endsWith(".inf");
}
});
if (files.size() == 1) {
m_logger.info("Found a valid generic online module.");
Properties inf = new Properties();
inf.load(zip.get((String) files.get(0)));
String ns = ((String) files.get(0)).substring("install/repository.".length(), ((String) files.get(0)).length() - 4);
name.setText(ns);
url.setText(inf.getProperty("repository." + ns + ":url:value", ""));
offset.setText(inf.getProperty("repository." + ns + ":skipbytes:value", "0"));
lastname.setText(inf.getProperty("repository." + ns + ":regexp.lastname:value", ""));
firstname.setText(inf.getProperty("repository." + ns + ":regexp.firstname:value", ""));
street.setText(inf.getProperty("repository." + ns + ":regexp.street:value", ""));
streetno.setText(inf.getProperty("repository." + ns + ":regexp.streetno:value", ""));
postal.setText(inf.getProperty("repository." + ns + ":regexp.pcode:value", ""));
city.setText(inf.getProperty("repository." + ns + ":regexp.city:value", ""));
area.setText(inf.getProperty("repository." + ns + ":regexp.areacode:value", ""));
number.setText(inf.getProperty("repository." + ns + ":regexp.phone:value", ""));
intarea.setText(inf.getProperty("repository." + ns + ":intareacode:value", ""));
}
zip.close();
} catch (ZipArchiveException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
} catch (IOException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
});
Label l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "name", "label", this.m_language));
GridData gd = new GridData();
gd.widthHint = 150;
name = new Text(co, SWT.BORDER);
name.setLayoutData(gd);
name.setText("");
name.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "version", "label", this.m_language));
gd = new GridData();
gd.widthHint = 50;
version = new Text(co, SWT.BORDER);
version.setLayoutData(gd);
version.setText("1.0.0");
version.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "url", "label", this.m_language));
url = new Text(co, SWT.BORDER);
gd.widthHint = 300;
url.setLayoutData(gd);
url.setText("");
url.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "offset", "label", this.m_language));
offset = new Text(co, SWT.BORDER);
offset.setText("");
offset.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "lastname", "label", this.m_language));
lastname = new Text(co, SWT.BORDER);
lastname.setLayoutData(gd);
lastname.setText("");
lastname.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
lastname.setForeground(new Color(lastname.getDisplay(), 0, 0, 0));
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "firstname", "label", this.m_language));
firstname = new Text(co, SWT.BORDER);
firstname.setText("");
firstname.setLayoutData(gd);
firstname.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
firstname.setForeground(new Color(firstname.getDisplay(), 0, 0, 0));
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "street", "label", this.m_language));
street = new Text(co, SWT.BORDER);
street.setLayoutData(gd);
street.setText("");
street.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
street.setForeground(new Color(street.getDisplay(), 0, 0, 0));
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "streetno", "label", this.m_language));
streetno = new Text(co, SWT.BORDER);
streetno.setLayoutData(gd);
streetno.setText("");
streetno.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
streetno.setForeground(new Color(streetno.getDisplay(), 0, 0, 0));
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "postal", "label", this.m_language));
postal = new Text(co, SWT.BORDER);
postal.setLayoutData(gd);
postal.setText("");
postal.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
postal.setForeground(new Color(postal.getDisplay(), 0, 0, 0));
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "city", "label", this.m_language));
city = new Text(co, SWT.BORDER);
city.setLayoutData(gd);
city.setText("");
city.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
city.setForeground(new Color(city.getDisplay(), 0, 0, 0));
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "area", "label", this.m_language));
area = new Text(co, SWT.BORDER);
area.setLayoutData(gd);
area.setText("");
area.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
area.setForeground(new Color(area.getDisplay(), 0, 0, 0));
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "number", "label", this.m_language));
number = new Text(co, SWT.BORDER);
number.setLayoutData(gd);
number.setText("");
number.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
number.setForeground(new Color(number.getDisplay(), 0, 0, 0));
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "intarea", "label", this.m_language));
intarea = new Text(co, SWT.BORDER);
intarea.setText("49");
intarea.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "locale", "label", this.m_language));
Locale[] locales = Locale.getAvailableLocales();
List localeList = new ArrayList(locales.length);
Locale lo = null;
for (int i = 0; i < locales.length; i++) {
lo = locales[i];
if (lo.toString().indexOf("_") > 0)
localeList.add(lo);
}
Collections.sort(localeList, new Comparator() {
public int compare(Object l1, Object l2) {
if (l1 instanceof Locale && l2 instanceof Locale) {
return ((Locale) l1).getDisplayCountry().compareTo(((Locale) l2).getDisplayCountry());
}
return 0;
}
});
String[] countryNames = new String[localeList.size()];
for (int i = 0; i < localeList.size(); i++) {
countryNames[i] = ((Locale) localeList.get(i)).getDisplayCountry() + " (" + ((Locale) localeList.get(i)).getDisplayLanguage() + ")";
}
locale = new Combo(co, SWT.READ_ONLY);
locale.setItems(countryNames);
for (int i = 0; i < countryNames.length; i++) {
locale.setData(countryNames[i], localeList.get(i));
}
locale.select(0);
locale.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
}
});
l = new Label(co, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "encoding", "label", this.m_language));
String[] encodings = new String[] { "ISO-8859-1", "UTF-8", "UTF-16" };
encoding = new Combo(co, SWT.READ_ONLY);
encoding.setItems(encodings);
for (int i = 0; i < encodings.length; i++) {
encoding.setData(encodings[i], encodings[i]);
}
encoding.select(0);
locale.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
setPageComplete(isComplete());
}
});
Composite dco2 = new Composite(co, SWT.NONE);
dco2.setLayout(new GridLayout(1, false));
gd = new GridData();
gd.horizontalSpan = 2;
dco2.setLayoutData(gd);
ffe = new FileFieldEditor(this.m_i18n.getString(this.getNamespace(), "fname", "label", this.m_language), this.m_i18n.getString(this.getNamespace(), "flabel", "label", this.m_language), dco2);
ffe.setFileExtensions(new String[] { "*.png" });
l = new Label(co, SWT.LEFT);
l = new Label(co, SWT.LEFT);
Composite dco = new Composite(co, SWT.NONE);
dco.setLayout(new GridLayout(1, false));
gd = new GridData();
gd.horizontalSpan = 2;
dco.setLayoutData(gd);
dfe = new DirectoryFieldEditor(this.m_i18n.getString(this.getNamespace(), "dname", "label", this.m_language), this.m_i18n.getString(this.getNamespace(), "dlabel", "label", this.m_language), this.m_i18n.getString(this.getNamespace(), "dmessage", "label", this.m_language), dco);
dfe.setStringValue(PathResolver.getInstance().getTempDirectory());
Group c2 = new Group(co, SWT.SHADOW_ETCHED_IN);
c2.setLayout(new GridLayout(2, false));
gd = new GridData();
gd.horizontalSpan = 2;
gd.horizontalAlignment = GridData.FILL_HORIZONTAL;
c2.setLayoutData(gd);
l = new Label(c2, SWT.LEFT);
l.setText(this.m_i18n.getString(this.getNamespace(), "testnumber", "label", this.m_language));
l = new Label(c2, SWT.LEFT);
final Text testnum = new Text(c2, SWT.BORDER);
testnum.setText("");
gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 400;
// gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
testnum.setLayoutData(gd);
final Button test = new Button(c2, SWT.PUSH);
test.setEnabled(false);
test.setText(this.m_i18n.getString(this.getNamespace(), "test", "label", this.m_language));
test.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(testnum.getText().startsWith("0") ? testnum.getText().substring(1) : testnum.getText());
pn.setIntAreaCode(intarea.getText());
Properties config = new Properties();
config.setProperty("version", version.getText());
config.setProperty("skipbytes", offset.getText());
config.setProperty("url", url.getText());
config.setProperty("regexp.lastname", lastname.getText());
config.setProperty("regexp.firstname", firstname.getText());
config.setProperty("regexp.street", street.getText());
config.setProperty("regexp.streetno", streetno.getText());
config.setProperty("regexp.pcode", postal.getText());
config.setProperty("regexp.city", city.getText());
config.setProperty("regexp.areacode", area.getText());
config.setProperty("regexp.phone", number.getText());
config.setProperty("intareacode", intarea.getText());
config.setProperty("locale", ((Locale) locale.getData(locale.getText())).toString());
config.setProperty("encoding", encoding.getText());
config.setProperty("icon", ffe.getStringValue());
TestWebCallerManager twcm = new TestWebCallerManager(config);
try {
ICaller c = twcm.getCaller(pn);
IService dialog = getRuntime().getServiceFactory().getService("DefaultCallDialogService");
if (dialog != null) {
ICall call = getRuntime().getCallFactory().createCall(c, getRuntime().getMsnManager().createMsn("12345"), getRuntime().getCipManager().createCip("1"));
if (dialog instanceof AbstractReceiverConfigurableService) {
((AbstractReceiverConfigurableService) dialog).receivedValidRule(call);
}
lastname.setForeground(new Color(lastname.getDisplay(), 0, 0, 0));
firstname.setForeground(new Color(firstname.getDisplay(), 0, 0, 0));
street.setForeground(new Color(street.getDisplay(), 0, 0, 0));
streetno.setForeground(new Color(streetno.getDisplay(), 0, 0, 0));
postal.setForeground(new Color(postal.getDisplay(), 0, 0, 0));
city.setForeground(new Color(city.getDisplay(), 0, 0, 0));
area.setForeground(new Color(area.getDisplay(), 0, 0, 0));
number.setForeground(new Color(number.getDisplay(), 0, 0, 0));
}
} catch (CallerNotFoundException ex) {
PropagationFactory.getInstance().fire(new Message(Message.INFO, getNamespace(), "notidentified", new String[] { pn.getTelephoneNumber() }, ex));
// first CallerNotFoundException
Throwable cause = ex.getCause();
if (cause != null && !(cause instanceof RegExpURLRequesterException)) {
cause = cause.getCause();
}
if (cause != null && cause instanceof RegExpURLRequesterException) {
List failure = ((RegExpURLRequesterException) cause).getFailures();
String c = null;
for (int i = 0; i < failure.size(); i++) {
c = (String) failure.get(i);
if (c.equalsIgnoreCase("regexp.lastname")) {
lastname.setForeground(new Color(lastname.getDisplay(), 255, 0, 0));
}
if (c.equalsIgnoreCase("regexp.firstname")) {
firstname.setForeground(new Color(firstname.getDisplay(), 255, 0, 0));
}
if (c.equalsIgnoreCase("regexp.street")) {
street.setForeground(new Color(street.getDisplay(), 255, 0, 0));
}
if (c.equalsIgnoreCase("regexp.streetno")) {
streetno.setForeground(new Color(streetno.getDisplay(), 255, 0, 0));
}
if (c.equalsIgnoreCase("regexp.pcode")) {
postal.setForeground(new Color(postal.getDisplay(), 255, 0, 0));
}
if (c.equalsIgnoreCase("regexp.city")) {
city.setForeground(new Color(city.getDisplay(), 255, 0, 0));
}
if (c.equalsIgnoreCase("regexp.areacode")) {
area.setForeground(new Color(area.getDisplay(), 255, 0, 0));
}
if (c.equalsIgnoreCase("regexp.phone")) {
number.setForeground(new Color(number.getDisplay(), 255, 0, 0));
}
}
}
} finally {
twcm = null;
}
}
});
testnum.addKeyListener(new KeyListener() {
public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
if (testnum.getText().length() > 0 && url.getText().length() > 0 && number.getText().length() > 0)
test.setEnabled(true);
else
test.setEnabled(false);
}
public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
}
});
this.setPageComplete(isComplete());
this.setControl(co);
}
Aggregations