use of ezvcard.io.xml.XCardElement.XCardValue in project ez-vcard by mangstadt.
the class VCardPropertyScribe method _parseXml.
/**
* <p>
* Unmarshals a property from an XML document (xCard).
* </p>
* <p>
* This method should be overridden by child classes that wish to support
* xCard. The default implementation of this method will find the first
* child element with the xCard namespace. The element's name will be used
* as the property's data type and its text content (escaped for inclusion
* in a text-based vCard, e.g. escaping comma characters) will be passed
* into the {@link #_parseText} method. If no such child element is found,
* then the parent element's text content will be passed into
* {@link #_parseText} and the data type will be {@code null}.
* </p>
* @param element the property's XML element
* @param parameters the parsed parameters. These parameters will be
* assigned to the property object once this method returns. Therefore, do
* not assign any parameters to the property object itself whilst inside of
* this method, or else they will be overwritten.
* @param context the parse context
* @return the unmarshalled property object
* @throws CannotParseException if the marshaller could not parse the
* property's value
* @throws SkipMeException if the property should not be added to the final
* {@link VCard} object
*/
protected T _parseXml(XCardElement element, VCardParameters parameters, ParseContext context) {
XCardValue firstValue = element.firstValue();
VCardDataType dataType = firstValue.getDataType();
String value = VObjectPropertyValues.escape(firstValue.getValue());
return _parseText(value, dataType, parameters, context);
}
use of ezvcard.io.xml.XCardElement.XCardValue in project ez-vcard by mangstadt.
the class XCardElementTest method firstValue.
@Test
public void firstValue() {
XCardElement xcardElement = build("<prop><text>one</text></prop>");
XCardValue child = xcardElement.firstValue();
assertEquals(VCardDataType.TEXT, child.getDataType());
assertEquals("one", child.getValue());
}
use of ezvcard.io.xml.XCardElement.XCardValue in project ez-vcard by mangstadt.
the class XCardElementTest method firstValue_no_xcard_children.
@Test
public void firstValue_no_xcard_children() {
XCardElement xcardElement = build("<prop><n:foo xmlns:n=\"http://example.com\">one</n:foo><n:bar xmlns:n=\"http://example.com\">two</n:bar></prop>");
XCardValue child = xcardElement.firstValue();
assertNull(child.getDataType());
assertEquals("onetwo", child.getValue());
}
use of ezvcard.io.xml.XCardElement.XCardValue in project ez-vcard by mangstadt.
the class RawPropertyScribe method _parseXml.
@Override
protected RawProperty _parseXml(XCardElement element, VCardParameters parameters, ParseContext context) {
XCardValue firstValue = element.firstValue();
VCardDataType dataType = firstValue.getDataType();
String value = firstValue.getValue();
RawProperty property = new RawProperty(propertyName, value);
property.setDataType(dataType);
return property;
}
use of ezvcard.io.xml.XCardElement.XCardValue in project ez-vcard by mangstadt.
the class XCardElementTest method firstValue_unknown.
@Test
public void firstValue_unknown() {
XCardElement xcardElement = build("<prop><unknown>one</unknown></prop>");
XCardValue child = xcardElement.firstValue();
assertNull(child.getDataType());
assertEquals("one", child.getValue());
}
Aggregations