Search in sources :

Example 76 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class XCardWriterTest method write_xmlVersion_invalid.

@Test
public void write_xmlVersion_invalid() throws Exception {
    StringWriter sw = new StringWriter();
    XCardWriter writer = new XCardWriter(sw, null, "10.17");
    VCard vcard = new VCard();
    writer.write(vcard);
    writer.close();
    String xml = sw.toString();
    assertTrue(xml.matches("(?i)<\\?xml.*?version=\"1.0\".*?\\?>.*"));
}
Also used : StringWriter(java.io.StringWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 77 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class XCardWriterTest method write_existing_dom_element.

@Test
public void write_existing_dom_element() throws Exception {
    Document document = XmlUtils.toDocument("<root><a /><b /></root>");
    Node element = document.getFirstChild().getFirstChild();
    XCardWriter writer = new XCardWriter(element);
    writer.setAddProdId(false);
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    writer.write(vcard);
    writer.close();
    // @formatter:off
    String xml = "<root>" + "<a>" + "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "</vcard>" + "</vcards>" + "</a>" + "<b />" + "</root>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(expected, document);
}
Also used : Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 78 with VCard

use of ezvcard.VCard 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 79 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class XCardWriterTest method write_parameters.

@Test
public void write_parameters() throws Exception {
    writer.registerParameterDataType("X-INT", VCardDataType.INTEGER);
    VCard vcard = new VCard();
    Note note = new Note("This is a\nnote.");
    note.setParameter(VCardParameters.ALTID, "value");
    note.setParameter(VCardParameters.CALSCALE, "value");
    note.setParameter(VCardParameters.GEO, "geo:123.456,234.567");
    note.setParameter(VCardParameters.LABEL, "value");
    note.setParameter(VCardParameters.LANGUAGE, "en");
    note.setParameter(VCardParameters.MEDIATYPE, "text/plain");
    note.getPids().add(new Pid(1, 1));
    note.setParameter(VCardParameters.PREF, "1");
    note.setParameter(VCardParameters.SORT_AS, "value");
    note.setParameter(VCardParameters.TYPE, "home");
    note.setParameter(VCardParameters.TZ, "America/New_York");
    note.setParameter("X-CUSTOM", "xxx");
    note.setParameter("X-INT", "11");
    vcard.addNote(note);
    writer.write(vcard);
    writer.close();
    // @formatter:off
    String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<note>" + "<parameters>" + "<altid><text>value</text></altid>" + "<calscale><text>value</text></calscale>" + "<geo><uri>geo:123.456,234.567</uri></geo>" + "<label><text>value</text></label>" + "<language><language-tag>en</language-tag></language>" + "<mediatype><text>text/plain</text></mediatype>" + "<pid><text>1.1</text></pid>" + "<pref><integer>1</integer></pref>" + "<sort-as><text>value</text></sort-as>" + "<type><text>home</text></type>" + "<tz><uri>America/New_York</uri></tz>" + "<x-custom><unknown>xxx</unknown></x-custom>" + "<x-int><integer>11</integer></x-int>" + "</parameters>" + "<text>This is a\nnote.</text>" + "</note>" + "</vcard>" + "</vcards>";
    // @formatter:on
    assertOutput(expected);
}
Also used : Note(ezvcard.property.Note) Pid(ezvcard.parameter.Pid) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 80 with VCard

use of ezvcard.VCard in project ez-vcard by mangstadt.

the class XCardWriterTest method write_group.

@Test
public void write_group() throws Exception {
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    Note note = vcard.addNote("This is a\nnote.");
    note.setGroup("group1");
    note.setLanguage("en");
    Photo photo = new Photo("http://example.com/image.jpg", ImageType.JPEG);
    photo.setGroup("group1");
    vcard.addPhoto(photo);
    note = new Note("Bonjour.");
    note.setGroup("group2");
    vcard.addNote(note);
    writer.write(vcard);
    writer.close();
    // @formatter:off
    String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "<group name=\"group1\">" + "<photo>" + "<parameters>" + "<mediatype><text>image/jpeg</text></mediatype>" + "</parameters>" + "<uri>http://example.com/image.jpg</uri>" + "</photo>" + "<note>" + "<parameters>" + "<language><language-tag>en</language-tag></language>" + "</parameters>" + "<text>This is a\nnote.</text>" + "</note>" + "</group>" + "<group name=\"group2\">" + "<note><text>Bonjour.</text></note>" + "</group>" + "</vcard>" + "</vcards>";
    // @formatter:on
    assertOutput(expected);
}
Also used : Note(ezvcard.property.Note) Photo(ezvcard.property.Photo) VCard(ezvcard.VCard) Test(org.junit.Test)

Aggregations

VCard (ezvcard.VCard)191 Test (org.junit.Test)134 StringWriter (java.io.StringWriter)29 StructuredName (ezvcard.property.StructuredName)23 Person (com.google.api.services.people.v1.model.Person)22 Telephone (ezvcard.property.Telephone)21 Photo (ezvcard.property.Photo)17 Email (ezvcard.property.Email)16 List (java.util.List)16 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)15 Document (org.w3c.dom.Document)15 VCardVersion (ezvcard.VCardVersion)14 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)14 Address (ezvcard.property.Address)14 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)13 Collectors (java.util.stream.Collectors)12 Name (com.google.api.services.people.v1.model.Name)11 File (java.io.File)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)10 Pair (com.google.gdata.util.common.base.Pair)10