Search in sources :

Example 6 with CannotParseException

use of ezvcard.io.CannotParseException in project ez-vcard by mangstadt.

the class ClientPidMapScribe method _parseText.

@Override
protected ClientPidMap _parseText(String value, VCardDataType dataType, VCardParameters parameters, ParseContext context) {
    SemiStructuredValueIterator it = new SemiStructuredValueIterator(value, 2);
    String pid = it.next();
    String uri = it.next();
    if (pid == null || uri == null) {
        throw new CannotParseException(3);
    }
    return parse(pid, uri);
}
Also used : CannotParseException(ezvcard.io.CannotParseException) SemiStructuredValueIterator(com.github.mangstadt.vinnie.io.VObjectPropertyValues.SemiStructuredValueIterator)

Example 7 with CannotParseException

use of ezvcard.io.CannotParseException in project ez-vcard by mangstadt.

the class GeoScribe method _parseText.

@Override
protected Geo _parseText(String value, VCardDataType dataType, VCardParameters parameters, ParseContext context) {
    if (value.length() == 0) {
        return new Geo((GeoUri) null);
    }
    switch(context.getVersion()) {
        case V2_1:
        case V3_0:
            int pos = value.indexOf(';');
            if (pos < 0) {
                throw new CannotParseException(11);
            }
            String latitudeStr = value.substring(0, pos);
            String longitudeStr = value.substring(pos + 1);
            Double latitude;
            try {
                latitude = Double.valueOf(latitudeStr);
            } catch (NumberFormatException e) {
                throw new CannotParseException(8, latitudeStr);
            }
            Double longitude;
            try {
                longitude = Double.valueOf(longitudeStr);
            } catch (NumberFormatException e) {
                throw new CannotParseException(10, longitudeStr);
            }
            return new Geo(latitude, longitude);
        case V4_0:
            value = VObjectPropertyValues.unescape(value);
            return parseGeoUri(value);
    }
    return null;
}
Also used : Geo(ezvcard.property.Geo) CannotParseException(ezvcard.io.CannotParseException)

Example 8 with CannotParseException

use of ezvcard.io.CannotParseException 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

CannotParseException (ezvcard.io.CannotParseException)8 DataUri (ezvcard.util.DataUri)3 Geo (ezvcard.property.Geo)2 SemiStructuredValueIterator (com.github.mangstadt.vinnie.io.VObjectPropertyValues.SemiStructuredValueIterator)1 VCard (ezvcard.VCard)1 EmbeddedVCardException (ezvcard.io.EmbeddedVCardException)1 SkipMeException (ezvcard.io.SkipMeException)1 HCardElement (ezvcard.io.html.HCardElement)1 RawPropertyScribe (ezvcard.io.scribe.RawPropertyScribe)1 VCardPropertyScribe (ezvcard.io.scribe.VCardPropertyScribe)1 ImageType (ezvcard.parameter.ImageType)1 SoundType (ezvcard.parameter.SoundType)1 Categories (ezvcard.property.Categories)1 Impp (ezvcard.property.Impp)1 Label (ezvcard.property.Label)1 Nickname (ezvcard.property.Nickname)1 RawProperty (ezvcard.property.RawProperty)1 Sound (ezvcard.property.Sound)1 Timezone (ezvcard.property.Timezone)1 VCardProperty (ezvcard.property.VCardProperty)1