Search in sources :

Example 11 with UtcOffset

use of ezvcard.util.UtcOffset in project ez-vcard by mangstadt.

the class TimezoneTest method toTimeZone_offset.

@Test
public void toTimeZone_offset() {
    Timezone t = new Timezone(new UtcOffset(false, -5, 30));
    TimeZone actual = t.toTimeZone();
    assertEquals(-(5 * 1000 * 60 * 60 + 30 * 1000 * 60), actual.getRawOffset());
}
Also used : UtcOffset(ezvcard.util.UtcOffset) TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) Test(org.junit.Test)

Example 12 with UtcOffset

use of ezvcard.util.UtcOffset in project ez-vcard by mangstadt.

the class TimezoneTest method validate.

@Test
public void validate() {
    Timezone empty = new Timezone((UtcOffset) null);
    assertValidate(empty).versions(VCardVersion.V2_1).run(8, 20);
    assertValidate(empty).versions(VCardVersion.V3_0).run(8);
    assertValidate(empty).versions(VCardVersion.V4_0).run(8);
    Timezone withOffset = new Timezone(new UtcOffset(false, -5, 30));
    assertValidate(withOffset).run();
    Timezone withText = new Timezone("America/New_York");
    assertValidate(withText).versions(VCardVersion.V2_1).run(20);
    assertValidate(withText).versions(VCardVersion.V3_0).run();
    assertValidate(withText).versions(VCardVersion.V4_0).run();
}
Also used : UtcOffset(ezvcard.util.UtcOffset) Test(org.junit.Test)

Example 13 with UtcOffset

use of ezvcard.util.UtcOffset in project ez-vcard by mangstadt.

the class JCardReaderTest method jcard_example.

@Test
public void jcard_example() throws Throwable {
    JCardReader reader = new JCardReader(getClass().getResourceAsStream("jcard-example.json"));
    VCardAsserter asserter = new VCardAsserter(reader);
    asserter.next(V4_0);
    // @formatter:off
    asserter.simpleProperty(FormattedName.class).value("Simon Perreault").noMore();
    asserter.structuredName().family("Perreault").given("Simon").suffixes("ing. jr", "M.Sc.").noMore();
    asserter.dateProperty(Birthday.class).partialDate(PartialDate.builder().month(2).date(3).build()).noMore();
    asserter.dateProperty(Anniversary.class).date("2009-08-08 19:30:00 +0000").noMore();
    asserter.property(Gender.class).expected(Gender.male()).noMore();
    asserter.simpleProperty(Language.class).value("fr").param("PREF", "1").next().value("en").param("PREF", "2").noMore();
    asserter.listProperty(Organization.class).values("Viagenie").param("TYPE", "work").noMore();
    asserter.address().extendedAddress("Suite D2-630").streetAddress("2875 Laurier").locality("Quebec").region("QC").postalCode("G1V 2M2").country("Canada").types(AddressType.WORK).noMore();
    asserter.telephone().uri(new TelUri.Builder("+1-418-656-9254").extension("102").build()).types(TelephoneType.WORK, TelephoneType.VOICE).param("PREF", "1").next().uri(new TelUri.Builder("+1-418-262-6501").build()).types(TelephoneType.WORK, TelephoneType.CELL, TelephoneType.VOICE, TelephoneType.VIDEO, TelephoneType.TEXT).noMore();
    asserter.email().value("simon.perreault@viagenie.ca").types(EmailType.WORK).noMore();
    asserter.geo().latitude(46.772673).longitude(-71.282945).param("TYPE", "work").noMore();
    asserter.binaryProperty(Key.class).url("http://www.viagenie.ca/simon.perreault/simon.asc").param("TYPE", "work").noMore();
    asserter.timezone().offset(new UtcOffset(false, -5, 0)).noMore();
    asserter.simpleProperty(Url.class).value("http://nomis80.org").param("TYPE", "home").noMore();
    // @formatter:on
    asserter.validate().run();
    asserter.done();
}
Also used : UtcOffset(ezvcard.util.UtcOffset) Organization(ezvcard.property.Organization) TelUri(ezvcard.util.TelUri) VCardAsserter(ezvcard.property.asserter.VCardAsserter) Key(ezvcard.property.Key) Url(ezvcard.property.Url) Test(org.junit.Test)

Example 14 with UtcOffset

use of ezvcard.util.UtcOffset 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 15 with UtcOffset

use of ezvcard.util.UtcOffset in project ez-vcard by mangstadt.

the class HCardPageTest method createFullVCard.

private VCard createFullVCard() throws IOException {
    VCard vcard = new VCard();
    StructuredName n = new StructuredName();
    n.setFamily("Claus");
    n.setGiven("Santa");
    n.getAdditionalNames().add("Saint Nicholas");
    n.getAdditionalNames().add("Father Christmas");
    n.getPrefixes().add("Mr");
    n.getPrefixes().add("Dr");
    n.getSuffixes().add("M.D.");
    n.setSortAs("Claus");
    vcard.setStructuredName(n);
    vcard.setClassification("public");
    vcard.setMailer("Thunderbird");
    vcard.setFormattedName("Santa Claus");
    vcard.setNickname("Kris Kringle");
    vcard.addTitle("Manager");
    vcard.addRole("Executive");
    vcard.addRole("Team Builder");
    vcard.addEmail("johndoe@hotmail.com", EmailType.HOME, EmailType.WORK);
    vcard.addEmail("doe.john@company.com", EmailType.WORK);
    Telephone tel = new Telephone(new TelUri.Builder("+1-555-222-3333").extension("101").build());
    vcard.addTelephoneNumber(tel);
    tel = new Telephone(new TelUri.Builder("+1-555-333-4444").build());
    tel.getTypes().add(TelephoneType.WORK);
    vcard.addTelephoneNumber(tel);
    vcard.addTelephoneNumber("(555) 111-2222", TelephoneType.HOME, TelephoneType.VOICE, TelephoneType.PREF);
    Address adr = new Address();
    adr.setStreetAddress("123 Main St");
    adr.setExtendedAddress("Apt 11");
    adr.setLocality("Austin");
    adr.setRegion("Tx");
    adr.setPostalCode("12345");
    adr.setCountry("USA");
    adr.setLabel("123 Main St." + NEWLINE + "Austin TX, 12345" + NEWLINE + "USA");
    adr.getTypes().add(AddressType.HOME);
    vcard.addAddress(adr);
    adr = new Address();
    adr.setPoBox("123");
    adr.setStreetAddress("456 Wall St.");
    adr.setLocality("New York");
    adr.setRegion("NY");
    adr.setPostalCode("11111");
    adr.setCountry("USA");
    adr.getTypes().add(AddressType.PREF);
    adr.getTypes().add(AddressType.WORK);
    vcard.addAddress(adr);
    vcard.setOrganization("Google", "GMail");
    Birthday bday = new Birthday(date("1970-03-08"), false);
    vcard.setBirthday(bday);
    vcard.addUrl("http://company.com");
    vcard.setCategories("business owner", "jolly");
    vcard.addImpp(Impp.aim("myhandle"));
    vcard.addImpp(Impp.yahoo("myhandle@yahoo.com"));
    vcard.addNote("I am proficient in Tiger-Crane Style," + NEWLINE + "and I am more than proficient in the exquisite art of the Samurai sword.");
    vcard.setGeo(123.456, -98.123);
    vcard.setTimezone(new Timezone(new UtcOffset(false, -6, 0), "America/Chicago"));
    InputStream in = getClass().getResourceAsStream("hcard-portrait.jpg");
    Photo photo = new Photo(in, ImageType.JPEG);
    vcard.addPhoto(photo);
    in = getClass().getResourceAsStream("hcard-sound.ogg");
    Sound sound = new Sound(in, SoundType.OGG);
    vcard.addSound(sound);
    vcard.setUid(new Uid("urn:uuid:ffce1595-cbe9-4418-9d0d-b015655d45f6"));
    vcard.setRevision(date("2000-03-10 13:22:44"));
    return vcard;
}
Also used : Timezone(ezvcard.property.Timezone) Telephone(ezvcard.property.Telephone) Address(ezvcard.property.Address) InputStream(java.io.InputStream) TelUri(ezvcard.util.TelUri) Birthday(ezvcard.property.Birthday) Photo(ezvcard.property.Photo) Sound(ezvcard.property.Sound) UtcOffset(ezvcard.util.UtcOffset) Uid(ezvcard.property.Uid) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName)

Aggregations

UtcOffset (ezvcard.util.UtcOffset)20 Test (org.junit.Test)13 Key (ezvcard.property.Key)8 VCard (ezvcard.VCard)7 TelUri (ezvcard.util.TelUri)7 Address (ezvcard.property.Address)6 StructuredName (ezvcard.property.StructuredName)6 Timezone (ezvcard.property.Timezone)6 Birthday (ezvcard.property.Birthday)5 Telephone (ezvcard.property.Telephone)5 VCardAsserter (ezvcard.property.asserter.VCardAsserter)5 Anniversary (ezvcard.property.Anniversary)4 Geo (ezvcard.property.Geo)4 Organization (ezvcard.property.Organization)4 Url (ezvcard.property.Url)4 Photo (ezvcard.property.Photo)3 SimpleTimeZone (java.util.SimpleTimeZone)3 TimeZone (java.util.TimeZone)3 Sound (ezvcard.property.Sound)2 FreeBusyUrl (ezvcard.property.FreeBusyUrl)1