Search in sources :

Example 16 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class JCardRawReader method parseParameters.

private VCardParameters parseParameters() throws IOException {
    checkNext(JsonToken.START_OBJECT);
    VCardParameters parameters = new VCardParameters();
    while (parser.nextToken() != JsonToken.END_OBJECT) {
        String parameterName = parser.getText();
        if (parser.nextToken() == JsonToken.START_ARRAY) {
            // multi-valued parameter
            while (parser.nextToken() != JsonToken.END_ARRAY) {
                parameters.put(parameterName, parser.getText());
            }
        } else {
            parameters.put(parameterName, parser.getValueAsString());
        }
    }
    return parameters;
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters)

Example 17 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class VCardPropertyScribeTest method prepareParameters.

@Test
public void prepareParameters() {
    VCardPropertyScribeImpl m = new VCardPropertyScribeImpl() {

        @Override
        protected void _prepareParameters(TestProperty property, VCardParameters copy, VCardVersion version, VCard vcard) {
            copy.put("PARAM", "value");
        }
    };
    TestProperty property = new TestProperty("value");
    VCardParameters copy = m.prepareParameters(property, V4_0, new VCard());
    assertNotSame(property.getParameters(), copy);
    assertEquals("value", copy.first("PARAM"));
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) VCardVersion(ezvcard.VCardVersion) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 18 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class VCardWriterTest method date_time_properties_should_not_have_a_VALUE_parameter.

@Test
public void date_time_properties_should_not_have_a_VALUE_parameter() throws Throwable {
    class DateTestScribe<T extends VCardProperty> extends VCardPropertyScribe<T> {

        private final VCardDataType dataType;

        public DateTestScribe(Class<T> clazz, String name, VCardDataType dataType) {
            super(clazz, name);
            this.dataType = dataType;
        }

        @Override
        protected VCardDataType _defaultDataType(VCardVersion version) {
            return VCardDataType.DATE_AND_OR_TIME;
        }

        @Override
        protected VCardDataType _dataType(T property, VCardVersion version) {
            return dataType;
        }

        @Override
        protected String _writeText(T property, WriteContext context) {
            return "value";
        }

        @Override
        protected T _parseText(String value, VCardDataType dataType, VCardParameters parameters, ParseContext context) {
            return null;
        }
    }
    class DateProperty extends VCardProperty {
        // empty
    }
    class DateTimeProperty extends VCardProperty {
        // empty
    }
    class TimeProperty extends VCardProperty {
        // empty
    }
    class DateAndOrTimeProperty extends VCardProperty {
        // empty
    }
    VCard vcard = new VCard();
    vcard.addProperty(new DateProperty());
    vcard.addProperty(new DateTimeProperty());
    vcard.addProperty(new TimeProperty());
    vcard.addProperty(new DateAndOrTimeProperty());
    StringWriter sw = new StringWriter();
    VCardWriter vcw = new VCardWriter(sw, VCardVersion.V4_0);
    vcw.registerScribe(new DateTestScribe<DateProperty>(DateProperty.class, "DATE", VCardDataType.DATE));
    vcw.registerScribe(new DateTestScribe<DateTimeProperty>(DateTimeProperty.class, "DATETIME", VCardDataType.DATE_TIME));
    vcw.registerScribe(new DateTestScribe<TimeProperty>(TimeProperty.class, "TIME", VCardDataType.TIME));
    vcw.registerScribe(new DateTestScribe<DateAndOrTimeProperty>(DateAndOrTimeProperty.class, "DATEANDORTIME", VCardDataType.DATE_AND_OR_TIME));
    vcw.setAddProdId(false);
    vcw.write(vcard);
    String actual = sw.toString();
    // @formatter:off
    String expected = "BEGIN:VCARD\r\n" + "VERSION:4.0\r\n" + "DATE:value\r\n" + "DATETIME:value\r\n" + "TIME:value\r\n" + "DATEANDORTIME:value\r\n" + "END:VCARD\r\n";
    // @formatter:on
    assertEquals(actual, expected);
}
Also used : VCardPropertyScribe(ezvcard.io.scribe.VCardPropertyScribe) VCardVersion(ezvcard.VCardVersion) VCardParameters(ezvcard.parameter.VCardParameters) StringWriter(java.io.StringWriter) ParseContext(ezvcard.io.ParseContext) VCardProperty(ezvcard.property.VCardProperty) VCardDataType(ezvcard.VCardDataType) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 19 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class JCardRawReaderTest method ignore_other_json.

@Test
public void ignore_other_json() throws Throwable {
    // @formatter:off
    String json = "{" + "\"website\": \"example.com\"," + "\"vcard\":" + "[\"vcard\"," + "[" + "[\"prop\", {}, \"text\", \"value\"]" + "]" + "]" + "}";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    verify(listener).beginVCard();
    verify(listener).readProperty(null, "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.single("value"));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Example 20 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class JCardRawReaderTest method group.

@Test
public void group() throws Throwable {
    // @formatter:off
    String json = "[\"vcard\"," + "[" + "[\"prop\", { \"group\": \"one\" }, \"text\", \"value\"]" + "]" + "]";
    // @formatter:on
    JCardRawReader reader = createReader(json);
    JCardDataStreamListener listener = mock(JCardDataStreamListener.class);
    reader.readNext(listener);
    verify(listener).beginVCard();
    verify(listener).readProperty("one", "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.single("value"));
    verifyNoMoreInteractions(listener);
}
Also used : VCardParameters(ezvcard.parameter.VCardParameters) JCardDataStreamListener(ezvcard.io.json.JCardRawReader.JCardDataStreamListener) Test(org.junit.Test)

Aggregations

VCardParameters (ezvcard.parameter.VCardParameters)32 Test (org.junit.Test)24 JCardDataStreamListener (ezvcard.io.json.JCardRawReader.JCardDataStreamListener)12 VCard (ezvcard.VCard)5 VCardVersion (ezvcard.VCardVersion)5 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)4 VCardDataType (ezvcard.VCardDataType)3 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)3 SkipMeException (ezvcard.io.SkipMeException)3 VCardProperty (ezvcard.property.VCardProperty)3 StringWriter (java.io.StringWriter)3 Pid (ezvcard.parameter.Pid)2 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)1 ParseContext (ezvcard.io.ParseContext)1 JCardValue (ezvcard.io.json.JCardValue)1 Xml (ezvcard.property.Xml)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1