OSDN Git Service

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

index b4f1f92..e7acd60 100644 (file)
@@ -65,19 +65,7 @@ public class CookieWinCrome extends Cookie {
      */
     private String tryReadingWin7() {
         final String localAppData = System.getenv("LOCALAPPDATA");
-        if (isNotEmpty(localAppData)) {
-            // Win7 32bit
-            final File cookieFile = new File(localAppData + COOKIE_PATH);
-            if (cookieFile.isFile()) {
-                try {
-                    final String dataStr = FileUtils.readFileToString(cookieFile, "UTF-8");
-                    return cutUserSession(dataStr);
-                } catch (IOException ex) {
-                    logger.error("cookie read error: " + cookieFile.getPath(), ex);
-                }
-            }
-        }
-        return null;
+        return tryReading(localAppData);
     }
 
     /**
@@ -85,27 +73,23 @@ public class CookieWinCrome extends Cookie {
      * @return ユーザセッション文字列. 取得できない場合はnull.
      */
     private String tryReadingXp() {
-        final String profile_dir = System.getenv("USERPROFILE");
-        if (isNotEmpty(profile_dir)) {
+        final String userProfile = System.getenv("USERPROFILE");
+        if (isNotEmpty(userProfile)) {
             // XP 32bit
-            final File cookieFile = new File(profile_dir + "\\Local Settings\\Application Data" + COOKIE_PATH);
-            if (cookieFile.isFile()) {
-                try {
-                    String dataStr = FileUtils.readFileToString(cookieFile, "UTF-8");
-                    return cutUserSession(dataStr);
-                } catch (IOException ex) {
-                    logger.error("cookie read error: " + cookieFile.getPath(), ex);
-                }
-            }
+            return tryReading(userProfile + "\\Local Settings\\Application Data");
         }
         return null;
     }
 
     private String tryReadingOther() {
+        // ??? just try
         final String appData = System.getenv("APPDATA");
-        if (isNotEmpty(appData)) {
-            // ??? just try
-            final File cookieFile = new File(appData + COOKIE_PATH);
+        return tryReading(appData);
+    }
+
+    private String tryReading(String pathPrefix) {
+        if (isNotEmpty(pathPrefix)) {
+            final File cookieFile = new File(pathPrefix + COOKIE_PATH);
             if (cookieFile.isFile()) {
                 try {
                     String dataStr = FileUtils.readFileToString(cookieFile, "UTF-8");