use of ezvcard.property.Agent in project ez-vcard by mangstadt.
the class AgentScribe method _parseText.
@Override
protected Agent _parseText(String value, VCardDataType dataType, VCardParameters parameters, ParseContext context) {
Agent property = new Agent();
if (dataType == null) {
throw new EmbeddedVCardException(new Injector(property));
}
property.setUrl(VObjectPropertyValues.unescape(value));
return property;
}
use of ezvcard.property.Agent in project ez-vcard by mangstadt.
the class VCardWriterTest method nestedVCard.
@Test
public void nestedVCard() throws Throwable {
VCard vcard = new VCard();
vcard.setFormattedName("Michael Angstadt");
VCard agentVcard = new VCard();
agentVcard.setFormattedName("Agent 007");
agentVcard.addNote("Make sure that it properly folds long lines which are part of a nested AGENT type in a version 2.1 vCard.");
Agent agent = new Agent(agentVcard);
vcard.setAgent(agent);
// i herd u liek AGENTs...
VCard secondAgentVCard = new VCard();
secondAgentVCard.setFormattedName("Agent 009");
secondAgentVCard.addNote("Make sure that it ALSO properly folds THIS long line because it's part of an AGENT that's inside of an AGENT.");
Agent secondAgent = new Agent(secondAgentVCard);
agentVcard.setAgent(secondAgent);
StringWriter sw = new StringWriter();
VCardWriter vcw = new VCardWriter(sw, VCardVersion.V2_1);
vcw.setAddProdId(false);
vcw.write(vcard);
String actual = sw.toString();
// @formatter:off
String expected = "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "FN:Michael Angstadt\r\n" + // nested types should not have X-GENERATOR
"AGENT:\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "FN:Agent 007\r\n" + "NOTE:Make sure that it properly folds long lines which are part of a nested \r\n" + " AGENT type in a version 2.1 vCard.\r\n" + "AGENT:\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "FN:Agent 009\r\n" + "NOTE:Make sure that it ALSO properly folds THIS long line because it's part \r\n" + " of an AGENT that's inside of an AGENT.\r\n" + "END:VCARD\r\n" + "END:VCARD\r\n" + "END:VCARD\r\n";
// @formatter:on
assertEquals(expected, actual);
}
use of ezvcard.property.Agent in project ez-vcard by mangstadt.
the class VCardWriterTest method setVersionStrict_nested.
@Test
public void setVersionStrict_nested() throws Throwable {
VCard vcard = new VCard();
VCard agentVCard = new VCard();
// only supported by 4.0
agentVCard.setGender(Gender.male());
Agent agent = new Agent(agentVCard);
vcard.setAgent(agent);
StringWriter sw = new StringWriter();
VCardWriter vcw = new VCardWriter(sw, VCardVersion.V2_1);
vcw.setAddProdId(false);
vcw.setVersionStrict(false);
vcw.write(vcard);
String actual = sw.toString();
// @formatter:off
String expected = "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "AGENT:\r\n" + "BEGIN:VCARD\r\n" + "VERSION:2.1\r\n" + "GENDER:M\r\n" + "END:VCARD\r\n" + "END:VCARD\r\n";
// @formatter:on
assertEquals(actual, expected);
}
use of ezvcard.property.Agent in project ez-vcard by mangstadt.
the class AgentScribe method _parseHtml.
@Override
protected Agent _parseHtml(HCardElement element, ParseContext context) {
Agent property = new Agent();
Set<String> classes = element.classNames();
if (classes.contains("vcard")) {
throw new EmbeddedVCardException(new Injector(property));
}
String url = element.absUrl("href");
if (url.length() == 0) {
url = element.value();
}
property.setUrl(url);
return property;
}
use of ezvcard.property.Agent in project ez-vcard by mangstadt.
the class VCardWriterTest method embeddedVCard.
@Test
public void embeddedVCard() throws Throwable {
VCard vcard = new VCard();
vcard.setFormattedName("Michael Angstadt");
VCard agentVcard = new VCard();
agentVcard.setFormattedName("Agent 007");
Note note = agentVcard.addNote("Bonne soir�e, 007.");
note.setLanguage("fr");
Agent agent = new Agent(agentVcard);
vcard.setAgent(agent);
// i herd u liek AGENTs...
VCard secondAgentVCard = new VCard();
secondAgentVCard.setFormattedName("Agent 009");
note = secondAgentVCard.addNote("Good evening, 009.");
note.setLanguage("en");
Agent secondAgent = new Agent(secondAgentVCard);
agentVcard.setAgent(secondAgent);
StringWriter sw = new StringWriter();
VCardWriter vcw = new VCardWriter(sw, VCardVersion.V3_0);
vcw.getVObjectWriter().getFoldedLineWriter().setLineLength(null);
vcw.setAddProdId(false);
vcw.write(vcard);
String actual = sw.toString();
// @formatter:off
String expected = "BEGIN:VCARD\r\n" + "VERSION:3.0\r\n" + "FN:Michael Angstadt\r\n" + // nested types should not have PRODID
"AGENT:" + "BEGIN:VCARD\\n" + "VERSION:3.0\\n" + "FN:Agent 007\\n" + "NOTE\\;LANGUAGE=fr:Bonne soir�e\\\\\\, 007.\\n" + "AGENT:" + "BEGIN:VCARD\\\\n" + "VERSION:3.0\\\\n" + "FN:Agent 009\\\\n" + "NOTE\\\\\\;LANGUAGE=en:Good evening\\\\\\\\\\\\\\, 009.\\\\n" + "END:VCARD\\\\n\\n" + "END:VCARD\\n\r\n" + "END:VCARD\r\n";
// @formatter:on
assertEquals(expected, actual);
}
Aggregations