Search in sources :

Example 16 with VObjectParameters

use of com.github.mangstadt.vinnie.VObjectParameters in project vinnie by mangstadt.

the class VObjectWriterTest method group.

@Test
public void group() throws Exception {
    for (SyntaxStyle style : SyntaxStyle.values()) {
        StringWriter sw = new StringWriter();
        VObjectWriter writer = new VObjectWriter(sw, style);
        writer.writeProperty("group", "PROP", new VObjectParameters(), "value");
        writer.writeProperty("", "PROP", new VObjectParameters(), "value");
        writer.writeProperty(null, "PROP", new VObjectParameters(), "value");
        String actual = sw.toString();
        // @formatter:off
        String expected = "group.PROP:value\r\n" + "PROP:value\r\n" + "PROP:value\r\n";
        // @formatter:on
        assertEquals(expected, actual);
    }
}
Also used : StringWriter(java.io.StringWriter) SyntaxStyle(com.github.mangstadt.vinnie.SyntaxStyle) VObjectParameters(com.github.mangstadt.vinnie.VObjectParameters) Test(org.junit.Test)

Example 17 with VObjectParameters

use of com.github.mangstadt.vinnie.VObjectParameters in project vinnie by mangstadt.

the class VObjectWriter method copyParameters.

/**
 * Copies the given list of parameters if it hasn't been copied before.
 * @param parameters the parameters
 * @return the copy or the same object if the parameters were copied before
 */
private VObjectParameters copyParameters(VObjectParameters parameters) {
    if (parametersCopied) {
        return parameters;
    }
    VObjectParameters copy = new VObjectParameters(parameters);
    parametersCopied = true;
    return copy;
}
Also used : VObjectParameters(com.github.mangstadt.vinnie.VObjectParameters)

Example 18 with VObjectParameters

use of com.github.mangstadt.vinnie.VObjectParameters 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

VObjectParameters (com.github.mangstadt.vinnie.VObjectParameters)18 StringWriter (java.io.StringWriter)16 SyntaxStyle (com.github.mangstadt.vinnie.SyntaxStyle)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)2 VCard (ezvcard.VCard)1 VCardVersion (ezvcard.VCardVersion)1 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)1 SkipMeException (ezvcard.io.SkipMeException)1 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)1 VCardParameters (ezvcard.parameter.VCardParameters)1 VCardProperty (ezvcard.property.VCardProperty)1 IOException (java.io.IOException)1