Search in sources :

Example 1 with SalaryScribe

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

the class XCardDocumentTest method add_extendedTypes.

@Test
public void add_extendedTypes() throws Throwable {
    VCard vcard = new VCard();
    // contains marshal methods and QName
    LuckyNumProperty num = new LuckyNumProperty(24);
    vcard.addProperty(num);
    // contains marshal methods, but does not have a QName
    SalaryProperty salary = new SalaryProperty(1000000);
    vcard.addProperty(salary);
    // does not contain marshal methods nor QName
    AgeProperty age = new AgeProperty(22);
    vcard.addProperty(age);
    XCardDocument xcard = new XCardDocument();
    XCardDocumentStreamWriter writer = xcard.writer();
    writer.setAddProdId(false);
    writer.registerScribe(new LuckyNumScribe());
    writer.registerScribe(new SalaryScribe());
    writer.registerScribe(new AgeScribe());
    writer.write(vcard);
    Document actual = xcard.getDocument();
    // @formatter:off
    String xml = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<a:lucky-num xmlns:a=\"http://luckynum.com\">24</a:lucky-num>" + "<x-salary>1000000</x-salary>" + "<x-age><unknown>22</unknown></x-age>" + "</vcard>" + "</vcards>";
    Document expected = XmlUtils.toDocument(xml);
    // @formatter:on
    assertXMLEqual(XmlUtils.toString(actual), expected, actual);
}
Also used : AgeScribe(ezvcard.io.AgeProperty.AgeScribe) AgeProperty(ezvcard.io.AgeProperty) SalaryProperty(ezvcard.io.SalaryProperty) XCardDocumentStreamWriter(ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter) LuckyNumScribe(ezvcard.io.LuckyNumProperty.LuckyNumScribe) SalaryScribe(ezvcard.io.SalaryProperty.SalaryScribe) LuckyNumProperty(ezvcard.io.LuckyNumProperty) Document(org.w3c.dom.Document) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 2 with SalaryScribe

use of ezvcard.io.SalaryProperty.SalaryScribe 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)

Example 3 with SalaryScribe

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

the class XCardWriterTest method write_extended_properties.

@Test
public void write_extended_properties() throws Exception {
    writer.registerScribe(new LuckyNumScribe());
    writer.registerScribe(new SalaryScribe());
    writer.registerScribe(new AgeScribe());
    VCard vcard = new VCard();
    // contains marshal methods and QName
    LuckyNumProperty num = new LuckyNumProperty(24);
    vcard.addProperty(num);
    // contains marshal methods, but does not have a QName
    SalaryProperty salary = new SalaryProperty(1000000);
    vcard.addProperty(salary);
    // does not contain marshal methods nor QName
    AgeProperty age = new AgeProperty(22);
    vcard.addProperty(age);
    writer.write(vcard);
    writer.close();
    // @formatter:off
    String expected = "<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + "<a:lucky-num xmlns:a=\"http://luckynum.com\">24</a:lucky-num>" + "<x-salary>1000000</x-salary>" + "<x-age><unknown>22</unknown></x-age>" + "</vcard>" + "</vcards>";
    // @formatter:on
    assertOutput(expected);
}
Also used : AgeScribe(ezvcard.io.AgeProperty.AgeScribe) AgeProperty(ezvcard.io.AgeProperty) SalaryProperty(ezvcard.io.SalaryProperty) LuckyNumScribe(ezvcard.io.LuckyNumProperty.LuckyNumScribe) SalaryScribe(ezvcard.io.SalaryProperty.SalaryScribe) LuckyNumProperty(ezvcard.io.LuckyNumProperty) VCard(ezvcard.VCard) Test(org.junit.Test)

Aggregations

VCard (ezvcard.VCard)3 AgeProperty (ezvcard.io.AgeProperty)3 AgeScribe (ezvcard.io.AgeProperty.AgeScribe)3 LuckyNumProperty (ezvcard.io.LuckyNumProperty)3 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)3 SalaryProperty (ezvcard.io.SalaryProperty)3 SalaryScribe (ezvcard.io.SalaryProperty.SalaryScribe)3 Test (org.junit.Test)3 MyFormattedNameProperty (ezvcard.io.MyFormattedNameProperty)1 MyFormattedNameScribe (ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe)1 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)1 RawProperty (ezvcard.property.RawProperty)1 Xml (ezvcard.property.Xml)1 Document (org.w3c.dom.Document)1