Search in sources :

Example 1 with UtcOffset

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

the class TimezoneScribe method _writeJson.

@Override
protected JCardValue _writeJson(Timezone property) {
    String text = property.getText();
    if (text != null) {
        return JCardValue.single(text);
    }
    UtcOffset offset = property.getOffset();
    if (offset != null) {
        return JCardValue.single(offset.toString(true));
    }
    return JCardValue.single("");
}
Also used : UtcOffset(ezvcard.util.UtcOffset)

Example 2 with UtcOffset

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

the class TimezoneScribe method _writeXml.

@Override
protected void _writeXml(Timezone property, XCardElement parent) {
    String text = property.getText();
    if (text != null) {
        parent.append(VCardDataType.TEXT, text);
        return;
    }
    UtcOffset offset = property.getOffset();
    if (offset != null) {
        parent.append(VCardDataType.UTC_OFFSET, offset.toString(false));
        return;
    }
    parent.append(VCardDataType.TEXT, "");
}
Also used : UtcOffset(ezvcard.util.UtcOffset)

Example 3 with UtcOffset

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

the class TimezoneScribe method _writeText.

@Override
protected String _writeText(Timezone property, WriteContext context) {
    String text = property.getText();
    UtcOffset offset = property.getOffset();
    switch(context.getVersion()) {
        case V2_1:
            if (offset != null) {
                // 2.1 allows either basic or extended
                return offset.toString(false);
            }
            if (text != null) {
                // attempt to find the offset by treating the text as a timezone ID, like "America/New_York"
                TimeZone timezone = timezoneFromId(text);
                if (timezone != null) {
                    UtcOffset tzOffset = offsetFromTimezone(timezone);
                    return tzOffset.toString(false);
                }
            }
            break;
        case V3_0:
            if (offset != null) {
                // 3.0 only allows extended
                return offset.toString(true);
            }
            if (text != null) {
                return VObjectPropertyValues.escape(text);
            }
            break;
        case V4_0:
            if (text != null) {
                return VObjectPropertyValues.escape(text);
            }
            if (offset != null) {
                // 4.0 only allows basic
                return offset.toString(false);
            }
            break;
    }
    return "";
}
Also used : UtcOffset(ezvcard.util.UtcOffset) TimeZone(java.util.TimeZone)

Example 4 with UtcOffset

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

the class SampleVCardsTest method lotusNotesVCard.

@Test
public void lotusNotesVCard() throws Throwable {
    VCardAsserter asserter = read("John_Doe_LOTUS_NOTES.vcf");
    asserter.next(V3_0);
    // @formatter:off
    asserter.simpleProperty(ProductId.class).value("-//Apple Inc.//Address Book 6.1//EN").noMore();
    asserter.structuredName().family("Doe").given("John").additional("Johny").prefixes("Mr.").suffixes("I").noMore();
    asserter.simpleProperty(FormattedName.class).value("Mr. Doe John I Johny").noMore();
    asserter.listProperty(Nickname.class).values("Johny,JayJay").noMore();
    asserter.listProperty(Organization.class).values("IBM", "SUN").noMore();
    asserter.simpleProperty(Title.class).value("Generic Accountant").noMore();
    asserter.email().types(EmailType.INTERNET, EmailType.WORK, EmailType.PREF).value("john.doe@ibm.com").next().types(EmailType.INTERNET, EmailType.WORK).value("billy_bob@gmail.com").noMore();
    asserter.telephone().types(TelephoneType.CELL, TelephoneType.VOICE, TelephoneType.PREF).text("+1 (212) 204-34456").next().types(TelephoneType.WORK, TelephoneType.FAX).text("00-1-212-555-7777").noMore();
    asserter.address().group("item1").streetAddress("25334" + NEWLINE + "South cresent drive, Building 5, 3rd floo r").locality("New York").region("New York").postalCode("NYC887").country("U.S.A.").types(AddressType.HOME, AddressType.PREF).noMore();
    asserter.simpleProperty(Note.class).value("THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"" + NEWLINE + "AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO , THE" + NEWLINE + "IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR P URPOSE" + NEWLINE + "ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTOR S BE" + NEWLINE + "LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR" + NEWLINE + "CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF" + NEWLINE + " SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS " + NEWLINE + "INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN" + NEWLINE + " CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)" + NEWLINE + "A RISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE" + NEWLINE + " POSSIBILITY OF SUCH DAMAGE.").noMore();
    asserter.simpleProperty(Url.class).group("item2").value("http://www.sun.com").param("TYPE", "pref").noMore();
    asserter.dateProperty(Birthday.class).date("1980-05-21").noMore();
    asserter.binaryProperty(Photo.class).param("ENCODING", "b").param("TYPE", "JPEG").contentType(ImageType.JPEG).dataLength(7957).noMore();
    asserter.simpleProperty(Uid.class).value("0e7602cc-443e-4b82-b4b1-90f62f99a199").noMore();
    asserter.geo().latitude(-2.6).longitude(3.4).noMore();
    asserter.simpleProperty(Classification.class).value("Public").noMore();
    asserter.simpleProperty(Profile.class).value("VCard").noMore();
    asserter.timezone().offset(new UtcOffset(true, 1, 0)).noMore();
    asserter.simpleProperty(Label.class).value("John Doe" + NEWLINE + "New York, NewYork," + NEWLINE + "South Crecent Dr ive," + NEWLINE + "Building 5, floor 3," + NEWLINE + "USA").param("TYPE", "HOME").param("TYPE", "PARCEL").param("TYPE", "PREF").noMore();
    asserter.simpleProperty(SortString.class).value("JOHN").noMore();
    asserter.simpleProperty(Role.class).value("Counting Money").noMore();
    asserter.simpleProperty(Source.class).value("Whatever").noMore();
    asserter.simpleProperty(Mailer.class).value("Mozilla Thunderbird").noMore();
    asserter.simpleProperty(SourceDisplayText.class).value("VCard for John Doe").noMore();
    asserter.rawProperty("X-ABLABEL").group("item2").value("_$!<HomePage>!$_").noMore();
    asserter.rawProperty("X-ABUID").value("0E7602CC-443E-4B82-B4B1-90F62F99A199:ABPerson").noMore();
    asserter.rawProperty("X-GENERATOR").value("Cardme Generator").noMore();
    asserter.rawProperty("X-LONG-STRING").value("12345678901234567890123456789012345678901234567890123456789012 34567890123456789012345678901234567890").noMore();
    VCard vcard = asserter.getVCard();
    asserter.validate().prop(vcard.getEmails().get(0), // "TYPE=WORK" not valid in vCard 3.0
    9).prop(vcard.getEmails().get(1), // "TYPE=WORK" not valid in vCard 3.0
    9).run();
    // @formatter:on
    asserter.done();
}
Also used : UtcOffset(ezvcard.util.UtcOffset) Label(ezvcard.property.Label) Photo(ezvcard.property.Photo) VCardAsserter(ezvcard.property.asserter.VCardAsserter) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 5 with UtcOffset

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

the class SampleVCardsTest method rfc6350_example.

@Test
public void rfc6350_example() throws Throwable {
    VCardAsserter asserter = read("rfc6350-example.vcf");
    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).partialDate(PartialDate.builder().year(2009).month(8).date(8).hour(14).minute(30).offset(new UtcOffset(false, -5, 0)).build()).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).param("TYPE", "work").values("Viagenie").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().types(TelephoneType.WORK, TelephoneType.VOICE).uri(new TelUri.Builder("+1-418-656-9254").extension("102").build()).param("PREF", "1").next().types(TelephoneType.WORK, TelephoneType.CELL, TelephoneType.VOICE, TelephoneType.VIDEO, TelephoneType.TEXT).uri(new TelUri.Builder("+1-418-262-6501").build()).noMore();
    asserter.email().types(EmailType.WORK).value("simon.perreault@viagenie.ca").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) FreeBusyUrl(ezvcard.property.FreeBusyUrl) Url(ezvcard.property.Url) Test(org.junit.Test)

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