OSDN Git Service

リファクタリング
authoryukihane <yukihane.feather@gmail.com>
Sat, 17 Sep 2011 08:45:15 +0000 (17:45 +0900)
committeryukihane <yukihane.feather@gmail.com>
Sat, 17 Sep 2011 08:45:15 +0000 (17:45 +0900)
frontend/src/saccubus/net/Cookie.java

index cf03ad0..a57f65e 100644 (file)
@@ -37,21 +37,7 @@ public abstract class Cookie {
     public abstract String getUserSessionString() throws IOException;
 
     /**
-     * 文字列から user_session_ で始まる文字列を切り出して返す。数字とアンダーバー以外の文字で切れる。
-     * @param str 切り出す対象文字列
-     * @return user_session 文字列。見つからなければnull。
-     */
-    private String cutUserSession(File cookieFile, String charsetName) throws IOException {
-        final String str = FileUtils.readFileToString(cookieFile, charsetName);
-        final Matcher mather = USER_SESSION_PATTERN.matcher(str);
-        if (mather.lookingAt()) {
-            return mather.group(1);
-        }
-        return null;
-    }
-
-    /**
-     * cookieDirs ディレクトリからクッキーを見つけて user_session を返す
+     * クッキーファイルを見つけて user_session を返す.
      * @param cookieFileOrDirs cookieが保存されたディレクトリの候補, あるいはcookieファイルの候補.
      * @return ユーザセッション文字列. 無ければnull.
      */
@@ -77,4 +63,22 @@ public abstract class Cookie {
 
         return null;
     }
+
+    /**
+     * 文字列から user_session_ で始まる文字列を切り出して返す。数字とアンダーバー以外の文字で切れる。
+     * @param cookieStr 切り出す対象文字列
+     * @return user_session 文字列。見つからなければnull。
+     */
+    protected final String getUserSession(final String cookieStr) {
+        final Matcher mather = USER_SESSION_PATTERN.matcher(cookieStr);
+        if (mather.lookingAt()) {
+            return mather.group(1);
+        }
+        return null;
+    }
+
+    private String cutUserSession(File cookieFile, String charsetName) throws IOException {
+        final String str = FileUtils.readFileToString(cookieFile, charsetName);
+        return getUserSession(str);
+    }
 }