Search in sources :

Example 1 with ImageType

use of ezvcard.parameter.ImageType in project ez-vcard by mangstadt.

the class ImagePropertyScribe method _parseHtml.

@Override
protected T _parseHtml(HCardElement element, ParseContext context) {
    String elementName = element.tagName();
    if (!"img".equals(elementName)) {
        return super._parseHtml(element, context);
    }
    String src = element.absUrl("src");
    if (src.length() == 0) {
        throw new CannotParseException(13);
    }
    try {
        DataUri uri = DataUri.parse(src);
        ImageType mediaType = _mediaTypeFromMediaTypeParameter(uri.getContentType());
        return _newInstance(uri.getData(), mediaType);
    } catch (IllegalArgumentException e) {
        // not a data URI
        String extension = getFileExtension(src);
        ImageType mediaType = (extension == null) ? null : _mediaTypeFromFileExtension(extension);
        return _newInstance(src, mediaType);
    }
}
Also used : CannotParseException(ezvcard.io.CannotParseException) DataUri(ezvcard.util.DataUri) ImageType(ezvcard.parameter.ImageType)

Aggregations

CannotParseException (ezvcard.io.CannotParseException)1 ImageType (ezvcard.parameter.ImageType)1 DataUri (ezvcard.util.DataUri)1