use of ezvcard.property.Email in project ofbiz-framework by apache.
the class VCard method exportVCard.
public static Map<String, Object> exportVCard(DispatchContext dctx, Map<String, ? extends Object> context) {
Delegator delegator = dctx.getDelegator();
String partyId = (String) context.get("partyId");
Locale locale = (Locale) context.get("locale");
File file = null;
try {
ezvcard.VCard vcard = new ezvcard.VCard();
StructuredName structuredName = new StructuredName();
GenericValue person = EntityQuery.use(delegator).from("Person").where("partyId", partyId).queryOne();
if (person != null) {
if (UtilValidate.isNotEmpty(person.getString("firstName")))
structuredName.setGiven(person.getString("firstName"));
if (UtilValidate.isNotEmpty(person.getString("lastName")))
structuredName.setFamily(person.getString("lastName"));
vcard.setStructuredName(structuredName);
}
String fullName = PartyHelper.getPartyName(delegator, partyId, false);
vcard.setFormattedName(fullName);
GenericValue postalAddress = PartyWorker.findPartyLatestPostalAddress(partyId, delegator);
if (postalAddress != null) {
Address address = new Address();
address.setStreetAddress(postalAddress.getString("address1"));
address.setLocality(postalAddress.getString("city"));
address.setPostalCode(postalAddress.getString("postalCode"));
GenericValue state = postalAddress.getRelatedOne("StateProvinceGeo", false);
if (state != null) {
address.setRegion(state.getString("geoName"));
}
GenericValue countryGeo = postalAddress.getRelatedOne("CountryGeo", false);
if (countryGeo != null) {
String country = postalAddress.getRelatedOne("CountryGeo", false).getString("geoName");
address.setCountry(country);
address.getTypes().add(AddressType.WORK);
;
// TODO : this can be better set by checking contactMechPurposeTypeId
}
vcard.addAddress(address);
}
GenericValue telecomNumber = PartyWorker.findPartyLatestTelecomNumber(partyId, delegator);
if (telecomNumber != null) {
Telephone tel = new Telephone(telecomNumber.getString("areaCode") + telecomNumber.getString("contactNumber"));
tel.getTypes().add(TelephoneType.WORK);
vcard.addTelephoneNumber(tel);
// TODO : this can be better set by checking contactMechPurposeTypeId
}
GenericValue emailAddress = PartyWorker.findPartyLatestContactMech(partyId, "EMAIL_ADDRESS", delegator);
if (emailAddress != null && UtilValidate.isNotEmpty(emailAddress.getString("infoString"))) {
vcard.addEmail(new Email(emailAddress.getString("infoString")));
}
// TODO : convert to directdownload of a vcf file
String saveToDirectory = EntityUtilProperties.getPropertyValue("sfa", "save.outgoing.directory", "", delegator);
if (UtilValidate.isEmpty(saveToDirectory)) {
saveToDirectory = System.getProperty("ofbiz.home");
}
String saveToFilename = fullName + ".vcf";
file = FileUtil.getFile(saveToDirectory + "/" + saveToFilename);
Ezvcard.write(vcard).go(file);
} catch (FileNotFoundException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "SfaExportVCardErrorOpeningFile", UtilMisc.toMap("errorString", file.getAbsolutePath()), locale));
} catch (IOException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "SfaExportVCardErrorWritingFile", UtilMisc.toMap("errorString", file.getAbsolutePath()), locale));
} catch (GenericEntityException e) {
return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "SfaExportVCardError", UtilMisc.toMap("errorString", e.getMessage()), locale));
}
return ServiceUtil.returnSuccess();
}
use of ezvcard.property.Email in project ez-vcard by mangstadt.
the class EmailScribe method _parseHtml.
@Override
protected Email _parseHtml(HCardElement element, ParseContext context) {
String href = element.attr("href");
String email = extractEmailFromHrefAttribute(href);
if (email == null) {
email = element.value();
}
Email property = new Email(email);
List<String> types = element.types();
property.getParameters().putAll(VCardParameters.TYPE, types);
return property;
}
use of ezvcard.property.Email in project ez-vcard by mangstadt.
the class EmailScribeTest method parseText.
@Test
public void parseText() {
Email expected = new Email("johndoe@example.com");
sensei.assertParseText("johndoe@example.com").run(expected);
}
use of ezvcard.property.Email in project ez-vcard by mangstadt.
the class EmailScribeTest method prepareParameters_type_pref.
@Test
public void prepareParameters_type_pref() {
Email property = new Email("johndoe@example.com");
property.getTypes().add(EmailType.PREF);
sensei.assertPrepareParams(property).versions(V2_1, V3_0).expected("TYPE", "pref").run();
sensei.assertPrepareParams(property).versions(V4_0).expected("PREF", "1").run();
}
use of ezvcard.property.Email in project ez-vcard by mangstadt.
the class EmailScribeTest method prepareParameters_pref_parameter.
@Test
public void prepareParameters_pref_parameter() {
Email property = new Email("johndoe@example.com");
property.setPref(1);
VCard vcard = new VCard();
vcard.addEmail(property);
sensei.assertPrepareParams(property).versions(V2_1, V3_0).vcard(vcard).expected("TYPE", "pref").run();
sensei.assertPrepareParams(property).versions(V4_0).vcard(vcard).expected("PREF", "1").run();
}
Aggregations