Search in sources :

Example 1 with XCardBuilder

use of ezvcard.util.XCardBuilder in project ez-vcard by mangstadt.

the class EzvcardTest method parseXml_all.

@Test
public void parseXml_all() throws Exception {
    XCardBuilder xb = new XCardBuilder();
    xb.prop("fn", "<text>John Doe</text>");
    xb.begin();
    xb.prop("fn", "<text>Jane Doe</text>");
    List<List<ParseWarning>> warnings = new ArrayList<List<ParseWarning>>();
    List<VCard> vcards = Ezvcard.parseXml(xb.toString()).warnings(warnings).all();
    Iterator<VCard> it = vcards.iterator();
    VCard vcard = it.next();
    assertVersion(VCardVersion.V4_0, vcard);
    assertEquals("John Doe", vcard.getFormattedName().getValue());
    vcard = it.next();
    assertVersion(VCardVersion.V4_0, vcard);
    assertEquals("Jane Doe", vcard.getFormattedName().getValue());
    assertEquals(2, warnings.size());
    assertParseWarnings(warnings.get(0));
    assertParseWarnings(warnings.get(1));
    assertFalse(it.hasNext());
}
Also used : ArrayList(java.util.ArrayList) XCardBuilder(ezvcard.util.XCardBuilder) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ParseWarning(ezvcard.io.ParseWarning) Test(org.junit.Test)

Example 2 with XCardBuilder

use of ezvcard.util.XCardBuilder in project ez-vcard by mangstadt.

the class EzvcardTest method parseXml_first.

@Test
public void parseXml_first() throws Exception {
    XCardBuilder xb = new XCardBuilder();
    xb.prop("fn", "<text>John Doe</text>");
    List<List<ParseWarning>> warnings = new ArrayList<List<ParseWarning>>();
    VCard vcard = Ezvcard.parseXml(xb.toString()).warnings(warnings).first();
    assertVersion(VCardVersion.V4_0, vcard);
    assertEquals("John Doe", vcard.getFormattedName().getValue());
    assertEquals(1, warnings.size());
    assertParseWarnings(warnings.get(0));
}
Also used : ArrayList(java.util.ArrayList) XCardBuilder(ezvcard.util.XCardBuilder) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ParseWarning(ezvcard.io.ParseWarning) Test(org.junit.Test)

Example 3 with XCardBuilder

use of ezvcard.util.XCardBuilder in project ez-vcard by mangstadt.

the class EzvcardTest method parseXml_register.

@Test
public void parseXml_register() throws Exception {
    XCardBuilder xb = new XCardBuilder();
    xb.prop("http://luckynum.com", "lucky-num", "<num>22</num>");
    VCard vcard = Ezvcard.parseXml(xb.toString()).register(new LuckyNumScribe()).first();
    assertVersion(VCardVersion.V4_0, vcard);
    List<LuckyNumProperty> ext = vcard.getProperties(LuckyNumProperty.class);
    assertEquals(1, ext.size());
    assertEquals(22, ext.get(0).luckyNum);
}
Also used : LuckyNumScribe(ezvcard.io.LuckyNumProperty.LuckyNumScribe) XCardBuilder(ezvcard.util.XCardBuilder) LuckyNumProperty(ezvcard.io.LuckyNumProperty) Test(org.junit.Test)

Aggregations

XCardBuilder (ezvcard.util.XCardBuilder)3 Test (org.junit.Test)3 ParseWarning (ezvcard.io.ParseWarning)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NodeList (org.w3c.dom.NodeList)2 LuckyNumProperty (ezvcard.io.LuckyNumProperty)1 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)1