Search in sources :

Example 16 with Note

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
}
Also used : Note(ezvcard.property.Note) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Test(org.junit.Test)

Example 17 with Note

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));
}
Also used : StringWriter(java.io.StringWriter) FormattedName(ezvcard.property.FormattedName) Note(ezvcard.property.Note) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 18 with Note

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;
}
Also used : Note(ezvcard.property.Note)

Example 19 with Note

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));
}
Also used : Note(ezvcard.property.Note) Test(org.junit.Test)

Example 20 with Note

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));
}
Also used : RawProperty(ezvcard.property.RawProperty) Note(ezvcard.property.Note) Test(org.junit.Test)

Aggregations

Note (ezvcard.property.Note)21 Test (org.junit.Test)18 VCard (ezvcard.VCard)9 VCardAsserter (ezvcard.property.asserter.VCardAsserter)6 FormattedName (ezvcard.property.FormattedName)4 Photo (ezvcard.property.Photo)4 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)2 Pid (ezvcard.parameter.Pid)2 Title (ezvcard.property.Title)2 Url (ezvcard.property.Url)2 StringWriter (java.io.StringWriter)2 Document (org.w3c.dom.Document)2 Address (ezvcard.property.Address)1 Agent (ezvcard.property.Agent)1 Categories (ezvcard.property.Categories)1 Email (ezvcard.property.Email)1 FreeBusyUrl (ezvcard.property.FreeBusyUrl)1 Impp (ezvcard.property.Impp)1 Key (ezvcard.property.Key)1 Nickname (ezvcard.property.Nickname)1