Search in sources :

Example 16 with StructuredName

use of ezvcard.property.StructuredName in project ez-vcard by mangstadt.

the class VCardWriterTest method setIncludeTrailingSemicolons.

@Test
public void setIncludeTrailingSemicolons() throws Throwable {
    VCard vcard = new VCard();
    StructuredName n = new StructuredName();
    n.setFamily("Family");
    vcard.setStructuredName(n);
    {
        StringWriter sw = new StringWriter();
        VCardWriter writer = new VCardWriter(sw, VCardVersion.V2_1);
        writer.setAddProdId(false);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(true);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(false);
        writer.write(vcard);
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "N:Family\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "N:Family;;;;\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "N:Family\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.setIncludeTrailingSemicolons(true);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(false);
        writer.write(vcard);
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "N:Family\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "N:Family;;;;\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "N:Family\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.setIncludeTrailingSemicolons(true);
        writer.write(vcard);
        writer.setIncludeTrailingSemicolons(false);
        writer.write(vcard);
        String actual = sw.toString();
        // @formatter:off
        String expected = "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "N:Family;;;;\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "N:Family;;;;\r\n" + "END:VCARD\r\n" + "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "N:Family\r\n" + "END:VCARD\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
}
Also used : StringWriter(java.io.StringWriter) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Test(org.junit.Test)

Example 17 with StructuredName

use of ezvcard.property.StructuredName 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");
}
Also used : Timezone(ezvcard.property.Timezone) Address(ezvcard.property.Address) Telephone(ezvcard.property.Telephone) Anniversary(ezvcard.property.Anniversary) TelUri(ezvcard.util.TelUri) Birthday(ezvcard.property.Birthday) Geo(ezvcard.property.Geo) UtcOffset(ezvcard.util.UtcOffset) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Key(ezvcard.property.Key) Test(org.junit.Test)

Example 18 with StructuredName

use of ezvcard.property.StructuredName 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");
}
Also used : Timezone(ezvcard.property.Timezone) Address(ezvcard.property.Address) Telephone(ezvcard.property.Telephone) Anniversary(ezvcard.property.Anniversary) TelUri(ezvcard.util.TelUri) Birthday(ezvcard.property.Birthday) Geo(ezvcard.property.Geo) UtcOffset(ezvcard.util.UtcOffset) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Key(ezvcard.property.Key) Test(org.junit.Test)

Example 19 with StructuredName

use of ezvcard.property.StructuredName in project ez-vcard by mangstadt.

the class StructuredNameScribeTest method parseText.

@Test
public void parseText() {
    StructuredName withAllValuesV2_1 = new StructuredName(withAllValues);
    withAllValuesV2_1.getAdditionalNames().clear();
    withAllValuesV2_1.getAdditionalNames().add("Joh;nny,,John");
    sensei.assertParseText("Doe;Jonathan;Joh\\;nny\\,,John;Mr.;III").versions(V2_1).run(withAllValuesV2_1);
    sensei.assertParseText("Doe;Jonathan;Joh\\;nny\\,,John;Mr.;III").versions(V3_0, V4_0).run(withAllValues);
    StructuredName withEmptyValuesV2_1 = new StructuredName(withEmptyValues);
    withEmptyValuesV2_1.getAdditionalNames().clear();
    withEmptyValuesV2_1.getAdditionalNames().add("Joh;nny,,John");
    sensei.assertParseText(";Jonathan;Joh\\;nny\\,,John;;").versions(V2_1).run(withEmptyValuesV2_1);
    sensei.assertParseText(";Jonathan;Joh\\;nny\\,,John;;").versions(V3_0, V4_0).run(withEmptyValues);
    sensei.assertParseText(";;;;").run(empty);
    sensei.assertParseText("").run(empty);
}
Also used : StructuredName(ezvcard.property.StructuredName) Test(org.junit.Test)

Example 20 with StructuredName

use of ezvcard.property.StructuredName 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;
}
Also used : Timezone(ezvcard.property.Timezone) UtcOffset(ezvcard.util.UtcOffset) Address(ezvcard.property.Address) Photo(ezvcard.property.Photo) Sound(ezvcard.property.Sound) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) File(java.io.File)

Aggregations

StructuredName (ezvcard.property.StructuredName)37 VCard (ezvcard.VCard)17 Telephone (ezvcard.property.Telephone)14 Test (org.junit.Test)13 Address (ezvcard.property.Address)11 Name (com.google.api.services.people.v1.model.Name)10 Email (ezvcard.property.Email)9 Person (com.google.api.services.people.v1.model.Person)8 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)6 FieldMetadata (com.google.api.services.people.v1.model.FieldMetadata)6 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)6 Source (com.google.api.services.people.v1.model.Source)6 Timezone (ezvcard.property.Timezone)6 TelUri (ezvcard.util.TelUri)6 UtcOffset (ezvcard.util.UtcOffset)6 Collections (java.util.Collections)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Birthday (ezvcard.property.Birthday)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)4