Search in sources :

Example 36 with VCard

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

the class JCardWriterTest method write_multiple_vcards.

@Test
public void write_multiple_vcards() throws Throwable {
    StringWriter sw = new StringWriter();
    JCardWriter writer = new JCardWriter(sw, true);
    writer.setAddProdId(false);
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    writer.write(vcard);
    vcard = new VCard();
    vcard.setFormattedName("Jane Doe");
    writer.write(vcard);
    writer.close();
    // @formatter:off
    String expected = "[" + "[\"vcard\"," + "[" + "[\"version\",{},\"text\",\"4.0\"]," + "[\"fn\",{},\"text\",\"John Doe\"]" + "]" + "]," + "[\"vcard\"," + "[" + "[\"version\",{},\"text\",\"4.0\"]," + "[\"fn\",{},\"text\",\"Jane Doe\"]" + "]" + "]" + "]";
    // @formatter:on
    assertEquals(expected, sw.toString());
}
Also used : StringWriter(java.io.StringWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 37 with VCard

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

the class JCardWriterTest method setPrettyPrinter.

@Test
public void setPrettyPrinter() throws Throwable {
    StringWriter sw = new StringWriter();
    JCardWriter writer = new JCardWriter(sw, true);
    writer.setAddProdId(false);
    writer.setPrettyPrinter(new JCardPrettyPrinter());
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    writer.write(vcard);
    vcard = new VCard();
    vcard.setFormattedName("John Doe");
    writer.write(vcard);
    writer.close();
    // @formatter:off
    String expected = "[" + NEWLINE + "  [" + NEWLINE + "    \"vcard\"," + NEWLINE + "    [" + NEWLINE + "      [ \"version\", { }, \"text\", \"4.0\" ]," + NEWLINE + "      [ \"fn\", { }, \"text\", \"John Doe\" ]" + NEWLINE + "    ]" + NEWLINE + "  ]," + NEWLINE + "  [" + NEWLINE + "    \"vcard\"," + NEWLINE + "    [" + NEWLINE + "      [ \"version\", { }, \"text\", \"4.0\" ]," + NEWLINE + "      [ \"fn\", { }, \"text\", \"John Doe\" ]" + NEWLINE + "    ]" + NEWLINE + "  ]" + NEWLINE + "]";
    // @formatter:on
    assertEquals(expected, sw.toString());
}
Also used : StringWriter(java.io.StringWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 38 with VCard

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

the class JCardWriterTest method skipMeException.

@Test
public void skipMeException() throws Throwable {
    StringWriter sw = new StringWriter();
    JCardWriter writer = new JCardWriter(sw);
    writer.registerScribe(new SkipMeScribe());
    writer.setAddProdId(false);
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    vcard.addProperty(new SkipMeProperty());
    writer.write(vcard);
    writer.close();
    // @formatter:off
    String expected = "[\"vcard\"," + "[" + "[\"version\",{},\"text\",\"4.0\"]," + "[\"fn\",{},\"text\",\"John Doe\"]" + "]" + "]";
    // @formatter:on
    assertEquals(expected, sw.toString());
}
Also used : StringWriter(java.io.StringWriter) SkipMeScribe(ezvcard.io.scribe.SkipMeScribe) SkipMeProperty(ezvcard.property.SkipMeProperty) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 39 with VCard

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

the class JCardWriterTest method write_single_vcard.

@Test
public void write_single_vcard() throws Throwable {
    StringWriter sw = new StringWriter();
    JCardWriter writer = new JCardWriter(sw);
    writer.setAddProdId(false);
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    writer.write(vcard);
    writer.close();
    // @formatter:off
    String expected = "[\"vcard\"," + "[" + "[\"version\",{},\"text\",\"4.0\"]," + "[\"fn\",{},\"text\",\"John Doe\"]" + "]" + "]";
    // @formatter:on
    assertEquals(expected, sw.toString());
}
Also used : StringWriter(java.io.StringWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 40 with VCard

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

the class JohnDoeVCard method main.

public static void main(String[] args) throws Throwable {
    VCard vcard = createVCard();
    // validate vCard for version 3.0
    System.out.println("Version 3.0 validation warnings:");
    System.out.println(vcard.validate(VCardVersion.V3_0));
    System.out.println();
    // validate vCard for version 4.0 (xCard and jCard use this version)
    System.out.println("Version 4.0 validation warnings:");
    System.out.println(vcard.validate(VCardVersion.V4_0));
    // write vCard
    File file = new File("john-doe.vcf");
    System.out.println("Writing " + file.getName() + "...");
    Ezvcard.write(vcard).version(VCardVersion.V3_0).go(file);
    // write xCard
    file = new File("john-doe.xml");
    System.out.println("Writing " + file.getName() + "...");
    Ezvcard.writeXml(vcard).indent(2).go(file);
    // write hCard
    file = new File("john-doe.html");
    System.out.println("Writing " + file.getName() + "...");
    Ezvcard.writeHtml(vcard).go(file);
    // write jCard
    file = new File("john-doe.json");
    System.out.println("Writing " + file.getName() + "...");
    Ezvcard.writeJson(vcard).go(file);
}
Also used : VCard(ezvcard.VCard) File(java.io.File)

Aggregations

VCard (ezvcard.VCard)189 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