Search in sources :

Example 6 with EmbeddedVCardException

use of ezvcard.io.EmbeddedVCardException in project ez-vcard by mangstadt.

the class AgentScribe method _writeText.

@Override
protected String _writeText(Agent property, WriteContext context) {
    String url = property.getUrl();
    if (url != null) {
        return url;
    }
    VCard vcard = property.getVCard();
    if (vcard != null) {
        throw new EmbeddedVCardException(vcard);
    }
    // don't write an empty value because parsers could interpret that as there being an embedded vCard on the next line
    throw new SkipMeException(Messages.INSTANCE.getValidationWarning(8));
}
Also used : EmbeddedVCardException(ezvcard.io.EmbeddedVCardException) SkipMeException(ezvcard.io.SkipMeException) VCard(ezvcard.VCard)

Example 7 with EmbeddedVCardException

use of ezvcard.io.EmbeddedVCardException 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 8 with EmbeddedVCardException

use of ezvcard.io.EmbeddedVCardException 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

EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)8 SkipMeException (ezvcard.io.SkipMeException)5 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)4 VCard (ezvcard.VCard)3 VCardParameters (ezvcard.parameter.VCardParameters)3 VCardProperty (ezvcard.property.VCardProperty)3 VCardVersion (ezvcard.VCardVersion)2 Agent (ezvcard.property.Agent)2 VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)1 VCardDataType (ezvcard.VCardDataType)1 CannotParseException (ezvcard.io.CannotParseException)1 RawPropertyScribe (ezvcard.io.scribe.RawPropertyScribe)1 WriteContext (ezvcard.io.text.WriteContext)1 Categories (ezvcard.property.Categories)1 Impp (ezvcard.property.Impp)1 Label (ezvcard.property.Label)1 Nickname (ezvcard.property.Nickname)1 RawProperty (ezvcard.property.RawProperty)1 Xml (ezvcard.property.Xml)1 QName (javax.xml.namespace.QName)1