List of usage examples for twitter4j Status isFavorited
boolean isFavorited();
From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java
License:Apache License
public static TwitterQueryResultItemAvro mapItem(String queryOwner, String queryName, String queryString, Status status) { TwitterQueryResultItemAvro result = new TwitterQueryResultItemAvro(); if (queryName != null) queryName = queryName.toLowerCase(); if (queryOwner != null) queryOwner = queryOwner.toLowerCase(); result.setQueryName(queryName);/*from w w w. jav a 2 s . c o m*/ result.setQueryOwner(queryOwner); result.setQuery(queryString); result.setStatusId(status.getId()); result.setText(status.getText()); result.setRelevantQueryTerms(TwitterUtils.relevantQueryTermsFromStatus(queryString, status)); result.setLang(status.getLang()); result.setCreatedAt(status.getCreatedAt().getTime()); User user = status.getUser(); result.setUserId(user.getId()); result.setScreenName(user.getScreenName()); result.setUserLocation(user.getLocation()); result.setUserName(user.getName()); result.setUserDescription(user.getDescription()); result.setUserIsProtected(user.isProtected()); result.setUserFollowersCount(user.getFollowersCount()); result.setUserCreatedAt(user.getCreatedAt().getTime()); result.setUserCreatedAtAsString(DateTimeUtils.getDateAsText(user.getCreatedAt())); result.setCreatedAtAsString(DateTimeUtils.getDateAsText(status.getCreatedAt())); result.setUserFriendsCount(user.getFriendsCount()); result.setUserListedCount(user.getListedCount()); result.setUserStatusesCount(user.getStatusesCount()); result.setUserFavoritesCount(user.getFavouritesCount()); result.setCurrentUserRetweetId(status.getCurrentUserRetweetId()); result.setInReplyToScreenName(status.getInReplyToScreenName()); result.setInReplyToStatusId(status.getInReplyToStatusId()); result.setInReplyToUserId(status.getInReplyToUserId()); if (status.getGeoLocation() != null) { result.setLatitude(status.getGeoLocation().getLatitude()); result.setLongitude(status.getGeoLocation().getLongitude()); } result.setSource(status.getSource()); result.setTrucated(status.isTruncated()); result.setPossiblySensitive(status.isPossiblySensitive()); result.setRetweet(status.getRetweetedStatus() != null); if (result.getRetweet()) { result.setRetweetStatusId(status.getRetweetedStatus().getId()); result.setRetweetedText(status.getRetweetedStatus().getText()); } result.setRetweeted(status.isRetweeted()); result.setRetweetCount(status.getRetweetCount()); result.setRetweetedByMe(status.isRetweetedByMe()); result.setFavoriteCount(status.getFavoriteCount()); result.setFavourited(status.isFavorited()); if (status.getPlace() != null) { result.setPlace(status.getPlace().getFullName()); } Scopes scopesObj = status.getScopes(); if (scopesObj != null) { List scopes = Arrays.asList(scopesObj.getPlaceIds()); result.setScopes(scopes); } return result; }
From source file:de.vanita5.twittnuker.model.ParcelableStatus.java
License:Open Source License
public ParcelableStatus(final Status orig, final long account_id, final boolean is_gap) { this.is_gap = is_gap; this.account_id = account_id; id = orig.getId();//from ww w. j a v a2s .c o m timestamp = getTime(orig.getCreatedAt()); is_retweet = orig.isRetweet(); final Status retweeted = orig.getRetweetedStatus(); final User retweet_user = retweeted != null ? orig.getUser() : null; retweet_id = retweeted != null ? retweeted.getId() : -1; //NOTE getTime(orig.getCreatedAt()) retweet_timestamp = retweeted != null ? getTime(retweeted.getCreatedAt()) : -1; retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1; retweeted_by_name = retweet_user != null ? retweet_user.getName() : null; retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null; retweeted_by_profile_image = retweet_user != null ? ParseUtils.parseString(retweet_user.getProfileImageUrlHttps()) : null; final Status status = retweeted != null ? retweeted : orig; final User user = status.getUser(); user_id = user.getId(); user_name = user.getName(); user_screen_name = user.getScreenName(); user_profile_image_url = ParseUtils.parseString(user.getProfileImageUrlHttps()); user_is_protected = user.isProtected(); user_is_verified = user.isVerified(); user_is_following = user.isFollowing(); text_html = formatStatusText(status); media = ParcelableMedia.fromEntities(status); text_plain = status.getText(); retweet_count = status.getRetweetCount(); favorite_count = status.getFavoriteCount(); reply_count = status.getReplyCount(); descendent_reply_count = status.getDescendentReplyCount(); in_reply_to_name = getInReplyToName(status); in_reply_to_screen_name = status.getInReplyToScreenName(); in_reply_to_status_id = status.getInReplyToStatusId(); in_reply_to_user_id = status.getInReplyToUserId(); source = status.getSource(); location = new ParcelableLocation(status.getGeoLocation()); is_favorite = status.isFavorited(); text_unescaped = toPlainText(text_html); my_retweet_id = retweeted_by_id == account_id ? id : -1; is_possibly_sensitive = status.isPossiblySensitive(); mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities()); first_media = media != null && media.length > 0 ? media[0].url : null; }
From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues makeStatusContentValues(final Status orig, final long accountId, final boolean largeProfileImage) { if (orig == null || orig.getId() <= 0) return null; final ContentValues values = new ContentValues(); values.put(Statuses.ACCOUNT_ID, accountId); values.put(Statuses.STATUS_ID, orig.getId()); values.put(Statuses.STATUS_TIMESTAMP, orig.getCreatedAt().getTime()); values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet()); final boolean isRetweet = orig.isRetweet(); final Status status; final Status retweetedStatus = isRetweet ? orig.getRetweetedStatus() : null; if (retweetedStatus != null) { final User retweetUser = orig.getUser(); values.put(Statuses.RETWEET_ID, retweetedStatus.getId()); values.put(Statuses.RETWEET_TIMESTAMP, retweetedStatus.getCreatedAt().getTime()); values.put(Statuses.RETWEETED_BY_USER_ID, retweetUser.getId()); values.put(Statuses.RETWEETED_BY_USER_NAME, retweetUser.getName()); values.put(Statuses.RETWEETED_BY_USER_SCREEN_NAME, retweetUser.getScreenName()); values.put(Statuses.RETWEETED_BY_USER_PROFILE_IMAGE, ParseUtils.parseString(retweetUser.getProfileImageUrlHttps())); status = retweetedStatus;//from w w w. ja v a 2s.com } else { status = orig; } final User user = status.getUser(); if (user != null) { final long userId = user.getId(); final String profileImageUrl = ParseUtils.parseString(user.getProfileImageUrlHttps()); final String name = user.getName(), screenName = user.getScreenName(); values.put(Statuses.USER_ID, userId); values.put(Statuses.USER_NAME, name); values.put(Statuses.USER_SCREEN_NAME, screenName); values.put(Statuses.IS_PROTECTED, user.isProtected()); values.put(Statuses.IS_VERIFIED, user.isVerified()); values.put(Statuses.USER_PROFILE_IMAGE_URL, largeProfileImage ? getBiggerTwitterProfileImage(profileImageUrl) : profileImageUrl); values.put(CachedUsers.IS_FOLLOWING, user.isFollowing()); } final String text_html = Utils.formatStatusText(status); values.put(Statuses.TEXT_HTML, text_html); values.put(Statuses.TEXT_PLAIN, status.getText()); values.put(Statuses.TEXT_UNESCAPED, toPlainText(text_html)); values.put(Statuses.RETWEET_COUNT, status.getRetweetCount()); values.put(Statuses.REPLY_COUNT, status.getReplyCount()); values.put(Statuses.DESCENDENT_REPLY_COUNT, status.getDescendentReplyCount()); values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId()); values.put(Statuses.IN_REPLY_TO_USER_ID, status.getInReplyToUserId()); values.put(Statuses.IN_REPLY_TO_USER_NAME, Utils.getInReplyToName(status)); values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, status.getInReplyToScreenName()); values.put(Statuses.SOURCE, status.getSource()); values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive()); final GeoLocation location = status.getGeoLocation(); if (location != null) { values.put(Statuses.LOCATION, location.getLatitude() + "," + location.getLongitude()); } values.put(Statuses.IS_RETWEET, isRetweet); values.put(Statuses.IS_FAVORITE, status.isFavorited()); final ParcelableMedia[] media = ParcelableMedia.fromEntities(status); if (media != null) { values.put(Statuses.MEDIA, JSONSerializer.toJSONArrayString(media)); values.put(Statuses.FIRST_MEDIA, media[0].url); } final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status); if (mentions != null) { values.put(Statuses.MENTIONS, JSONSerializer.toJSONArrayString(mentions)); } return values; }
From source file:ezbake.training.TweetIngestParser.java
License:Apache License
private Tweet convertToTweet(Status status) { Tweet tweet = new Tweet(); tweet.setTimestamp(status.getCreatedAt().getTime()); tweet.setId(status.getId());//from w w w . j av a 2 s .com tweet.setText(status.getText()); tweet.setUserId(status.getUser().getId()); tweet.setUserName(status.getUser().getName()); tweet.setIsFavorite(status.isFavorited()); tweet.setIsRetweet(status.isRetweet()); if (status.getGeoLocation() != null) { tweet.setGeoLocation( new Coordinate(status.getGeoLocation().getLatitude(), status.getGeoLocation().getLongitude())); } return tweet; }
From source file:gh.polyu.user.TrackUsers.java
License:Apache License
public void track(final int no, final int p) { final TwitterDBHandle handle = new TwitterDBHandle(); handle.intialTwitterDBhandle();//ww w . j av a2 s. com while (alive) { alive = false; StatusListener listener = new StatusListener() { ArrayList<_TweetLink> listlink = new ArrayList<_TweetLink>(); int cnt = 0; String oldmonth = "20138"; String table = "UserTweet20138"; String oldday = ""; String currentday = ""; String currentmonth = ""; long lastinsert = 0l; long nowinsert = 0l; int newday = 0; String newtime = ""; @Override public void onStatus(Status status) { if (status.getId() == 123 && status.getText().equals("YOU are WORNG!.")) { System.out.println("Connection Need to be rebuilt!!"); alive = true; } else if (status.getLang().equals("en")) { _TweetLink tweet = new _TweetLink(); String Test = status.getText(); tweet.setText(Test); Date time = status.getCreatedAt(); tweet.setTime(time); tweet.setUserName(status.getUser().getName()); HashtagEntity[] hashtagentity = status.getHashtagEntities(); StringBuffer hashen = new StringBuffer(); for (int i = 0; i < hashtagentity.length; i++) { hashen.append(hashtagentity[i].getText()); hashen.append(";"); } tweet.setHashtag(hashen.toString()); URLEntity[] URLEn = status.getURLEntities(); StringBuffer URL = new StringBuffer(); for (int i = 0; i < URLEn.length; i++) { URL.append(URLEn[i].getURL()); URL.append(";"); } tweet.setURL(URL.toString()); //user mention UserMentionEntity[] userEn = status.getUserMentionEntities(); StringBuffer mentuser = new StringBuffer(); for (int i = 0; i < userEn.length; i++) { mentuser.append(userEn[i].getId()); mentuser.append(";"); } tweet.setUerMention(mentuser.toString()); //if(mentuser.length()!=0); //System.out.println("mentuser: "+ mentuser); //tweetID tweet.setTweetID(status.getId()); //if(ID!=null) // original twitterID tweet.setOriginID(status.getInReplyToStatusId()); //original user ID tweet.setOriginUser(status.getInReplyToUserId()); // user ID User users = status.getUser(); tweet.setTweetUser(users.getId()); //places Place Pl = status.getPlace(); String place = ""; if (Pl != null) { place = Pl.getFullName(); //System.out.println("place "+place); } tweet.setPlace(place); // Retweetcoun long num = 0; if (status.getRetweetedStatus() != null) { num = status.getRetweetedStatus().getRetweetCount(); //System.out.println("retweetcount"+num); tweet.setRetweetCount(num); tweet.setRetweet(1); } else { tweet.setRetweetCount(0); tweet.setRetweet(0); } // if(Retweet!=null) //System.out.println("Retweetcount: "+ Retweet); //isfavourate boolean favourate = status.isFavorited(); /*if(favourate) { fav = 1; tweet.setFavourate(fav); fav =0; System.out.println("isf "+ fav); }*/ // is retweet //String other = status.toString(); // tweet.setOther(other); listlink.add(tweet); Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); currentmonth = String.valueOf(year) + String.valueOf(month); currentday = String.valueOf(day); if (currentmonth.equals(oldmonth)) { if (currentday.equals(oldday)) ; else { newday = 1; SimpleDateFormat formatter = new SimpleDateFormat("MMddHH:mm:ss "); Date curDate = new Date(System.currentTimeMillis());// newtime = formatter.format(curDate); } } else { try { handle.database_connection(); table = "UserTweet" + String.valueOf(year) + String.valueOf(month); System.out.println("create new table " + table); String CREATE_TABLE = "create table " + table + "(TweetID varchar(100), UserName varchar(200), TwitterUser varchar(145), OriginID varchar(100), OriginUser varchar(100), place varchar(100), RetweetCount varchar(100), isRetweet int(5), Text varchar(500), Time datetime," + "Hashtag varchar(200), URL varchar(200), UerMention varchar(200))"; Statement st = handle.conn.createStatement(); st.execute(CREATE_TABLE); String Create_Index = "alter table " + table + " add index time (Time)"; st.execute(Create_Index); String Create_Index2 = "alter table " + table + " add index userID (TwitterUser)"; st.execute(Create_Index2); String key = "ALTER TABLE " + table + " ADD PRIMARY KEY (TweetID)"; st.execute(key); } catch (SQLException e) { e.printStackTrace(); } handle.close_databasehandle(); try { TwitterDBHandle handle2 = new TwitterDBHandle(); handle2.intialTwitterDBhandle2(); handle2.database_connection(); table = "UserTweet" + String.valueOf(year) + String.valueOf(month); System.out.println("create new table " + table); String CREATE_TABLE = "create table " + table + "(TweetID varchar(100), UserName varchar(200), TwitterUser varchar(145), OriginID varchar(100), OriginUser varchar(100), place varchar(100), RetweetCount varchar(100), isRetweet int(5), Text varchar(500), Time datetime," + "Hashtag varchar(200), URL varchar(200), UerMention varchar(200))"; Statement st = handle2.conn.createStatement(); st.execute(CREATE_TABLE); String Create_Index = "alter table " + table + " add index time (Time)"; st.execute(Create_Index); String Create_Index2 = "alter table " + table + " add index userID (TwitterUser)"; st.execute(Create_Index2); String key = "ALTER TABLE " + table + " ADD PRIMARY KEY (TweetID)"; st.execute(key); handle2.close_databasehandle(); } catch (SQLException e) { e.printStackTrace(); } } //System.out.println("OTHER: "+ other); if ((cnt++) % 1000 == 0) { if (newday == 1) { newday = 0; oldday = currentday; GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy"); gs.send("THREAD" + p + " :" + "program no" + no + "message" + newtime, "I am still alive"); newtime = ""; } try { handle.database_connection(); handle.userTweet(table, listlink); nowinsert = System.currentTimeMillis(); System.err.println( "No: " + no + "program " + "totally " + cnt + " tweets downloaded!\n" + new Date(nowinsert) + " " + new Date(lastinsert)); lastinsert = nowinsert; nowinsert = 0l; handle.close_databasehandle(); } catch (SQLException e) { handle.close_databasehandle(); e.printStackTrace(); // TODO Auto-generated catch block TwitterDBHandle handle2 = new TwitterDBHandle(); handle2.intialTwitterDBhandle2(); handle2.database_connection(); try { handle2.userTweet(table, listlink); nowinsert = System.currentTimeMillis(); System.err.println("New Database No: " + no + "program " + "totally " + cnt + " tweets downloaded!\n" + new Date(nowinsert) + new Date(lastinsert)); lastinsert = nowinsert; nowinsert = 0l; handle2.close_databasehandle(); } catch (SQLException e1) { // TODO Auto-generated catch block GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy"); try { gs.SendSSLMessage("cscchenyoyo@gmail.com", "program error", "both databases are down"); } catch (MessagingException ee) { // TODO Auto-generated catch block e.printStackTrace(); } } GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy"); try { gs.SendSSLMessage("cscchenyoyo@gmail.com", "program error", "change database to another one"); } catch (MessagingException ee) { // TODO Auto-generated catch block e.printStackTrace(); } } listlink.clear(); } } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { //System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { //System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { //System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { //System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } }; TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterOAuth twtOauth = new twitterOAuth(); twtOauth.AuthoritywithS(twitterStream, key); twitterStream.addListener(listener); twitterStream.filter(new FilterQuery(0, follow)); /* try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ } }
From source file:info.maslowis.twitterripper.util.Util.java
License:Open Source License
/** * Returns a representation the status (tweet) as string * * @return a representation the status as string in format <em>Status{id=, text='', lang='', createdAt=, geoLocation=, isFavorited=, isRetweeted=, retweetCount=, isTruncated=}</em> *///from w w w. jav a 2 s .c o m public static String toString(final Status status) { return "Status{id=" + status.getId() + ", text='" + status.getText() + "', lang='" + status.getLang() + "', createdAt=" + status.getCreatedAt() + ", geoLocation=" + status.getGeoLocation() + ", isFavorited=" + status.isFavorited() + ", isRetweeted=" + status.isRetweeted() + ", retweetCount=" + status.getRetweetCount() + ", isTruncated=" + status.isTruncated() + "}"; }
From source file:jp.gihyo.wicket.page.ajax.AjaxTimeline.java
License:Apache License
private void constructPage() { final TweetForm form = new TweetForm("tweetForm"); add(form);/*from w ww .ja v a 2 s . c o m*/ feedback = new FeedbackPanel("feedback"); feedback.setOutputMarkupId(true); add(feedback); IModel<List<Status>> statusModel = new LoadableDetachableModel<List<Status>>() { @Override protected List<Status> load() { try { Twitter twitter = AppSession.get().getTwitterSession(); return twitter.getFriendsTimeline(new Paging(currentPageNumber, ITEMS_PER_PAGE)); } catch (TwitterException ex) { AjaxTimeline.this.error(getString("canNotRetrieveFriendTimeline")); return Collections.emptyList(); } } }; ListView<Status> timeline = new ListView<Status>("statusView", statusModel) { @Override protected void populateItem(final ListItem<Status> item) { final Status status = item.getModelObject(); String userUrl = "http://twitter.com/" + status.getUser().getScreenName(); ExternalLink imageLink = new ExternalLink("imageLink", userUrl); //ImageR|?[lg?A<img>^Osrc??X`?X WebMarkupContainer userImage = new WebMarkupContainer("userImage"); userImage.add(new SimpleAttributeModifier("src", status.getUser().getProfileImageURL().toString())); imageLink.add(userImage); item.add(imageLink); ExternalLink screenNameLink = new ExternalLink("screenName", userUrl, status.getUser().getScreenName()); item.add(screenNameLink); Label content = new Label("tweetContent", status.getText()); item.add(content); ExternalLink tweetLink = new ExternalLink("tweetLink", userUrl + "/status/" + status.getId(), null); item.add(tweetLink); Label time = new Label("tweetTime", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(status.getCreatedAt())); tweetLink.add(time); Label clientName = new Label("clientName", status.getSource()); item.add(clientName.setEscapeModelStrings(false)); /* * YXe?[^XCo^\xNX?B * ?\bh?A??[JNX`?B * ??[JNX?ANXOstatus?ANZX?B */ class FavorateLabel extends Label { private static final long serialVersionUID = -2194580825236126312L; private Status targetStatus; private boolean needRefresh; public FavorateLabel(String id) { super(id); this.targetStatus = status; setDefaultModel(new AbstractReadOnlyModel<String>() { @Override public String getObject() { try { if (needRefresh) { targetStatus = getCurrentStatus(status.getId()); needRefresh = false; } return targetStatus == null ? "" : targetStatus.isFavorited() ? "unfav" : "fav"; } catch (TwitterException ex) { LOGGER.error("Can not fetch current status for status id = " + status.getId(), ex); return "error"; } } }); } public void setNeedRefresh(boolean needRefresh) { this.needRefresh = needRefresh; } } //CNx final FavorateLabel favName = new FavorateLabel("favName"); favName.setOutputMarkupId(true); /* * AjaxCN?B * Xe?[^XCo^o^?Ao^???s?B * o^???AAjaxg?Ay?[WS?ACo^Xe?[^X * Nx??B */ AjaxLink<Void> favLink = new AjaxLink<Void>("favLink") { @Override public void onClick(AjaxRequestTarget target) { try { Status currentStatus = getCurrentStatus(status.getId()); Twitter twitterSession = AppSession.get().getTwitterSession(); if (currentStatus.isFavorited()) { twitterSession.destroyFavorite(currentStatus.getId()); info(getString("favorateRemoved")); } else { twitterSession.createFavorite(currentStatus.getId()); info(getString("favorateRegistered")); } favName.setNeedRefresh(true); target.addComponent(feedback); //o^?bZ?[W\?AtB?[hobNpl?X?V?B target.addComponent(favName); } catch (TwitterException ex) { String message = getString("catNotCreateFavorite") + ": " + ex.getStatusCode(); error(message); LOGGER.error(message, ex); } } }; item.add(favLink); favLink.add(favName); //AJAX LINK item.add(new AjaxLink<Void>("replyLink") { @Override public void onClick(AjaxRequestTarget target) { String targetScreenName = status.getUser().getScreenName(); form.insertText(target, "@" + targetScreenName + " "); } }); //Q?l?AreplyLinkJavaScriptp // item.add(new Link<Void>("replyLink") { // @Override // public void onClick() { // } // // @Override // protected CharSequence getOnClickScript(CharSequence url) { // return "getElementById('" + form.getTextAreaId() + "').value = '@" + status.getUser().getScreenName() + " ';" + // "getElementById('" + form.getTextAreaId() + "').focus(); return false;"; // } // }); } }; //ListView\e?s????BreuseItemsv?peB??A //y?[W\?Ay?[WTu~bg?AXgeIuWFNg\??B //twitterey?[We?X??AXg????AXge? //Xe?[^Xu?A??dv?B timeline.setReuseItems(true); add(timeline); /* * y?[WO?EirQ?[^ */ add(new PagingLink("paging", AjaxTimeline.class, new AbstractReadOnlyModel<Integer>() { @Override public Integer getObject() { return getCurrentPage(); } })); }
From source file:jp.gihyo.wicket.page.paging.PagingTimeline.java
License:Apache License
private void constructPage() { final TweetForm form = new TweetForm("tweetForm"); add(form);//www. j a v a2 s .c o m feedback = new FeedbackPanel("feedback"); feedback.setOutputMarkupId(true); add(feedback); /* * ^CCpIModel?B * ??[hf?[^NGXg?EX|X?ETCNLbV?A * LoadableDetachableModelNXgp?B */ IModel<List<Status>> statusModel = new LoadableDetachableModel<List<Status>>() { @Override protected List<Status> load() { try { Twitter twitter = AppSession.get().getTwitterSession(); return twitter.getFriendsTimeline(new Paging(currentPageNumber, ITEMS_PER_PAGE)); } catch (TwitterException ex) { PagingTimeline.this.error(getString("canNotRetrieveFriendTimeline")); return Collections.emptyList(); } } }; /* * ^CCXg */ ListView<Status> timeline = new ListView<Status>("statusView", statusModel) { @Override protected void populateItem(final ListItem<Status> item) { final Status status = item.getModelObject(); String userUrl = "http://twitter.com/" + status.getUser().getScreenName(); ExternalLink imageLink = new ExternalLink("imageLink", userUrl); //ImageR|?[lg?A<img>^Osrc??X`?X WebMarkupContainer userImage = new WebMarkupContainer("userImage"); userImage.add(new SimpleAttributeModifier("src", status.getUser().getProfileImageURL().toString())); imageLink.add(userImage); item.add(imageLink); ExternalLink screenNameLink = new ExternalLink("screenName", userUrl, status.getUser().getScreenName()); item.add(screenNameLink); Label content = new Label("tweetContent", status.getText()); item.add(content); ExternalLink tweetLink = new ExternalLink("tweetLink", userUrl + "/status/" + status.getId(), null); item.add(tweetLink); Label time = new Label("tweetTime", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(status.getCreatedAt())); tweetLink.add(time); Label clientName = new Label("clientName", status.getSource()); item.add(clientName.setEscapeModelStrings(false)); /* * CNx?BIModel?f?A?fav/unfav * \?B */ final Label favName = new Label("favName", new AbstractReadOnlyModel<String>() { @Override public String getObject() { return status.isFavorited() ? "unfav" : "fav"; } }); /* * CN?BNbN?C?E??s?B */ Link<Void> favLink = new Link<Void>("favLink") { @Override public void onClick() { try { Twitter twitterSession = AppSession.get().getTwitterSession(); if (status.isFavorited()) { twitterSession.destroyFavorite(status.getId()); info(getString("favorateRemoved")); } else { twitterSession.createFavorite(status.getId()); info(getString("favorateRegistered")); } } catch (TwitterException ex) { String message = getString("catNotCreateFavorite") + ": " + ex.getStatusCode(); error(message); LOGGER.error(message, ex); } } }; item.add(favLink); favLink.add(favName); /* * vCpN?B * ?u@screenName?v?B */ item.add(new Link<Void>("replyLink") { @Override public void onClick() { String targetScreenName = status.getUser().getScreenName(); form.insertText("@" + targetScreenName + " "); } }); } }; //ListView\e?s????BreuseItemsv?peB??A //y?[W\?Ay?[WTu~bg?AXgeIuWFNg\??B //twitterey?[We?X??AXg????AXge? //Xe?[^Xu?A??dv?B timeline.setReuseItems(true); add(timeline); /* * y?[WO?EirQ?[^ */ add(new PagingLink("paging", PagingTimeline.class, new AbstractReadOnlyModel<Integer>() { @Override public Integer getObject() { return getCurrentPage(); } })); }
From source file:jp.gihyo.wicket.page.simple.MyTimeline.java
License:Apache License
private void constructPage() { final TweetForm form = new TweetForm("tweetForm"); add(form);/* www . ja v a 2 s .c om*/ feedback = new FeedbackPanel("feedback"); feedback.setOutputMarkupId(true); add(feedback); /* * ^CCpIModel?B * ??[hf?[^NGXg?EX|X?ETCNLbV?A * LoadableDetachableModelNXgp?B */ IModel<List<Status>> statusModel = new LoadableDetachableModel<List<Status>>() { @Override protected List<Status> load() { try { Twitter twitter = AppSession.get().getTwitterSession(); return twitter.getFriendsTimeline(new Paging(1, ITEMS_PER_PAGE)); } catch (TwitterException ex) { MyTimeline.this.error(getString("canNotRetrieveFriendTimeline")); return Collections.emptyList(); } } }; /* * ^CCXg */ ListView<Status> timeline = new ListView<Status>("statusView", statusModel) { @Override protected void populateItem(final ListItem<Status> item) { final Status status = item.getModelObject(); String userUrl = "http://twitter.com/" + status.getUser().getScreenName(); ExternalLink imageLink = new ExternalLink("imageLink", userUrl); byte[] byteArray = {};/* f?[^?? */ UrlResourceStream stream = new UrlResourceStream(status.getUser().getProfileImageURL()); try { stream.getInputStream().read(byteArray); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ResourceStreamNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } Image userImage = new Image("userImage", new ByteArrayResource("image/jpeg", byteArray)); imageLink.add(userImage); item.add(imageLink); ExternalLink screenNameLink = new ExternalLink("screenName", userUrl, status.getUser().getScreenName()); item.add(screenNameLink); Label content = new Label("tweetContent", status.getText()); item.add(content); ExternalLink tweetLink = new ExternalLink("tweetLink", userUrl + "/status/" + status.getId(), null); item.add(tweetLink); Label time = new Label("tweetTime", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(status.getCreatedAt())); tweetLink.add(time); Label clientName = new Label("clientName", status.getSource()); item.add(clientName.setEscapeModelStrings(false)); /* * CNx?BIModel?f?A?fav/unfav * \?B */ final Label favName = new Label("favName", new AbstractReadOnlyModel<String>() { @Override public String getObject() { return status.isFavorited() ? "unfav" : "fav"; } }); /* * CN?BNbN?C?E??s?B */ Link<Void> favLink = new Link<Void>("favLink") { @Override public void onClick() { try { Twitter twitterSession = AppSession.get().getTwitterSession(); if (status.isFavorited()) { twitterSession.destroyFavorite(status.getId()); info(getString("favorateRemoved")); } else { twitterSession.createFavorite(status.getId()); info(getString("favorateRegistered")); } } catch (TwitterException ex) { String message = getString("catNotCreateFavorite") + ": " + ex.getStatusCode(); error(message); LOGGER.error(message, ex); } } }; item.add(favLink); favLink.add(favName); /* * vCpN?B * ?u@screenName?v?B */ item.add(new Link<Void>("replyLink") { @Override public void onClick() { String targetScreenName = status.getUser().getScreenName(); form.insertText("@" + targetScreenName + " "); } }); } }; //ListView\e?s????BreuseItemsv?peB??A //y?[W\?Ay?[WTu~bg?AXgeIuWFNg\??B //twitterey?[We?X??AXg????AXge? //Xe?[^Xu?A??dv?B timeline.setReuseItems(true); add(timeline); }
From source file:net.lacolaco.smileessence.data.FavoriteCache.java
License:Open Source License
/** * Put status into cache// www. j a va2s. c om */ public void put(Status status) { if (!status.isRetweet()) { cache.put(status.getId(), status.isFavorited()); } }