use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class VcfParser30 method parse.
public ICallerList parse() throws VcfParserException {
if (this.m_buffer == null)
this.read();
if (this.m_buffer.length() < 64)
throw new VcfParserException("VCF file contains only " + this.m_buffer.length() + " characters.");
ICallerList cl = PIMRuntime.getInstance().getCallerFactory().createCallerList();
String[] entries = this.m_buffer.toString().split(BEGIN_VCARD);
this.m_logger.info("Entries in generic VcfParser vcf file: " + entries.length);
this.m_total = entries.length;
for (int i = 0; i < entries.length; i++) {
try {
this.m_current++;
IAttributeMap private_attributes = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
IAttributeMap bussiness_attributes = PIMRuntime.getInstance().getCallerFactory().createAttributeMap();
List private_phones = new ArrayList();
List bussiness_phones = new ArrayList();
String[] lines = entries[i].split(IJAMConst.CRLF);
// parse single entry
String line = null;
String[] value = null;
for (int j = 0; j < lines.length; j++) {
line = lines[j];
// check name
if (line.toLowerCase().startsWith(N) || line.toLowerCase().startsWith(N2)) {
value = line.substring(line.indexOf(":") + 1).split(";");
if (value.length >= 2) {
this.m_logger.info("Set attribute name.");
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, value[1]));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_FIRSTNAME, value[1]));
}
if (value.length == 1) {
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_LASTNAME, value[0]));
}
}
if (line.toLowerCase().startsWith(ORG) || line.toLowerCase().startsWith(ORG2)) {
value = line.split(":");
if (value.length >= 2) {
this.m_logger.info("Set attribute organization.");
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, value[1]));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_ADDITIONAL, value[1]));
}
}
if (line.toLowerCase().startsWith(ADR)) {
String[] tokens = line.split(":");
if (tokens.length == 2) {
boolean isBusiness = false;
String[] attributes = tokens[0].split(";");
for (int k = 0; k < attributes.length; k++) {
if (attributes[k].toLowerCase().startsWith(ATTRIBUTE_TYPE)) {
String[] values = attributes[k].toLowerCase().substring(ATTRIBUTE_TYPE.length()).split(";");
for (int l = 0; l < values.length; l++) {
if (values[l].equalsIgnoreCase(ADR_TYPES[1])) {
isBusiness = true;
}
}
}
if (attributes[k].toLowerCase().startsWith(ADR_TYPES[1])) {
isBusiness = true;
}
}
value = tokens[1].split(";");
if (value.length >= 6 && (value.length > 6 ? value[6].trim().length() > 0 : true) && value[3].trim().length() > 0) {
if (isBusiness) {
this.m_logger.info("Set attribute work address.");
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, value[2]));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, value[5]));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, value[3] + (value[4].trim().length() > 0 ? ", " + value[4] : "")));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, (value.length > 6 ? value[6] : "")));
} else {
this.m_logger.info("Set attribute home address.");
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STREET, value[2]));
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE, value[5]));
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CITY, value[3] + (value[4].trim().length() > 0 ? ", " + value[4] : "")));
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_COUNTRY, (value.length > 6 ? value[6] : "")));
}
}
}
}
if (line.toLowerCase().startsWith(TEL)) {
value = line.split(":");
if (value.length == 2 && value[1].trim().length() > 0) {
boolean isBusiness = false;
boolean isFax = false;
boolean isCell = false;
String[] attributes = value[0].split(";");
for (int k = 0; k < attributes.length; k++) {
if (attributes[k].toLowerCase().startsWith(ATTRIBUTE_TYPE)) {
String[] values = attributes[k].toLowerCase().substring(ATTRIBUTE_TYPE.length()).split(",");
for (int l = 0; l < values.length; l++) {
if (values[l].equalsIgnoreCase(TEL_TYPES[1])) {
isBusiness = true;
}
if (values[l].equalsIgnoreCase(TEL_TYPES[3])) {
isFax = true;
}
if (values[l].equalsIgnoreCase(TEL_TYPES[2])) {
isCell = true;
}
}
}
if (attributes[k].toLowerCase().startsWith(TEL_TYPES[1])) {
isBusiness = true;
}
if (attributes[k].toLowerCase().startsWith(TEL_TYPES[3])) {
isFax = true;
}
if (attributes[k].toLowerCase().startsWith(TEL_TYPES[2])) {
isCell = true;
}
}
try {
IPhonenumber pn = parsePhonenumber(value[1]);
if (pn != null && !bussiness_phones.contains(pn)) {
if (isBusiness) {
this.m_logger.info("Set attribute work");
bussiness_phones.add(pn);
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), (isFax ? IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE : (isCell ? IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE : IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))));
} else {
this.m_logger.info("Set attribute home");
private_phones.add(pn);
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_NUMBER_TYPE + pn.getTelephoneNumber(), (isFax ? IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE : (isCell ? IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE : IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE))));
}
}
} catch (Exception ex) {
this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
if (line.toLowerCase().startsWith(EMAIL)) {
value = line.split(":");
if (value.length == 2 && value[1].trim().length() > 0) {
boolean isBusiness = false;
String[] attributes = value[0].split(";");
for (int k = 0; k < attributes.length; k++) {
if (attributes[k].toLowerCase().startsWith(ATTRIBUTE_TYPE)) {
String[] values = attributes[k].toLowerCase().substring(ATTRIBUTE_TYPE.length()).split(",");
for (int l = 0; l < values.length; l++) {
if (values[l].equalsIgnoreCase(EMAIL_TYPES[1])) {
isBusiness = true;
}
}
}
if (attributes[k].toLowerCase().startsWith(EMAIL_TYPES[1])) {
isBusiness = true;
}
}
if (isBusiness) {
this.m_logger.info("Set attribute work");
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL, value[1]));
} else {
this.m_logger.info("Set attribute home");
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL, value[1]));
}
}
}
if (line.toLowerCase().startsWith(GEO)) {
value = line.split(":");
if (value.length == 2) {
value = value[1].split(";");
if (value.length == 2) {
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, value[0]));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, value[1]));
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT, value[0]));
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG, value[1]));
}
}
}
if (line.toLowerCase().startsWith(PHOTO) || line.toLowerCase().startsWith(MS_CARDPICTURE)) {
value = new String[2];
value[0] = line.substring(0, line.indexOf(":"));
value[1] = line.substring(line.indexOf(":") + 1);
if (value.length == 2) {
boolean isUrl = false;
boolean isEncoding = false;
String img_type = null;
String[] attributes = value[0].split(";");
for (int k = 0; k < attributes.length; k++) {
if (attributes[k].toLowerCase().startsWith(PHOTO_TYPES[0]) || attributes[k].toLowerCase().startsWith(PHOTO_TYPES[1])) {
isUrl = true;
}
if (attributes[k].toLowerCase().startsWith(PHOTO_TYPES[2])) {
isEncoding = true;
}
if (attributes[k].toLowerCase().startsWith(PHOTO_TYPES[3])) {
img_type = attributes[k].split("=")[1].toLowerCase();
}
}
if (isUrl) {
String img = getImageFromURL(value[1]);
if (img != null) {
this.m_logger.info("Set attribute photo.");
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
}
}
if (isEncoding) {
try {
if (img_type == null || img_type.trim().length() == 0)
img_type = "jpg";
StringBuffer img_content = new StringBuffer();
img_content.append(value[1]);
img_content.append("\n");
do {
j++;
value[1] = lines[j];
if (value[1].startsWith(" "))
value[1] = value[1].substring(1);
img_content.append(value[1]);
img_content.append("\n");
} while (value[1].indexOf("=") < 0);
String img = getImageFromBase64(img_content.toString(), img_type);
if (img != null) {
this.m_logger.info("Set attribute photo.");
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, PathResolver.getInstance().encode(img)));
private_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
bussiness_attributes.add(PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEURL, value[1]));
}
} catch (Exception ex) {
this.m_logger.log(Level.SEVERE, "VCF parsing error: PHOTO: " + ex.getMessage(), ex);
}
}
}
}
}
// create ICaller objects
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
if (private_phones.size() > 0 && private_attributes.size() > 0) {
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, private_phones);
c.setAttributes(private_attributes);
cl.add(c);
}
if (bussiness_phones.size() > 0 && bussiness_attributes.size() > 0) {
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, bussiness_phones);
c.setAttributes(bussiness_attributes);
cl.add(c);
}
} catch (Exception e) {
this.m_logger.log(Level.SEVERE, "VCF parsing error: " + e.getMessage(), e);
// throw new VcfParserException("parsing error: "+e.getMessage(), e);
}
}
return cl;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class OldDatFileCallImporter method parsePhone.
private IPhonenumber parsePhone(String caller) {
if (caller.indexOf("(0") > -1) {
IPhonenumber phone = null;
String pn = caller.substring(caller.indexOf("(0") + 2, caller.lastIndexOf(")"));
if (pn.length() > 0) {
phone = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(pn);
ICallerManager cm = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
if (cm != null && cm.isActive() && cm.isSupported(IIdentifyCallerRepository.class)) {
try {
ICaller parsedCaller = ((IIdentifyCallerRepository) cm).getCaller(phone);
return parsedCaller.getPhoneNumber();
} catch (CallerNotFoundException e) {
this.m_logger.warning(e.getMessage());
}
}
}
}
return PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class OldDatFileCallImporter method migrateCallFromString.
private ICall migrateCallFromString(String scall, String datePattern) {
if (scall != null && scall.trim().length() == 0)
return null;
try {
StringTokenizer st = new StringTokenizer(scall, "%$");
if (st.countTokens() < 5) {
this.m_logger.warning("Invalid entry found: entry was dropped for migration.");
return null;
}
String state = st.nextToken().trim();
String msn = st.nextToken().trim();
String caller = st.nextToken().trim();
String cip = st.nextToken().trim();
String date = st.nextToken().trim();
// parse MSN
IMsn parsedMSN = this.parseMsn(msn);
ICip parsedCIP = this.parseCip(cip);
IAttribute att = this.parseState(state);
IPhonenumber phone = this.parsePhone(caller);
IName name = this.parseName(caller);
ICaller parsedCaller = PIMRuntime.getInstance().getCallerFactory().createCaller(name, phone);
Date parsedDate = this.parseDate(date, datePattern);
ICall aCall = PIMRuntime.getInstance().getCallFactory().createCall(parsedCaller, parsedMSN, parsedCIP, parsedDate);
if (!att.getName().equalsIgnoreCase("")) {
aCall.setAttribute(att);
}
this.m_logger.info(aCall.toString());
return aCall;
} catch (NoSuchElementException ex) {
this.m_logger.warning("FormatException: migration failed due to incompatible format information.");
} catch (NullPointerException ex) {
this.m_logger.warning("Invalid entry found: entry was dropped for migration.");
}
return null;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class OldDatFileCallerImporter method migrateCallerFromString.
private ICaller migrateCallerFromString(String scaller) {
if (scaller != null && scaller.trim().length() == 0)
return null;
StringTokenizer st = new StringTokenizer(scaller, ";");
String number = st.nextToken().trim();
String caller = st.nextToken().trim();
String reject = "0";
if (st.hasMoreTokens())
reject = st.nextToken().trim();
IPhonenumber pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(number.substring(1));
try {
ICaller migCaller = null;
ICallerManager def = PIMRuntime.getInstance().getCallerManagerFactory().getDefaultCallerManager();
if (def != null && def.isActive() && def.isSupported(IIdentifyCallerRepository.class)) {
migCaller = ((IIdentifyCallerRepository) def).getCaller(pn);
} else
throw new CallerNotFoundException();
StringTokenizer ctoken = new StringTokenizer(caller, " ");
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
if (ctoken.hasMoreTokens()) {
name.setFirstname(ctoken.nextToken());
}
if (ctoken.hasMoreTokens()) {
name.setLastname(ctoken.nextToken());
}
if (ctoken.hasMoreTokens()) {
name.setAdditional(ctoken.nextToken());
}
while (ctoken.hasMoreTokens()) {
name.setAdditional(name.getAdditional() + " " + ctoken.nextToken());
}
migCaller.setName(name);
if (reject.equalsIgnoreCase("1")) {
IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_YES);
migCaller.setAttribute(att);
}
if (reject.equalsIgnoreCase("0")) {
IAttribute att = PIMRuntime.getInstance().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_REJECT, IJAMConst.ATTRIBUTE_VALUE_NO);
migCaller.setAttribute(att);
}
LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).info(migCaller.toString());
return migCaller;
} catch (CallerNotFoundException e) {
LogManager.getLogManager().getLogger(IJAMConst.DEFAULT_LOGGER).warning(e.getMessage());
}
return null;
}
use of de.janrufmonitor.framework.IPhonenumber in project janrufmonitor by tbrandt77.
the class VcfFileCallerExporter method doExport.
public boolean doExport() {
File db = new File(m_filename);
try {
StringBuffer vcf = new StringBuffer();
Formatter f = Formatter.getInstance(PIMRuntime.getInstance());
String number_pattern = "+%intareacode% (%areacode%) %callnumber%";
ICaller c = null;
for (int i = 0, j = this.m_callerList.size(); i < j; i++) {
c = this.m_callerList.get(i);
vcf.append("BEGIN:VCARD");
vcf.append(CRLF);
vcf.append("VERSION:3.0");
vcf.append(CRLF);
vcf.append("N;CHARSET=ISO-8859-1:");
vcf.append(c.getName().getLastname());
vcf.append(";");
vcf.append(c.getName().getFirstname());
vcf.append(";;");
vcf.append(CRLF);
vcf.append("FN;CHARSET=ISO-8859-1:");
vcf.append(c.getName().getFirstname());
vcf.append(" ");
vcf.append(c.getName().getLastname());
vcf.append(CRLF);
if (c.getName().getAdditional().trim().length() > 0)
vcf.append("ORG;CHARSET=ISO-8859-1:");
vcf.append(c.getName().getAdditional());
vcf.append(CRLF);
vcf.append("SORT-STRING:");
vcf.append(c.getName().getLastname());
vcf.append(CRLF);
vcf.append("CLASS:PRIVATE");
vcf.append(CRLF);
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_EMAIL)) {
vcf.append("EMAIL;TYPE=home:");
vcf.append(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_EMAIL).getValue());
vcf.append(CRLF);
}
vcf.append("ADR;TYPE=home;CHARSET=ISO-8859-1:;;");
vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_STREET));
vcf.append(" ");
vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_STREET_NO));
vcf.append(";");
vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_CITY));
vcf.append(";;");
vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_POSTAL_CODE));
vcf.append(";");
vcf.append(this.getAttribute(c, IJAMConst.ATTRIBUTE_NAME_COUNTRY));
vcf.append(CRLF);
if (c instanceof IMultiPhoneCaller) {
List pns = ((IMultiPhoneCaller) c).getPhonenumbers();
IPhonenumber p = null;
for (int k = 0, l = pns.size(); k < l; k++) {
p = (IPhonenumber) pns.get(k);
if (p.isClired())
continue;
String numbertype = this.getPhoneType(p, c);
if (PhonenumberAnalyzer.getInstance(PIMRuntime.getInstance()).isInternal(p)) {
if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE)) {
vcf.append("TEL;TYPE=home:");
vcf.append(p.getCallNumber());
vcf.append(CRLF);
}
if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
vcf.append("TEL;TYPE=fax,home:");
vcf.append(p.getCallNumber());
vcf.append(CRLF);
}
if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
vcf.append("TEL;TYPE=cell:");
vcf.append(p.getCallNumber());
vcf.append(CRLF);
}
} else {
if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE)) {
vcf.append("TEL;TYPE=home:");
vcf.append(f.parse(number_pattern, p));
vcf.append(CRLF);
}
if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
vcf.append("TEL;TYPE=fax,home:");
vcf.append(f.parse(number_pattern, p));
vcf.append(CRLF);
}
if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
vcf.append("TEL;TYPE=cell:");
vcf.append(f.parse(number_pattern, p));
vcf.append(CRLF);
}
}
}
} else {
String numbertype = this.getPhoneType(c.getPhoneNumber(), c);
if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_LANDLINE_TYPE)) {
vcf.append("TEL;TYPE=home:");
vcf.append(f.parse(number_pattern, c.getPhoneNumber()));
vcf.append(CRLF);
}
if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_FAX_TYPE)) {
vcf.append("TEL;TYPE=fax,home:");
vcf.append(f.parse(number_pattern, c.getPhoneNumber()));
vcf.append(CRLF);
}
if (numbertype.equalsIgnoreCase(IJAMConst.ATTRIBUTE_VALUE_MOBILE_TYPE)) {
vcf.append("TEL;TYPE=cell:");
vcf.append(f.parse(number_pattern, c.getPhoneNumber()));
vcf.append(CRLF);
}
}
if (ImageHandler.getInstance().hasImage(c)) {
vcf.append("PHOTO;ENCODING=b;TYPE=JPEG:");
InputStream fim = ImageHandler.getInstance().getImageStream(c);
if (c != null) {
ByteArrayOutputStream encodedOut = new ByteArrayOutputStream();
// finalize lines with '\n ' instead of '\n'
Base64Encoder b64 = new Base64Encoder(encodedOut, " ".getBytes());
Stream.copy(fim, b64);
b64.flush();
b64.close();
String imagedata = new String(encodedOut.toByteArray());
int size = imagedata.length();
vcf.append(imagedata.substring(0, 43));
int z = 43;
while (z < imagedata.length()) {
vcf.append(imagedata.substring(z, Math.min((z + 69), size)));
z += 69;
}
vcf.append(CRLF);
}
} else if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)) {
// add embedded photo as base 64 encoded object
String file = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH).getValue();
File img = new File(PathResolver.getInstance().resolve(file));
if (img.exists()) {
vcf.append("PHOTO;ENCODING=b;TYPE=JPEG:");
FileInputStream fim = new FileInputStream(img);
ByteArrayOutputStream encodedOut = new ByteArrayOutputStream();
// finalize lines with '\n ' instead of '\n'
Base64Encoder b64 = new Base64Encoder(encodedOut, " ".getBytes());
Stream.copy(fim, b64);
b64.flush();
b64.close();
String imagedata = new String(encodedOut.toByteArray());
int size = imagedata.length();
vcf.append(imagedata.substring(0, 43));
int z = 43;
while (z < imagedata.length()) {
vcf.append(imagedata.substring(z, Math.min((z + 69), size)));
z += 69;
}
vcf.append(CRLF);
}
}
if (c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GEO_LAT) && c.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_GEO_LNG)) {
// add geo tagging
vcf.append("GEO:");
vcf.append(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LAT).getValue());
vcf.append(";");
vcf.append(c.getAttribute(IJAMConst.ATTRIBUTE_NAME_GEO_LNG).getValue());
vcf.append(CRLF);
}
vcf.append("PRODID:-//jAnrufmonitor//www.janrufmonitor.de//Version 5.0");
vcf.append(CRLF);
vcf.append("UID:JAM-UID-");
vcf.append(c.getUUID());
vcf.append(CRLF);
vcf.append("REV:");
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
vcf.append(sdf.format(new Date()));
vcf.append(CRLF);
vcf.append("END:VCARD");
vcf.append(CRLF);
vcf.append(CRLF);
}
FileOutputStream fos = new FileOutputStream(db);
ByteArrayInputStream bin = new ByteArrayInputStream(vcf.toString().getBytes());
Stream.copy(bin, fos, true);
} 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