Search in sources :

Example 1 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_basicType.

@Test
public void add_basicType() throws Throwable {
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "</vcard>" + "</vcards>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(expected, actual);
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 2 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method write_prettyPrint.

@Test
public void write_prettyPrint() throws Throwable {
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.write(vcard);
    String actual = xcard.write(2);
    // @formatter:off
    String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + NEWLINE + "  <vcard>" + NEWLINE + "    <fn>" + NEWLINE + "      <text>John Doe</text>" + NEWLINE + "    </fn>" + NEWLINE + "  </vcard>" + NEWLINE + "</vcards>";
    // @formatter:on
    // use "String.contains()" to ignore the XML declaration at the top
    assertTrue("Expected:" + NEWLINE + expected + NEWLINE + NEWLINE + "Actual:" + NEWLINE + actual, actual.contains(expected));
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 3 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_group.

@Test
public void add_group() throws Throwable {
    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 = vcard.addNote("Bonjour.");
    note.setGroup("group2");
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<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>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(expected, actual);
}
Also used : Note(ezvcard.property.Note) XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) Photo(ezvcard.property.Photo) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 4 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_xml_property_with_null_value.

@Test
public void add_xml_property_with_null_value() throws Throwable {
    VCard vcard = new VCard();
    Xml xmlProperty = new Xml((Document) null);
    vcard.addXml(xmlProperty);
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard />" + "</vcards>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(expected, actual);
}
Also used : Xml(ezvcard.property.Xml) XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 5 with XCardDocumentStreamWriter

use of ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter in project ez-vcard by mangstadt.

the class XCardDocumentTest method add_existing_vcards_element.

@Test
public void add_existing_vcards_element() throws Throwable {
    VCard vcard = new VCard();
    vcard.setFormattedName("John Doe");
    XCardDocument xcard = new XCardDocument("<root><vcards xmlns=\"" + V4_0.getXmlNamespace() + "\"><a /></vcards></root>");
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<root>" + "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<a />" + "<vcard>" + "<fn><text>John Doe</text></fn>" + "</vcard>" + "</vcards>" + "</root>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(expected, actual);
}
Also used : XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Aggregations

XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)15 VCard (ezvcard.VCard)14 Test (org.junit.Test)13 Document (org.w3c.dom.Document)11 Note (ezvcard.property.Note)2 Xml (ezvcard.property.Xml)2 VCardDataType (ezvcard.VCardDataType)1 AgeProperty (ezvcard.io.AgeProperty)1 AgeScribe (ezvcard.io.AgeProperty.AgeScribe)1 LuckyNumProperty (ezvcard.io.LuckyNumProperty)1 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)1 SalaryProperty (ezvcard.io.SalaryProperty)1 SalaryScribe (ezvcard.io.SalaryProperty.SalaryScribe)1 SkipMeScribe (ezvcard.io.scribe.SkipMeScribe)1 XCardDocument (ezvcard.io.xml.XCardDocument)1 Pid (ezvcard.parameter.Pid)1 Photo (ezvcard.property.Photo)1 SkipMeProperty (ezvcard.property.SkipMeProperty)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1