Search in sources :

Example 1 with MyFormattedNameProperty

use of ezvcard.io.MyFormattedNameProperty in project ez-vcard by mangstadt.

the class VCardReaderTest method extended_properties_override_standard_property_scribes.

@Test
public void extended_properties_override_standard_property_scribes() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "FN:John Doe\r\n" + "END:VCARD\r\n";
        // @formatter:on
        VCardReader reader = new VCardReader(str);
        reader.registerScribe(new MyFormattedNameScribe());
        VCard vcard = reader.readNext();
        assertVersion(version, vcard);
        assertPropertyCount(1, vcard);
        // read a type that has a type class
        MyFormattedNameProperty fn = vcard.getProperty(MyFormattedNameProperty.class);
        assertEquals("JOHN DOE", fn.value);
        assertParseWarnings(reader);
        assertNoMoreVCards(reader);
    }
}
Also used : MyFormattedNameScribe(ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe) MyFormattedNameProperty(ezvcard.io.MyFormattedNameProperty) VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 2 with MyFormattedNameProperty

use of ezvcard.io.MyFormattedNameProperty in project ez-vcard by mangstadt.

the class JCardReaderTest method readExtendedType_override_standard_type_classes.

@Test
public void readExtendedType_override_standard_type_classes() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"version\", {}, \"text\", \"4.0\"]," + "[\"fn\", {}, \"text\", \"John Doe\"]" + "]" + "]";
    // @formatter:on
    JCardReader reader = new JCardReader(json);
    reader.registerScribe(new MyFormattedNameScribe());
    VCard vcard = reader.readNext();
    assertPropertyCount(1, vcard);
    assertVersion(V4_0, vcard);
    MyFormattedNameProperty prop = vcard.getProperty(MyFormattedNameProperty.class);
    assertEquals("JOHN DOE", prop.value);
    assertParseWarnings(reader);
    assertNoMoreVCards(reader);
}
Also used : MyFormattedNameScribe(ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe) MyFormattedNameProperty(ezvcard.io.MyFormattedNameProperty) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 3 with MyFormattedNameProperty

use of ezvcard.io.MyFormattedNameProperty in project ez-vcard by mangstadt.

the class XCardReaderTest method read_non_standard_properties.

@Test
public void read_non_standard_properties() throws Exception {
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + // expected:         XML property
    "<foo xmlns=\"http://example.com\">bar</foo>" + // expected:         LuckyNumProperty
    "<a:lucky-num xmlns:a=\"http://luckynum.com\"><a:num>21</a:num></a:lucky-num>" + // expected:         SalaryProperty
    "<x-salary><integer>1000000</integer></x-salary>" + // expected:         AgeProperty (should be unmarshalled using the default parseXml implementation)
    "<x-age><integer>24</integer></x-age>" + // expected:         RawProperty
    "<x-gender><text>m</text></x-gender>" + // expected:         MyFormattedNameProperty
    "<fn><name>John Doe</name></fn>" + "</vcard>" + "</vcards>";
    // @formatter:on
    XCardReader reader = new XCardReader(xml);
    reader.registerScribe(new LuckyNumScribe());
    reader.registerScribe(new SalaryScribe());
    reader.registerScribe(new AgeScribe());
    reader.registerScribe(new MyFormattedNameScribe());
    {
        VCard vcard = reader.readNext();
        assertVersion(V4_0, vcard);
        assertPropertyCount(6, vcard);
        {
            Iterator<Xml> xmlIt = vcard.getXmls().iterator();
            Xml xmlType = xmlIt.next();
            assertXMLEqual(XmlUtils.toDocument("<foo xmlns=\"http://example.com\">bar</foo>"), xmlType.getValue());
            assertFalse(xmlIt.hasNext());
        }
        LuckyNumProperty luckyNum = vcard.getProperty(LuckyNumProperty.class);
        assertEquals(21, luckyNum.luckyNum);
        SalaryProperty salary = vcard.getProperty(SalaryProperty.class);
        assertEquals(1000000, salary.salary);
        AgeProperty age = vcard.getProperty(AgeProperty.class);
        assertEquals(24, age.age);
        RawProperty gender = vcard.getExtendedProperty("X-GENDER");
        assertEquals(VCardDataType.TEXT, gender.getDataType());
        assertEquals("m", gender.getValue());
        MyFormattedNameProperty fn = vcard.getProperty(MyFormattedNameProperty.class);
        assertEquals("JOHN DOE", fn.value);
        assertParseWarnings(reader);
    }
    assertNoMoreVCards(reader);
}
Also used : SalaryProperty(ezvcard.io.SalaryProperty) LuckyNumScribe(ezvcard.io.LuckyNumProperty.LuckyNumScribe) LuckyNumProperty(ezvcard.io.LuckyNumProperty) AgeScribe(ezvcard.io.AgeProperty.AgeScribe) MyFormattedNameScribe(ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe) AgeProperty(ezvcard.io.AgeProperty) RawProperty(ezvcard.property.RawProperty) MyFormattedNameProperty(ezvcard.io.MyFormattedNameProperty) Xml(ezvcard.property.Xml) SalaryScribe(ezvcard.io.SalaryProperty.SalaryScribe) VCard(ezvcard.VCard) Test(org.junit.Test)

Aggregations

VCard (ezvcard.VCard)3 MyFormattedNameProperty (ezvcard.io.MyFormattedNameProperty)3 MyFormattedNameScribe (ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe)3 Test (org.junit.Test)3 VCardVersion (ezvcard.VCardVersion)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 RawProperty (ezvcard.property.RawProperty)1 Xml (ezvcard.property.Xml)1