Search in sources :

Example 11 with FormattedName

use of ezvcard.property.FormattedName in project ez-vcard by mangstadt.

the class EzvcardTest method writeHtml_one.

@Test
public void writeHtml_one() throws Exception {
    VCard vcard = new VCard();
    vcard.setFormattedName(new FormattedName("John Doe"));
    String actual = Ezvcard.writeHtml(vcard).go();
    org.jsoup.nodes.Document document = Jsoup.parse(actual);
    assertEquals(1, document.select(".vcard").size());
    assertEquals(1, document.select(".vcard .fn").size());
}
Also used : FormattedName(ezvcard.property.FormattedName) Test(org.junit.Test)

Example 12 with FormattedName

use of ezvcard.property.FormattedName in project ring-client-android by savoirfairelinux.

the class TVAccountWizard method saveProfile.

@Override
public void saveProfile(final String accountID, final RingAccountViewModel ringAccountViewModel) {
    runOnUiThread(() -> {
        RingAccountViewModelImpl ringAccountViewModelImpl = (RingAccountViewModelImpl) ringAccountViewModel;
        VCard vcard = new VCard();
        vcard.setFormattedName(new FormattedName(ringAccountViewModelImpl.getFullName()));
        vcard.setUid(new Uid(ringAccountViewModelImpl.getUsername()));
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        if (ringAccountViewModelImpl.getPhoto() != null) {
            Bitmap reduced = BitmapUtils.reduceBitmap(ringAccountViewModelImpl.getPhoto(), VCardUtils.VCARD_PHOTO_SIZE);
            reduced.compress(Bitmap.CompressFormat.PNG, 100, stream);
            Photo photoVCard = new Photo(stream.toByteArray(), ImageType.PNG);
            vcard.removeProperties(Photo.class);
            vcard.addPhoto(photoVCard);
        }
        vcard.removeProperties(RawProperty.class);
        VCardUtils.saveLocalProfileToDisk(vcard, accountID, getFilesDir());
    });
}
Also used : Uid(ezvcard.property.Uid) Bitmap(android.graphics.Bitmap) FormattedName(ezvcard.property.FormattedName) Photo(ezvcard.property.Photo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RingAccountViewModelImpl(cx.ring.account.RingAccountViewModelImpl) VCard(ezvcard.VCard)

Example 13 with FormattedName

use of ezvcard.property.FormattedName in project ez-vcard by mangstadt.

the class StreamWriterTest method productId_order.

/**
 * Asserts that the PRODID property is always put at the front of the vCard.
 */
@Test
public void productId_order() throws IOException {
    vcard.setFormattedName("Name");
    {
        writer.write(vcard, V2_1);
        Iterator<VCardProperty> it = writer.propertiesList.iterator();
        VCardProperty property = it.next();
        assertTrue(property instanceof RawProperty);
        property = it.next();
        assertTrue(property instanceof FormattedName);
        assertFalse(it.hasNext());
    }
    for (VCardVersion version : each(V3_0, V4_0)) {
        writer.write(vcard, version);
        Iterator<VCardProperty> it = writer.propertiesList.iterator();
        VCardProperty property = it.next();
        assertTrue(property instanceof ProductId);
        property = it.next();
        assertTrue(property instanceof FormattedName);
        assertFalse(it.hasNext());
    }
    vcard.setProductId("value");
    writer.setAddProdId(false);
    for (VCardVersion version : each(V3_0, V4_0)) {
        writer.write(vcard, version);
        Iterator<VCardProperty> it = writer.propertiesList.iterator();
        VCardProperty property = it.next();
        assertTrue(property instanceof ProductId);
        property = it.next();
        assertTrue(property instanceof FormattedName);
        assertFalse(it.hasNext());
    }
}
Also used : RawProperty(ezvcard.property.RawProperty) FormattedName(ezvcard.property.FormattedName) Iterator(java.util.Iterator) VCardProperty(ezvcard.property.VCardProperty) VCardVersion(ezvcard.VCardVersion) ProductId(ezvcard.property.ProductId) Test(org.junit.Test)

Example 14 with FormattedName

use of ezvcard.property.FormattedName 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 15 with FormattedName

use of ezvcard.property.FormattedName in project ez-vcard by mangstadt.

the class VCard method setFormattedName.

/**
 * <p>
 * Sets the person's full name.
 * </p>
 * <p>
 * <b>Property name:</b> {@code FN}<br>
 * <b>Supported versions:</b> {@code 2.1, 3.0, 4.0}
 * </p>
 * @param formattedName the formatted name (e.g. "John Doe") or null to
 * remove
 * @return the property object that was created
 * @see <a href="http://tools.ietf.org/html/rfc6350#page-28">RFC 6350
 * p.28</a>
 * @see <a href="http://tools.ietf.org/html/rfc2426#page-8">RFC 2426 p.8</a>
 * @see <a href="http://www.imc.org/pdi/vcard-21.doc">vCard 2.1 p.9</a>
 */
public FormattedName setFormattedName(String formattedName) {
    FormattedName type = (formattedName == null) ? null : new FormattedName(formattedName);
    setFormattedName(type);
    return type;
}
Also used : FormattedName(ezvcard.property.FormattedName)

Aggregations

FormattedName (ezvcard.property.FormattedName)19 Test (org.junit.Test)11 VCard (ezvcard.VCard)6 RawProperty (ezvcard.property.RawProperty)3 StructuredName (ezvcard.property.StructuredName)3 Uid (ezvcard.property.Uid)3 Photo (ezvcard.property.Photo)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Bitmap (android.graphics.Bitmap)1 RingAccountViewModelImpl (cx.ring.account.RingAccountViewModelImpl)1 VCardVersion (ezvcard.VCardVersion)1 VCardReader (ezvcard.io.text.VCardReader)1 AddressType (ezvcard.parameter.AddressType)1 EmailType (ezvcard.parameter.EmailType)1 TelephoneType (ezvcard.parameter.TelephoneType)1 Address (ezvcard.property.Address)1 Email (ezvcard.property.Email)1 Note (ezvcard.property.Note)1 ProductId (ezvcard.property.ProductId)1 Telephone (ezvcard.property.Telephone)1