use of ezvcard.util.TelUri 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.util.TelUri 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.util.TelUri in project ez-vcard by mangstadt.
the class HCardPageTest method create_then_parse.
@Test
public void create_then_parse() throws Exception {
// create template
VCard expected = createFullVCard();
HCardPage template = new HCardPage();
template.add(expected);
String html = template.write();
// write to file for manual inspection
FileWriter writer = new FileWriter(new File("target", "vcard.html"));
writer.write(html);
writer.close();
// parse template
HCardParser reader = new HCardParser(html);
VCard actual = reader.readNext();
reader.close();
assertEquals("Claus", actual.getSortString().getValue());
assertEquals(expected.getClassification().getValue(), actual.getClassification().getValue());
assertEquals(expected.getMailer().getValue(), actual.getMailer().getValue());
assertEquals(expected.getFormattedName().getValue(), actual.getFormattedName().getValue());
assertEquals(expected.getUid().getValue(), actual.getUid().getValue());
assertEquals(expected.getNickname().getValues(), actual.getNickname().getValues());
assertEquals(expected.getOrganization().getValues(), actual.getOrganization().getValues());
assertEquals(expected.getCategories().getValues(), actual.getCategories().getValues());
assertEquals(expected.getBirthday().getDate(), actual.getBirthday().getDate());
assertEquals(expected.getRevision().getValue(), actual.getRevision().getValue());
assertEquals(expected.getGeo().getLatitude(), actual.getGeo().getLatitude());
assertEquals(expected.getGeo().getLongitude(), actual.getGeo().getLongitude());
assertEquals(expected.getTimezone().getOffset(), actual.getTimezone().getOffset());
// text value is not written
assertNull(actual.getTimezone().getText());
{
StructuredName e = expected.getStructuredName();
StructuredName a = actual.getStructuredName();
assertEquals(e.getFamily(), a.getFamily());
assertEquals(e.getGiven(), a.getGiven());
assertEquals(e.getAdditionalNames(), a.getAdditionalNames());
assertEquals(e.getPrefixes(), a.getPrefixes());
assertEquals(e.getSuffixes(), a.getSuffixes());
assertTrue(a.getSortAs().isEmpty());
}
assertEquals(expected.getTitles().size(), actual.getTitles().size());
for (int i = 0; i < expected.getTitles().size(); i++) {
Title e = expected.getTitles().get(i);
Title a = actual.getTitles().get(i);
assertEquals(e.getValue(), a.getValue());
}
assertEquals(expected.getRoles().size(), actual.getRoles().size());
for (int i = 0; i < expected.getRoles().size(); i++) {
Role e = expected.getRoles().get(i);
Role a = actual.getRoles().get(i);
assertEquals(e.getValue(), a.getValue());
}
assertEquals(expected.getNotes().size(), actual.getNotes().size());
for (int i = 0; i < expected.getNotes().size(); i++) {
Note e = expected.getNotes().get(i);
Note a = actual.getNotes().get(i);
assertEquals(e.getValue(), a.getValue());
}
assertEquals(expected.getUrls().size(), actual.getUrls().size());
for (int i = 0; i < expected.getUrls().size(); i++) {
Url e = expected.getUrls().get(i);
Url a = actual.getUrls().get(i);
assertEquals(e.getValue(), a.getValue());
}
assertEquals(expected.getImpps().size(), actual.getImpps().size());
for (int i = 0; i < expected.getImpps().size(); i++) {
Impp e = expected.getImpps().get(i);
Impp a = actual.getImpps().get(i);
assertEquals(e.getUri(), a.getUri());
}
assertEquals(expected.getEmails().size(), actual.getEmails().size());
for (int i = 0; i < expected.getEmails().size(); i++) {
Email e = expected.getEmails().get(i);
Email a = actual.getEmails().get(i);
assertEquals(e.getValue(), a.getValue());
assertEquals(e.getTypes(), a.getTypes());
}
assertEquals(expected.getTelephoneNumbers().size(), actual.getTelephoneNumbers().size());
for (int i = 0; i < expected.getTelephoneNumbers().size(); i++) {
Telephone e = expected.getTelephoneNumbers().get(i);
Telephone a = actual.getTelephoneNumbers().get(i);
if (e.getText() != null) {
assertEquals(e.getText(), a.getText());
} else {
TelUri uri = e.getUri();
if (uri.getExtension() == null) {
assertEquals(e.getUri().getNumber(), a.getText());
} else {
assertEquals(e.getUri().getNumber() + " x" + uri.getExtension(), a.getText());
}
}
assertEquals(e.getTypes(), a.getTypes());
}
assertEquals(expected.getAddresses().size(), actual.getAddresses().size());
for (int i = 0; i < expected.getAddresses().size(); i++) {
Address e = expected.getAddresses().get(i);
Address a = actual.getAddresses().get(i);
assertEquals(e.getPoBox(), a.getPoBox());
assertEquals(e.getExtendedAddress(), a.getExtendedAddress());
assertEquals(e.getStreetAddress(), a.getStreetAddress());
assertEquals(e.getLocality(), a.getLocality());
assertEquals(e.getRegion(), a.getRegion());
assertEquals(e.getPostalCode(), a.getPostalCode());
assertEquals(e.getCountry(), a.getCountry());
assertEquals(e.getLabel(), a.getLabel());
assertEquals(e.getTypes(), a.getTypes());
}
assertEquals(expected.getPhotos().size(), actual.getPhotos().size());
for (int i = 0; i < expected.getPhotos().size(); i++) {
Photo e = expected.getPhotos().get(i);
Photo a = actual.getPhotos().get(i);
assertEquals(e.getContentType(), a.getContentType());
assertArrayEquals(e.getData(), a.getData());
}
assertEquals(expected.getSounds().size(), actual.getSounds().size());
for (int i = 0; i < expected.getSounds().size(); i++) {
Sound e = expected.getSounds().get(i);
Sound a = actual.getSounds().get(i);
assertEquals(e.getContentType(), a.getContentType());
assertArrayEquals(e.getData(), a.getData());
}
assertEquals("ez-vcard " + Ezvcard.VERSION, actual.getProductId().getValue());
}
use of ezvcard.util.TelUri 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;
}
use of ezvcard.util.TelUri in project ez-vcard by mangstadt.
the class TelephoneScribe method _writeText.
@Override
protected String _writeText(Telephone property, WriteContext context) {
String text = property.getText();
if (text != null) {
return escape(text, context);
}
TelUri uri = property.getUri();
if (uri != null) {
if (context.getVersion() == VCardVersion.V4_0) {
return uri.toString();
}
String ext = uri.getExtension();
String value = (ext == null) ? uri.getNumber() : uri.getNumber() + " x" + ext;
return escape(value, context);
}
return "";
}
Aggregations