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());
}
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());
});
}
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());
}
}
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));
}
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;
}
Aggregations