Search in sources :

Example 1 with VCardVersion

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

the class DateOrTimePropertyScribe method _writeText.

@Override
protected String _writeText(T property, WriteContext context) {
    VCardVersion version = context.getVersion();
    Date date = property.getDate();
    if (date != null) {
        boolean extended = (version == VCardVersion.V3_0);
        return date(date).time(property.hasTime()).extended(extended).utc(false).write();
    }
    if (version == VCardVersion.V4_0) {
        String text = property.getText();
        if (text != null) {
            return VObjectPropertyValues.escape(text);
        }
        PartialDate partialDate = property.getPartialDate();
        if (partialDate != null) {
            return partialDate.toISO8601(false);
        }
    }
    return "";
}
Also used : VCardVersion(ezvcard.VCardVersion) PartialDate(ezvcard.util.PartialDate) Date(java.util.Date) PartialDate(ezvcard.util.PartialDate)

Example 2 with VCardVersion

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

the class VCardPropertyScribeTest method handlePrefParam_from_4.

@Test
public void handlePrefParam_from_4() {
    VCard vcard = new VCard();
    TestProperty two = new TestProperty("");
    two.getParameters().setPref(2);
    vcard.addProperty(two);
    TestProperty nullPref = new TestProperty("");
    vcard.addProperty(nullPref);
    TestProperty invalidPref = new TestProperty("");
    invalidPref.getParameters().replace("PREF", "invalid");
    vcard.addProperty(invalidPref);
    TestProperty one = new TestProperty("");
    one.getParameters().setPref(1);
    vcard.addProperty(one);
    TestProperty three = new TestProperty("");
    three.getParameters().setPref(3);
    vcard.addProperty(three);
    // no change
    {
        VCardVersion version = V4_0;
        for (TestProperty p : vcard.getProperties(TestProperty.class)) {
            VCardParameters copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertEquals(p.getParameters(), copy);
        }
    }
    for (VCardVersion version : each(V2_1, V3_0)) {
        VCardParameters copy = new VCardParameters(one.getParameters());
        VCardPropertyScribe.handlePrefParam(one, copy, version, vcard);
        assertEquals("pref", copy.getType());
        assertNull(copy.getPref());
        for (TestProperty p : each(nullPref, invalidPref, two, three)) {
            copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertNull(copy.getType());
            assertNull(copy.getPref());
        }
    }
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 3 with VCardVersion

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

the class VCardPropertyScribeTest method handlePrefParam_to_4.

@Test
public void handlePrefParam_to_4() {
    VCard vcard = new VCard();
    TestProperty two = new TestProperty("");
    two.getParameters().setType("HOME");
    vcard.addProperty(two);
    TestProperty one = new TestProperty("");
    one.getParameters().setType("PREF");
    vcard.addProperty(one);
    TestProperty three = new TestProperty("");
    vcard.addProperty(three);
    // no change
    for (VCardVersion version : each(V2_1, V3_0)) {
        for (TestProperty p : vcard.getProperties(TestProperty.class)) {
            VCardParameters copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertEquals(p.getParameters(), copy);
        }
    }
    {
        VCardVersion version = V4_0;
        VCardParameters copy = new VCardParameters(one.getParameters());
        VCardPropertyScribe.handlePrefParam(one, copy, version, vcard);
        assertIntEquals(1, copy.getPref());
        assertNull(copy.getType());
        for (TestProperty p : each(two, three)) {
            copy = new VCardParameters(p.getParameters());
            VCardPropertyScribe.handlePrefParam(p, copy, version, vcard);
            assertEquals(p.getParameters(), copy);
        }
    }
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 4 with VCardVersion

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

the class VCardReaderTest method value_parameter.

@Test
public void value_parameter() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        String str = "BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "VAL;VALUE=text;LANGUAGE=en:value\r\n" + "VAL;LANGUAGE=en:value\r\n" + "VAL;VALUE=text:value\r\n" + "VAL:value\r\n" + "END:VCARD\r\n";
        // @formatter:on
        VCardReader reader = new VCardReader(str);
        reader.registerScribe(new ValueScribe());
        VCard vcard = reader.readNext();
        assertVersion(version, vcard);
        assertPropertyCount(4, vcard);
        Iterator<ValueProp> it = vcard.getProperties(ValueProp.class).iterator();
        ValueProp prop = it.next();
        assertEquals(TEXT, prop.dataType);
        assertEquals(1, prop.getParameters().size());
        assertNull(prop.getParameters().getValue());
        assertEquals("en", prop.getParameters().getLanguage());
        prop = it.next();
        assertEquals(INTEGER, prop.dataType);
        assertEquals(1, prop.getParameters().size());
        assertNull(prop.getParameters().getValue());
        assertEquals("en", prop.getParameters().getLanguage());
        prop = it.next();
        assertEquals(TEXT, prop.dataType);
        assertEquals(0, prop.getParameters().size());
        assertNull(prop.getParameters().getValue());
        assertNull(prop.getParameters().getLanguage());
        prop = it.next();
        assertEquals(INTEGER, prop.dataType);
        assertEquals(0, prop.getParameters().size());
        assertNull(prop.getParameters().getValue());
        assertNull(prop.getParameters().getLanguage());
        assertParseWarnings(reader);
        assertNoMoreVCards(reader);
    }
}
Also used : VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 5 with VCardVersion

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

the class VCardReaderTest method invalid_line.

@Test
public void invalid_line() throws Exception {
    for (VCardVersion version : VCardVersion.values()) {
        // @formatter:off
        VCardAsserter asserter = read("BEGIN:VCARD\r\n" + "VERSION:" + version + "\r\n" + "bad-line\r\n" + "END:VCARD\r\n");
        // @formatter:on
        asserter.next(version);
        asserter.warnings(27);
        asserter.done();
    }
}
Also used : VCardVersion(ezvcard.VCardVersion) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Aggregations

VCardVersion (ezvcard.VCardVersion)36 Test (org.junit.Test)30 VCard (ezvcard.VCard)14 VCardAsserter (ezvcard.property.asserter.VCardAsserter)10 VCardParameters (ezvcard.parameter.VCardParameters)5 Label (ezvcard.property.Label)4 RawProperty (ezvcard.property.RawProperty)4 VCardProperty (ezvcard.property.VCardProperty)4 Address (ezvcard.property.Address)3 ProductId (ezvcard.property.ProductId)3 VCardDataType (ezvcard.VCardDataType)2 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)2 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)2 ArrayList (java.util.ArrayList)2 SyntaxStyle (com.github.mangstadt.vinnie.SyntaxStyle)1 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)1 AllowedCharacters (com.github.mangstadt.vinnie.validate.AllowedCharacters)1 ValidationWarning (ezvcard.ValidationWarning)1 LuckyNumProperty (ezvcard.io.LuckyNumProperty)1 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)1