Example usage for twitter4j EntitySupport getURLEntities

List of usage examples for twitter4j EntitySupport getURLEntities

Introduction

In this page you can find the example usage for twitter4j EntitySupport getURLEntities.

Prototype

URLEntity[] getURLEntities();

Source Link

Document

Returns an array if URLEntity mentioned in the tweet.

Usage

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

private static void parseEntities(final HtmlBuilder builder, final EntitySupport entities) {
    final URLEntity[] urls = entities.getURLEntities();
    // Format media.
    final MediaEntity[] medias = entities.getMediaEntities();
    if (medias != null) {
        for (final MediaEntity media : medias) {
            final URL media_url = media.getMediaURL();
            if (media_url != null) {
                builder.addLink(parseString(media_url), media.getDisplayURL(), media.getStart(),
                        media.getEnd());
            }/* w  w  w.  ja va2s. c o  m*/
        }
    }
    if (urls != null) {
        for (final URLEntity url : urls) {
            final URL tco_url = url.getURL();
            final URL expanded_url = url.getExpandedURL();
            if (tco_url != null && !url.getDisplayURL().contains("tl.gd")) {
                builder.addLink(parseString(tco_url), url.getDisplayURL(), url.getStart(), url.getEnd());
            } else if (expanded_url != null && url.getDisplayURL().contains("tl.gd")) {
                builder.addLink(parseString(expanded_url), url.getDisplayURL(), url.getStart(), url.getEnd());
            }
        }
    }
}

From source file:de.vanita5.twittnuker.model.ParcelableMedia.java

License:Open Source License

public static ParcelableMedia[] fromEntities(final EntitySupport entities) {
    final List<ParcelableMedia> list = new ArrayList<>();
    final MediaEntity[] mediaEntities;
    if (entities instanceof ExtendedEntitySupport) {
        final ExtendedEntitySupport extendedEntities = (ExtendedEntitySupport) entities;
        final MediaEntity[] extendedMedias = extendedEntities.getExtendedMediaEntities();
        mediaEntities = extendedMedias != null ? extendedMedias : entities.getMediaEntities();
    } else {//from   w  w w.  j av a 2 s .  c om
        mediaEntities = entities.getMediaEntities();
    }
    if (mediaEntities != null) {
        for (final MediaEntity media : mediaEntities) {
            final URL mediaURL = media.getMediaURL();
            if (mediaURL != null) {
                list.add(new ParcelableMedia(media));
            }
        }
    }
    final URLEntity[] urlEntities = entities.getURLEntities();
    if (urlEntities != null) {
        for (final URLEntity url : urlEntities) {
            final String expanded = ParseUtils.parseString(url.getExpandedURL());
            final String media_url = MediaPreviewUtils.getSupportedLink(expanded);
            if (expanded != null && media_url != null) {
                list.add(new ParcelableMedia(expanded, media_url, url.getStart(), url.getEnd(), TYPE_IMAGE));
            }
        }
    }
    if (list.isEmpty())
        return null;
    return list.toArray(new ParcelableMedia[list.size()]);
}

From source file:de.vanita5.twittnuker.util.TwitterContentUtils.java

License:Open Source License

private static void parseEntities(final HtmlBuilder builder, final EntitySupport entities) {
    // Format media.
    final MediaEntity[] mediaEntities = entities.getMediaEntities();
    if (mediaEntities != null) {
        for (final MediaEntity mediaEntity : mediaEntities) {
            final int start = mediaEntity.getStart(), end = mediaEntity.getEnd();
            final URL mediaUrl = mediaEntity.getMediaURL();
            if (mediaUrl != null && start >= 0 && end >= 0) {
                builder.addLink(ParseUtils.parseString(mediaUrl), mediaEntity.getDisplayURL(), start, end);
            }/*www .j  a  v  a  2  s.com*/
        }
    }
    final URLEntity[] urlEntities = entities.getURLEntities();
    if (urlEntities != null) {
        for (final URLEntity urlEntity : urlEntities) {
            final int start = urlEntity.getStart(), end = urlEntity.getEnd();
            final URL expandedUrl = urlEntity.getExpandedURL();
            if (expandedUrl != null && start >= 0 && end >= 0) {
                builder.addLink(ParseUtils.parseString(expandedUrl), urlEntity.getDisplayURL(), start, end);
            }
        }
    }
}

From source file:org.getlantern.firetweet.util.TwitterContentUtils.java

License:Open Source License

private static void parseEntities(final HtmlBuilder builder, final EntitySupport entities) {
    // Format media.
    final MediaEntity[] mediaEntities = entities.getMediaEntities();
    if (mediaEntities != null) {
        for (final MediaEntity mediaEntity : mediaEntities) {
            final int start = mediaEntity.getStart(), end = mediaEntity.getEnd();
            final String mediaUrl = mediaEntity.getMediaURL();
            if (mediaUrl != null && start >= 0 && end >= 0) {
                builder.addLink(mediaUrl, mediaEntity.getDisplayURL(), start, end);
            }//from   w w  w.ja va  2 s  .c o  m
        }
    }
    final URLEntity[] urlEntities = entities.getURLEntities();
    if (urlEntities != null) {
        for (final URLEntity urlEntity : urlEntities) {
            final int start = urlEntity.getStart(), end = urlEntity.getEnd();
            final String expandedUrl = urlEntity.getExpandedURL();
            if (expandedUrl != null && start >= 0 && end >= 0) {
                builder.addLink(expandedUrl, urlEntity.getDisplayURL(), start, end);
            }
        }
    }
}