use of ezvcard.property.Address in project ez-vcard by mangstadt.
the class AddressScribeTest method prepareParameters_type_pref.
/**
* If a property contains a "TYPE=pref" parameter and it's being marshalled
* to 4.0, it should replace "TYPE=pref" with "PREF=1".
*/
@Test
public void prepareParameters_type_pref() {
Address property = new Address();
property.getTypes().add(AddressType.PREF);
// 2.1 and 3.0 keep it
sensei.assertPrepareParams(property).versions(V2_1, V3_0).expected("TYPE", "pref").run();
// 4.0 converts it to "PREF=1"
sensei.assertPrepareParams(property).versions(V4_0).expected("PREF", "1").run();
}
use of ezvcard.property.Address in project ez-vcard by mangstadt.
the class JohnDoeVCard method createVCard.
private static VCard createVCard() throws IOException {
VCard vcard = new VCard();
vcard.setKind(Kind.individual());
vcard.setGender(Gender.male());
vcard.addLanguage("en-US");
StructuredName n = new StructuredName();
n.setFamily("Doe");
n.setGiven("Jonathan");
n.getPrefixes().add("Mr");
vcard.setStructuredName(n);
vcard.setFormattedName("Jonathan Doe");
vcard.setNickname("John", "Jonny");
vcard.addTitle("Widget Engineer");
vcard.setOrganization("Acme Co. Ltd.", "Widget Department");
Address adr = new Address();
adr.setStreetAddress("123 Wall St.");
adr.setLocality("New York");
adr.setRegion("NY");
adr.setPostalCode("12345");
adr.setCountry("USA");
adr.setLabel("123 Wall St.\nNew York, NY 12345\nUSA");
adr.getTypes().add(AddressType.WORK);
vcard.addAddress(adr);
adr = new Address();
adr.setStreetAddress("123 Main St.");
adr.setLocality("Albany");
adr.setRegion("NY");
adr.setPostalCode("54321");
adr.setCountry("USA");
adr.setLabel("123 Main St.\nAlbany, NY 54321\nUSA");
adr.getTypes().add(AddressType.HOME);
vcard.addAddress(adr);
vcard.addTelephoneNumber("1-555-555-1234", TelephoneType.WORK);
vcard.addTelephoneNumber("1-555-555-5678", TelephoneType.WORK, TelephoneType.CELL);
vcard.addEmail("johndoe@hotmail.com", EmailType.HOME);
vcard.addEmail("doe.john@acme.com", EmailType.WORK);
vcard.addUrl("http://www.acme-co.com");
vcard.setCategories("widgetphile", "biker", "vCard expert");
vcard.setGeo(37.6, -95.67);
vcard.setTimezone(new Timezone(new UtcOffset(false, -5, 0), "America/New_York"));
File file = new File("portrait.jpg");
Photo photo = new Photo(file, ImageType.JPEG);
vcard.addPhoto(photo);
file = new File("pronunciation.ogg");
Sound sound = new Sound(file, SoundType.OGG);
vcard.addSound(sound);
vcard.setUid(Uid.random());
vcard.setRevision(Revision.now());
return vcard;
}
use of ezvcard.property.Address in project ez-vcard by mangstadt.
the class AddressScribe method _parseXml.
@Override
protected Address _parseXml(XCardElement element, VCardParameters parameters, ParseContext context) {
Address property = new Address();
property.getPoBoxes().addAll(sanitizeXml(element, "pobox"));
property.getExtendedAddresses().addAll(sanitizeXml(element, "ext"));
property.getStreetAddresses().addAll(sanitizeXml(element, "street"));
property.getLocalities().addAll(sanitizeXml(element, "locality"));
property.getRegions().addAll(sanitizeXml(element, "region"));
property.getPostalCodes().addAll(sanitizeXml(element, "code"));
property.getCountries().addAll(sanitizeXml(element, "country"));
return property;
}
use of ezvcard.property.Address in project ez-vcard by mangstadt.
the class AddressScribe method parseStructuredValue.
private static Address parseStructuredValue(StructuredValueIterator it) {
Address property = new Address();
property.getPoBoxes().addAll(it.nextComponent());
property.getExtendedAddresses().addAll(it.nextComponent());
property.getStreetAddresses().addAll(it.nextComponent());
property.getLocalities().addAll(it.nextComponent());
property.getRegions().addAll(it.nextComponent());
property.getPostalCodes().addAll(it.nextComponent());
property.getCountries().addAll(it.nextComponent());
return property;
}
use of ezvcard.property.Address in project ez-vcard by mangstadt.
the class VCardWriterTest method rfc6350_example.
@Test
public void rfc6350_example() throws Throwable {
VCard vcard = new VCard();
vcard.setFormattedName("Simon Perreault");
StructuredName n = new StructuredName();
n.setFamily("Perreault");
n.setGiven("Simon");
n.getSuffixes().add("ing. jr");
n.getSuffixes().add("M.Sc.");
vcard.setStructuredName(n);
Birthday bday = new Birthday(PartialDate.builder().month(2).date(3).build());
vcard.setBirthday(bday);
Anniversary anniversary = new Anniversary(PartialDate.builder().year(2009).month(8).date(8).hour(14).minute(30).offset(new UtcOffset(false, -5, 0)).build());
vcard.setAnniversary(anniversary);
vcard.setGender(Gender.male());
vcard.addLanguage("fr").setPref(1);
vcard.addLanguage("en").setPref(2);
vcard.setOrganization("Viagenie").setType("work");
Address adr = new Address();
adr.setExtendedAddress("Suite D2-630");
adr.setStreetAddress("2875 Laurier");
adr.setLocality("Quebec");
adr.setRegion("QC");
adr.setPostalCode("G1V 2M2");
adr.setCountry("Canada");
adr.getTypes().add(AddressType.WORK);
vcard.addAddress(adr);
TelUri telUri = new TelUri.Builder("+1-418-656-9254").extension("102").build();
Telephone tel = new Telephone(telUri);
tel.setPref(1);
tel.getTypes().add(TelephoneType.WORK);
tel.getTypes().add(TelephoneType.VOICE);
vcard.addTelephoneNumber(tel);
tel = new Telephone(new TelUri.Builder("+1-418-262-6501").build());
tel.getTypes().add(TelephoneType.WORK);
tel.getTypes().add(TelephoneType.VOICE);
tel.getTypes().add(TelephoneType.CELL);
tel.getTypes().add(TelephoneType.VIDEO);
tel.getTypes().add(TelephoneType.TEXT);
vcard.addTelephoneNumber(tel);
vcard.addEmail("simon.perreault@viagenie.ca", EmailType.WORK);
Geo geo = new Geo(46.772673, -71.282945);
geo.setType("work");
vcard.setGeo(geo);
Key key = new Key("http://www.viagenie.ca/simon.perreault/simon.asc", null);
key.setType("work");
vcard.addKey(key);
vcard.setTimezone(new Timezone(new UtcOffset(false, -5, 0)));
vcard.addUrl("http://nomis80.org").setType("home");
assertValidate(vcard).versions(VCardVersion.V4_0).run();
StringWriter sw = new StringWriter();
VCardWriter writer = new VCardWriter(sw, VCardVersion.V4_0);
writer.setAddProdId(false);
writer.write(vcard);
writer.close();
// @formatter:off
String expected = "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "FN:Simon Perreault\r\n" + "N:Perreault;Simon;;;ing. jr,M.Sc.\r\n" + "BDAY:--0203\r\n" + "ANNIVERSARY:20090808T1430-0500\r\n" + "GENDER:M\r\n" + "LANG;PREF=1:fr\r\n" + "LANG;PREF=2:en\r\n" + "ORG;TYPE=work:Viagenie\r\n" + "ADR;TYPE=work:;Suite D2-630;2875 Laurier;Quebec;QC;G1V 2M2;Canada\r\n" + "TEL;PREF=1;TYPE=work,voice;VALUE=uri:tel:+1-418-656-9254;ext=102\r\n" + "TEL;TYPE=work,voice,cell,video,text;VALUE=uri:tel:+1-418-262-6501\r\n" + "EMAIL;TYPE=work:simon.perreault@viagenie.ca\r\n" + "GEO;TYPE=work:geo:46.772673,-71.282945\r\n" + "KEY;TYPE=work:http://www.viagenie.ca/simon.perreault/simon.asc\r\n" + "TZ;VALUE=utc-offset:-0500\r\n" + "URL;TYPE=home:http://nomis80.org\r\n" + "END:VCARD\r\n";
// @formatter:on
String actual = sw.toString();
assertEquals(expected, actual);
}
Aggregations