use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class JCardRawWriterTest method group.
@Test
public void group() throws Throwable {
StringWriter sw = new StringWriter();
JCardRawWriter writer = new JCardRawWriter(sw, false);
writer.writeStartVCard();
writer.writeProperty("one", "prop", new VCardParameters(), VCardDataType.TEXT, JCardValue.single("value"));
writer.close();
String actual = sw.toString();
// @formatter:off
String expected = "[\"vcard\"," + "[" + "[\"prop\",{\"group\":\"one\"},\"text\",\"value\"]" + "]" + "]";
// @formatter:on
assertEquals(expected, actual);
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class VCardPropertyScribe method prepareParameters.
/**
* Sanitizes a property's parameters (called before the property is
* written). Note that a copy of the parameters is returned so that the
* property object does not get modified.
* @param property the property
* @param version the version of the vCard that is being generated
* @param vcard the vCard that the property belongs to
* @return the sanitized parameters
*/
public final VCardParameters prepareParameters(T property, VCardVersion version, VCard vcard) {
// make a copy because the property should not get modified when it is marshalled
VCardParameters copy = new VCardParameters(property.getParameters());
_prepareParameters(property, copy, version, vcard);
return copy;
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class VCardPropertyScribe method _parseHtml.
/**
* <p>
* Unmarshals the property from an hCard (HTML document).
* </p>
* <p>
* This method should be overridden by child classes that wish to support
* hCard. The default implementation of this method will retrieve the HTML
* element's hCard value (as described in {@link HCardElement#value}), and
* pass it into the {@link #_parseText} method.
* </p>
* @param element the property's HTML element
* @param context the parse context
* @return the unmarshalled property object
* @throws CannotParseException if the property value could not be parsed
* @throws SkipMeException if this property should NOT be added to the
* {@link VCard} object
* @throws EmbeddedVCardException if the value of this property is an
* embedded vCard (i.e. the AGENT property)
*/
protected T _parseHtml(HCardElement element, ParseContext context) {
String value = VObjectPropertyValues.escape(element.value());
VCardParameters parameters = new VCardParameters();
T property = _parseText(value, null, parameters, context);
property.setParameters(parameters);
return property;
}
use of ezvcard.parameter.VCardParameters 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);
}
use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.
the class JCardWriter method _write.
/**
* Writes a vCard to the stream.
* @param vcard the vCard that is being written
* @param properties the properties to write
* @throws IOException if there's a problem writing to the output stream
* @throws IllegalArgumentException if a scribe hasn't been registered for a
* custom property class (see: {@link #registerScribe registerScribe})
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void _write(VCard vcard, List<VCardProperty> properties) throws IOException {
Object previousValue = getCurrentValue();
writer.writeStartVCard();
writer.writeProperty("version", VCardDataType.TEXT, JCardValue.single(targetVersion.getVersion()));
for (VCardProperty property : properties) {
VCardPropertyScribe scribe = index.getPropertyScribe(property);
// marshal the value
JCardValue value;
try {
value = scribe.writeJson(property);
} catch (SkipMeException e) {
// property has requested not to be written
continue;
} catch (EmbeddedVCardException e) {
// don't write because jCard does not support embedded vCards
continue;
}
String group = property.getGroup();
String name = scribe.getPropertyName().toLowerCase();
VCardParameters parameters = scribe.prepareParameters(property, targetVersion, vcard);
VCardDataType dataType = scribe.dataType(property, targetVersion);
writer.writeProperty(group, name, parameters, dataType, value);
}
writer.writeEndVCard();
setCurrentValue(previousValue);
}
Aggregations