Search in sources :

Example 31 with VCardParameters

use of ezvcard.parameter.VCardParameters 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)

Example 32 with VCardParameters

use of ezvcard.parameter.VCardParameters in project ez-vcard by mangstadt.

the class XCardWriter method write.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void write(VCardProperty property, VCard vcard) throws SAXException {
    VCardPropertyScribe scribe = index.getPropertyScribe(property);
    VCardParameters parameters = scribe.prepareParameters(property, targetVersion, vcard);
    // get the property element to write
    Element propertyElement;
    if (property instanceof Xml) {
        Xml xml = (Xml) property;
        Document value = xml.getValue();
        if (value == null) {
            return;
        }
        propertyElement = value.getDocumentElement();
    } else {
        QName qname = scribe.getQName();
        propertyElement = DOC.createElementNS(qname.getNamespaceURI(), qname.getLocalPart());
        try {
            scribe.writeXml(property, propertyElement);
        } catch (SkipMeException e) {
            return;
        } catch (EmbeddedVCardException e) {
            return;
        }
    }
    start(propertyElement);
    write(parameters);
    write(propertyElement);
    end(propertyElement);
}
Also used : VCardPropertyScribe(ezvcard.io.scribe.VCardPropertyScribe) VCardParameters(ezvcard.parameter.VCardParameters) EmbeddedVCardException(ezvcard.io.EmbeddedVCardException) Xml(ezvcard.property.Xml) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) SkipMeException(ezvcard.io.SkipMeException) Document(org.w3c.dom.Document)

Aggregations

VCardParameters (ezvcard.parameter.VCardParameters)32 Test (org.junit.Test)24 JCardDataStreamListener (ezvcard.io.json.JCardRawReader.JCardDataStreamListener)12 VCard (ezvcard.VCard)5 VCardVersion (ezvcard.VCardVersion)5 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)4 VCardDataType (ezvcard.VCardDataType)3 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)3 SkipMeException (ezvcard.io.SkipMeException)3 VCardProperty (ezvcard.property.VCardProperty)3 StringWriter (java.io.StringWriter)3 Pid (ezvcard.parameter.Pid)2 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)1 ParseContext (ezvcard.io.ParseContext)1 JCardValue (ezvcard.io.json.JCardValue)1 Xml (ezvcard.property.Xml)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 QName (javax.xml.namespace.QName)1