Search in sources :

Example 36 with VCardVersion

use of ezvcard.VCardVersion in project ez-vcard by mangstadt.

the class VCardWriter method _write.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void _write(VCard vcard, List<VCardProperty> propertiesToAdd) throws IOException {
    VCardVersion targetVersion = getTargetVersion();
    TargetApplication targetApplication = getTargetApplication();
    Boolean includeTrailingSemicolons = this.includeTrailingSemicolons;
    if (includeTrailingSemicolons == null) {
        includeTrailingSemicolons = (targetVersion == VCardVersion.V4_0);
    }
    WriteContext context = new WriteContext(targetVersion, targetApplication, includeTrailingSemicolons);
    writer.writeBeginComponent("VCARD");
    writer.writeVersion(targetVersion.getVersion());
    for (VCardProperty property : propertiesToAdd) {
        VCardPropertyScribe scribe = index.getPropertyScribe(property);
        String value = null;
        VCard nestedVCard = null;
        try {
            value = scribe.writeText(property, context);
        } catch (SkipMeException e) {
            continue;
        } catch (EmbeddedVCardException e) {
            nestedVCard = e.getVCard();
        }
        VCardParameters parameters = scribe.prepareParameters(property, targetVersion, vcard);
        if (nestedVCard != null) {
            writeNestedVCard(nestedVCard, property, scribe, parameters, value);
            continue;
        }
        handleValueParameter(property, scribe, parameters);
        handleLabelParameter(property, parameters);
        writer.writeProperty(property.getGroup(), scribe.getPropertyName(), new VObjectParameters(parameters.getMap()), value);
        fixBinaryPropertyForOutlook(property);
    }
    writer.writeEndComponent("VCARD");
}
Also used : VCardPropertyScribe(ezvcard.io.scribe.VCardPropertyScribe) VCardParameters(ezvcard.parameter.VCardParameters) EmbeddedVCardException(ezvcard.io.EmbeddedVCardException) VObjectParameters(com.github.mangstadt.vinnie.VObjectParameters) VCardProperty(ezvcard.property.VCardProperty) VCardVersion(ezvcard.VCardVersion) SkipMeException(ezvcard.io.SkipMeException) VCard(ezvcard.VCard)

Aggregations

VCardVersion (ezvcard.VCardVersion)36 Test (org.junit.Test)30 VCard (ezvcard.VCard)14 VCardAsserter (ezvcard.property.asserter.VCardAsserter)10 VCardParameters (ezvcard.parameter.VCardParameters)5 Label (ezvcard.property.Label)4 RawProperty (ezvcard.property.RawProperty)4 VCardProperty (ezvcard.property.VCardProperty)4 Address (ezvcard.property.Address)3 ProductId (ezvcard.property.ProductId)3 VCardDataType (ezvcard.VCardDataType)2 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)2 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)2 ArrayList (java.util.ArrayList)2 SyntaxStyle (com.github.mangstadt.vinnie.SyntaxStyle)1 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)1 AllowedCharacters (com.github.mangstadt.vinnie.validate.AllowedCharacters)1 ValidationWarning (ezvcard.ValidationWarning)1 LuckyNumProperty (ezvcard.io.LuckyNumProperty)1 LuckyNumScribe (ezvcard.io.LuckyNumProperty.LuckyNumScribe)1