use of de.janrufmonitor.util.formatter.Formatter in project janrufmonitor by tbrandt77.
the class Dialog method getParsedCaller.
private String getParsedCaller() {
Formatter formatter = Formatter.getInstance(this.getRuntime());
String name = "";
if (this.getCaller() != null && this.getCaller().getPhoneNumber().isClired()) {
name = this.getRuntime().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_CLIR);
} else {
name = formatter.parse(IJAMConst.GLOBAL_VARIABLE_CALLERNAME, this.getCall());
// hack for 4.2.1 & sign is not shown
name = StringUtils.replaceString(name, "&", "%amp%");
name = StringUtils.replaceString(name, "%amp%", "&&");
}
return name;
}
use of de.janrufmonitor.util.formatter.Formatter in project janrufmonitor by tbrandt77.
the class CallStatistic method run.
public void run() {
Object[] o = this.m_app.getController().getElementArray();
if (o != null && o.length > 0 && o[0] instanceof ICall) {
Map msnStats = new HashMap();
int count = o.length;
int accumated = 0;
ICall c = null;
IAttribute att = null;
for (int i = 0; i < o.length; i++) {
c = (ICall) o[i];
att = c.getAttribute("fritzbox.duration");
if (att != null) {
int call_dur = 0;
try {
call_dur = Integer.parseInt(att.getValue());
} catch (Exception e) {
this.m_logger.log(Level.SEVERE, e.toString(), e);
}
accumated += call_dur;
if (msnStats.containsKey(c.getMSN().getMSN())) {
int d = ((Integer) msnStats.get(c.getMSN().getMSN())).intValue();
d += call_dur;
msnStats.put(c.getMSN().getMSN(), new Integer(d));
} else {
msnStats.put(c.getMSN().getMSN(), new Integer(call_dur));
}
}
}
accumated = accumated / 60;
int h = accumated / 60;
int min = accumated % 60;
Iterator iter = msnStats.keySet().iterator();
StringBuffer sb = new StringBuffer();
String msn = null;
Formatter f = Formatter.getInstance(getRuntime());
String CRLF = "\n";
while (iter.hasNext()) {
msn = (String) iter.next();
int value = ((Integer) msnStats.get(msn)).intValue() / 60;
sb.append("\t");
sb.append(f.parse(IJAMConst.GLOBAL_VARIABLE_MSNFORMAT, getRuntime().getMsnManager().createMsn(msn)));
sb.append(": ");
sb.append((value / 60));
sb.append("h ");
sb.append((value % 60));
sb.append("min ");
if (iter.hasNext())
sb.append(CRLF);
}
String text = this.getI18nManager().getString(this.getNamespace(), "stat", "description", this.getLanguage());
text = StringUtils.replaceString(text, "{%1}", Integer.toString(count));
text = StringUtils.replaceString(text, "{%2}", Integer.toString(h) + "h " + Integer.toString(min) + "min");
text = StringUtils.replaceString(text, "{%3}", sb.toString());
MessageDialog.openInformation(new Shell(DisplayManager.getDefaultDisplay()), this.getI18nManager().getString(this.getNamespace(), "stat", "label", this.getLanguage()), text);
this.m_app.updateViews(false);
return;
}
}
use of de.janrufmonitor.util.formatter.Formatter in project janrufmonitor by tbrandt77.
the class CallingStatsAction method getStatisticItems.
public List getStatisticItems() {
final List items = new ArrayList();
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
isCalculating = true;
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "calculating", "label", getLanguage()), IProgressMonitor.UNKNOWN);
progressMonitor.worked(1);
final Properties stat = new Properties();
if (m_cl != null) {
ICaller caller = null;
Formatter formatter = Formatter.getInstance(getRuntime());
ICall c = null;
for (int i = 0; i < m_cl.size(); i++) {
c = m_cl.get(i);
if (isOutgoingCall(c)) {
caller = c.getCaller();
String displayName = formatter.parse("%a:ln%, %a:fn% (%a:add%)", caller);
if (displayName.trim().length() == 0)
displayName = formatter.parse("%a:city%", caller);
String number = formatter.parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, caller);
String key = number;
// remove CRLF
displayName = StringUtils.replaceString(displayName, IJAMConst.CRLF, " ");
if (displayName.length() > 32)
displayName = displayName.substring(0, 29) + "...";
String value = stat.getProperty(key, "");
if (value.length() == 0) {
stat.setProperty(key.trim(), "1");
stat.setProperty(key + ".name", displayName);
stat.setProperty(key + ".number", number);
} else {
int val = new Integer(value).intValue();
val++;
stat.setProperty(key.trim(), new Integer(val).toString());
m_maxcount = Math.max(m_maxcount, val);
}
}
}
}
progressMonitor.worked(1);
progressMonitor.setTaskName(getI18nManager().getString(getNamespace(), "createstatistic", "label", getLanguage()));
Iterator iter = stat.keySet().iterator();
String key = null;
String count = null;
while (iter.hasNext()) {
key = (String) iter.next();
if (!(key.endsWith(".name") || key.endsWith(".number"))) {
count = stat.getProperty(key, "");
items.add(new String[] { stat.getProperty(key + ".name"), stat.getProperty(key + ".number"), count });
}
}
stat.clear();
Collections.sort(items, new StatisticComparator());
progressMonitor.done();
isCalculating = false;
}
};
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);
isCalculating = false;
} catch (InvocationTargetException e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
isCalculating = false;
}
while (isCalculating) try {
Thread.sleep(250);
} catch (InterruptedException e) {
}
return items;
}
use of de.janrufmonitor.util.formatter.Formatter in project janrufmonitor by tbrandt77.
the class JournalBuilder method parseSingleCall.
private static String parseSingleCall(String text, ICall call) throws IOException {
String prefix = "<!-- start_call:";
String postfix = ":end_call-->";
String scall = text.substring(text.indexOf(prefix) + prefix.length(), text.indexOf(postfix));
Formatter f = Formatter.getInstance(PIMRuntime.getInstance());
return StringUtils.replaceString(text, prefix + scall + postfix, f.parse(parseRenderer(parseCallerImage(scall, call), call), call) + IJAMConst.CRLF + prefix + scall + postfix);
}
use of de.janrufmonitor.util.formatter.Formatter in project janrufmonitor by tbrandt77.
the class Dialog method getParsedNumber.
private String getParsedNumber() {
Formatter formatter = Formatter.getInstance(this.getRuntime());
String number = "";
if (this.getCaller() != null && !this.getCaller().getPhoneNumber().isClired()) {
number = formatter.parse(IJAMConst.GLOBAL_VARIABLE_CALLERNUMBER, this.getCall());
}
return number;
}
Aggregations