Example usage for twitter4j URLEntity getStart

List of usage examples for twitter4j URLEntity getStart

Introduction

In this page you can find the example usage for twitter4j URLEntity getStart.

Prototype

@Override
int getStart();

Source Link

Document

Returns the index of the start character of the URL mentioned in the tweet.

Usage

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);
            }/*from www  . ja  v a 2  s .co m*/
        }
    }
    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:de.vanita5.twittnuker.util.Utils.java

License:Open Source License

public static String parseURLEntities(String text, final URLEntity[] entities) {
    for (URLEntity entity : entities) {
        final int start = entity.getStart(), end = entity.getEnd();
        final String displayUrl = entity.getDisplayURL();
        if (displayUrl != null && !displayUrl.isEmpty() && start >= 0 && end >= 0) {
            StringBuffer bf = new StringBuffer(text);
            return bf.replace(start, end, displayUrl).toString();
        }/*from   w  w  w .j  a v a 2s  . c o  m*/
    }
    return text;
}

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

License:Open Source License

public static String formatExpandedUserDescription(final User user) {
    if (user == null)
        return null;
    final String text = user.getDescription();
    if (text == null)
        return null;
    final HtmlBuilder builder = new HtmlBuilder(text, false, true, true);
    final URLEntity[] urls = user.getDescriptionEntities();
    if (urls != null) {
        for (final URLEntity url : urls) {
            final String expanded_url = url.getExpandedURL();
            if (expanded_url != null) {
                builder.addLink(expanded_url, expanded_url, url.getStart(), url.getEnd());
            }//from  ww w .j a v  a  2 s.c om
        }
    }
    return toPlainText(builder.build().replace("\n", "<br/>"));
}

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

License:Open Source License

public static String formatUserDescription(final User user) {
    if (user == null)
        return null;
    final String text = user.getDescription();
    if (text == null)
        return null;
    final HtmlBuilder builder = new HtmlBuilder(text, false, true, true);
    final URLEntity[] urls = user.getDescriptionEntities();
    if (urls != null) {
        for (final URLEntity url : urls) {
            final String expanded_url = url.getExpandedURL();
            if (expanded_url != null) {
                builder.addLink(expanded_url, url.getDisplayURL(), url.getStart(), url.getEnd());
            }// w  w  w .  j  a va2s  . c  om
        }
    }
    return builder.build().replace("\n", "<br/>");
}

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 .  j  a v a 2s .c  om
        }
    }
    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);
            }
        }
    }
}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

private void write(URLEntity u) throws XMLStreamException {
    attribute("display-url", u.getDisplayURL());
    attribute("end", u.getEnd());
    attribute("expanded-url", u.getExpandedURL().toString());
    attribute("start", u.getStart());
    attribute("url", u.getURL().toString());

}