use of ezvcard.property.Note in project ez-vcard by mangstadt.
the class XCardReaderTest method read_parameters.
@Test
public void read_parameters() throws Exception {
// @formatter:off
VCardAsserter asserter = readXml("<vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + "<vcard>" + // zero params
"<note>" + "<text>Note 1</text>" + "</note>" + // one param
"<note>" + "<parameters>" + "<altid><text>1</text></altid>" + "</parameters>" + "<text>Hello world!</text>" + "</note>" + // one param, but doesn't have a value element, so it should be ignored
"<note>" + "<parameters>" + "<altid>1</altid>" + "</parameters>" + "<text>Hallo Welt!</text>" + "</note>" + // two params
"<note>" + "<parameters>" + "<altid><text>1</text></altid>" + "<language><language-tag>fr</language-tag></language>" + "</parameters>" + "<text>Bonjour tout le monde!</text>" + "</note>" + // a param with multiple values
"<tel>" + "<parameters>" + "<type>" + "<text>work</text>" + "<text>voice</text>" + "</type>" + "</parameters>" + "<uri>tel:+1-555-555-1234</uri>" + "</tel>" + "</vcard>" + "</vcards>");
asserter.next(V4_0);
asserter.simpleProperty(Note.class).value("Note 1").next().value("Hello world!").param("ALTID", "1").next().value("Hallo Welt!").next().value("Bonjour tout le monde!").param("ALTID", "1").param("LANGUAGE", "fr").noMore();
asserter.telephone().uri(new TelUri.Builder("+1-555-555-1234").build()).types(TelephoneType.WORK, TelephoneType.VOICE).noMore();
asserter.done();
// @formatter:on
}
use of ezvcard.property.Note in project ez-vcard by mangstadt.
the class XCardWriterTest method write_prettyPrint.
@Test
public void write_prettyPrint() throws Exception {
StringWriter sw = new StringWriter();
XCardWriter writer = new XCardWriter(sw, 2);
writer.setAddProdId(false);
VCard vcard = new VCard();
FormattedName fn = vcard.setFormattedName("John Doe");
fn.setParameter("x-foo", "bar");
Note note = vcard.addNote("note");
note.setGroup("group");
writer.write(vcard);
writer.close();
String actual = sw.toString();
String nl = "(\r\n|\n|\r)";
// @formatter:off
String expectedRegex = "<\\?xml version=\"1.0\" encoding=\"(utf|UTF)-8\"\\?><vcards xmlns=\"" + V4_0.getXmlNamespace() + "\">" + nl + " <vcard>" + nl + " <fn>" + nl + " <parameters>" + nl + " <x-foo>" + nl + " <unknown>bar</unknown>" + nl + " </x-foo>" + nl + " </parameters>" + nl + " <text>John Doe</text>" + nl + " </fn>" + nl + " <group name=\"group\">" + nl + " <note>" + nl + " <text>note</text>" + nl + " </note>" + nl + " </group>" + nl + " </vcard>" + nl + "</vcards>" + nl;
// @formatter:on
assertTrue(actual.matches(expectedRegex));
}
use of ezvcard.property.Note in project ez-vcard by mangstadt.
the class VCard method addNote.
/**
* <p>
* Adds a note. Notes contain free-form, miscellaneous text.
* </p>
* <p>
* <b>Property name:</b> {@code NOTE}<br>
* <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
* </p>
* @param note the note to add
* @return the property object that was created
* @see <a href="http://tools.ietf.org/html/rfc6350#page-44">RFC 6350
* p.44</a>
* @see <a href="http://tools.ietf.org/html/rfc2426#page-21">RFC 2426
* p.21</a>
* @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.19</a>
*/
public Note addNote(String note) {
Note type = new Note(note);
addNote(type);
return type;
}
use of ezvcard.property.Note in project ez-vcard by mangstadt.
the class VCardTest method addProperty.
@Test
public void addProperty() {
VCard vcard = new VCard();
assertEquals(asList(), vcard.getProperties(Note.class));
Note property1 = new Note("value");
vcard.addProperty(property1);
assertEquals(asList(property1), vcard.getProperties(Note.class));
Note property2 = new Note("value2");
vcard.addProperty(property2);
assertEquals(asList(property1, property2), vcard.getProperties(Note.class));
}
use of ezvcard.property.Note in project ez-vcard by mangstadt.
the class VCardTest method getProperties.
@Test
public void getProperties() {
VCard vcard = new VCard();
assertCollectionContains(vcard.getProperties());
assertEquals(asList(), vcard.getProperties(Note.class));
assertEquals(asList(), vcard.getProperties(RawProperty.class));
Note property1 = new Note("value");
vcard.addProperty(property1);
assertCollectionContains(vcard.getProperties(), property1);
assertEquals(asList(property1), vcard.getProperties(Note.class));
assertEquals(asList(), vcard.getProperties(RawProperty.class));
RawProperty property2 = vcard.addExtendedProperty("X-GENDER", "male");
RawProperty property3 = vcard.addExtendedProperty("X-MANAGER", "Michael Scott");
assertCollectionContains(vcard.getProperties(), property1, property2, property3);
assertEquals(asList(property1), vcard.getProperties(Note.class));
assertEquals(asList(property2, property3), vcard.getProperties(RawProperty.class));
}
Aggregations