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 "";
}
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());
}
}
}
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);
}
}
}
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);
}
}
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();
}
}
Aggregations