use of ezvcard.VCard in project ez-vcard by mangstadt.
the class JohnDoeVCard method createVCard.
private static VCard createVCard() throws IOException {
VCard vcard = new VCard();
vcard.setKind(Kind.individual());
vcard.setGender(Gender.male());
vcard.addLanguage("en-US");
StructuredName n = new StructuredName();
n.setFamily("Doe");
n.setGiven("Jonathan");
n.getPrefixes().add("Mr");
vcard.setStructuredName(n);
vcard.setFormattedName("Jonathan Doe");
vcard.setNickname("John", "Jonny");
vcard.addTitle("Widget Engineer");
vcard.setOrganization("Acme Co. Ltd.", "Widget Department");
Address adr = new Address();
adr.setStreetAddress("123 Wall St.");
adr.setLocality("New York");
adr.setRegion("NY");
adr.setPostalCode("12345");
adr.setCountry("USA");
adr.setLabel("123 Wall St.\nNew York, NY 12345\nUSA");
adr.getTypes().add(AddressType.WORK);
vcard.addAddress(adr);
adr = new Address();
adr.setStreetAddress("123 Main St.");
adr.setLocality("Albany");
adr.setRegion("NY");
adr.setPostalCode("54321");
adr.setCountry("USA");
adr.setLabel("123 Main St.\nAlbany, NY 54321\nUSA");
adr.getTypes().add(AddressType.HOME);
vcard.addAddress(adr);
vcard.addTelephoneNumber("1-555-555-1234", TelephoneType.WORK);
vcard.addTelephoneNumber("1-555-555-5678", TelephoneType.WORK, TelephoneType.CELL);
vcard.addEmail("johndoe@hotmail.com", EmailType.HOME);
vcard.addEmail("doe.john@acme.com", EmailType.WORK);
vcard.addUrl("http://www.acme-co.com");
vcard.setCategories("widgetphile", "biker", "vCard expert");
vcard.setGeo(37.6, -95.67);
vcard.setTimezone(new Timezone(new UtcOffset(false, -5, 0), "America/New_York"));
File file = new File("portrait.jpg");
Photo photo = new Photo(file, ImageType.JPEG);
vcard.addPhoto(photo);
file = new File("pronunciation.ogg");
Sound sound = new Sound(file, SoundType.OGG);
vcard.addSound(sound);
vcard.setUid(Uid.random());
vcard.setRevision(Revision.now());
return vcard;
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class HCardPageTest method logic_for_displaying_a_photo.
@Test
public void logic_for_displaying_a_photo() throws Exception {
VCard vcard = new VCard();
Document document = generate(vcard);
assertTrue(document.select(".vcard .photo").isEmpty());
assertTrue(document.select(".vcard .logo").isEmpty());
vcard = new VCard();
Photo photo = new Photo(mockData, ImageType.JPEG);
vcard.addPhoto(photo);
document = generate(vcard);
assertEquals(1, document.select(".vcard .photo").size());
assertTrue(document.select(".vcard .logo").isEmpty());
vcard = new VCard();
Logo logo = new Logo(mockData, ImageType.PNG);
vcard.addLogo(logo);
document = generate(vcard);
assertTrue(document.select(".vcard .photo").isEmpty());
assertEquals(1, document.select(".vcard .logo").size());
vcard = new VCard();
photo = new Photo(mockData, ImageType.JPEG);
vcard.addPhoto(photo);
logo = new Logo(mockData, ImageType.PNG);
vcard.addLogo(logo);
document = generate(vcard);
assertEquals(1, document.select(".vcard .photo").size());
assertTrue(document.select(".vcard .logo").isEmpty());
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class HCardParserTest method registerExtendedProperty.
@Test
public void registerExtendedProperty() throws Exception {
// @formatter:off
String html = "<html>" + "<body>" + "<div class=\"vcard\">" + "<span class=\"x-lucky-num\">24</span>" + "<span class=\"x-lucky-num\">22</span>" + "<span class=\"x-gender\">male</span>" + "</div>" + "</body>" + "</html>";
// @formatter:on
HCardParser parser = new HCardParser(html);
parser.registerScribe(new LuckyNumScribe());
VCard vcard = parser.readNext();
assertVersion(V3_0, vcard);
assertPropertyCount(3, vcard);
// read a type that has a type class
List<LuckyNumProperty> luckyNumTypes = vcard.getProperties(LuckyNumProperty.class);
assertEquals(2, luckyNumTypes.size());
assertEquals(24, luckyNumTypes.get(0).luckyNum);
assertEquals(22, luckyNumTypes.get(1).luckyNum);
// read a type without a type class
assertEquals("male", vcard.getExtendedProperty("X-GENDER").getValue());
assertParseWarnings(parser);
assertNoMoreVCards(parser);
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class JCardDeserializerTest method deserialize_multiple.
@Test
public void deserialize_multiple() throws Exception {
// @formatter:off
String json = "[" + "[\"vcard\"," + "[" + "[\"version\", {}, \"text\", \"4.0\"]," + "[\"fn\", {}, \"text\", \"John Doe\"]" + "]" + "]," + "[\"vcard\"," + "[" + "[\"version\", {}, \"text\", \"4.0\"]," + "[\"fn\", {}, \"text\", \"Jane Doe\"]" + "]" + "]" + "]";
// @formatter:on
JCardModule module = new JCardModule();
mapper.registerModule(module);
List<VCard> expected = new ArrayList<VCard>();
VCard vcard = new VCard();
vcard.setVersion(VCardVersion.V4_0);
vcard.setFormattedName("John Doe");
expected.add(vcard);
vcard = new VCard();
vcard.setVersion(VCardVersion.V4_0);
vcard.setFormattedName("Jane Doe");
expected.add(vcard);
List<VCard> actual = mapper.readValue(json, new TypeReference<List<VCard>>() {
});
assertEquals(expected, actual);
}
use of ezvcard.VCard in project ez-vcard by mangstadt.
the class JCardReader method _readNext.
@Override
protected VCard _readNext() throws IOException {
if (reader.eof()) {
return null;
}
context.setVersion(VCardVersion.V4_0);
JCardDataStreamListenerImpl listener = new JCardDataStreamListenerImpl();
reader.readNext(listener);
VCard vcard = listener.vcard;
if (vcard != null && !listener.versionFound) {
// @formatter:off
warnings.add(new ParseWarning.Builder().lineNumber(reader.getLineNum()).message(29).build());
// @formatter:on
}
return vcard;
}
Aggregations