use of ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe 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);
}
}
use of ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe 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);
}
use of ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe in project ez-vcard by mangstadt.
the class HCardParserTest method registerExtendedProperty_overrides_standard_type_classes.
@Test
public void registerExtendedProperty_overrides_standard_type_classes() throws Exception {
// @formatter:off
String html = "<html>" + "<body>" + "<div class=\"vcard\">" + "<span class=\"fn\">John Doe</span>" + "</div>" + "</body>" + "</html>";
// @formatter:on
HCardParser parser = new HCardParser(html);
parser.registerScribe(new MyFormattedNameScribe());
VCard vcard = parser.readNext();
assertVersion(V3_0, vcard);
assertPropertyCount(1, vcard);
// read a type that has a type class
assertEquals("JOHN DOE", vcard.getProperty(MyFormattedNameProperty.class).value);
assertParseWarnings(parser);
assertNoMoreVCards(parser);
}
use of ezvcard.io.MyFormattedNameProperty.MyFormattedNameScribe 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);
}
Aggregations