Example usage for twitter4j Status getURLEntities

List of usage examples for twitter4j Status getURLEntities

Introduction

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

Prototype

URLEntity[] getURLEntities();

Source Link

Document

Returns an array if URLEntity mentioned in the tweet.

Usage

From source file:net.nokok.twitduke.core.twitter.StatusParser.java

License:Open Source License

/**
 * ???URL????/*  w ww.  j  a  v a  2s  .c  o m*/
 *
 * @param status 
 *
 * @return URL?
 */
public List<URLEntity> createURLEntityList(Status status) {
    return Stream.of(status.getURLEntities()).collect(Collectors.toCollection(ArrayList::new));
}

From source file:nl.isaac.dotcms.twitter.pojo.CustomStatus.java

License:Creative Commons License

public CustomStatus(Status status) {
    this.createdAt = status.getCreatedAt();
    this.id = status.getId();
    this.id_str = String.valueOf(status.getId());
    this.text = status.getText();
    this.source = status.getSource();
    this.isTruncated = status.isTruncated();
    this.inReplyToStatusId = status.getInReplyToStatusId();
    this.inReplyToUserId = status.getInReplyToUserId();
    this.isFavorited = status.isFavorited();
    this.inReplyToScreenName = status.getInReplyToScreenName();
    this.geoLocation = status.getGeoLocation();
    this.place = status.getPlace();
    this.retweetCount = status.getRetweetCount();
    this.isPossiblySensitive = status.isPossiblySensitive();

    this.contributorsIDs = status.getContributors();

    this.retweetedStatus = status.getRetweetedStatus();
    this.userMentionEntities = status.getUserMentionEntities();
    this.urlEntities = status.getURLEntities();
    this.hashtagEntities = status.getHashtagEntities();
    this.mediaEntities = status.getMediaEntities();
    this.currentUserRetweetId = status.getCurrentUserRetweetId();

    this.isRetweet = status.isRetweet();
    this.isRetweetedByMe = status.isRetweetedByMe();

    this.rateLimitStatus = status.getRateLimitStatus();
    this.accessLevel = status.getAccessLevel();
    this.user = status.getUser();
}

From source file:nz.net.speakman.android.dreamintweets.twitterstream.TwitterStreamAdapter.java

License:Apache License

private Spanned getTweetText(Status tweet) {
    String text = tweet.getText();

    for (URLEntity urlEntity : tweet.getURLEntities()) {
        text = text.replace(urlEntity.getURL(), getClickableUrl(urlEntity));
    }//from  ww w .j  ava  2  s . co  m

    for (MediaEntity mediaEntity : tweet.getMediaEntities()) {
        // TODO Optionally load images into stream
        text = text.replace(mediaEntity.getURL(), getClickableMedia(mediaEntity));
    }

    //        for (HashtagEntity hashtagEntity : tweet.getHashtagEntities()) {
    //            // TODO Make clickable
    //        }
    return Html.fromHtml(text);
}

From source file:org.codice.ddf.catalog.twitter.source.TwitterSource.java

License:Open Source License

private Metacard getMetacard(Status status) {
    MetacardImpl metacard = new MetacardImpl();
    metacard.setSourceId(id);// www  . j  av  a  2 s.  co m
    metacard.setId(String.valueOf(status.getId()));
    metacard.setTitle(status.getText());
    metacard.setMetadata("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<Resource>"
            + "<name>" + status.getText() + "</name>" + "</Resource>");
    metacard.setCreatedDate(status.getCreatedAt());
    metacard.setModifiedDate(status.getCreatedAt());
    metacard.setEffectiveDate(status.getCreatedAt());
    metacard.setPointOfContact(status.getUser().getName());
    if (status.getURLEntities() != null && status.getURLEntities().length > 0) {
        try {
            metacard.setResourceURI(new URI(status.getURLEntities()[0].getExpandedURL()));
        } catch (URISyntaxException e) {
            LOGGER.error("Unable to set resource URI.", e);
        }
    } else if (status.getMediaEntities() != null && status.getMediaEntities().length > 0) {
        try {
            metacard.setResourceURI(new URI(status.getMediaEntities()[0].getExpandedURL()));
        } catch (URISyntaxException e) {
            LOGGER.error("Unable to set resource URI.", e);
        }
    } else if (status.getExtendedMediaEntities() != null && status.getExtendedMediaEntities().length > 0) {
        try {
            metacard.setResourceURI(new URI(status.getExtendedMediaEntities()[0].getExpandedURL()));
        } catch (URISyntaxException e) {
            LOGGER.error("Unable to set resource URI.", e);
        }
    }
    GeoLocation geoLocation = status.getGeoLocation();
    if (geoLocation != null) {
        metacard.setLocation("POINT (" + geoLocation.getLongitude() + " " + geoLocation.getLatitude() + ")");
    }

    return metacard;
}

From source file:org.gabrielebaldassarre.twitter.stream.tweet.TalendRowTweetBehaviour.java

License:Open Source License

public void visit(TalendFlow target) {
    ResourceBundle rb = ResourceBundle.getBundle("tTwitterStreamInput", Locale.getDefault());
    valid = false;//from  ww w  .j  a  v a  2s .c om

    if (status != null) {

        TalendRowFactory rowFactory = target.getModel().getRowFactory();
        Status tweet = status;
        status = null;
        TalendRow current = rowFactory.newRow(target);

        Iterator<Entry<TalendColumn, TweetField>> col = associations.entrySet().iterator();
        while (col.hasNext()) {
            List<String> h;
            List<Long> l;

            Map.Entry<TalendColumn, TweetField> row = (Map.Entry<TalendColumn, TweetField>) col.next();

            if (target != null && !row.getKey().getFlow().equals(target)) {
                throw new IllegalArgumentException(String.format(rb.getString("exception.columnNotInFlow"),
                        row.getKey().getName(), target.getName()));
            }

            switch (row.getValue()) {
            case CREATION_DATE:
                String literalDate = (new StringBuilder(
                        TalendRowTweetBehaviour.DATEFORMAT.format(tweet.getCreatedAt()))).toString();

                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(literalDate));
                case LONG:
                    current.setValue(row.getKey(), Long.parseLong(literalDate));
                case DOUBLE:
                    current.setValue(row.getKey(), Double.parseDouble(literalDate));
                case FLOAT:
                    current.setValue(row.getKey(), Float.parseFloat(literalDate));
                case INTEGER:
                    current.setValue(row.getKey(), Integer.parseInt(literalDate));
                case DATE:
                    current.setValue(row.getKey(), tweet.getCreatedAt());
                    break;
                case STRING:
                    current.setValue(row.getKey(), literalDate);
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case FROM_NAME:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getUser().getName());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case FROM_USERID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getUser().getId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getUser().getId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getUser().getId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getUser().getId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getUser().getId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case FROM_SCREEN_NAME:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getUser().getScreenName());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case HASHTAGS:
                List<HashtagEntity> hashtags = Arrays.asList(tweet.getHashtagEntities());
                h = new ArrayList<String>(hashtags.size());

                for (HashtagEntity hashtag : hashtags) {
                    h.add((includeHash() ? "#" : "") + hashtag.getText());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h
                            : Joiner.on(getEntitiesSeparator()).join(h));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case IS_FAVORITED:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.isFavorited() ? 1 : 0));
                    break;
                case BOOLEAN:
                    current.setValue(row.getKey(), tweet.isFavorited());
                    break;
                case BYTE:
                    current.setValue(row.getKey(), (byte) (tweet.isFavorited() ? 1 : 0));
                    break;
                case CHARACTER:
                    current.setValue(row.getKey(), (tweet.isFavorited() ? '1' : '0'));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), (double) (tweet.isFavorited() ? 1d : 0d));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), (float) (tweet.isFavorited() ? 1f : 0f));
                    break;
                case INTEGER:
                    current.setValue(row.getKey(), (tweet.isFavorited() ? 1 : 0));
                    break;
                case LONG:
                    current.setValue(row.getKey(), (long) (tweet.isFavorited() ? 1l : 0l));
                    break;
                case SHORT:
                    current.setValue(row.getKey(), (short) (tweet.isFavorited() ? (short) 1 : (short) 0));
                    break;
                case STRING:
                    current.setValue(row.getKey(), (tweet.isFavorited() ? "1" : "0"));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));

                }
                break;
            case IS_POSSIBLY_SENSITIVE:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.isPossiblySensitive() ? 1 : 0));
                    break;
                case BOOLEAN:
                    current.setValue(row.getKey(), tweet.isPossiblySensitive());
                    break;
                case BYTE:
                    current.setValue(row.getKey(), (byte) (tweet.isPossiblySensitive() ? 1 : 0));
                    break;
                case CHARACTER:
                    current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? '1' : '0'));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), (double) (tweet.isPossiblySensitive() ? 1d : 0d));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), (float) (tweet.isPossiblySensitive() ? 1f : 0f));
                    break;
                case INTEGER:
                    current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? 1 : 0));
                    break;
                case LONG:
                    current.setValue(row.getKey(), (long) (tweet.isPossiblySensitive() ? 1l : 0l));
                    break;
                case SHORT:
                    current.setValue(row.getKey(),
                            (short) (tweet.isPossiblySensitive() ? (short) 1 : (short) 0));
                    break;
                case STRING:
                    current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? "1" : "0"));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case IS_RETWEET:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.isRetweet() ? 1 : 0));
                    break;
                case BOOLEAN:
                    current.setValue(row.getKey(), tweet.isRetweet());
                    break;
                case BYTE:
                    current.setValue(row.getKey(), (byte) (tweet.isRetweet() ? 1 : 0));
                    break;
                case CHARACTER:
                    current.setValue(row.getKey(), (tweet.isRetweet() ? '1' : '0'));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), (double) (tweet.isRetweet() ? 1d : 0d));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), (float) (tweet.isRetweet() ? 1f : 0f));
                    break;
                case INTEGER:
                    current.setValue(row.getKey(), (tweet.isRetweet() ? 1 : 0));
                    break;
                case LONG:
                    current.setValue(row.getKey(), (long) (tweet.isRetweet() ? 1l : 0l));
                    break;
                case SHORT:
                    current.setValue(row.getKey(), (short) (tweet.isRetweet() ? (short) 1 : (short) 0));
                    break;
                case STRING:
                    current.setValue(row.getKey(), (tweet.isRetweet() ? "1" : "0"));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                current.setValue(row.getKey(), tweet.isRetweet());
                break;
            case LOCATION:
                GeoLocation g = tweet.getGeoLocation();
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(),
                            g != null
                                    ? String.valueOf(g.getLatitude()) + getEntitiesSeparator()
                                            + String.valueOf(g.getLongitude())
                                    : null);
                    break;
                case OBJECT:
                    current.setValue(row.getKey(), g);
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case REPLYTO_SCREEN_NAME:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getInReplyToScreenName());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case REPLYTO_STATUSID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getInReplyToStatusId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getInReplyToStatusId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getInReplyToStatusId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getInReplyToStatusId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getInReplyToStatusId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case REPLYTO_USERID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getInReplyToUserId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getInReplyToUserId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getInReplyToUserId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getInReplyToUserId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getInReplyToUserId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case RETWEET_COUNT:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getRetweetCount()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getRetweetCount()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getRetweetCount()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getRetweetCount()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getRetweetCount())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case SOURCE:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getSource());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case STATUS_ID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case TEXT:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getText());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case URL_ENTITIES:
            case URL_ENTITIES_STRING:
                List<URLEntity> urlEntities = Arrays.asList(tweet.getURLEntities());
                h = new ArrayList<String>(urlEntities.size());

                for (URLEntity urlEntity : urlEntities) {
                    h.add(urlEntity.getExpandedURL());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h
                            : Joiner.on(getEntitiesSeparator()).join(h));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case USER_MENTIONS:
                List<UserMentionEntity> userMentionsEntities = Arrays.asList(tweet.getUserMentionEntities());
                l = new ArrayList<Long>(userMentionsEntities.size());

                for (UserMentionEntity userMention : userMentionsEntities) {
                    l.add(userMention.getId());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? l
                            : Joiner.on(getEntitiesSeparator()).join(l));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case USER_MENTIONS_SCREEN_NAME:
                List<UserMentionEntity> userMentionsScreen = Arrays.asList(tweet.getUserMentionEntities());
                h = new ArrayList<String>(userMentionsScreen.size());

                for (UserMentionEntity userMention : userMentionsScreen) {
                    h.add((includeHash() ? "@" : "") + userMention.getScreenName());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h
                            : Joiner.on(getEntitiesSeparator()).join(h));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            default:
                throw new IllegalArgumentException(
                        String.format(rb.getString("exception.unparseableColumn"), row.getKey().getName()));

            }
        }

    }

    valid = true;
}

From source file:org.gabrielebaldassarre.twitter.stream.tweet.TalendRowTweetBehaviour.java

License:Open Source License

private boolean filter(Status status) {

    if (filter_links && status.getURLEntities().length == 0)
        return false;

    if (excludes.length == 0 && froms.length == 0 && ats.length == 0)
        return true;

    HashtagEntity[] hashtagEntities = status.getHashtagEntities();
    List<String> hashtagEntityList = new ArrayList<String>();
    for (HashtagEntity hashtagEntity : hashtagEntities) {
        hashtagEntityList.add(hashtagEntity.getText());
    }//from   w w w.j  a v a2s  .  c  om

    if (this.twitterLogicalOperator.equals(TwitterQueryBuilderLogicalOperator.AND)) {

        for (String exclude : excludes) {
            if (status.getText().contains(exclude))
                return false;
        }

        for (String from : froms) {
            if (!status.getUser().getScreenName().equalsIgnoreCase(from))
                return false;
        }

        for (String at : ats) {
            if (!hashtagEntityList.contains(at))
                return false;
        }

    } else {
        for (String exclude : excludes) {
            if (!status.getText().contains(exclude))
                return true;
        }

        for (String from : froms) {
            if (status.getUser().getScreenName().equalsIgnoreCase(from))
                return true;
        }

        for (String at : ats) {
            if (hashtagEntityList.contains(at))
                return true;
        }

        return false;
    }

    return true;
}

From source file:org.gabrielebaldassarre.twitter.tweet.TalendFlowTweetBehaviour.java

License:Open Source License

/**
 * Visit a target {@link TalendFlow} for parsed or raw json output.
 * /*ww  w .  ja va 2  s.c o m*/
 * @param target the data flow to fill
 */
public void visit(TalendFlow target) {
    ResourceBundle rb = ResourceBundle.getBundle("tTwitterInput", Locale.getDefault());

    TalendRowFactory rowFactory = target.getModel().getRowFactory();
    valid = false;

    @SuppressWarnings("unchecked")
    List<Status> tweets = (List<Status>) resultSet.getValue();
    for (int i = 0; i < tweets.size(); i++) {
        Status tweet = tweets.get(i);
        TalendRow current = rowFactory.newRow(target);

        Iterator<Entry<TalendColumn, TweetField>> col = associations.entrySet().iterator();
        while (col.hasNext()) {
            List<String> h;
            List<Long> l;

            Map.Entry<TalendColumn, TweetField> row = (Map.Entry<TalendColumn, TweetField>) col.next();

            if (target != null && !row.getKey().getFlow().equals(target)) {
                throw new IllegalArgumentException(String.format(rb.getString("exception.columnNotInFlow"),
                        row.getKey().getName(), target.getName()));
            }

            switch (row.getValue()) {
            case CREATION_DATE:
                String literalDate = (new StringBuilder(
                        TalendFlowTweetBehaviour.DATEFORMAT.format(tweet.getCreatedAt()))).toString();

                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(literalDate));
                case LONG:
                    current.setValue(row.getKey(), Long.parseLong(literalDate));
                case DOUBLE:
                    current.setValue(row.getKey(), Double.parseDouble(literalDate));
                case FLOAT:
                    current.setValue(row.getKey(), Float.parseFloat(literalDate));
                case INTEGER:
                    current.setValue(row.getKey(), Integer.parseInt(literalDate));
                case DATE:
                    current.setValue(row.getKey(), tweet.getCreatedAt());
                    break;
                case STRING:
                    current.setValue(row.getKey(), literalDate);
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case FROM_NAME:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getUser().getName());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case FROM_USERID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getUser().getId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getUser().getId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getUser().getId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getUser().getId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getUser().getId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case FROM_SCREEN_NAME:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getUser().getScreenName());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case HASHTAGS:
                List<HashtagEntity> hashtags = Arrays.asList(tweet.getHashtagEntities());
                h = new ArrayList<String>(hashtags.size());

                for (HashtagEntity hashtag : hashtags) {
                    h.add((includeHash() ? "#" : "") + hashtag.getText());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h
                            : Joiner.on(getEntitiesSeparator()).join(h));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case IS_FAVORITED:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.isFavorited() ? 1 : 0));
                    break;
                case BOOLEAN:
                    current.setValue(row.getKey(), tweet.isFavorited());
                    break;
                case BYTE:
                    current.setValue(row.getKey(), (byte) (tweet.isFavorited() ? 1 : 0));
                    break;
                case CHARACTER:
                    current.setValue(row.getKey(), (tweet.isFavorited() ? '1' : '0'));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), (double) (tweet.isFavorited() ? 1d : 0d));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), (float) (tweet.isFavorited() ? 1f : 0f));
                    break;
                case INTEGER:
                    current.setValue(row.getKey(), (tweet.isFavorited() ? 1 : 0));
                    break;
                case LONG:
                    current.setValue(row.getKey(), (long) (tweet.isFavorited() ? 1l : 0l));
                    break;
                case SHORT:
                    current.setValue(row.getKey(), (short) (tweet.isFavorited() ? (short) 1 : (short) 0));
                    break;
                case STRING:
                    current.setValue(row.getKey(), (tweet.isFavorited() ? "1" : "0"));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));

                }
                break;
            case IS_POSSIBLY_SENSITIVE:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.isPossiblySensitive() ? 1 : 0));
                    break;
                case BOOLEAN:
                    current.setValue(row.getKey(), tweet.isPossiblySensitive());
                    break;
                case BYTE:
                    current.setValue(row.getKey(), (byte) (tweet.isPossiblySensitive() ? 1 : 0));
                    break;
                case CHARACTER:
                    current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? '1' : '0'));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), (double) (tweet.isPossiblySensitive() ? 1d : 0d));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), (float) (tweet.isPossiblySensitive() ? 1f : 0f));
                    break;
                case INTEGER:
                    current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? 1 : 0));
                    break;
                case LONG:
                    current.setValue(row.getKey(), (long) (tweet.isPossiblySensitive() ? 1l : 0l));
                    break;
                case SHORT:
                    current.setValue(row.getKey(),
                            (short) (tweet.isPossiblySensitive() ? (short) 1 : (short) 0));
                    break;
                case STRING:
                    current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? "1" : "0"));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case IS_RETWEET:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.isRetweet() ? 1 : 0));
                    break;
                case BOOLEAN:
                    current.setValue(row.getKey(), tweet.isRetweet());
                    break;
                case BYTE:
                    current.setValue(row.getKey(), (byte) (tweet.isRetweet() ? 1 : 0));
                    break;
                case CHARACTER:
                    current.setValue(row.getKey(), (tweet.isRetweet() ? '1' : '0'));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), (double) (tweet.isRetweet() ? 1d : 0d));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), (float) (tweet.isRetweet() ? 1f : 0f));
                    break;
                case INTEGER:
                    current.setValue(row.getKey(), (tweet.isRetweet() ? 1 : 0));
                    break;
                case LONG:
                    current.setValue(row.getKey(), (long) (tweet.isRetweet() ? 1l : 0l));
                    break;
                case SHORT:
                    current.setValue(row.getKey(), (short) (tweet.isRetweet() ? (short) 1 : (short) 0));
                    break;
                case STRING:
                    current.setValue(row.getKey(), (tweet.isRetweet() ? "1" : "0"));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                current.setValue(row.getKey(), tweet.isRetweet());
                break;
            case LOCATION:
                GeoLocation g = tweet.getGeoLocation();
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(),
                            g != null
                                    ? String.valueOf(g.getLatitude()) + getEntitiesSeparator()
                                            + String.valueOf(g.getLongitude())
                                    : null);
                    break;
                case OBJECT:
                    current.setValue(row.getKey(), g);
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case REPLYTO_SCREEN_NAME:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getInReplyToScreenName());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case REPLYTO_STATUSID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getInReplyToStatusId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getInReplyToStatusId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getInReplyToStatusId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getInReplyToStatusId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getInReplyToStatusId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case REPLYTO_USERID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getInReplyToUserId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getInReplyToUserId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getInReplyToUserId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getInReplyToUserId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getInReplyToUserId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case RETWEET_COUNT:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getRetweetCount()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getRetweetCount()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getRetweetCount()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getRetweetCount()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getRetweetCount())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case SOURCE:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getSource());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case STATUS_ID:
                switch (row.getKey().getType()) {
                case BIGDECIMAL:
                    current.setValue(row.getKey(), new BigDecimal(tweet.getId()));
                    break;
                case DOUBLE:
                    current.setValue(row.getKey(), new Double(tweet.getId()));
                    break;
                case FLOAT:
                    current.setValue(row.getKey(), new Float(tweet.getId()));
                    break;
                case LONG:
                    current.setValue(row.getKey(), new Long(tweet.getId()));
                    break;
                case STRING:
                    current.setValue(row.getKey(), String.valueOf((tweet.getId())));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case TEXT:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), tweet.getText());
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case URL_ENTITIES:
            case URL_ENTITIES_STRING:
                List<URLEntity> urlEntities = Arrays.asList(tweet.getURLEntities());
                h = new ArrayList<String>(urlEntities.size());

                for (URLEntity urlEntity : urlEntities) {
                    h.add(urlEntity.getExpandedURL());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h
                            : Joiner.on(getEntitiesSeparator()).join(h));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case USER_MENTIONS:
                List<UserMentionEntity> userMentionsEntities = Arrays.asList(tweet.getUserMentionEntities());
                l = new ArrayList<Long>(userMentionsEntities.size());

                for (UserMentionEntity userMention : userMentionsEntities) {
                    l.add(userMention.getId());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? l
                            : Joiner.on(getEntitiesSeparator()).join(l));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case USER_MENTIONS_SCREEN_NAME:
                List<UserMentionEntity> userMentionsScreen = Arrays.asList(tweet.getUserMentionEntities());
                h = new ArrayList<String>(userMentionsScreen.size());

                for (UserMentionEntity userMention : userMentionsScreen) {
                    h.add((includeHash() ? "@" : "") + userMention.getScreenName());
                }
                switch (row.getKey().getType()) {
                case STRING:
                case LIST:
                    current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h
                            : Joiner.on(getEntitiesSeparator()).join(h));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            case JSON:
                switch (row.getKey().getType()) {
                case STRING:
                    current.setValue(row.getKey(), DataObjectFactory.getRawJSON(tweet));
                    break;
                default:
                    throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"),
                            row.getKey().getType().getTypeString(), row.getKey().getName()));
                }
                break;
            default:
                throw new IllegalArgumentException(
                        String.format(rb.getString("exception.unparseableColumn"), row.getKey().getName()));

            }

        }

    }
    valid = true;
}

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

License:Open Source License

public static String getSupportedFirstLink(final Status status) {
    if (status == null)
        return null;
    final MediaEntity[] mediaEntities = status.getMediaEntities();
    if (mediaEntities != null) {
        for (final MediaEntity mediaEntity : mediaEntities) {
            final String expanded = mediaEntity.getMediaURLHttps();
            if (getSupportedLink(expanded) != null)
                return expanded;
        }//from   w w w.ja va  2  s  .  c  om
    }
    final URLEntity[] urlEntities = status.getURLEntities();
    if (urlEntities != null) {
        for (final URLEntity urlEntity : urlEntities) {
            final String expanded = urlEntity.getExpandedURL();
            if (getSupportedLink(expanded) != null)
                return expanded;
        }
    }
    return null;
}

From source file:org.mariotaku.twidere.extension.streaming.util.MediaPreviewUtils.java

License:Open Source License

public static String getSupportedFirstLink(final Status status) {
    if (status == null)
        return null;
    final MediaEntity[] medias = status.getMediaEntities();
    if (medias != null) {
        for (final MediaEntity entity : medias) {
            final String expanded = ParseUtils.parseString(entity.getMediaURLHttps());
            if (getSupportedLink(expanded) != null)
                return expanded;
        }/*from  www . j  a  va2  s  .  com*/
    }
    final URLEntity[] urls = status.getURLEntities();
    if (urls != null) {
        for (final URLEntity entity : urls) {
            final String expanded = ParseUtils.parseString(entity.getExpandedURL());
            if (getSupportedLink(expanded) != null)
                return expanded;
        }
    }
    return null;
}

From source file:org.nsoft.openbus.model.Mensagem.java

License:Open Source License

private static JSONObject createAddtions(Status s) throws JSONException {
    JSONObject json = new JSONObject();

    Vector<String> metions = new Vector<String>();
    UserMentionEntity[] in_metions = s.getUserMentionEntities();
    if (in_metions != null) {
        for (UserMentionEntity metion : in_metions) {
            metions.add(metion.getName());
        }// w w w. j a  v a  2  s .  c o  m
    }

    URLEntity[] urls = s.getURLEntities();

    Vector<String> image_files = new Vector<String>();
    MediaEntity[] in_medias = s.getMediaEntities();
    if (in_medias != null) {
        for (MediaEntity media : in_medias) {
            image_files.add(media.getMediaURL().toString());
        }
    }

    json.put("metions", metions);
    json.put("image_files", metions);

    json.put("inReplyId", s.getInReplyToStatusId());
    return json;

}