OSDN Git Service

自分が誰をフォローしているかを確認できる機能の基礎部分を実装。
[nt-manager/nt-manager.git] / src / twitter / gui / action / TweetMainAction.java
index 97cbdce..71a9e63 100644 (file)
@@ -18,6 +18,7 @@ import java.net.URL;
 import java.net.URLEncoder;
 import java.text.DateFormat;
 import java.util.ArrayList;
+import java.util.BitSet;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Locale;
@@ -73,11 +74,13 @@ import twitter.gui.form.ConfigurationDialog;
 import twitter.gui.form.DirectMessageDialog;
 import twitter.gui.form.HashtagSearchDialog;
 import twitter.gui.form.KeywordSearchDialog;
+import twitter.gui.form.OutputCSVLogDialog;
 import twitter.gui.form.UserListDialog;
 import twitter.gui.form.UserSearchDialog;
 import twitter.log.TwitterLogManager;
 import twitter.manage.TweetConfiguration;
 import twitter.manage.TweetManager;
+import twitter.manage.URLBitlyConverter;
 import twitter.task.ExistTimerIDException;
 import twitter.task.TimerID;
 import twitter.task.TweetTaskException;
@@ -86,6 +89,7 @@ import twitter.task.TweetUpdateTask;
 import twitter.util.HTMLEncode;
 import twitter4j.Status;
 import twitter4j.TwitterException;
+import twitter4j.User;
 
 /**
  * GUIのアクション部分
@@ -224,6 +228,8 @@ public class TweetMainAction {
        private UserListDialog userListDialog = null;
         //ユーザサーチダイアログ
         private UserSearchDialog userSearchDialog = null;
+        //CSVログ出力ダイアログ
+        private OutputCSVLogDialog outputCSVLogDialog = null;
 
        // 情報更新間隔[sec]
        private int getTimelinePeriod = 60;
@@ -1055,6 +1061,32 @@ public class TweetMainAction {
                Matcher matcher = convURLLinkPtn.matcher(message);
                return matcher.replaceAll("<a href=\"$0\">$0</a>");
        }
+       
+       /**
+        * メッセージ内にあるURLをBitlyに変換する
+        * @param message
+        * @return
+        */
+       public String actionConvertURLToBitly(String message) {
+               String result = new String( message );
+               //URLをbitlyに変換
+               Matcher matcher = convURLLinkPtn.matcher(message);
+               while( matcher.find() ) {
+                       String source = matcher.group();
+                       String conv = URLBitlyConverter.convertUrlToBitly( source );
+                       result = result.replaceAll( source , conv );
+               }
+               return result;
+       }
+       
+       /**
+        * つぶやきボックス内のURLをbitlyに変換
+        */
+       public void actionConvertTweetBoxURLToBitly() {
+               String message = this.tweetBoxPane.getText();
+               String conv = actionConvertURLToBitly(message);
+               this.tweetBoxPane.setText( conv );
+       }
 
        /**
         * @ユーザ名の部分をa hrefリンクに変換
@@ -1325,6 +1357,15 @@ public class TweetMainAction {
             dialog.setVisible(true);
         }
 
+        /**
+         * CSVログ出力ダイアログを表示
+         */
+        public void actionShowOutputCSVLogDialog() {
+            OutputCSVLogDialog dialog = getOutputCSVLogDialog();
+            dialog.setLocationRelativeTo(null);
+            dialog.setVisible(true);
+        }
+
        /**
         * ハッシュタグ検索ダイアログを表示
         */
@@ -1482,17 +1523,53 @@ public class TweetMainAction {
         * デバッグ用
         */
        public void debug() {
-               TwitterLogManager logManager = new TwitterLogManager();
-               try {
-                       List<Status> statuses = logManager.get();
-                       logManager.outputCSVLog("./test.csv", statuses, true, true, true, true, true, false, false, false, true, true, true);
-               } catch (SAXParseException e) {
-                       e.printStackTrace();
-               } catch (IOException e) {
-                       e.printStackTrace();
+/*             String message = "こんにちは http://densan-labs.net/でした。 http://google.com/ あいうえお";
+               System.out.println( this.actionConvertURLToBitly( message ));*/
+               //this.actionConvertTweetBoxURLToBitly();
+               for(int i=0; i < 5; i++) {
+                       List<User> lists = this.tweetManager.getFollowingUser("nishio_dens", i);
+                       for(User u : lists) {
+                               System.out.println( u );
+                       }
                }
+//             String url = "http://google.com";
+//             System.out.println( URLBitlyConverter.convertUrlToBitly(url));
        }
 
+        /**
+         * ログデータを保存
+         * @param logFilePath
+         * @param outputFilePath
+         * @param showUsername
+         * @param showScreenName
+         * @param showText
+         * @param showUpdateTime
+         * @param showClient
+         * @param showUserDescription
+         * @param showFollowing
+         * @param showFollower
+         * @param showUpdateCount
+         * @param showUserURL
+         * @param showProfileImageURL
+         * @throws SAXParseException
+         * @throws IOException
+         */
+        public void outputLogToCSV(String logFilePath, String outputFilePath,
+                boolean showUsername, boolean showScreenName,
+                       boolean showText,
+                       boolean showUpdateTime, boolean showClient,
+                       boolean showUserDescription,
+                       boolean showFollowing, boolean showFollower,
+                       boolean showUpdateCount, boolean showUserURL,
+                       boolean showProfileImageURL) throws SAXParseException, IOException {
+            TwitterLogManager logManager = new TwitterLogManager();
+            List<Status> statuses = logManager.get(logFilePath);
+            logManager.outputCSVLog( outputFilePath, statuses, showUsername, showScreenName,
+                    showText, showUpdateTime, showClient,
+                    showUserDescription, showFollowing, showFollower,
+                    showUpdateCount, showUserURL,showProfileImageURL);
+        }
+
        /**
         * 基本設定用ダイアログを取得
         * 
@@ -1565,6 +1642,17 @@ public class TweetMainAction {
             return this.userSearchDialog;
         }
 
+        /**
+         * CSVログ出力ダイアログを表示
+         * @return
+         */
+        public OutputCSVLogDialog getOutputCSVLogDialog() {
+            if( this.outputCSVLogDialog == null ) {
+                this.outputCSVLogDialog = new OutputCSVLogDialog(mainFrame, true, this);
+            }
+            return this.outputCSVLogDialog;
+        }
+
        /**
         * hashtag検索ダイアログ
         *