use of com.github.mangstadt.vinnie.VObjectParameters in project ez-vcard by mangstadt.
the class VCardWriter method writeNestedVCard.
@SuppressWarnings("rawtypes")
private void writeNestedVCard(VCard nestedVCard, VCardProperty property, VCardPropertyScribe scribe, VCardParameters parameters, String value) throws IOException {
if (targetVersion == VCardVersion.V2_1) {
// write a nested vCard (2.1 style)
writer.writeProperty(property.getGroup(), scribe.getPropertyName(), new VObjectParameters(parameters.getMap()), value);
prodIdStack.add(addProdId);
addProdId = false;
write(nestedVCard);
addProdId = prodIdStack.remove(prodIdStack.size() - 1);
} else {
// write an embedded vCard (3.0 style)
StringWriter sw = new StringWriter();
VCardWriter agentWriter = new VCardWriter(sw, targetVersion);
agentWriter.getVObjectWriter().getFoldedLineWriter().setLineLength(null);
agentWriter.setAddProdId(false);
agentWriter.setCaretEncodingEnabled(isCaretEncodingEnabled());
agentWriter.setIncludeTrailingSemicolons(this.includeTrailingSemicolons);
agentWriter.setScribeIndex(index);
agentWriter.setTargetApplication(targetApplication);
agentWriter.setVersionStrict(versionStrict);
try {
agentWriter.write(nestedVCard);
} catch (IOException e) {
// should never be thrown because we're writing to a string
} finally {
IOUtils.closeQuietly(agentWriter);
}
String vcardStr = sw.toString();
vcardStr = VObjectPropertyValues.escape(vcardStr);
writer.writeProperty(property.getGroup(), scribe.getPropertyName(), new VObjectParameters(parameters.getMap()), vcardStr);
}
}
use of com.github.mangstadt.vinnie.VObjectParameters in project vinnie by mangstadt.
the class VObjectWriterTest method property_name_starts_with_whitespace.
@Test
public void property_name_starts_with_whitespace() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
for (char c : " \t".toCharArray()) {
try {
writer.writeProperty(null, c + "", new VObjectParameters(), "");
fail("IllegalArgumentException expected when property name starts with character " + ch(c) + " and style is " + style.name());
} catch (IllegalArgumentException e) {
// expected
}
writer.writeProperty(null, "PROP" + c, new VObjectParameters(), "");
}
String actual = sw.toString();
// @formatter:off
String expected = "PROP :\r\n" + "PROP :\r\n";
// @formatter:on
assertEquals(expected, actual);
}
}
use of com.github.mangstadt.vinnie.VObjectParameters in project vinnie by mangstadt.
the class VObjectWriterTest method parameters_invalid_characters_in_name.
@Test
public void parameters_invalid_characters_in_name() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
for (boolean caretEncoding : new boolean[] { false, true }) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
writer.setCaretEncodingEnabled(caretEncoding);
for (char c : ";:=\n\r".toCharArray()) {
VObjectParameters parameters = new VObjectParameters();
parameters.put(c + "", "");
try {
writer.writeProperty(null, "PROP", parameters, "");
fail("IllegalArgumentException expected when parameter name contains character " + ch(c) + " and style is " + style.name());
} catch (IllegalArgumentException e) {
// expected
}
String actual = sw.toString();
// @formatter:off
String expected = "";
// @formatter:on
assertEquals(expected, actual);
}
}
}
}
use of com.github.mangstadt.vinnie.VObjectParameters in project vinnie by mangstadt.
the class VObjectWriterTest method property_name_invalid_characters.
@Test
public void property_name_invalid_characters() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
for (char c : ".;:\n\r".toCharArray()) {
try {
writer.writeProperty(null, c + "", new VObjectParameters(), "");
fail("IllegalArgumentException expected when property name contains character " + ch(c) + " and style is " + style.name());
} catch (IllegalArgumentException e) {
// expected
}
String actual = sw.toString();
// @formatter:off
String expected = "";
// @formatter:on
assertEquals(expected, actual);
}
}
}
use of com.github.mangstadt.vinnie.VObjectParameters in project vinnie by mangstadt.
the class VObjectWriterTest method group_invalid_characters.
@Test
public void group_invalid_characters() throws Exception {
for (SyntaxStyle style : SyntaxStyle.values()) {
StringWriter sw = new StringWriter();
VObjectWriter writer = new VObjectWriter(sw, style);
for (char c : ".;:\n\r".toCharArray()) {
try {
writer.writeProperty(c + "", "PROP", new VObjectParameters(), "");
fail("IllegalArgumentException expected when group name contains character " + ch(c) + " and style is " + style.name());
} catch (IllegalArgumentException e) {
// expected
}
}
String actual = sw.toString();
// @formatter:off
String expected = "";
// @formatter:on
assertEquals(expected, actual);
}
}
Aggregations