Example usage for twitter4j Status getText

List of usage examples for twitter4j Status getText

Introduction

In this page you can find the example usage for twitter4j Status getText.

Prototype

String getText();

Source Link

Document

Returns the text of the status

Usage

From source file:com.daemon.database.Transactor.java

License:Open Source License

/**
* Creates an error message with tweet information for further analysis.
* @param tweet The tweet whose information is to be represented.
* @return The error message./*from   w  ww. j  a va  2s .  c o m*/
 **/
private String getTweetErrorString(Status tweet) {
    StringBuffer sb = new StringBuffer();

    sb.append("Tweet information:\n");
    sb.append("  id: " + tweet.getId() + "\n");
    sb.append("  text: " + tweet.getText() + "\n");
    sb.append("    length: " + tweet.getText().length() + "\n");
    sb.append("   elength: " + StringUtil.escapeNonAscii(tweet.getText()).length() + "\n");
    sb.append("  iso lang. code: " + tweet.getIsoLanguageCode());
    if (tweet.isRetweet())
        sb.append("\n  retweet of id: " + tweet.getRetweetedStatus().getId());

    return sb.toString();
}

From source file:com.daemon.database.Transactor.java

License:Open Source License

/**
 * Adds the relation between the given tweet and the search term-id (DB
 * specific) the tweet was found with to the SQL Batched executed by 
 * the saveAllTransactionSafe Function//from   w  ww  . ja  v a  2 s . c  o  m
 * 
 * @param tweet  The tweet related to the search term-id.
 * @param term   The search term related to the tweet.
 * @throws SQLException
 */
private void saveTweetWithTerm(Status tweet, SearchTerm term, RegressionSentimentClassifier sentimentClassifier)
        throws SQLException {
    try {
        prepStatementTweetWithTerm.setLong(1, tweet.getId()); // tweet_id
        prepStatementTweetWithTerm.setInt(2, term.getId()); // search_term_id
        prepStatementTweetWithTerm.setString(3, tweet.getIsoLanguageCode()); // iso__language_code
        // sentiment
        Float sentiment = sentimentClassifier.determineSentiment(tweet.getText(), tweet.getIsoLanguageCode());
        if (sentiment == null) {
            prepStatementTweetWithTerm.setNull(4, java.sql.Types.NULL);
        } else {
            prepStatementTweetWithTerm.setFloat(4,
                    sentimentClassifier.determineSentiment(tweet.getText(), tweet.getIsoLanguageCode()));
        }

        // created_at
        java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(tweet.getCreatedAt().getTime());
        prepStatementTweetWithTerm.setTimestamp(5, sqlTimestamp);
        // is_retweet_of_id
        if (tweet.getRetweetedStatus() != null) {
            prepStatementTweetWithTerm.setLong(6, tweet.getRetweetedStatus().getId());
        } else {
            prepStatementTweetWithTerm.setNull(6, java.sql.Types.NULL);
        }
        // retweet_count
        prepStatementTweetWithTerm.setInt(7, tweet.getRetweetCount());

        prepStatementTweetWithTerm.addBatch();
    } catch (Exception e) {
        // Doesn't make sense. we wouldn't find the tweet for the
        // search term if the search term was not in the database
        throw new SQLException(
                "Cannot save tweet with search term. The term has no Id (it was not inserted, yet).");
    }
}

From source file:com.daiv.android.twitter.adapters.PicturesArrayAdapter.java

License:Apache License

public void bindView(final View view, Context mContext, final String url, final Status status) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    Log.v("Test_picture", "text: " + status.getText());

    Status thisStatus;/*from   w  w w.j  av  a 2 s .c  om*/

    String retweeter;
    final long time = status.getCreatedAt().getTime();
    long originalTime = 0;

    if (status.isRetweet()) {
        retweeter = status.getUser().getScreenName();

        thisStatus = status.getRetweetedStatus();
        originalTime = thisStatus.getCreatedAt().getTime();
    } else {
        retweeter = "";

        thisStatus = status;
    }
    final String fRetweeter = retweeter;

    final long fOriginalTime = originalTime;

    User user = thisStatus.getUser();

    final long id = thisStatus.getId();
    final String profilePic = user.getBiggerProfileImageURL();
    String tweetTexts = thisStatus.getText();
    final String name = user.getName();
    final String screenname = user.getScreenName();

    String[] html = TweetLinkUtils.getLinksInStatus(thisStatus);
    final String tweetText = html[0];
    final String picUrl = html[1];
    final String otherUrl = html[2];
    final String hashtags = html[3];
    final String users = html[4];

    holder.url = url;

    holder.iv.loadImage(url, false, new NetworkedCacheableImageView.OnImageLoadedListener() {
        @Override
        public void onImageLoaded(CacheableBitmapDrawable result) {
            holder.iv.setBackgroundDrawable(null);
        }
    });

    holder.iv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String link;

            boolean displayPic = !picUrl.equals("");
            if (displayPic) {
                link = picUrl;
            } else {
                link = otherUrl.split("  ")[0];
            }

            Log.v("tweet_page", "clicked");
        }
    });

}

From source file:com.daiv.android.twitter.adapters.TimelineArrayAdapter.java

License:Apache License

public void bindView(final View view, Status status, int position) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    if (holder.expandArea.getVisibility() == View.VISIBLE) {
        removeExpansionNoAnimation(holder);
    }/*from  ww w  . j  a  v a 2 s  . com*/

    Status thisStatus;

    String retweeter;
    final long time = status.getCreatedAt().getTime();
    long originalTime = 0;

    if (status.isRetweet()) {
        retweeter = status.getUser().getScreenName();

        thisStatus = status.getRetweetedStatus();
        originalTime = thisStatus.getCreatedAt().getTime();
    } else {
        retweeter = "";

        thisStatus = status;
    }

    final long fOriginalTime = originalTime;

    User user = thisStatus.getUser();

    holder.tweetId = thisStatus.getId();
    final long id = holder.tweetId;
    final String profilePic = user.getOriginalProfileImageURL();
    String tweetTexts = thisStatus.getText();
    final String name = user.getName();
    final String screenname = user.getScreenName();

    String[] html = TweetLinkUtils.getLinksInStatus(thisStatus);

    final String tweetText = html[0];
    final String picUrl = html[1];
    holder.picUrl = picUrl;
    final String otherUrl = html[2];
    final String hashtags = html[3];
    final String users = html[4];

    final boolean inAConversation = thisStatus.getInReplyToStatusId() != -1;

    holder.gifUrl = TweetLinkUtils.getGIFUrl(status, otherUrl);

    if (holder.isAConversation != null) {
        if (inAConversation) {
            if (holder.isAConversation.getVisibility() != View.VISIBLE) {
                holder.isAConversation.setVisibility(View.VISIBLE);
            }
        } else {
            if (holder.isAConversation.getVisibility() != View.GONE) {
                holder.isAConversation.setVisibility(View.GONE);
            }
        }
    }

    if (!settings.reverseClickActions) {
        final String fRetweeter = retweeter;
        holder.background.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {

                String link;

                boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
                boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube")
                        && !(hasGif);
                if (displayPic) {
                    link = holder.picUrl;
                } else {
                    link = otherUrl.split("  ")[0];
                }

                Log.v("tweet_page", "clicked");

                return true;
            }
        });

        holder.background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.preventNextClick) {
                    holder.preventNextClick = false;
                    return;
                }
                if (holder.expandArea.getVisibility() == View.GONE) {
                    addExpansion(holder, screenname, users, otherUrl.split("  "), holder.picUrl, id);
                } else {
                    removeExpansionWithAnimation(holder);
                    removeKeyboard(holder);
                }
            }
        });

    } else {
        final String fRetweeter = retweeter;
        holder.background.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (holder.preventNextClick) {
                    holder.preventNextClick = false;
                    return;
                }

                String link;

                boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
                boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube")
                        && !(hasGif);
                if (displayPic) {
                    link = holder.picUrl;
                } else {
                    link = otherUrl.split("  ")[0];
                }

                Log.v("tweet_page", "clicked");
            }
        });

        holder.background.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                if (holder.expandArea.getVisibility() == View.GONE) {
                    addExpansion(holder, screenname, users, otherUrl.split("  "), holder.picUrl, id);
                } else {
                    removeExpansionWithAnimation(holder);
                    removeKeyboard(holder);
                }

                return true;
            }
        });
    }

    if (!screenname.equals(username)) {

    } else {
        // need to clear the click listener so it isn't left over from another profile
        holder.profilePic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

        holder.profilePic.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View view) {
                return true;
            }
        });
    }

    if (TestLayout == AppSettings.LAYOUT_FULL_SCREEN
            || (settings.nameAndHandleOnTweet && settings.addonTheme)) {
        if (holder.screenTV.getVisibility() == View.GONE) {
            holder.screenTV.setVisibility(View.VISIBLE);
        }
        holder.screenTV.setText("@" + screenname);
        holder.name.setText(name);
    } else {
        if (!settings.showBoth) {
            holder.name.setText(settings.displayScreenName ? "@" + screenname : name);
        } else {
            if (holder.screenTV.getVisibility() == View.GONE) {
                holder.screenTV.setVisibility(View.VISIBLE);
            }
            holder.name.setText(name);
            holder.screenTV.setText("@" + screenname);
        }
    }

    if (!settings.absoluteDate) {
        holder.time.setText(Utils.getTimeAgo(time, context));
    } else {
        Date date = new Date(time);
        holder.time
                .setText(timeFormatter.format(date).replace("24:", "00:") + ", " + dateFormatter.format(date));
    }

    holder.tweet.setText(tweetText);

    boolean picture = false;

    if (settings.inlinePics) {
        if (holder.picUrl.equals("")) {
            if (holder.image.getVisibility() != View.GONE) {
                holder.image.setVisibility(View.GONE);
            }

            if (holder.playButton.getVisibility() == View.VISIBLE) {
                holder.playButton.setVisibility(View.GONE);
            }
        } else {
            if (holder.picUrl.contains("youtube")
                    || (holder.gifUrl != null && !android.text.TextUtils.isEmpty(holder.gifUrl))) {

                if (holder.playButton.getVisibility() == View.GONE) {
                    holder.playButton.setVisibility(View.VISIBLE);
                }

                final String fRetweeter = retweeter;

                holder.image.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        String link;

                        boolean hasGif = holder.gifUrl != null && !holder.gifUrl.isEmpty();
                        boolean displayPic = !holder.picUrl.equals("") && !holder.picUrl.contains("youtube")
                                && !(hasGif);
                        if (displayPic) {
                            link = holder.picUrl;
                        } else {
                            link = otherUrl.split("  ")[0];
                        }
                    }
                });

                holder.image.setImageDrawable(transparent);

                picture = true;

            } else {
                holder.image.setImageDrawable(transparent);

                picture = true;

                if (holder.playButton.getVisibility() == View.VISIBLE) {
                    holder.playButton.setVisibility(View.GONE);
                }
            }

            if (holder.image.getVisibility() == View.GONE) {
                holder.image.setVisibility(View.VISIBLE);
            }
        }
    }

    if (type == NORMAL) {
        if (retweeter.length() > 0) {
            holder.retweeter.setText(context.getResources().getString(R.string.retweeter) + retweeter);
            holder.retweeterName = retweeter;
            holder.retweeter.setVisibility(View.VISIBLE);
        } else if (holder.retweeter.getVisibility() == View.VISIBLE) {
            holder.retweeter.setVisibility(View.GONE);
        }
    } else if (type == RETWEET) {

        int count = status.getRetweetCount();

        if (count > 1) {
            holder.retweeter.setText(
                    status.getRetweetCount() + " " + context.getResources().getString(R.string.retweets_lower));
            holder.retweeter.setVisibility(View.VISIBLE);
        } else if (count == 1) {
            holder.retweeter.setText(
                    status.getRetweetCount() + " " + context.getResources().getString(R.string.retweet_lower));
            holder.retweeter.setVisibility(View.VISIBLE);
        }
    }

    if (picture) {
        CacheableBitmapDrawable wrapper = mCache.getFromMemoryCache(holder.picUrl);
        if (wrapper != null) {
            holder.image.setImageDrawable(wrapper);
            picture = false;
        }
    }

    final boolean hasPicture = picture;
    mHandler[currHandler].removeCallbacksAndMessages(null);
    mHandler[currHandler].postDelayed(new Runnable() {
        @Override
        public void run() {
            if (holder.tweetId == id) {
                if (hasPicture) {
                    loadImage(context, holder, holder.picUrl, mCache, id);
                }

                if (settings.useEmoji
                        && (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || EmojiUtils.ios)) {
                    String text = holder.tweet.getText().toString();
                    if (EmojiUtils.emojiPattern.matcher(text).find()) {
                        final Spannable span = EmojiUtils.getSmiledText(context, Html.fromHtml(tweetText));
                        holder.tweet.setText(span);
                    }
                }

                holder.tweet.setSoundEffectsEnabled(false);
                holder.tweet.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (!TouchableMovementMethod.touched) {
                            // we need to manually set the background for click feedback because the spannable
                            // absorbs the click on the background
                            if (!holder.preventNextClick) {
                                holder.background.getBackground()
                                        .setState(new int[] { android.R.attr.state_pressed });
                                new Handler().postDelayed(new Runnable() {
                                    @Override
                                    public void run() {
                                        holder.background.getBackground()
                                                .setState(new int[] { android.R.attr.state_empty });
                                    }
                                }, 25);
                            }

                            holder.background.performClick();
                        }
                    }
                });

                holder.tweet.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View view) {
                        if (!TouchableMovementMethod.touched) {
                            holder.background.performLongClick();
                            holder.preventNextClick = true;
                        }
                        return false;
                    }
                });

                if (holder.retweeter.getVisibility() == View.VISIBLE) {
                    holder.retweeter.setSoundEffectsEnabled(false);
                    holder.retweeter.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (!TouchableMovementMethod.touched) {
                                if (!holder.preventNextClick) {
                                    holder.background.getBackground()
                                            .setState(new int[] { android.R.attr.state_pressed });
                                    new Handler().postDelayed(new Runnable() {
                                        @Override
                                        public void run() {
                                            holder.background.getBackground()
                                                    .setState(new int[] { android.R.attr.state_empty });
                                        }
                                    }, 25);
                                }

                                holder.background.performClick();
                            }
                        }
                    });

                    holder.retweeter.setOnLongClickListener(new View.OnLongClickListener() {
                        @Override
                        public boolean onLongClick(View view) {
                            if (!TouchableMovementMethod.touched) {
                                holder.background.performLongClick();
                                holder.preventNextClick = true;
                            }
                            return false;
                        }
                    });
                }

                TextUtils.linkifyText(context, holder.tweet, holder.background, true, otherUrl, false);
                TextUtils.linkifyText(context, holder.retweeter, holder.background, true, "", false);
            }
        }
    }, 400);
    currHandler++;

    if (currHandler == 10) {
        currHandler = 0;
    }

    if (openFirst && position == 0) {
        holder.background.performClick();
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.InteractionsDataSource.java

License:Apache License

public synchronized void createMention(Context context, Status status, int account) {
    ContentValues values = new ContentValues();
    long id = status.getId();
    long time = new GregorianCalendar().getTime().getTime(); // current time
    int type = TYPE_MENTION;

    User user = status.getUser();/*ww  w  .j  ava 2  s  . com*/
    String users = "@" + user.getScreenName() + " ";
    String text = status.getText();
    String title = context.getResources().getString(R.string.mentioned_by) + " <b>@" + user.getScreenName()
            + "</b>";

    values.put(InteractionsSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(InteractionsSQLiteHelper.COLUMN_TEXT, text);
    values.put(InteractionsSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, user.getOriginalProfileImageURL());
    values.put(InteractionsSQLiteHelper.COLUMN_TIME, time);
    values.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1);
    values.put(InteractionsSQLiteHelper.COLUMN_USERS, users);
    values.put(InteractionsSQLiteHelper.COLUMN_TYPE, type);
    values.put(InteractionsSQLiteHelper.COLUMN_TITLE, title);

    try {
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    } catch (Exception e) {
        open();
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.InteractionsDataSource.java

License:Apache License

public synchronized void createFavoriteUserInter(Context context, Status status, int account) {
    ContentValues values = new ContentValues();
    long id = status.getId();
    long time = new GregorianCalendar().getTime().getTime(); // current time
    int type = TYPE_FAV_USER;

    User user = status.getUser();//from  w ww  .  j a  v a  2  s  .  co m
    String users = "@" + user.getScreenName() + " ";
    String text = status.getText();
    String title = "<b>@" + user.getScreenName() + "</b> " + context.getResources().getString(R.string.tweeted);

    values.put(InteractionsSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(InteractionsSQLiteHelper.COLUMN_TEXT, text);
    values.put(InteractionsSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, user.getOriginalProfileImageURL());
    values.put(InteractionsSQLiteHelper.COLUMN_TIME, time);
    values.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1);
    values.put(InteractionsSQLiteHelper.COLUMN_USERS, users);
    values.put(InteractionsSQLiteHelper.COLUMN_TYPE, type);
    values.put(InteractionsSQLiteHelper.COLUMN_TITLE, title);

    try {
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    } catch (Exception e) {
        open();
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    }
}

From source file:com.daiv.android.twitter.data.sq_lite.InteractionsDataSource.java

License:Apache License

public synchronized void createInteraction(Context context, User source, Status status, int account, int type) {
    ContentValues values = new ContentValues();
    long id;//from w w w  .  ja v  a 2 s.  c om
    if (status != null) {
        id = status.getId();
    } else {
        id = 0; // 0 will be used for whenever it is just a follow
    }
    long time = new GregorianCalendar().getTime().getTime(); // current time

    String users = "@" + source.getScreenName() + " ";

    String text = "";

    String title = "";

    switch (type) {
    case TYPE_FAVORITE:
        title = "<b>@" + source.getScreenName() + "</b> "
                + context.getResources().getString(R.string.favorited);
        text = status.getText();
        break;
    case TYPE_RETWEET:
        title = "<b>@" + source.getScreenName() + "</b> "
                + context.getResources().getString(R.string.retweeted);
        text = status.getRetweetedStatus().getText();
        break;
    case TYPE_FOLLOWER:
        title = "<b>@" + source.getScreenName() + "</b> " + context.getResources().getString(R.string.followed);
        break;
    case TYPE_QUOTED_TWEET:
        title = "<b>@" + source.getScreenName() + "</b> " + context.getResources().getString(R.string.quoted);
        text = status.getText();
        break;
    }

    values.put(InteractionsSQLiteHelper.COLUMN_ACCOUNT, account);
    values.put(InteractionsSQLiteHelper.COLUMN_TEXT, text);
    values.put(InteractionsSQLiteHelper.COLUMN_TWEET_ID, id);
    values.put(InteractionsSQLiteHelper.COLUMN_PRO_PIC, source.getOriginalProfileImageURL());
    values.put(InteractionsSQLiteHelper.COLUMN_TIME, time);
    values.put(InteractionsSQLiteHelper.COLUMN_UNREAD, 1);
    values.put(InteractionsSQLiteHelper.COLUMN_USERS, users);
    values.put(InteractionsSQLiteHelper.COLUMN_TYPE, type);
    values.put(InteractionsSQLiteHelper.COLUMN_TITLE, title);

    try {
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    } catch (Exception e) {
        open();
        database.insert(InteractionsSQLiteHelper.TABLE_INTERACTIONS, null, values);
    }
}

From source file:com.daiv.android.twitter.utils.TweetLinkUtils.java

License:Apache License

public static String[] getLinksInStatus(Status status) {
    UserMentionEntity[] users = status.getUserMentionEntities();
    String mUsers = "";

    for (UserMentionEntity name : users) {
        String n = name.getScreenName();
        if (n.length() > 1) {
            mUsers += n + "  ";
        }/*from  w w w  .  j  ava  2s.  co  m*/
    }

    HashtagEntity[] hashtags = status.getHashtagEntities();
    String mHashtags = "";

    for (HashtagEntity hashtagEntity : hashtags) {
        String text = hashtagEntity.getText();
        if (text.length() > 1) {
            mHashtags += text + "  ";
        }
    }

    URLEntity[] urls = status.getURLEntities();
    String expandedUrls = "";
    String compressedUrls = "";

    for (URLEntity entity : urls) {
        String url = entity.getExpandedURL();
        if (url.length() > 1) {
            expandedUrls += url + "  ";
            compressedUrls += entity.getURL() + "  ";
        }
    }

    MediaEntity[] medias = status.getMediaEntities();
    String mediaExp = "";
    String mediaComp = "";
    String mediaDisplay = "";

    for (MediaEntity e : medias) {
        String url = e.getURL();
        if (url.length() > 1) {
            mediaComp += url + "  ";
            mediaExp += e.getExpandedURL() + "  ";
            mediaDisplay += e.getDisplayURL() + "  ";
        }
    }

    String[] sExpandedUrls;
    String[] sCompressedUrls;
    String[] sMediaExp;
    String[] sMediaComp;
    String[] sMediaDisplay;

    try {
        sCompressedUrls = compressedUrls.split("  ");
    } catch (Exception e) {
        sCompressedUrls = new String[0];
    }

    try {
        sExpandedUrls = expandedUrls.split("  ");
    } catch (Exception e) {
        sExpandedUrls = new String[0];
    }

    try {
        sMediaComp = mediaComp.split("  ");
    } catch (Exception e) {
        sMediaComp = new String[0];
    }

    try {
        sMediaExp = mediaExp.split("  ");
    } catch (Exception e) {
        sMediaExp = new String[0];
    }

    try {
        sMediaDisplay = mediaDisplay.split("  ");
    } catch (Exception e) {
        sMediaDisplay = new String[0];
    }

    String tweetTexts = status.getText();

    String imageUrl = "";
    String otherUrl = "";

    for (int i = 0; i < sCompressedUrls.length; i++) {
        String comp = sCompressedUrls[i];
        String exp = sExpandedUrls[i];

        if (comp.length() > 1 && exp.length() > 1) {
            String str = exp.toLowerCase();

            try {
                String replacement = exp.replace("http://", "").replace("https://", "").replace("www.", "");

                boolean hasCom = replacement.contains(".com");
                replacement = replacement.substring(0, 30) + "...";

                if (hasCom && !replacement.contains(".com")) { // the link was too long...
                    replacement = exp.replace("http://", "").replace("https://", "").replace("www.", "");
                    replacement = replacement.substring(0, replacement.indexOf(".com") + 6) + "...";
                }

                tweetTexts = tweetTexts.replace(comp, replacement);
            } catch (Exception e) {
                tweetTexts = tweetTexts.replace(comp,
                        exp.replace("http://", "").replace("https://", "").replace("www.", ""));
            }
            if (str.contains("instag") && !str.contains("blog.insta")) {
                imageUrl = exp + "media/?size=l";
                otherUrl += exp + "  ";
            } else if (exp.toLowerCase().contains("youtub")
                    && !(str.contains("channel") || str.contains("user"))) {
                // first get the youtube video code
                int start = exp.indexOf("v=") + 2;
                int end = exp.length();
                if (exp.substring(start).contains("&")) {
                    end = exp.indexOf("&");
                } else if (exp.substring(start).contains("?")) {
                    end = exp.indexOf("?");
                }
                try {
                    imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg";
                } catch (Exception e) {
                    imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, exp.length() - 1)
                            + "/hqdefault.jpg";
                }
                otherUrl += exp + "  ";
            } else if (str.contains("youtu.be")) {
                // first get the youtube video code
                int start = exp.indexOf(".be/") + 4;
                int end = exp.length();
                if (exp.substring(start).contains("&")) {
                    end = exp.indexOf("&");
                } else if (exp.substring(start).contains("?")) {
                    end = exp.indexOf("?");
                }
                try {
                    imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg";
                } catch (Exception e) {
                    imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, exp.length() - 1)
                            + "/hqdefault.jpg";
                }
                otherUrl += exp + "  ";
            } else if (str.contains("twitpic")) {
                int start = exp.indexOf(".com/") + 5;
                imageUrl = "http://twitpic.com/show/full/" + exp.substring(start).replace("/", "");
                otherUrl += exp + "  ";
            } else if (str.contains("i.imgur") && !str.contains("/a/")) {
                int start = exp.indexOf(".com/") + 5;
                imageUrl = "http://i.imgur.com/" + exp.replace("http://i.imgur.com/", "").replace(".jpg", "")
                        + "l.jpg";
                imageUrl = imageUrl.replace("gallery/", "");
                otherUrl += exp + "  ";
            } else if (str.contains("imgur") && !str.contains("/a/")) {
                int start = exp.indexOf(".com/") + 6;
                imageUrl = "http://i.imgur.com/" + exp.replace("http://imgur.com/", "").replace(".jpg", "")
                        + "l.jpg";
                imageUrl = imageUrl.replace("gallery/", "").replace("a/", "");
                otherUrl += exp + "  ";
            } else if (str.contains("pbs.twimg.com")) {
                imageUrl = exp;
                otherUrl += exp + "  ";
            } else if (str.contains("ow.ly/i/")) {
                imageUrl = "http://static.ow.ly/photos/original/"
                        + exp.substring(exp.lastIndexOf("/")).replaceAll("/", "") + ".jpg";
                otherUrl += exp + "  ";
            } else if (str.contains("p.twipple.jp")) {
                imageUrl = "http://p.twipple.jp/show/large/" + exp.replace("p.twipple.jp/", "")
                        .replace("http://", "").replace("https://", "").replace("www.", "");
                otherUrl += exp + "  ";
            } else if (str.contains(".jpg") || str.contains(".png")) {
                imageUrl = exp;
                otherUrl += exp + "  ";
            } else if (str.contains("img.ly")) {
                imageUrl = exp.replace("https", "http").replace("http://img.ly/", "http://img.ly/show/large/");
                otherUrl += exp + "  ";
            } else {
                otherUrl += exp + "  ";
            }
        }
    }

    for (int i = 0; i < sMediaComp.length; i++) {
        String comp = sMediaComp[i];
        String exp = sMediaExp[i];

        if (comp.length() > 1 && exp.length() > 1) {
            try {
                String replacement = sMediaDisplay[i].replace("http://", "").replace("https://", "")
                        .replace("www.", "");

                boolean hasCom = replacement.contains(".com");
                replacement = replacement.substring(0, 22) + "...";

                if (hasCom && !replacement.contains(".com")) { // the link was too long...
                    replacement = sMediaDisplay[i].replace("http://", "").replace("https://", "")
                            .replace("www.", "");
                    replacement = replacement.substring(0, replacement.indexOf(".com") + 6) + "...";
                }

                tweetTexts = tweetTexts.replace(comp, replacement);
            } catch (Exception e) {
                tweetTexts = tweetTexts.replace(comp,
                        sMediaDisplay[i].replace("http://", "").replace("https://", "").replace("www.", ""));
            }
            imageUrl = status.getMediaEntities()[0].getMediaURL();

            for (MediaEntity m : status.getExtendedMediaEntities()) {
                if (m.getType().equals("photo")) {
                    if (!imageUrl.contains(m.getMediaURL())) {
                        imageUrl += " " + m.getMediaURL();
                    }
                }
            }

            otherUrl += sMediaDisplay[i];
        }
    }

    return new String[] { tweetTexts, imageUrl, otherUrl, mHashtags, mUsers };
}

From source file:com.datatorrent.contrib.twitter.TwitterSampleInput.java

License:Open Source License

@Override
public void emitTuples() {
    for (int size = statuses.size(); size-- > 0;) {
        Status s = statuses.poll();
        if (status.isConnected()) {
            status.emit(s);/* ww  w . j  a  v a2  s .co  m*/
        }

        if (text.isConnected()) {
            text.emit(s.getText());
        }

        if (url.isConnected()) {
            URLEntity[] entities = s.getURLEntities();
            if (entities != null) {
                for (URLEntity ue : entities) {
                    url.emit((ue.getExpandedURL() == null ? ue.getURL() : ue.getExpandedURL()).toString());
                }
            }
        }

        if (hashtag.isConnected()) {
            HashtagEntity[] hashtagEntities = s.getHashtagEntities();
            if (hashtagEntities != null) {
                for (HashtagEntity he : hashtagEntities) {
                    hashtag.emit(he.getText());
                }
            }
        }
    }
}

From source file:com.datatorrent.demos.twitter.TwitterSampleInput.java

License:Open Source License

@Override
public void emitTuples() {
    for (int size = statuses.size(); size-- > 0;) {
        Status s = statuses.poll();
        if (status.isConnected()) {
            status.emit(s);/*from w w w . j a va 2  s  .  c  o m*/
        }

        if (text.isConnected()) {
            text.emit(s.getText());
        }

        if (url.isConnected()) {
            URLEntity[] entities = s.getURLEntities();
            if (entities != null) {
                for (URLEntity ue : entities) {
                    url.emit((ue.getExpandedURL() == null ? ue.getURL() : ue.getExpandedURL()).toString());
                }
            }
        }
        // do the same thing for all the other output ports.
    }
}