use of ezvcard.property.Key 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);
}
use of ezvcard.property.Key in project ez-vcard by mangstadt.
the class XCardDocumentTest method write_rfc6351_example.
@Test
public void write_rfc6351_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.setStreetAddress("2875 boul. Laurier, suite D2-630");
adr.setLocality("Quebec");
adr.setRegion("QC");
adr.setPostalCode("G1V 2M2");
adr.setCountry("Canada");
adr.getTypes().add(AddressType.WORK);
adr.setLabel("Simon Perreault\n2875 boul. Laurier, suite D2-630\nQuebec, QC, Canada\nG1V 2M2");
vcard.addAddress(adr);
TelUri telUri = new TelUri.Builder("+1-418-656-9254").extension("102").build();
Telephone tel = new Telephone(telUri);
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.TEXT);
tel.getTypes().add(TelephoneType.VOICE);
tel.getTypes().add(TelephoneType.CELL);
tel.getTypes().add(TelephoneType.VIDEO);
vcard.addTelephoneNumber(tel);
vcard.addEmail("simon.perreault@viagenie.ca", EmailType.WORK);
Geo geo = new Geo(46.766336, -71.28955);
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("America/Montreal"));
vcard.addUrl("http://nomis80.org").setType("home");
assertValidate(vcard).versions(V4_0).run();
assertExample(vcard, "rfc6351-example.xml");
}
use of ezvcard.property.Key in project ez-vcard by mangstadt.
the class XCardWriterTest method write_rfc6351_example.
@Test
public void write_rfc6351_example() throws Exception {
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.setStreetAddress("2875 boul. Laurier, suite D2-630");
adr.setLocality("Quebec");
adr.setRegion("QC");
adr.setPostalCode("G1V 2M2");
adr.setCountry("Canada");
adr.getTypes().add(AddressType.WORK);
adr.setLabel("Simon Perreault\n2875 boul. Laurier, suite D2-630\nQuebec, QC, Canada\nG1V 2M2");
vcard.addAddress(adr);
TelUri telUri = new TelUri.Builder("+1-418-656-9254").extension("102").build();
Telephone tel = new Telephone(telUri);
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.TEXT);
tel.getTypes().add(TelephoneType.VOICE);
tel.getTypes().add(TelephoneType.CELL);
tel.getTypes().add(TelephoneType.VIDEO);
vcard.addTelephoneNumber(tel);
vcard.addEmail("simon.perreault@viagenie.ca", EmailType.WORK);
Geo geo = new Geo(46.766336, -71.28955);
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("America/Montreal"));
vcard.addUrl("http://nomis80.org").setType("home");
assertValidate(vcard).versions(V4_0).run();
assertExample(vcard, "rfc6351-example.xml");
}
use of ezvcard.property.Key in project ez-vcard by mangstadt.
the class VCardWriterTest method setTargetApplication_outlook.
@Test
public void setTargetApplication_outlook() throws Throwable {
VCard vcard = new VCard();
byte[] data = "foobar".getBytes();
vcard.addKey(new Key(data, KeyType.X509));
vcard.addPhoto(new Photo(data, ImageType.JPEG));
vcard.addLogo(new Logo("http://www.company.com/logo.png", ImageType.PNG));
vcard.addNote("note");
{
StringWriter sw = new StringWriter();
VCardWriter writer = new VCardWriter(sw, VCardVersion.V2_1);
writer.setAddProdId(false);
writer.write(vcard);
writer.setTargetApplication(TargetApplication.OUTLOOK);
writer.write(vcard);
String actual = sw.toString();
// @formatter:off
String expected = "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "KEY;ENCODING=BASE64;TYPE=x509:Zm9vYmFy\r\n" + "PHOTO;ENCODING=BASE64;TYPE=jpeg:Zm9vYmFy\r\n" + "LOGO;TYPE=png;VALUE=url:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "KEY;ENCODING=BASE64;TYPE=x509:Zm9vYmFy\r\n" + "\r\n" + "PHOTO;ENCODING=BASE64;TYPE=jpeg:Zm9vYmFy\r\n" + "\r\n" + "LOGO;TYPE=png;VALUE=url:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n";
// @formatter:on
assertEquals(expected, actual);
}
{
StringWriter sw = new StringWriter();
VCardWriter writer = new VCardWriter(sw, VCardVersion.V3_0);
writer.setAddProdId(false);
writer.write(vcard);
writer.setTargetApplication(TargetApplication.OUTLOOK);
writer.write(vcard);
String actual = sw.toString();
// @formatter:off
String expected = "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "KEY;ENCODING=b;TYPE=x509:Zm9vYmFy\r\n" + "PHOTO;ENCODING=b;TYPE=jpeg:Zm9vYmFy\r\n" + "LOGO;TYPE=png;VALUE=uri:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "KEY;ENCODING=b;TYPE=x509:Zm9vYmFy\r\n" + "\r\n" + "PHOTO;ENCODING=b;TYPE=jpeg:Zm9vYmFy\r\n" + "\r\n" + "LOGO;TYPE=png;VALUE=uri:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n";
// @formatter:on
assertEquals(expected, actual);
}
{
StringWriter sw = new StringWriter();
VCardWriter writer = new VCardWriter(sw, VCardVersion.V4_0);
writer.setAddProdId(false);
writer.write(vcard);
writer.setTargetApplication(TargetApplication.OUTLOOK);
writer.write(vcard);
String actual = sw.toString();
// @formatter:off
String expected = "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "KEY:data:application/x509;base64,Zm9vYmFy\r\n" + "PHOTO:data:image/jpeg;base64,Zm9vYmFy\r\n" + "LOGO;MEDIATYPE=image/png:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "KEY:data:application/x509;base64,Zm9vYmFy\r\n" + "PHOTO:data:image/jpeg;base64,Zm9vYmFy\r\n" + "LOGO;MEDIATYPE=image/png:http://www.company.com/logo.png\r\n" + "NOTE:note\r\n" + "END:VCARD\r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
use of ezvcard.property.Key in project ez-vcard by mangstadt.
the class JCardWriterTest method createExample.
public static VCard createExample() {
VCard vcard = new VCard();
vcard.setFormattedName("SimonPerreault");
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).second(0).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("SuiteD2-630");
adr.setStreetAddress("2875Laurier");
adr.setLocality("Quebec");
adr.setRegion("QC");
adr.setPostalCode("G1V2M2");
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.getTypes().add(TelephoneType.WORK);
tel.getTypes().add(TelephoneType.VOICE);
tel.setPref(1);
vcard.addTelephoneNumber(tel);
tel = new Telephone(new TelUri.Builder("+1-418-262-6501").build());
tel.getTypes().add(TelephoneType.WORK);
tel.getTypes().add(TelephoneType.CELL);
tel.getTypes().add(TelephoneType.VOICE);
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");
return vcard;
}
Aggregations