Search in sources :

Example 6 with Timezone

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

the class JCardWriterTest method createExample.

public static VCard createExample() {
    VCard vcard = new VCard();
    vcard.setFormattedName("SimonPerreault");
    StructuredName n = new StructuredName();
    n.setFamily("Perreault");
    n.setGiven("Simon");
    n.getSuffixes().add("ing.jr");
    n.getSuffixes().add("M.Sc.");
    vcard.setStructuredName(n);
    Birthday bday = new Birthday(PartialDate.builder().month(2).date(3).build());
    vcard.setBirthday(bday);
    Anniversary anniversary = new Anniversary(PartialDate.builder().year(2009).month(8).date(8).hour(14).minute(30).second(0).offset(new UtcOffset(false, -5, 0)).build());
    vcard.setAnniversary(anniversary);
    vcard.setGender(Gender.male());
    vcard.addLanguage("fr").setPref(1);
    vcard.addLanguage("en").setPref(2);
    vcard.setOrganization("Viagenie").setType("work");
    Address adr = new Address();
    adr.setExtendedAddress("SuiteD2-630");
    adr.setStreetAddress("2875Laurier");
    adr.setLocality("Quebec");
    adr.setRegion("QC");
    adr.setPostalCode("G1V2M2");
    adr.setCountry("Canada");
    adr.getTypes().add(AddressType.WORK);
    vcard.addAddress(adr);
    TelUri telUri = new TelUri.Builder("+1-418-656-9254").extension("102").build();
    Telephone tel = new Telephone(telUri);
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.VOICE);
    tel.setPref(1);
    vcard.addTelephoneNumber(tel);
    tel = new Telephone(new TelUri.Builder("+1-418-262-6501").build());
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.CELL);
    tel.getTypes().add(TelephoneType.VOICE);
    tel.getTypes().add(TelephoneType.VIDEO);
    tel.getTypes().add(TelephoneType.TEXT);
    vcard.addTelephoneNumber(tel);
    vcard.addEmail("simon.perreault@viagenie.ca", EmailType.WORK);
    Geo geo = new Geo(46.772673, -71.282945);
    geo.setType("work");
    vcard.setGeo(geo);
    Key key = new Key("http://www.viagenie.ca/simon.perreault/simon.asc", null);
    key.setType("work");
    vcard.addKey(key);
    vcard.setTimezone(new Timezone(new UtcOffset(false, -5, 0)));
    vcard.addUrl("http://nomis80.org").setType("home");
    return vcard;
}
Also used : Timezone(ezvcard.property.Timezone) Address(ezvcard.property.Address) Telephone(ezvcard.property.Telephone) Anniversary(ezvcard.property.Anniversary) TelUri(ezvcard.util.TelUri) Birthday(ezvcard.property.Birthday) Geo(ezvcard.property.Geo) UtcOffset(ezvcard.util.UtcOffset) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Key(ezvcard.property.Key)

Example 7 with Timezone

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

the class TimezoneScribe method _parseXml.

@Override
protected Timezone _parseXml(XCardElement element, VCardParameters parameters, ParseContext context) {
    String text = element.first(VCardDataType.TEXT);
    if (text != null) {
        return new Timezone(text);
    }
    String utcOffset = element.first(VCardDataType.UTC_OFFSET);
    if (utcOffset != null) {
        try {
            return new Timezone(UtcOffset.parse(utcOffset));
        } catch (IllegalArgumentException e) {
            throw new CannotParseException(19);
        }
    }
    throw missingXmlElements(VCardDataType.TEXT, VCardDataType.UTC_OFFSET);
}
Also used : Timezone(ezvcard.property.Timezone) CannotParseException(ezvcard.io.CannotParseException)

Aggregations

Timezone (ezvcard.property.Timezone)7 VCard (ezvcard.VCard)6 Address (ezvcard.property.Address)6 StructuredName (ezvcard.property.StructuredName)6 UtcOffset (ezvcard.util.UtcOffset)6 Birthday (ezvcard.property.Birthday)5 Telephone (ezvcard.property.Telephone)5 TelUri (ezvcard.util.TelUri)5 Anniversary (ezvcard.property.Anniversary)4 Geo (ezvcard.property.Geo)4 Key (ezvcard.property.Key)4 Test (org.junit.Test)3 Photo (ezvcard.property.Photo)2 Sound (ezvcard.property.Sound)2 CannotParseException (ezvcard.io.CannotParseException)1 Uid (ezvcard.property.Uid)1 File (java.io.File)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1