Example usage for twitter4j HashtagEntity getText

List of usage examples for twitter4j HashtagEntity getText

Introduction

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

Prototype

@Override
String getText();

Source Link

Document

Returns the text of the hashtag without #.

Usage

From source file:com.klinker.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   www .  j  a va 2s  .c  o  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 {
                tweetTexts = tweetTexts.replace(comp,
                        exp.replace("http://", "").replace("https://", "").replace("www.", "").substring(0, 30)
                                + "...");
            } 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=m";
                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)
                            + "/mqefault.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", "")
                        + "m.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", "")
                        + "m.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 {
                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 {
                tweetTexts = tweetTexts.replace(comp, sMediaDisplay[i].replace("http://", "")
                        .replace("https://", "").replace("www.", "").substring(0, 22) + "...");
            } 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.klinker.android.twitter.utils.TweetLinkUtils.java

License:Apache License

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

    for (UserMentionEntity name : users) {
        String n = name.getScreenName();
        if (n.length() > 1) {
            mUsers += n + "  ";
        }//  www  .j av  a 2 s  .  c om
    }

    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[] sMediaDisply;

    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 {
        sMediaDisply = mediaDisplay.split("  ");
    } catch (Exception e) {
        sMediaDisply = 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();

            tweetTexts = tweetTexts.replace(comp,
                    exp.replace("http://", "").replace("https://", "").replace("www.", ""));

            if (str.contains("instag") && !str.contains("blog.instag")) {
                imageUrl = exp + "media/?size=m";
                otherUrl += exp + "  ";
            } else if (str.contains("youtub") && !(str.contains("channel") || str.contains("user"))) { // normal youtube link
                // 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("?");
                }
                imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, end) + "/hqdefault.jpg";
                otherUrl += exp + "  ";
            } else if (str.contains("youtu.be")) { // shortened youtube link
                // 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("?");
                }
                imageUrl = "http://img.youtube.com/vi/" + exp.substring(start, end) + "/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("imgur") && !str.contains("/a/")) {
                int start = exp.indexOf(".com/") + 6;
                imageUrl = "http://i.imgur.com/" + exp.substring(start) + "m.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")) {
                Log.v("talon_owly", exp);
                imageUrl = "http://static.ow.ly/photos/original/"
                        + exp.substring(exp.lastIndexOf("/")).replaceAll("/", "") + ".jpg";
                otherUrl += exp + "  ";
            } else if (str.contains(".jpg") || str.contains(".png")) {
                imageUrl = exp;
                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) {
            tweetTexts = tweetTexts.replace(comp, sMediaDisply[i]);
            /*try {
            tweetTexts = tweetTexts.replace(comp, exp.replace("http://", "").replace("https://", "").replace("www.", "").substring(0, 30) + "...");
            } catch (Exception e) {
            tweetTexts = tweetTexts.replace(comp, exp.replace("http://", "").replace("https://", "").replace("www.", ""));
            }*/
            imageUrl = status.getMediaEntities()[0].getMediaURL();
            otherUrl += sMediaDisply[i];
        }
    }

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

From source file:com.lambda.stack.HashTagMapper.java

@Override
public Iterable<Tuple2<String, Integer>> call(Status t) throws Exception {
    List<Tuple2<String, Integer>> result = new LinkedList<>();

    for (HashtagEntity he : t.getHashtagEntities()) {
        result.add(new Tuple2<>(he.getText(), Integer.valueOf(1)));

    }/*from  w ww  .  j ava  2  s  . c  o m*/

    return result;
}

From source file:com.lambda.stack.HashTagUsageMapper.java

@Override
public Iterable<Tuple2<Tuple3<Integer, Integer, Integer>, Integer>> call(Tuple3<Status, Integer, Integer> t)
        throws Exception {
    List<Tuple2<Tuple3<Integer, Integer, Integer>, Integer>> result = new ArrayList<>();
    Set<String> tags = new HashSet<>();

    for (HashtagEntity he : t._1().getHashtagEntities()) {
        tags.add(he.getText());
    }//from  w w w .ja va 2 s . c  o  m

    DatabaseHelper dh = null;

    try {
        dh = DatabaseHelper.openDB();
        for (Object[] o : dh.listMonitoredTags()) {
            //if(tags.contains(o[0])){
            result.add(new Tuple2(new Tuple3(o[1], t._2(), t._3()), Integer.valueOf(1)));
            //}
        }
    } catch (SQLException e) {
        if (dh != null)
            dh.close();
    }

    return result;
}

From source file:com.mothsoft.alexis.engine.retrieval.TwitterRetrievalTaskImpl.java

License:Apache License

private List<TweetHashtag> readHashtags(Status status) {
    final List<TweetHashtag> hashtags = new ArrayList<TweetHashtag>();

    if (status.getHashtagEntities() != null) {
        for (final HashtagEntity entity : status.getHashtagEntities()) {

            final TweetHashtag hashtag = new TweetHashtag((short) entity.getStart(), (short) entity.getEnd(),
                    entity.getText());
            hashtags.add(hashtag);//from   w  w  w  . j  a  v  a  2  s  .co m
        }
    }

    return hashtags;
}

From source file:com.raythos.sentilexo.twitter.utils.StatusArraysHelper.java

public static List<String> getHashTagsList(Status status) {
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
    List<String> result = new ArrayList<>();
    for (HashtagEntity h : status.getHashtagEntities()) {
        result.add(h.getText().toLowerCase());
    }/* w w w. j a  v a  2s. c o  m*/
    return result;
}

From source file:com.twitstreet.twitter.AdsListenerMgrImpl.java

License:Open Source License

private static String constructAdsMessage(String screenName, HashtagEntity[] hashtagEntities, String lang) {
    String message = "@" + screenName;
    for (HashtagEntity hashtagEntity : hashtagEntities) {
        message += " #" + hashtagEntity.getText();
    }//from ww w.ja  v a  2s .  co m
    return message + " " + getRandomMessage(lang);
}

From source file:com.twitter.graphjet.demo.TwitterStreamReader.java

License:Open Source License

public static void main(String[] argv) throws Exception {
    final TwitterStreamReaderArgs args = new TwitterStreamReaderArgs();

    CmdLineParser parser = new CmdLineParser(args, ParserProperties.defaults().withUsageWidth(90));

    try {//w  w  w. j ava 2s .c om
        parser.parseArgument(argv);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        parser.printUsage(System.err);
        return;
    }

    final Date demoStart = new Date();
    final MultiSegmentPowerLawBipartiteGraph userTweetBigraph = new MultiSegmentPowerLawBipartiteGraph(
            args.maxSegments, args.maxEdgesPerSegment, args.leftSize, args.leftDegree,
            args.leftPowerLawExponent, args.rightSize, args.rightDegree, args.rightPowerLawExponent,
            new IdentityEdgeTypeMask(), new NullStatsReceiver());

    final MultiSegmentPowerLawBipartiteGraph tweetHashtagBigraph = new MultiSegmentPowerLawBipartiteGraph(
            args.maxSegments, args.maxEdgesPerSegment, args.leftSize, args.leftDegree,
            args.leftPowerLawExponent, args.rightSize, args.rightDegree, args.rightPowerLawExponent,
            new IdentityEdgeTypeMask(), new NullStatsReceiver());

    // Note that we're keeping track of the nodes on the left and right sides externally, apart from the bigraphs,
    // because the bigraph currently does not provide an API for enumerating over nodes. Currently, this is liable to
    // running out of memory, but this is fine for the demo.
    Long2ObjectOpenHashMap<String> users = new Long2ObjectOpenHashMap<>();
    LongOpenHashSet tweets = new LongOpenHashSet();
    Long2ObjectOpenHashMap<String> hashtags = new Long2ObjectOpenHashMap<>();
    // It is accurate of think of these two data structures as holding all users and tweets observed on the stream since
    // the demo program was started.

    StatusListener listener = new StatusListener() {
        long statusCnt = 0;

        public void onStatus(Status status) {

            String screenname = status.getUser().getScreenName();
            long userId = status.getUser().getId();
            long tweetId = status.getId();
            long resolvedTweetId = status.isRetweet() ? status.getRetweetedStatus().getId() : status.getId();
            HashtagEntity[] hashtagEntities = status.getHashtagEntities();

            userTweetBigraph.addEdge(userId, resolvedTweetId, (byte) 0);

            if (!users.containsKey(userId)) {
                users.put(userId, screenname);
            }

            if (!tweets.contains(tweetId)) {
                tweets.add(tweetId);
            }
            if (!tweets.contains(resolvedTweetId)) {
                tweets.add(resolvedTweetId);
            }

            for (HashtagEntity entity : hashtagEntities) {
                long hashtagHash = (long) entity.getText().toLowerCase().hashCode();
                tweetHashtagBigraph.addEdge(tweetId, hashtagHash, (byte) 0);
                if (!hashtags.containsKey(hashtagHash)) {
                    hashtags.put(hashtagHash, entity.getText().toLowerCase());
                }
            }

            statusCnt++;

            // Note that status updates are currently performed synchronously (i.e., blocking). Best practices dictate that
            // they should happen on another thread so as to not interfere with ingest, but this is okay for the pruposes
            // of the demo and the volume of the sample stream.

            // Minor status update: just print counters.
            if (statusCnt % args.minorUpdateInterval == 0) {
                long duration = (new Date().getTime() - demoStart.getTime()) / 1000;

                System.out.println(String.format(
                        "%tc: %,d statuses, %,d unique tweets, %,d unique hashtags (observed); "
                                + "%.2f edges/s; totalMemory(): %,d bytes, freeMemory(): %,d bytes",
                        new Date(), statusCnt, tweets.size(), hashtags.size(), (float) statusCnt / duration,
                        Runtime.getRuntime().totalMemory(), Runtime.getRuntime().freeMemory()));
            }

            // Major status update: iterate over right and left nodes.
            if (statusCnt % args.majorUpdateInterval == 0) {
                int leftCnt = 0;
                LongIterator leftIter = tweets.iterator();
                while (leftIter.hasNext()) {
                    if (userTweetBigraph.getLeftNodeDegree(leftIter.nextLong()) != 0)
                        leftCnt++;
                }

                int rightCnt = 0;
                LongIterator rightIter = hashtags.keySet().iterator();
                while (rightIter.hasNext()) {
                    if (userTweetBigraph.getRightNodeDegree(rightIter.nextLong()) != 0)
                        rightCnt++;
                }
                System.out.println(String.format("%tc: Current user-tweet graph state: %,d left nodes (users), "
                        + "%,d right nodes (tweets)", new Date(), leftCnt, rightCnt));
            }
        }

        public void onScrubGeo(long userId, long upToStatusId) {
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        public void onStallWarning(StallWarning warning) {
        }

        public void onException(Exception e) {
            e.printStackTrace();
        }
    };

    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.addListener(listener);
    twitterStream.sample();

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");

    Server jettyServer = new Server(args.port);
    jettyServer.setHandler(context);

    context.addServlet(new ServletHolder(new TopUsersServlet(userTweetBigraph, users)),
            "/userTweetGraph/topUsers");
    context.addServlet(
            new ServletHolder(
                    new TopTweetsServlet(userTweetBigraph, tweets, TopTweetsServlet.GraphType.USER_TWEET)),
            "/userTweetGraph/topTweets");
    context.addServlet(new ServletHolder(
            new TopTweetsServlet(tweetHashtagBigraph, tweets, TopTweetsServlet.GraphType.TWEET_HASHTAG)),
            "/tweetHashtagGraph/topTweets");
    context.addServlet(new ServletHolder(new TopHashtagsServlet(tweetHashtagBigraph, hashtags)),
            "/tweetHashtagGraph/topHashtags");
    context.addServlet(new ServletHolder(new GetEdgesServlet(userTweetBigraph, GetEdgesServlet.Side.LEFT)),
            "/userTweetGraphEdges/users");
    context.addServlet(new ServletHolder(new GetEdgesServlet(userTweetBigraph, GetEdgesServlet.Side.RIGHT)),
            "/userTweetGraphEdges/tweets");
    context.addServlet(new ServletHolder(new GetEdgesServlet(tweetHashtagBigraph, GetEdgesServlet.Side.LEFT)),
            "/tweetHashtagGraphEdges/tweets");
    context.addServlet(new ServletHolder(new GetEdgesServlet(tweetHashtagBigraph, GetEdgesServlet.Side.RIGHT)),
            "/tweetHashtagGraphEdges/hashtags");
    context.addServlet(new ServletHolder(new GetSimilarHashtagsServlet(tweetHashtagBigraph, hashtags)),
            "/similarHashtags");

    System.out.println(String.format("%tc: Starting service on port %d", new Date(), args.port));
    try {
        jettyServer.start();
        jettyServer.join();
    } finally {
        jettyServer.destroy();
    }
}

From source file:com.wso2.stream.connector.protocol.TweetContent.java

License:Open Source License

public OMElement createBodyContent(OMFactory omFactory, Status status) {
    OMElement tweet = omFactory.createOMElement(qTweet);

    OMElement text = omFactory.createOMElement(qText);
    tweet.addChild(text);/*  w  ww .  j  a  va2s.  c o m*/
    text.addChild(omFactory.createOMText(status.getText()));

    OMElement createdAt = omFactory.createOMElement(qCreatedAt);
    tweet.addChild(createdAt);
    createdAt.addChild(omFactory.createOMText(status.getCreatedAt().toString()));

    OMElement latitude = omFactory.createOMElement(qLatitude);
    tweet.addChild(latitude);
    OMElement longitude = omFactory.createOMElement(qLongitude);
    tweet.addChild(longitude);
    if (status.getGeoLocation() != null) {
        latitude.addChild(omFactory.createOMText(String.valueOf(status.getGeoLocation().getLatitude())));
        longitude.addChild(omFactory.createOMText(String.valueOf(status.getGeoLocation().getLongitude())));
    }

    OMElement country = omFactory.createOMElement(qCountry);
    tweet.addChild(country);
    OMElement countryCode = omFactory.createOMElement(qCountryCode);
    tweet.addChild(countryCode);

    if (status.getPlace() != null) {
        country.addChild(omFactory.createOMText(status.getPlace().getCountry()));
        countryCode.addChild(omFactory.createOMText(status.getPlace().getCountryCode()));
    }

    OMElement location = omFactory.createOMElement(qLocation);
    tweet.addChild(location);
    if (status.getUser() != null) {
        location.addChild(omFactory.createOMText(status.getUser().getLocation()));
    }

    OMElement hashTags = omFactory.createOMElement(qHasTags);
    tweet.addChild(hashTags);

    if (status.getHashtagEntities().length > 0) {
        String tags = "";
        for (HashtagEntity h : status.getHashtagEntities()) {
            tags += h.getText() + ";";
        }
        tags = tags.substring(0, tags.length() - 1);
        hashTags.addChild(omFactory.createOMText(tags));
    }

    return tweet;

}

From source file:crawler.DataStorage.java

License:Apache License

private static void sqlStore(Status status) throws SQLException {
    long sql_pid = Settings.pid;
    Settings.pid++;//from w ww. j a v a  2 s  .c  o  m

    SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd, HH:mm:ss, z");
    String sqlCreateAt = tempDate.format(new java.util.Date(status.getCreatedAt().getTime()));

    double sqlGeoLocationLat = 0;
    double sqlGeoLocationLong = 0;

    if (status.getGeoLocation() != null) {
        sqlGeoLocationLat = status.getGeoLocation().getLatitude();
        sqlGeoLocationLong = status.getGeoLocation().getLongitude();
    }

    String sqlPlace = (status.getPlace() != null ? status.getPlace().getFullName() : "");
    long sqlId = status.getId();
    String sqlTweet = status.getText().replace("'", "''");
    String sqlSource = status.getSource().replace("'", "''");
    sqlSource = sqlSource.replace("\\", "\\\\");
    String sqlLang = status.getUser().getLang();
    String sqlScreenName = status.getUser().getScreenName();
    String sqlReplyTo = status.getInReplyToScreenName();
    long sqlRtCount = status.getRetweetCount();

    HashtagEntity[] hashs = status.getHashtagEntities();
    String sqlHashtags = "";
    for (HashtagEntity hash : hashs)
        sqlHashtags += hash.getText() + " ";

    pstm.setLong(1, sql_pid);
    pstm.setString(2, sqlCreateAt);
    pstm.setDouble(3, sqlGeoLocationLat);
    pstm.setDouble(4, sqlGeoLocationLong);
    pstm.setString(5, sqlPlace);
    pstm.setLong(6, sqlId);
    pstm.setString(7, sqlTweet);
    pstm.setString(8, sqlSource);
    pstm.setString(9, sqlLang);
    pstm.setString(10, sqlScreenName);
    pstm.setString(11, sqlReplyTo);
    pstm.setLong(12, sqlRtCount);
    pstm.setString(13, sqlHashtags);

    pstm.addBatch();
}