use of ezvcard.VCardDataType in project ez-vcard by mangstadt.
the class VCardPropertyScribe method missingXmlElements.
/**
* Creates a {@link CannotParseException} to indicate that a scribe could
* not find the necessary XML elements required in order to successfully
* parse a property (xCards only).
* @param dataTypes the expected data types (null for "unknown")
* @return the exception object (note that the exception is NOT thrown!)
*/
protected static CannotParseException missingXmlElements(VCardDataType... dataTypes) {
String[] elements = new String[dataTypes.length];
for (int i = 0; i < dataTypes.length; i++) {
VCardDataType dataType = dataTypes[i];
elements[i] = (dataType == null) ? "unknown" : dataType.getName().toLowerCase();
}
return missingXmlElements(elements);
}
use of ezvcard.VCardDataType 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.VCardDataType in project ez-vcard by mangstadt.
the class VCardPropertyScribe method _writeXml.
/**
* <p>
* Marshals a property's value to an XML element (xCard).
* </p>
* <p>
* This method should be overridden by child classes that wish to support
* xCard. The default implementation of this method will append one child
* element to the property's XML element. The child element's name will be
* that of the property's data type (retrieved using the {@link #dataType}
* method), and the child element's text content will be set to the
* property's marshalled plain-text value (retrieved using the
* {@link #writeText} method).
* </p>
* @param property the property
* @param element the property's XML element
* @throws SkipMeException if the property should not be written to the data
* stream
*/
protected void _writeXml(T property, XCardElement element) {
String value = writeText(property, new WriteContext(VCardVersion.V4_0, null, false));
VCardDataType dataType = dataType(property, VCardVersion.V4_0);
element.append(dataType, value);
}
use of ezvcard.VCardDataType in project ez-vcard by mangstadt.
the class DateOrTimePropertyScribe method _writeXml.
@Override
protected void _writeXml(T property, XCardElement parent) {
Date date = property.getDate();
if (date != null) {
boolean hasTime = property.hasTime();
String value = date(date).time(hasTime).extended(false).utc(false).write();
VCardDataType dataType = hasTime ? VCardDataType.DATE_TIME : VCardDataType.DATE;
parent.append(dataType, value);
return;
}
PartialDate partialDate = property.getPartialDate();
if (partialDate != null) {
VCardDataType dataType;
if (partialDate.hasTimeComponent() && partialDate.hasDateComponent()) {
dataType = VCardDataType.DATE_TIME;
} else if (partialDate.hasTimeComponent()) {
dataType = VCardDataType.TIME;
} else if (partialDate.hasDateComponent()) {
dataType = VCardDataType.DATE;
} else {
dataType = VCardDataType.DATE_AND_OR_TIME;
}
parent.append(dataType, partialDate.toISO8601(false));
return;
}
String text = property.getText();
if (text != null) {
parent.append(VCardDataType.TEXT, text);
return;
}
parent.append(VCardDataType.DATE_AND_OR_TIME, "");
}
use of ezvcard.VCardDataType in project ez-vcard by mangstadt.
the class JCardRawReader method parseProperty.
private void parseProperty() throws IOException {
// get property name
checkCurrent(JsonToken.VALUE_STRING);
String propertyName = parser.getValueAsString().toLowerCase();
// get parameters
VCardParameters parameters = parseParameters();
// get group
List<String> removed = parameters.removeAll("group");
String group = removed.isEmpty() ? null : removed.get(0);
// get data type
checkNext(JsonToken.VALUE_STRING);
String dataTypeStr = parser.getText().toLowerCase();
VCardDataType dataType = "unknown".equals(dataTypeStr) ? null : VCardDataType.get(dataTypeStr);
// get property value(s)
List<JsonValue> values = parseValues();
JCardValue value = new JCardValue(values);
listener.readProperty(group, propertyName, parameters, dataType, value);
}
Aggregations