Changeset 37411
- Timestamp:
- 05/07/10 00:49:57 (3 years ago)
- Location:
- lang/java/misc/hatenahaiku4j/trunk
- Files:
-
- 18 modified
- 2 copied
-
. (modified) (1 prop)
-
build.xml (modified) (1 diff)
-
changelog.txt (modified) (1 diff)
-
src/hatenahaiku4j/Const.java (modified) (5 diffs)
-
src/hatenahaiku4j/EntityAPI.java (modified) (3 diffs)
-
src/hatenahaiku4j/HatenaHaikuAPI.java (modified) (8 diffs)
-
src/hatenahaiku4j/HatenaHaikuAPIHTML.java (copied) (copied from lang/java/misc/hatenahaiku4j/tags/v1.2.0-beta5/src/hatenahaiku4j/HatenaHaikuAPIHTML.java)
-
src/hatenahaiku4j/HatenaHaikuAPILight.java (modified) (20 diffs)
-
src/hatenahaiku4j/Keyword.java (modified) (4 diffs)
-
src/hatenahaiku4j/KeywordAPI.java (modified) (1 diff)
-
src/hatenahaiku4j/QueryParameter.java (modified) (12 diffs)
-
src/hatenahaiku4j/Status.java (modified) (4 diffs)
-
src/hatenahaiku4j/StatusAPI.java (modified) (1 diff)
-
src/hatenahaiku4j/User.java (modified) (1 diff)
-
src/hatenahaiku4j/UserAPI.java (modified) (1 diff)
-
src/hatenahaiku4j/sample/Sample001.java (modified) (3 diffs)
-
src/hatenahaiku4j/sample/Sample006.java (copied) (copied from lang/java/misc/hatenahaiku4j/tags/v1.2.0-beta5/src/hatenahaiku4j/sample/Sample006.java)
-
src/hatenahaiku4j/util/HttpUtil.java (modified) (1 diff)
-
src/hatenahaiku4j/util/StringUtil.java (modified) (1 diff)
-
src/hatenahaiku4j/util/XmlUtil.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/java/misc/hatenahaiku4j/trunk
- Property svn:mergeinfo
-
old new 1 /lang/java/misc/hatenahaiku4j/branches/for-HTML-scraping:35625-37409 1 2 /lang/java/misc/hatenahaiku4j/branches/v0.0.2:35324-35341 2 3 /lang/java/misc/hatenahaiku4j/tags/v0.0.2:35323 4 /lang/java/misc/hatenahaiku4j/tags/v1.2.0-beta5:37410
-
- Property svn:mergeinfo
-
lang/java/misc/hatenahaiku4j/trunk/build.xml
r35938 r37411 3 3 4 4 <!-- HatenaHaiku4Jのバージョン --> 5 <property name="version" value="1. 1.4"/>5 <property name="version" value="1.2.0"/> 6 6 7 7 <!-- 概要 --> -
lang/java/misc/hatenahaiku4j/trunk/changelog.txt
r35938 r37411 1 HatenaHaiku4J v1.1.4 2009-11-18 1.1.4 1 HatenaHaiku4J v1.2.0 2010-05-07 2 ・HatenaHaikuAPIHTML(HTMLスクレイピング版)を追加した。 3 4 HatenaHaiku4J v1.1.4 2009-11-18 2 5 ・StringUtil#encodeで「+」「.」「-」「*」「_」もURLエンコードするよう修正。 3 6 -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/Const.java
r35938 r37411 11 11 public static final String API_NAME = "HatenaHaiku4J"; 12 12 /** バージョン */ 13 public static final String VERSION = "v1. 1.4";13 public static final String VERSION = "v1.2.0"; 14 14 15 15 /** コロン */ … … 32 32 /** mobile */ 33 33 public static final String MOBILE = "mobile"; 34 /** api */ 35 public static final String API = "api"; 34 36 35 37 /** URL: はてなハイクベースURL */ … … 42 44 /** URL: はてなハイクモバイルベースURL */ 43 45 public static final String MOBILE_BASE_URL = BASE_URL + MOBILE + SLASH; 44 /** URL: はてなハイクモバイル キーワードベースURL */46 /** URL: はてなハイクモバイルIDベースURL */ 45 47 public static final String MOBILE_ID_BASE_URL = MOBILE_BASE_URL + ID + SLASH; 46 48 /** URL: はてなハイクモバイルキーワードベースURL */ … … 49 51 /** URL: はてなプロフィールベースURL */ 50 52 public static final String HATENA_PROFILE_BASE_URL = "http://www.hatena.ne.jp/"; 53 /** URL: はてなstベースURL */ 54 public static final String HATENA_ST_BASE_URL = "http://www.st-hatena.com/"; 51 55 56 /** URL: はてなハイクAPIベースURL */ 57 public static final String API_BASE_URL = BASE_URL + API + SLASH; 58 52 59 /** はてなIDプレフィックス */ 53 60 public static final String ID_COLON = ID + COLON; 61 /** キーワードプレフィックス */ 62 public static final String KEYWORD_COLON = KEYWORD + COLON; 54 63 55 64 /** エンコーディング:UTF-8 */ … … 57 66 /** 拡張子:XML (.xml) */ 58 67 public static final String EXT_XML = ".xml"; 68 69 /** XMLヘッダ */ 70 public static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"" + UTF8 + "\" ?>"; 59 71 } -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/EntityAPI.java
r35467 r37411 1 1 package hatenahaiku4j; 2 3 import hatenahaiku4j.op.CollectOp; 4 5 import java.util.ArrayList; 6 import java.util.List; 2 7 3 8 /** … … 12 17 /** はてなハイクAPI(認証なし) */ 13 18 protected HatenaHaikuAPILight apiLight; 19 /** はてなハイクAPI(HTMLスクレイピング版) */ 20 protected HatenaHaikuAPIHTML apiHtml; 14 21 15 22 /** … … 29 36 return apiAuth != null; 30 37 } 38 39 /** 40 * HTMLスクレイピング版かどうか返却します。 41 * 42 * @return HTMLスクレイピング版かどうか 43 * @since v1.2.0 44 */ 45 protected boolean isHTML() { 46 return apiHtml != null; 47 } 48 49 /** 50 * 標準の集合操作を返却します。<br/> 51 * {@link java.util.ArrayList}にaddしていく。 52 * 53 * @param <E> 集めるEntity 54 * @return 指定したEntityのArrayListによる集合操作 55 * @since v1.1.0 56 */ 57 static <E extends Entity<E>> CollectOp<E, List<E>> createCollectOp() { 58 return new CollectOp<E, List<E>>(new ArrayList<E>()); 59 } 60 31 61 } -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/HatenaHaikuAPI.java
r35648 r37411 24 24 public class HatenaHaikuAPI extends HatenaHaikuAPILight { 25 25 /** URL: フレンドタイムライン(XML) */ 26 protected static final String URL_FRIENDS_TIMELINE_XML = "http://h.hatena.ne.jp/api/statuses/friends_timeline.xml";26 protected static final String URL_FRIENDS_TIMELINE_XML = Const.API_BASE_URL + "statuses/friends_timeline.xml"; 27 27 /** URL: ユーザタイムライン(XML) */ 28 protected static final String URL_USER_TIMELINE_XML = "http://h.hatena.ne.jp/api/statuses/user_timeline.xml";28 protected static final String URL_USER_TIMELINE_XML = Const.API_BASE_URL + "statuses/user_timeline.xml"; 29 29 /** URL: 投稿(XML) */ 30 protected static final String URL_UPDATE_STATUS_XML = "http://h.hatena.ne.jp/api/statuses/update.xml";30 protected static final String URL_UPDATE_STATUS_XML = Const.API_BASE_URL + "statuses/update.xml"; 31 31 /** URL: エントリを削除 */ 32 protected static final String URL_DELETE_STATUS = "http://h.hatena.ne.jp/api/statuses/destroy/";32 protected static final String URL_DELETE_STATUS = Const.API_BASE_URL + "statuses/destroy/"; 33 33 /** URL: エントリにスターを一つ追加 */ 34 protected static final String URL_ADD_STAR = "http://h.hatena.ne.jp/api/favorites/create/";34 protected static final String URL_ADD_STAR = Const.API_BASE_URL + "favorites/create/"; 35 35 /** URL: エントリのスターを一つ減らす */ 36 protected static final String URL_DELETE_STAR = "http://h.hatena.ne.jp/api/favorites/destroy/";36 protected static final String URL_DELETE_STAR = Const.API_BASE_URL + "favorites/destroy/"; 37 37 /** URL: ユーザがフォローしているユーザのリスト(XML) */ 38 protected static final String URL_FOLLOWING_LIST_XML = "http://h.hatena.ne.jp/api/statuses/friends.xml";38 protected static final String URL_FOLLOWING_LIST_XML = Const.API_BASE_URL + "statuses/friends.xml"; 39 39 /** URL: ユーザをフォローしているユーザのリスト(XML) */ 40 protected static final String URL_FOLLOWERS_LIST_XML = "http://h.hatena.ne.jp/api/statuses/followers.xml";40 protected static final String URL_FOLLOWERS_LIST_XML = Const.API_BASE_URL + "statuses/followers.xml"; 41 41 /** URL: ユーザをフォローする */ 42 protected static final String URL_FOLLOW_USER = "http://h.hatena.ne.jp/api/friendships/create/";42 protected static final String URL_FOLLOW_USER = Const.API_BASE_URL + "friendships/create/"; 43 43 /** URL: ユーザのフォローをやめる */ 44 protected static final String URL_UNFOLLOW_USER = "http://h.hatena.ne.jp/api/friendships/destroy/";44 protected static final String URL_UNFOLLOW_USER = Const.API_BASE_URL + "friendships/destroy/"; 45 45 /** URL: ユーザがフォローしているキーワードのリスト(XML) */ 46 protected static final String URL_FOLLOWING_KEYWORD_LIST_XML = "http://h.hatena.ne.jp/api/statuses/keywords.xml";46 protected static final String URL_FOLLOWING_KEYWORD_LIST_XML = Const.API_BASE_URL + "statuses/keywords.xml"; 47 47 /** URL: キーワードをフォローする */ 48 protected static final String URL_FOLLOW_KEYWORD = "http://h.hatena.ne.jp/api/keywords/create/";48 protected static final String URL_FOLLOW_KEYWORD = Const.API_BASE_URL + "keywords/create/"; 49 49 /** URL: キーワードのフォローをやめる */ 50 protected static final String URL_UNFOLLOW_KEYWORD = "http://h.hatena.ne.jp/api/keywords/destroy/";50 protected static final String URL_UNFOLLOW_KEYWORD = Const.API_BASE_URL + "keywords/destroy/"; 51 51 /** URL: 関連キーワードを設定(XML) */ 52 protected static final String URL_RELATE_KEYWORD_XML = "http://h.hatena.ne.jp/api/keywords/relation/create.xml";52 protected static final String URL_RELATE_KEYWORD_XML = Const.API_BASE_URL + "keywords/relation/create.xml"; 53 53 /** URL: 関連キーワードを解除(XML) */ 54 protected static final String URL_UNRELATE_KEYWORD_XML = "http://h.hatena.ne.jp/api/keywords/relation/destroy.xml";54 protected static final String URL_UNRELATE_KEYWORD_XML = Const.API_BASE_URL + "keywords/relation/destroy.xml"; 55 55 56 56 /** ログインユーザ */ … … 127 127 */ 128 128 public List<Status> getFriendsTimeline(int page, int count, Date since) throws HatenaHaikuException { 129 return getFriendsTimeline( this.<Status>createCollectOp(), page, count, since);129 return getFriendsTimeline(EntityAPI.<Status>createCollectOp(), page, count, since); 130 130 } 131 131 … … 218 218 */ 219 219 public List<Status> getUserTimeline(int page, int count, Date since) throws HatenaHaikuException { 220 return getUserTimeline( this.<Status>createCollectOp(), page, count, since);220 return getUserTimeline(EntityAPI.<Status>createCollectOp(), page, count, since); 221 221 } 222 222 … … 293 293 */ 294 294 public List<Status> getHotUserTimeline(int page, int count, Date since) throws HatenaHaikuException { 295 return getHotUserTimeline( this.<Status>createCollectOp(), page, count, since);295 return getHotUserTimeline(EntityAPI.<Status>createCollectOp(), page, count, since); 296 296 } 297 297 … … 329 329 private <T> T _getUserTimeline(ReduceOp<Status, T> op, int page, int count, Date since, boolean isHot) throws HatenaHaikuException { 330 330 try { 331 QueryParameter param = new QueryParameter(isHot); 331 QueryParameter param = new QueryParameter(); 332 if (isHot) { 333 param.setSort(QueryParameter.HOT); // 人気順 334 } 332 335 param.setPage(page); 333 336 param.setCount(count); … … 729 732 */ 730 733 public List<User> getFollowingList(int page) throws HatenaHaikuException { 731 return getFollowingList( this.<User>createCollectOp(), page);734 return getFollowingList(EntityAPI.<User>createCollectOp(), page); 732 735 } 733 736 … … 772 775 */ 773 776 public List<User> getFollowersList() throws HatenaHaikuException { 774 return getFollowersList( this.<User>createCollectOp());777 return getFollowersList(EntityAPI.<User>createCollectOp()); 775 778 } 776 779 … … 883 886 */ 884 887 public List<Keyword> getFollowingKeywordList() throws HatenaHaikuException { 885 return getFollowingKeywordList( this.<Keyword>createCollectOp());888 return getFollowingKeywordList(EntityAPI.<Keyword>createCollectOp()); 886 889 } 887 890 -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/HatenaHaikuAPILight.java
r35817 r37411 1 1 package hatenahaiku4j; 2 2 3 import hatenahaiku4j.op.CollectOp;4 3 import hatenahaiku4j.op.ReduceOp; 5 4 import hatenahaiku4j.util.DateUtil; … … 29 28 public class HatenaHaikuAPILight { 30 29 /** URL: パブリックタイムライン(XML) */ 31 protected static final String URL_PUBLIC_TIMELINE_XML = "http://h.hatena.ne.jp/api/statuses/public_timeline.xml";30 protected static final String URL_PUBLIC_TIMELINE_XML = Const.API_BASE_URL + "statuses/public_timeline.xml"; 32 31 /** URL: フレンドタイムライン */ 33 protected static final String URL_FRIENDS_TIMELINE = "http://h.hatena.ne.jp/api/statuses/friends_timeline/";32 protected static final String URL_FRIENDS_TIMELINE = Const.API_BASE_URL + "statuses/friends_timeline/"; 34 33 /** URL: ユーザタイムライン */ 35 protected static final String URL_USER_TIMELINE = "http://h.hatena.ne.jp/api/statuses/user_timeline/";34 protected static final String URL_USER_TIMELINE = Const.API_BASE_URL + "statuses/user_timeline/"; 36 35 /** URL: キーワードタイムライン */ 37 protected static final String URL_KEYWORD_TIMELINE = "http://h.hatena.ne.jp/api/statuses/keyword_timeline/";36 protected static final String URL_KEYWORD_TIMELINE = Const.API_BASE_URL + "statuses/keyword_timeline/"; 38 37 /** URL: アルバムタイムライン(XML) */ 39 protected static final String URL_ALBUM_TIMELINE_XML = "http://h.hatena.ne.jp/api/statuses/album.xml";38 protected static final String URL_ALBUM_TIMELINE_XML = Const.API_BASE_URL + "statuses/album.xml"; 40 39 /** URL: アルバムタイムライン */ 41 protected static final String URL_ALBUM_TIMELINE = "http://h.hatena.ne.jp/api/statuses/album/";40 protected static final String URL_ALBUM_TIMELINE = Const.API_BASE_URL + "statuses/album/"; 42 41 /** URL: ステータス情報 */ 43 protected static final String URL_STATUS = "http://h.hatena.ne.jp/api/statuses/show/";42 protected static final String URL_STATUS = Const.API_BASE_URL + "statuses/show/"; 44 43 /** URL: ユーザがフォローしているユーザのリスト */ 45 protected static final String URL_FOLLOWING_LIST = "http://h.hatena.ne.jp/api/statuses/friends/";44 protected static final String URL_FOLLOWING_LIST = Const.API_BASE_URL + "statuses/friends/"; 46 45 /** URL: ユーザをフォローしているユーザのリスト */ 47 protected static final String URL_FOLLOWERS_LIST = "http://h.hatena.ne.jp/api/statuses/followers/";46 protected static final String URL_FOLLOWERS_LIST = Const.API_BASE_URL + "statuses/followers/"; 48 47 /** URL: ユーザ情報 */ 49 protected static final String URL_USER = "http://h.hatena.ne.jp/api/friendships/show/";48 protected static final String URL_USER = Const.API_BASE_URL + "friendships/show/"; 50 49 /** URL: ホットキーワードのリスト(XML) */ 51 protected static final String URL_HOT_KEYWORD_LIST_XML = "http://h.hatena.ne.jp/api/keywords/hot.xml";50 protected static final String URL_HOT_KEYWORD_LIST_XML = Const.API_BASE_URL + "keywords/hot.xml"; 52 51 /** URL: キーワードのリスト(XML) */ 53 protected static final String URL_KEYWORD_LIST_XML = "http://h.hatena.ne.jp/api/keywords/list.xml";52 protected static final String URL_KEYWORD_LIST_XML = Const.API_BASE_URL + "keywords/list.xml"; 54 53 /** URL: ユーザがフォローしているキーワードのリスト */ 55 protected static final String URL_FOLLOWING_KEYWORD_LIST = "http://h.hatena.ne.jp/api/statuses/keywords/";54 protected static final String URL_FOLLOWING_KEYWORD_LIST = Const.API_BASE_URL + "statuses/keywords/"; 56 55 /** URL: キーワード情報 */ 57 protected static final String URL_KEYWORD = "http://h.hatena.ne.jp/api/keywords/show/";56 protected static final String URL_KEYWORD = Const.API_BASE_URL + "keywords/show/"; 58 57 59 58 /** HTTP通信ログ出力要否 */ … … 177 176 */ 178 177 public List<Status> getPublicTimeline(int page, Date since) throws HatenaHaikuException { 179 return getPublicTimeline( this.<Status>createCollectOp(), page, since);178 return getPublicTimeline(EntityAPI.<Status>createCollectOp(), page, since); 180 179 } 181 180 … … 271 270 */ 272 271 public List<Status> getFriendsTimeline(String userId, int page, int count, Date since) throws HatenaHaikuException { 273 return getFriendsTimeline( this.<Status>createCollectOp(), userId, page, count, since);272 return getFriendsTimeline(EntityAPI.<Status>createCollectOp(), userId, page, count, since); 274 273 } 275 274 … … 367 366 */ 368 367 public List<Status> getUserTimeline(String userId, int page, int count, Date since) throws HatenaHaikuException { 369 return getUserTimeline( this.<Status>createCollectOp(), userId, page, count, since);368 return getUserTimeline(EntityAPI.<Status>createCollectOp(), userId, page, count, since); 370 369 } 371 370 … … 447 446 */ 448 447 public List<Status> getHotUserTimeline(String userId, int page, int count, Date since) throws HatenaHaikuException { 449 return getHotUserTimeline( this.<Status>createCollectOp(), userId, page, count, since);448 return getHotUserTimeline(EntityAPI.<Status>createCollectOp(), userId, page, count, since); 450 449 } 451 450 … … 485 484 private <T> T _getUserTimeline(ReduceOp<Status, T> op, String userId, int page, int count, Date since, boolean isHot) throws HatenaHaikuException { 486 485 try { 487 QueryParameter param = new QueryParameter(isHot); 486 QueryParameter param = new QueryParameter(); 487 if (isHot) { 488 param.setSort(QueryParameter.HOT); // 人気順 489 } 488 490 param.setPage(page); 489 491 param.setCount(count); … … 562 564 */ 563 565 public List<Status> getIdTimeline(String userId, int page, int count, Date since) throws HatenaHaikuException { 564 return getIdTimeline( this.<Status>createCollectOp(), userId, page, count, since);566 return getIdTimeline(EntityAPI.<Status>createCollectOp(), userId, page, count, since); 565 567 } 566 568 … … 642 644 */ 643 645 public List<Status> getKeywordTimeline(String keyword, int page, int count, Date since) throws HatenaHaikuException { 644 return getKeywordTimeline( this.<Status>createCollectOp(), keyword, page, count, since);646 return getKeywordTimeline(EntityAPI.<Status>createCollectOp(), keyword, page, count, since); 645 647 } 646 648 … … 722 724 */ 723 725 public List<Status> getHotKeywordTimeline(String keyword, int page, int count, Date since) throws HatenaHaikuException { 724 return getHotKeywordTimeline( this.<Status>createCollectOp(), keyword, page, count, since);726 return getHotKeywordTimeline(EntityAPI.<Status>createCollectOp(), keyword, page, count, since); 725 727 } 726 728 … … 760 762 private <T> T _getKeywordTimeline(ReduceOp<Status, T> op, String keyword, int page, int count, Date since, boolean isHot) throws HatenaHaikuException { 761 763 try { 762 QueryParameter param = new QueryParameter(isHot); 764 QueryParameter param = new QueryParameter(); 765 if (isHot) { 766 param.setSort(QueryParameter.HOT); // 人気順 767 } 763 768 param.setPage(page); 764 769 param.setCount(count); … … 833 838 */ 834 839 public List<Status> getAlbumTimeline(int page, int count, Date since) throws HatenaHaikuException { 835 return getAlbumTimeline( this.<Status>createCollectOp(), page, count, since);840 return getAlbumTimeline(EntityAPI.<Status>createCollectOp(), page, count, since); 836 841 } 837 842 … … 928 933 */ 929 934 public List<Status> getAlbumKeywordTimeline(String keyword, int page, int count, Date since) throws HatenaHaikuException { 930 return getAlbumKeywordTimeline( this.<Status>createCollectOp(), keyword, page, count, since);935 return getAlbumKeywordTimeline(EntityAPI.<Status>createCollectOp(), keyword, page, count, since); 931 936 } 932 937 … … 1029 1034 */ 1030 1035 public List<User> getFollowingList(String userId, int page) throws HatenaHaikuException { 1031 return getFollowingList( this.<User>createCollectOp(), userId, page);1036 return getFollowingList(EntityAPI.<User>createCollectOp(), userId, page); 1032 1037 } 1033 1038 … … 1074 1079 */ 1075 1080 public List<User> getFollowersList(String userId) throws HatenaHaikuException { 1076 return getFollowersList( this.<User>createCollectOp(), userId);1081 return getFollowersList(EntityAPI.<User>createCollectOp(), userId); 1077 1082 } 1078 1083 … … 1146 1151 */ 1147 1152 public List<Keyword> getHotKeywordList() throws HatenaHaikuException { 1148 return getHotKeywordList( this.<Keyword>createCollectOp());1153 return getHotKeywordList(EntityAPI.<Keyword>createCollectOp()); 1149 1154 } 1150 1155 … … 1219 1224 */ 1220 1225 public List<Keyword> getKeywordList(String searchWord, int page) throws HatenaHaikuException { 1221 return getKeywordList( this.<Keyword>createCollectOp(), searchWord, page);1226 return getKeywordList(EntityAPI.<Keyword>createCollectOp(), searchWord, page); 1222 1227 } 1223 1228 … … 1266 1271 */ 1267 1272 public List<Keyword> getFollowingKeywordList(String userId) throws HatenaHaikuException { 1268 return getFollowingKeywordList( this.<Keyword>createCollectOp(), userId);1273 return getFollowingKeywordList(EntityAPI.<Keyword>createCollectOp(), userId); 1269 1274 } 1270 1275 … … 1369 1374 // お気に入られ 1370 1375 status.setFavorited(Integer.parseInt(XmlUtil.getText(elemStatus, "favorited"))); 1371 // 返信 先ステータスID1376 // 返信元ステータスID 1372 1377 status.setInReplyToStatusId(XmlUtil.getText(elemStatus, "in_reply_to_status_id")); 1373 // 返信 先ユーザID1378 // 返信元ユーザID 1374 1379 status.setInReplyToUserId(XmlUtil.getText(elemStatus, "in_reply_to_user_id")); 1375 1380 // キーワード … … 1498 1503 } 1499 1504 1500 /**1501 * 標準の集合操作を返却します。<br/>1502 * {@link java.util.ArrayList}にaddしていく。1503 *1504 * @param <E> 集めるEntity1505 * @return 指定したEntityのArrayListによる集合操作1506 * @since v1.1.01507 */1508 protected <E extends Entity<E>> CollectOp<E, List<E>> createCollectOp() {1509 return new CollectOp<E, List<E>>(new ArrayList<E>());1510 }1511 1512 1505 } -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/Keyword.java
r35648 r37411 23 23 /** キーワードタイトル */ 24 24 private String title; 25 /** クラウド */ 26 private int cloud; 25 27 26 28 /** … … 78 80 79 81 /** 82 * インスタンスを取得します。(パッケージプライベート) 83 * 84 * @param apiHtml はてなハイクAPI(HTMLスクレイピング版) 85 * @since v1.2.0 86 */ 87 static Keyword create(HatenaHaikuAPIHTML apiHtml) { 88 Keyword keyword = new Keyword(); 89 keyword.api.init(keyword, apiHtml); 90 return keyword; 91 } 92 93 /** 80 94 * 投稿数を取得します。 81 95 * … … 138 152 139 153 /** 154 * クラウドを取得します。<br/> 155 * クラウドはタグクラウド用の値(1~7)らしい。<br/> 156 * 尚、当値は、{@link HatenaHaikuAPIHTML#getHotKeywordList()}にて<br/> 157 * Keywordを取得時にしか設定されない値であることに注意されたい。<br/> 158 * (未設定時は常に0が返却されます) 159 * 160 * <table> 161 * <tr><th>class名</th><th>重要度</th></tr> 162 * <tr><td>cloud7</td><td rowspan="7">高<br/><br/>↑<br/>|<br/>↓<br/><br/>低</td></tr> 163 * <tr><td>cloud6</td></tr> 164 * <tr><td>cloud5</td></tr> 165 * <tr><td>cloud4</td></tr> 166 * <tr><td>cloud3</td></tr> 167 * <tr><td>cloud2</td></tr> 168 * <tr><td>cloud1</td></tr> 169 * </table> 170 * 171 * 172 * @return cloudの値(数値)。未設定の場合0。 173 * @since v1.2.0 174 */ 175 public int getCloud() { 176 return cloud; 177 } 178 179 /** 140 180 * idページかどうかを取得します。 141 181 * … … 195 235 void setTitle(String title) { 196 236 this.title = title; 237 } 238 239 /** 240 * クラウドを設定します。 241 * 242 * @param cloud クラウド 243 * @since v1.2.0 244 */ 245 void setCloud(int cloud) { 246 this.cloud = cloud; 197 247 } 198 248 -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/KeywordAPI.java
r35695 r37411 50 50 } 51 51 52 /** 53 * 初期化します。 54 * 55 * @param keyword キーワード情報 56 * @param apiHtml はてなハイクAPI(HTMLスクレイピング版) 57 * @since v1.2.0 58 */ 59 void init(Keyword keyword, HatenaHaikuAPIHTML apiHtml) { 60 this.keyword = keyword; 61 this.apiHtml = apiHtml; 62 } 63 52 64 // ------------------以下、認証が不要なAPI 53 65 -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/QueryParameter.java
r35467 r37411 22 22 /** カウントの最大値 */ 23 23 private static final int MAX_COUNT = 200; 24 /** 人気順(HOT) */ 25 private static final String HOT = "hot"; 24 25 /** 26 * 人気順(HOT)として指定する際の値 27 */ 28 static final String HOT = "hot"; 29 30 /** 31 * アルバムとして指定する際の値 32 */ 33 static final String ALBUM = "album"; 34 35 /** 最大値を突破するかどうか */ 36 private boolean breakthroughMaxLimit; 26 37 27 38 /** その日時よりも新しい投稿のみに絞り込むための日時を指定します。 */ … … 37 48 /** 関連付けキーワード2 */ 38 49 private String word2; 39 /** 人気順*/50 /** 並び順の種類 */ 40 51 private String sort; 52 /** モードの種類 */ 53 private String mode; 41 54 42 55 /** … … 52 65 * コンストラクタです。 53 66 * 54 * @param isHot 人気順取得用かどうか 55 * @since v1.0.0 56 */ 57 QueryParameter(boolean isHot) { 58 if (isHot) { 59 this.sort = HOT; 60 } 67 * @param breakthroughMaxLimit 最大値を突破するかどうか 68 * @since v1.2.0 69 */ 70 QueryParameter(boolean breakthroughMaxLimit) { 71 this.breakthroughMaxLimit = breakthroughMaxLimit; 61 72 } 62 73 … … 94 105 * <li>指定されたページが0の場合、デフォルトページ(1ページ目)を取得します。</li> 95 106 * </ul> 107 * ただし、breakthroughMaxLimitがtrueに指定されている場合、最大数制限は適用されません。 96 108 * 97 109 * @param page 取得するページ … … 99 111 */ 100 112 public void setPage(int page) { 101 this.page = Math.min(Math.max(page, MIN_PAGE), MAX_PAGE); 113 if (breakthroughMaxLimit) { 114 this.page = Math.max(page, MIN_PAGE); 115 } else { 116 this.page = Math.min(Math.max(page, MIN_PAGE), MAX_PAGE); 117 } 102 118 } 103 119 … … 119 135 * <li>指定された取得数が0の場合、デフォルトの取得件数で取得します。</li> 120 136 * </ul> 137 * ただし、breakthroughMaxLimitがtrueに指定されている場合、最大数制限は適用されません。 121 138 * 122 139 * @param count 取得数 … … 124 141 */ 125 142 public void setCount(int count) { 126 this.count = Math.min(Math.max(count, MIN_COUNT), MAX_COUNT); 143 if (breakthroughMaxLimit) { 144 this.count = Math.max(count, MIN_COUNT); 145 } else { 146 this.count = Math.min(Math.max(count, MIN_COUNT), MAX_COUNT); 147 } 127 148 } 128 149 … … 188 209 189 210 /** 190 * 人気順を取得します。191 * 192 * @return 人気順211 * 並び順の種類を取得します。 212 * 213 * @return 並び順の種類 193 214 * @since v1.0.0 194 215 */ … … 198 219 199 220 /** 200 * 人気順を設定します。201 * 202 * @param sort 人気順221 * 並び順の種類を設定します。 222 * 223 * @param sort 並び順の種類 203 224 * @since v1.0.0 204 225 */ 205 226 public String setSort(String sort) { 206 227 return this.sort = sort; 228 } 229 230 /** 231 * モードの種類を取得します。 232 * 233 * @return モードの種類 234 * @since v1.2.0 235 */ 236 public String getMode() { 237 return mode; 238 } 239 240 /** 241 * モードの種類を設定します。 242 * 243 * @param mode モードの種類 244 * @since v1.2.0 245 */ 246 public String setMode(String mode) { 247 return this.mode = mode; 207 248 } 208 249 … … 222 263 /** sort */ 223 264 private static final String PARAM_KEY_SORT = "sort"; 265 /** mode */ 266 private static final String PARAM_KEY_MODE = "mode"; 224 267 225 268 /** … … 258 301 if (sort != null) { 259 302 ps.addProperty(PARAM_KEY_SORT, sort); 303 } 304 // mode 305 if (mode != null) { 306 ps.addProperty(PARAM_KEY_MODE, mode); 260 307 } 261 308 } … … 275 322 System.out.println("[word2: " + word2 + "]"); 276 323 System.out.println("[sort: " + sort + "]"); 324 System.out.println("[mode: " + mode + "]"); 277 325 } 278 326 } -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/Status.java
r35648 r37411 97 97 98 98 /** 99 * インスタンスを取得します。(パッケージプライベート) 100 * 101 * @param apiHtml はてなハイクAPI(HTMLスクレイピング版) 102 * @since v1.2.0 103 */ 104 static Status create(HatenaHaikuAPIHTML apiHtml) { 105 Status status = new Status(); 106 status.api.init(status, apiHtml); 107 return status; 108 } 109 110 /** 99 111 * ステータスIDを取得します。 100 112 * … … 204 216 */ 205 217 public List<Status> getReplies() { 206 // 自動更新するなら 207 if (api.apiLight .isAutoRefreshReplies()) {218 // 自動更新するなら(APIHTMLでない場合のみ) 219 if (api.apiLight != null && api.apiLight.isAutoRefreshReplies()) { 208 220 if (shadow) { 209 221 try { … … 255 267 */ 256 268 public String getUserId() { 257 return user .getUserId();269 return user == null ? "" : user.getUserId(); 258 270 } 259 271 … … 266 278 */ 267 279 public String getUserIdNotation() { 268 return user .getUserIdNotation();280 return user == null ? "" : user.getUserIdNotation(); 269 281 } 270 282 -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/StatusAPI.java
r35467 r37411 48 48 49 49 /** 50 * 初期化します。 51 * 52 * @param status ステータス情報 53 * @param apiHtml はてなハイクAPI(HTMLスクレイピング版) 54 * @since v1.2.0 55 */ 56 void init(Status status, HatenaHaikuAPIHTML apiHtml) { 57 this.status = status; 58 this.apiHtml = apiHtml; 59 } 60 61 /** 50 62 * このステータスを返信先状態に取得しなおします。 51 63 * -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/User.java
r35648 r37411 74 74 75 75 /** 76 * インスタンスを取得します。(パッケージプライベート) 77 * 78 * @param apiHtml はてなハイクAPI(HTMLスクレイピング版) 79 * @since v1.2.0 80 */ 81 static User create(HatenaHaikuAPIHTML apiHtml) { 82 User user = new User(); 83 user.api.init(user, apiHtml); 84 return user; 85 } 86 87 /** 88 * ユーザIDから設定できる項目をある程度埋めたインスタンスを取得します。(パッケージプライベート) 89 * 90 * @param apiHtml はてなハイクAPI(HTMLスクレイピング版) 91 * @param userId ユーザID 92 * @since v1.2.0 93 */ 94 static User create(HatenaHaikuAPIHTML apiHtml, String userId) { 95 User user = create(apiHtml); 96 // ユーザID 97 user.setUserId(userId); 98 // ユーザ名 99 user.setName(userId); 100 // ユーザプロフィール画像URL 101 user.setProfileImageUrl(Const.HATENA_ST_BASE_URL + "users" 102 + Const.SLASH + userId.substring(0, 2) + Const.SLASH + userId 103 + Const.SLASH + "profile.gif"); 104 // ユーザ表示名 105 user.setScreenName(userId); 106 // ユーザのエントリページのURL 107 user.setUrl(Const.BASE_URL + userId + Const.SLASH); 108 return user; 109 } 110 111 /** 76 112 * ユーザ名を取得します。 77 113 * -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/UserAPI.java
r35695 r37411 50 50 } 51 51 52 /** 53 * 初期化します。 54 * 55 * @param user ユーザ情報 56 * @param apiHtml はてなハイクAPI(HTMLスクレイピング版) 57 * @since v1.2.0 58 */ 59 void init(User user, HatenaHaikuAPIHTML apiHtml) { 60 this.user = user; 61 this.apiHtml = apiHtml; 62 } 63 52 64 // ------------------以下、認証が不要なAPI 53 65 -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/sample/Sample001.java
r35665 r37411 5 5 import hatenahaiku4j.HatenaHaikuAPILight; 6 6 import hatenahaiku4j.HatenaHaikuException; 7 import hatenahaiku4j.Keyword; 7 8 import hatenahaiku4j.LoginUser; 8 9 import hatenahaiku4j.Status; … … 88 89 sb.append(HatenaUtil.formatDate(status.getCreatedAt())); 89 90 sb.append("〔☆×").append(status.getFavorited()).append("〕"); 90 sb.append(status.getText());91 91 if (!StringUtil.isEmpty(status.getInReplyToStatusId())) { 92 sb.append(" reply to ").append(status.getInReplyToUserId()); 92 sb.append(" @").append(status.getInReplyToUserId()) 93 .append("(").append(status.getInReplyToStatusId()).append(")"); 93 94 } 95 sb.append(" ").append(status.getText()); 94 96 sb.append(" by ").append(status.getUserId()); 95 97 sb.append(" from ").append(status.getSource()); … … 101 103 } 102 104 replies.append(reply.getUserId()); 105 replies.append("(").append(reply.getStatusId()).append(")"); 103 106 } 104 107 sb.append(" replied from ").append(replies); 105 108 } 109 System.out.println(sb.toString()); 110 } 111 112 /** 113 * キーワード情報を標準出力に出力します。 114 * 115 * @param keyword キーワード情報 116 */ 117 public static void printKeyword(Keyword keyword) { 118 StringBuilder sb = new StringBuilder(); 119 sb.append("【").append(keyword.getTitle()).append("】"); 120 sb.append("(" + keyword.getEntryCount() + ")"); 121 sb.append(" cloud").append(keyword.getCloud()); 122 sb.append(" "); 123 sb.append(keyword.getLink()); 106 124 System.out.println(sb.toString()); 107 125 } -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/util/HttpUtil.java
r35469 r37411 223 223 String line; 224 224 while((line = responseReader.readLine()) != null) { 225 if (responseBody.length() > 0) { 226 responseBody.append("\r\n"); 227 } 225 228 responseBody.append(line); 226 229 } -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/util/StringUtil.java
r35938 r37411 95 95 + String.valueOf(Math.random()).replaceAll("[-.]", ""); 96 96 } 97 97 98 /** 99 * 一括置換を行います。<br/> 100 * templateがnull, replaceがnullまたは長さが不正(2の倍数でない)場合、空文字を返却します。 101 * 102 * @param template 置換を施すベースとなるテンプレート 103 * @param replace 置換文字列 104 * @return 一括置換された文字列 105 * @since v1.2.0 106 */ 107 public static String lumpReplace(String template, String... replace) { 108 if (template == null) { 109 return ""; 110 } 111 if (replace == null) { 112 return ""; 113 } 114 if (replace.length < 2 || replace.length % 2 != 0) { 115 return ""; 116 } 117 String result = template; 118 for (int i = 0; i < replace.length; i += 2) { 119 result = result.replaceAll(replace[i], replace[i + 1]); 120 } 121 return result; 122 } 123 98 124 } -
lang/java/misc/hatenahaiku4j/trunk/src/hatenahaiku4j/util/XmlUtil.java
r35467 r37411 38 38 * @since v0.0.1 39 39 */ 40 public static Element getRootElement(String resultXml) throws ParserConfigurationException, UnsupportedEncodingException, SAXException, IOException { 40 public static Element getRootElement(String resultXml) 41 throws ParserConfigurationException, UnsupportedEncodingException, 42 SAXException, IOException { 43 41 44 // ドキュメントビルダーファクトリを生成 42 45 DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); 46 dbfactory.setIgnoringElementContentWhitespace(true); // 余分なホワイトスペースは削除 47 dbfactory.setIgnoringComments(true); // コメントノードは不要 48 43 49 // ドキュメントビルダーを生成 44 50 DocumentBuilder builder = dbfactory.newDocumentBuilder(); 51 45 52 // パースを実行してDocumentオブジェクトを取得 46 Document doc = builder.parse(new ByteArrayInputStream(resultXml.getBytes(Const.UTF8))); 53 Document doc = builder.parse( 54 new ByteArrayInputStream( 55 escapeAmp(removeIllegalChar(resultXml)).getBytes(Const.UTF8) 56 ) 57 ); 47 58 48 59 return doc.getDocumentElement(); … … 144 155 return result; 145 156 } 157 158 /** 159 * 0x1bを除去する。 160 * 161 * @param source 元の文字列 162 * @return 0x1bを除去後の文字列 163 * @since v1.2.0 164 */ 165 private static String removeIllegalChar(String source) { 166 return source.replaceAll(new String(new char[]{ (char)0x1b }), ""); 167 } 168 169 /** 170 * & を &amp; に変換します。 171 * 172 * @param source 元の文字列 173 * @return 変換した文字列 174 * @since v1.2.0 175 */ 176 private static String escapeAmp(String source) { 177 /* 178 * thanks: 179 * http://www.tipsblogger.com/2009/02/reference-to-entity-xx-must-end-with.html 180 */ 181 return source.replaceAll("&", "&"); 182 } 183 146 184 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)