List of usage examples for twitter4j URLEntity getStart
@Override
int getStart();
From source file:ac.simons.tweetarchive.tweets.TweetStorageService.java
License:Apache License
String extractContent(final Status status) { // TODO Handle quoted tweets final Status workStatus; if (status.isRetweet()) { workStatus = status.getRetweetedStatus(); } else {// www . j a v a 2 s . c o m workStatus = status; } final StringBuilder rv = new StringBuilder(); final String text = workStatus.getText(); int pos = 0; for (URLEntity urlEntity : workStatus.getURLEntities()) { rv.append(text.substring(pos, urlEntity.getStart())); rv.append(urlEntity.getExpandedURL()); pos = urlEntity.getEnd(); } if (pos <= text.length()) { rv.append(text.substring(pos, text.length())); } if (status.isRetweet()) { rv.insert(0, String.format("RT @%s: ", workStatus.getUser().getScreenName())); } return rv.toString(); }
From source file:com.alainesp.fan.sanderson.SummaryFragment.java
License:Open Source License
private String getTweetText(twitter4j.Status tweet) { SpannableStringBuilder text = new SpannableStringBuilder(tweet.getText()); URLEntity[] urls = tweet.getURLEntities(); MediaEntity[] medias = tweet.getMediaEntities(); for (MediaEntity media : medias) if ("photo".equals(media.getType())) { InternetHelper.getRemoteFile(media.getMediaURLHttps()); text.setSpan(new ImageSpan(null, media.getMediaURLHttps()), media.getStart(), media.getEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }// w w w.ja v a2 s. c om for (URLEntity url : urls) { text.setSpan(new URLSpan(url.getURL()), url.getStart(), url.getEnd(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); text.replace(url.getStart(), url.getEnd(), url.getExpandedURL()); } return Html.toHtml(text); }
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()); }/*from ww w. java 2 s. com*/ } } 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:com.freshdigitable.udonroad.module.realm.URLEntityRealm.java
License:Apache License
URLEntityRealm(URLEntity urlEntity) { this.url = urlEntity.getURL(); this.expandedUrl = urlEntity.getExpandedURL(); this.displayUrl = urlEntity.getDisplayURL(); this.start = urlEntity.getStart(); this.end = urlEntity.getEnd(); }
From source file:com.github.daytron.twaattin.ui.tabledecorator.TweetColumnDecorator.java
License:Open Source License
void createFragmentsWithUrl(URLEntity[] urls) { if (urls != null) { for (URLEntity url : urls) { String expandedUrl = url.getExpandedURL(); int start = url.getStart(); int end = url.getEnd(); String href = "<a href='" + expandedUrl + "' target='_blank' + title='" + expandedUrl + "'>"; TweetFragment fragment = new TweetFragment(start, end, href + url.getURL() + "</a>"); fragments.add(fragment);//from w w w . jav a 2s. com } } }
From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java
License:Apache License
static Struct convertURLEntity(URLEntity uRLEntity) { return new Struct(SCHEMA_URL_ENTITY).put("URL", uRLEntity.getURL()).put("Text", uRLEntity.getText()) .put("ExpandedURL", uRLEntity.getExpandedURL()).put("Start", uRLEntity.getStart()) .put("End", uRLEntity.getEnd()).put("DisplayURL", uRLEntity.getDisplayURL()); }
From source file:com.mothsoft.alexis.engine.retrieval.TwitterRetrievalTaskImpl.java
License:Apache License
private List<TweetLink> readLinks(Status status) { final List<TweetLink> links = new ArrayList<TweetLink>(); if (status.getURLEntities() != null) { for (final URLEntity entity : status.getURLEntities()) { final String displayUrl = entity.getDisplayURL(); final String expandedUrl = entity.getExpandedURL(); final String url = entity.getURL(); final TweetLink link = new TweetLink((short) entity.getStart(), (short) entity.getEnd(), displayUrl, expandedUrl, url);/*from w ww . j a v a 2s . c o m*/ links.add(link); } } return links; }
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 {// w ww .j av a2 s . c o m 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
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 = ParseUtils.parseString(url.getExpandedURL()); if (expanded_url != null) { builder.addLink(expanded_url, expanded_url, url.getStart(), url.getEnd()); }/*from w w w . j a v a 2s . c o m*/ } } return toPlainText(builder.build().replace("\n", "<br/>")); }
From source file:de.vanita5.twittnuker.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 URL expanded_url = url.getExpandedURL(); if (expanded_url != null) { builder.addLink(ParseUtils.parseString(expanded_url), url.getDisplayURL(), url.getStart(), url.getEnd());/*w ww .j a va 2 s .c o m*/ } } } return builder.build().replace("\n", "<br/>"); }