use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class AbstractFilterSerializer method getFilterFromString.
/**
* Transforms a String representation of a filter into an IFilter object.
* @param fstring string representation of the filter
* @return a valid IFilter object or null, if string is invalid.
*/
public IFilter getFilterFromString(String fstring) {
// IFilter filter = null;
if (fstring.length() > 0) {
StringTokenizer st = new StringTokenizer(fstring, ",");
String token = null;
if (st.countTokens() > 0) {
token = st.nextToken().trim();
FilterType ft = new FilterType(Integer.parseInt(token));
if (ft.equals(FilterType.DATE)) {
Date d1 = null;
long dl1 = Long.parseLong(st.nextToken());
if (dl1 > 0)
d1 = new Date(dl1);
Date d2 = new Date(Long.parseLong(st.nextToken()));
long frame = -1;
if (st.hasMoreTokens())
frame = Long.parseLong(st.nextToken());
// calculate today
if (frame == -100) {
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
d2 = c.getTime();
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 0);
d1 = c.getTime();
return new DateFilter(d1, d2, frame);
}
if (frame == -101) {
Calendar c = Calendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.set(Calendar.DAY_OF_WEEK, c.get(Calendar.DAY_OF_WEEK) - 1);
// 2008/03/25: fixed sunday switch bug
if (c.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
c.add(Calendar.WEEK_OF_MONTH, -1);
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
}
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
d2 = c.getTime();
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 0);
d1 = c.getTime();
return new DateFilter(d1, d2, frame);
}
if (frame == -107) {
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 0);
d1 = c.getTime();
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
d2 = c.getTime();
return new DateFilter(d1, d2, frame);
}
if (frame == -108) {
Calendar c = Calendar.getInstance();
c.add(Calendar.WEEK_OF_MONTH, -1);
c.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 0);
d1 = c.getTime();
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
d2 = c.getTime();
return new DateFilter(d1, d2, frame);
}
if (frame == -130) {
Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 0);
d1 = c.getTime();
c.set(Calendar.DAY_OF_MONTH, 1);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
d2 = c.getTime();
return new DateFilter(d1, d2, frame);
}
if (frame == -131) {
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, -1);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 0);
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
d1 = c.getTime();
c.set(Calendar.DAY_OF_MONTH, 1);
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
d2 = c.getTime();
return new DateFilter(d1, d2, frame);
}
if (frame > -1)
return new DateFilter(frame);
return new DateFilter(d1, d2);
}
if (ft.equals(FilterType.YEAR)) {
String y = st.nextToken();
return new YearFilter(Integer.parseInt(y));
}
if (ft.equals(FilterType.MONTH_YEAR)) {
String y = st.nextToken();
String m = st.nextToken();
return new MonthYearFilter(Integer.parseInt(y), Integer.parseInt(m));
}
if (ft.equals(FilterType.MSN)) {
IMsn[] msns = new IMsn[st.countTokens()];
int i = 0;
while (st.hasMoreTokens()) {
msns[i] = this.getRuntime().getCallFactory().createMsn(st.nextToken(), "");
i++;
}
return new MsnFilter(msns);
}
if (ft.equals(FilterType.CIP)) {
String cip = st.nextToken();
return new CipFilter(this.getRuntime().getCallFactory().createCip(cip, ""));
}
if (ft.equals(FilterType.CALLER)) {
String caller = st.nextToken();
if (caller.equalsIgnoreCase("clired")) {
IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(true);
ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn);
return new CallerFilter(c);
}
if (caller.equalsIgnoreCase(IJAMConst.INTERNAL_CALL)) {
IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(caller, "", st.nextToken());
ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn);
return new CallerFilter(c);
} else {
IPhonenumber pn = getRuntime().getCallerFactory().createPhonenumber(caller, st.nextToken(), st.nextToken());
ICaller c = getRuntime().getCallerFactory().createCaller(getRuntime().getCallerFactory().createName("", ""), pn);
return new CallerFilter(c);
}
}
if (ft.equals(FilterType.PHONENUMBER)) {
String intarea = st.nextToken();
String area = "";
String number = "";
if (st.hasMoreTokens())
area = st.nextToken().trim();
if (area.equalsIgnoreCase("+"))
area = "";
if (st.hasMoreTokens())
number = st.nextToken().trim();
if (number.equalsIgnoreCase("+"))
number = "";
IPhonenumber pn = this.getRuntime().getCallerFactory().createPhonenumber(intarea, area, number);
return new PhonenumberFilter(pn);
}
if (ft.equals(FilterType.ITEMCOUNT)) {
String limit = st.nextToken().trim();
return new ItemCountFilter(Integer.parseInt(limit));
}
if (ft.equals(FilterType.ATTRIBUTE)) {
IAttributeMap m = getRuntime().getCallFactory().createAttributeMap();
// return new AttributeFilter(m);
String[] t = null;
while (st.hasMoreTokens()) {
t = st.nextToken().split("=");
m.add(getRuntime().getCallFactory().createAttribute(t[0], t[1]));
}
return new AttributeFilter(m);
}
if (ft.equals(FilterType.CHARACTER)) {
String[] t = st.nextToken().split("=");
return new CharacterFilter(t[1].trim(), t[0].trim());
}
if (ft.equals(FilterType.UUID)) {
String[] uuids = st.nextToken().split(";");
return new UUIDFilter(uuids);
}
// TODO: more filters to be added here
}
}
return null;
}
use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class AbstractConfigurableCallerManager method applyFilters.
protected void applyFilters(ICallerList cl, IFilter[] filters) {
if (cl == null)
return;
if (filters == null)
return;
IFilter f = null;
for (int i = 0; i < filters.length; i++) {
f = filters[i];
if (f.getType() == FilterType.CHARACTER) {
CharacterFilter cf = ((CharacterFilter) f);
ICaller c = null;
for (int j = cl.size() - 1; j >= 0; j--) {
c = cl.get(j);
if (!c.getAttributes().contains(cf.getAttributeName())) {
cl.remove(c);
} else if (c.getAttributes().contains(cf.getAttributeName())) {
if (!c.getAttribute(cf.getAttributeName()).getValue().startsWith(cf.getCharacter())) {
cl.remove(c);
}
}
}
}
if (f.getType() == FilterType.PHONENUMBER) {
PhonenumberFilter cf = ((PhonenumberFilter) f);
ICaller c = null;
for (int j = cl.size() - 1; j >= 0; j--) {
c = cl.get(j);
if (!c.getPhoneNumber().getIntAreaCode().equalsIgnoreCase(cf.getPhonenumber().getIntAreaCode())) {
cl.remove(c);
} else if (!c.getPhoneNumber().getAreaCode().equalsIgnoreCase(cf.getPhonenumber().getAreaCode())) {
cl.remove(c);
}
}
}
if (f.getType() == FilterType.ATTRIBUTE) {
AttributeFilter cf = ((AttributeFilter) f);
ICaller c = null;
for (int j = cl.size() - 1; j >= 0; j--) {
c = cl.get(j);
IAttributeMap atts = cf.getAttributeMap();
Iterator iter = atts.iterator();
IAttribute a = null;
while (iter.hasNext()) {
a = (IAttribute) iter.next();
if (!c.getAttributes().contains(a)) {
cl.remove(c);
} else if (c.getAttributes().contains(a) && !c.getAttribute(a.getName()).getValue().equalsIgnoreCase(a.getValue())) {
cl.remove(c);
}
}
}
}
}
}
use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class EabFileCallerExporter method doExport.
public boolean doExport() {
File db = new File(m_filename);
try {
Properties addressbook = new Properties();
FileOutputStream fo = new FileOutputStream(db);
ICaller c = null;
addressbook.setProperty("total", Integer.toString(this.m_callerList.size()));
for (int i = 0; i < this.m_callerList.size(); i++) {
c = this.m_callerList.get(i);
if (c instanceof IMultiPhoneCaller) {
List phones = ((IMultiPhoneCaller) c).getPhonenumbers();
addressbook.setProperty((i + 1) + ".phonecount", Integer.toString(phones.size()));
for (int a = 0, b = phones.size(); a < b; a++) {
addressbook.setProperty((i + 1) + ".intarea." + a, ((IPhonenumber) phones.get(a)).getIntAreaCode());
addressbook.setProperty((i + 1) + ".area." + a, ((IPhonenumber) phones.get(a)).getAreaCode());
addressbook.setProperty((i + 1) + ".phone." + a, ((IPhonenumber) phones.get(a)).getCallNumber());
}
} else {
addressbook.setProperty((i + 1) + ".intarea", c.getPhoneNumber().getIntAreaCode());
addressbook.setProperty((i + 1) + ".area", c.getPhoneNumber().getAreaCode());
addressbook.setProperty((i + 1) + ".phone", c.getPhoneNumber().getCallNumber());
}
IAttributeMap attributes = c.getAttributes();
Iterator iter = attributes.iterator();
IAttribute a = null;
while (iter.hasNext()) {
a = (IAttribute) iter.next();
addressbook.setProperty((i + 1) + "." + a.getName(), a.getValue());
}
}
addressbook.store(fo, "");
fo.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + m_filename);
return false;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return false;
}
return true;
}
use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class EabFileCallerImporter method doImport.
public ICallerList doImport() {
this.m_current = 0;
m_callerList = PIMRuntime.getInstance().getCallerFactory().createCallerList();
Date startDate = new Date();
File db = new File(m_filename);
try {
FileInputStream in = new FileInputStream(db);
Properties addressbook = new Properties();
addressbook.load(in);
in.close();
m_total = Integer.parseInt(addressbook.getProperty("total", "1"));
boolean hasMore = true;
int i = 1;
String key = null;
while (hasMore && addressbook.size() > 0) {
key = addressbook.getProperty(i + ".phonecount");
addressbook.remove(i + ".phonecount");
// found old format
if (key == null) {
key = addressbook.getProperty(i + ".phone");
addressbook.remove(i + ".phone");
if (key != null && key.length() > 0) {
IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(false);
pn.setCallNumber(key);
pn.setAreaCode(addressbook.getProperty(i + ".area"));
addressbook.remove(i + ".area");
key = addressbook.getProperty(i + ".intarea");
addressbook.remove(i + ".intarea");
if (key == null || key.length() == 0)
key = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA);
pn.setIntAreaCode(key);
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
Enumeration en = addressbook.keys();
List keys = new ArrayList();
while (en.hasMoreElements()) {
key = (String) en.nextElement();
if (key.startsWith(i + ".")) {
keys.add(key);
m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(key.substring((i + ".").length()), addressbook.getProperty(key)));
}
}
if (keys.size() > 0) {
for (int j = 0; j < keys.size(); j++) {
addressbook.remove(keys.get(j));
}
keys.clear();
keys = null;
}
ICaller caller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
caller.setAttributes(m);
this.m_callerList.add(caller);
i++;
} else {
this.m_logger.info("Found no more valid keys. Left data: " + addressbook);
hasMore = false;
}
} else {
// new format since 5.0.0
int phonecount = Integer.parseInt(key);
List phones = new ArrayList(1);
ICaller caller = null;
for (int a = 0; a < phonecount; a++) {
key = addressbook.getProperty(i + ".phone." + a);
addressbook.remove(i + ".phone." + a);
if (key != null && key.length() > 0) {
IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(false);
pn.setCallNumber(key);
pn.setAreaCode(addressbook.getProperty(i + ".area." + a));
addressbook.remove(i + ".area." + a);
key = addressbook.getProperty(i + ".intarea." + a);
addressbook.remove(i + ".intarea." + a);
if (key == null || key.length() == 0)
key = PIMRuntime.getInstance().getConfigManagerFactory().getConfigManager().getProperty(IJAMConst.GLOBAL_NAMESPACE, IJAMConst.GLOBAL_INTAREA);
pn.setIntAreaCode(key);
phones.add(pn);
}
}
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
IAttributeMap m = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
Enumeration en = addressbook.keys();
List keys = new ArrayList();
while (en.hasMoreElements()) {
key = (String) en.nextElement();
if (key.startsWith(i + ".")) {
keys.add(key);
m.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(key.substring((i + ".").length()), addressbook.getProperty(key)));
}
}
if (keys.size() > 0) {
for (int j = 0; j < keys.size(); j++) {
addressbook.remove(keys.get(j));
}
keys.clear();
keys = null;
}
caller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phones);
caller.setAttributes(m);
this.m_callerList.add(caller);
i++;
this.m_current++;
}
}
} catch (FileNotFoundException ex) {
this.m_logger.warning("Cannot find caller backup file " + m_filename);
return this.m_callerList;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return this.m_callerList;
}
Date endDate = new Date();
this.m_logger.info("Successfully imported caller file " + m_filename);
this.m_logger.info("Found " + new Integer(this.m_callerList.size()).toString() + " caller items in " + new Float((endDate.getTime() - startDate.getTime()) / 1000).toString() + " secs.");
return this.m_callerList;
}
use of de.janrufmonitor.framework.IAttributeMap in project janrufmonitor by tbrandt77.
the class GpxCallerExporter method doExport.
public boolean doExport() {
File db = new File(m_filename);
try {
StringBuffer xml = new StringBuffer();
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>");
xml.append(IJAMConst.CRLF);
xml.append("<gpx xmlns=\"http://www.topografix.com/GPX/1/1\" creator=\"jAnrufmonitor\" version=\"1.1\"");
xml.append(IJAMConst.CRLF);
xml.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
xml.append(IJAMConst.CRLF);
xml.append("xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">");
xml.append(IJAMConst.CRLF);
ICaller c = null;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
String now = df.format(new Date());
for (int i = 0; i < this.m_callerList.size(); i++) {
c = this.m_callerList.get(i);
IAttributeMap attributes = c.getAttributes();
if (attributes.contains(IJAMConst.ATTRIBUTE_NAME_GEO_ACC) && attributes.contains(IJAMConst.ATTRIBUTE_NAME_GEO_LNG) && attributes.contains(IJAMConst.ATTRIBUTE_NAME_GEO_LAT)) {
xml.append("<wpt lat=\"");
xml.append(attributes.get(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
xml.append("\" lon=\"");
xml.append(attributes.get(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
xml.append("\">");
xml.append(IJAMConst.CRLF);
xml.append("<time>");
xml.append(now);
xml.append("</time>");
xml.append(IJAMConst.CRLF);
xml.append("<name>");
try {
xml.append(StringEscapeUtils.escapeXml(StringUtils.replaceString(Formatter.getInstance(PIMRuntime.getInstance()).parse(IJAMConst.GLOBAL_VARIABLE_CALLERNAME, c), IJAMConst.CRLF, " ").trim()));
} catch (Exception e) {
m_logger.log(Level.SEVERE, e.toString(), e);
}
xml.append("</name>");
xml.append(IJAMConst.CRLF);
xml.append("<sym>Dot</sym>");
xml.append(IJAMConst.CRLF);
xml.append("</wpt>");
xml.append(IJAMConst.CRLF);
}
}
xml.append("</gpx>");
FileOutputStream fo = new FileOutputStream(db);
ByteArrayInputStream bin = new ByteArrayInputStream(xml.toString().getBytes());
Stream.copy(bin, fo, true);
fo.close();
} catch (FileNotFoundException ex) {
this.m_logger.severe("File not found: " + m_filename);
return false;
} catch (IOException ex) {
this.m_logger.severe("IOException on file " + m_filename);
return false;
}
return true;
}
Aggregations