Search in sources :

Example 41 with VCard

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;
}
Also used : Timezone(ezvcard.property.Timezone) UtcOffset(ezvcard.util.UtcOffset) Address(ezvcard.property.Address) Photo(ezvcard.property.Photo) Sound(ezvcard.property.Sound) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) File(java.io.File)

Example 42 with 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());
}
Also used : Photo(ezvcard.property.Photo) Document(org.jsoup.nodes.Document) VCard(ezvcard.VCard) Logo(ezvcard.property.Logo) Test(org.junit.Test)

Example 43 with VCard

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);
}
Also used : LuckyNumScribe(ezvcard.io.LuckyNumProperty.LuckyNumScribe) LuckyNumProperty(ezvcard.io.LuckyNumProperty) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 44 with VCard

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);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 45 with VCard

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

Aggregations

VCard (ezvcard.VCard)189 Test (org.junit.Test)134 StringWriter (java.io.StringWriter)29 StructuredName (ezvcard.property.StructuredName)23 Person (com.google.api.services.people.v1.model.Person)22 Telephone (ezvcard.property.Telephone)21 Photo (ezvcard.property.Photo)17 Email (ezvcard.property.Email)16 List (java.util.List)16 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)15 Document (org.w3c.dom.Document)15 VCardVersion (ezvcard.VCardVersion)14 XCardDocumentStreamWriter (ezvcard.io.xml.XCardDocument.XCardDocumentStreamWriter)14 Address (ezvcard.property.Address)14 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)13 Collectors (java.util.stream.Collectors)12 Name (com.google.api.services.people.v1.model.Name)11 File (java.io.File)11 Truth.assertThat (com.google.common.truth.Truth.assertThat)10 Pair (com.google.gdata.util.common.base.Pair)10