OSDN Git Service

IE cookie 取得処理クラス実装開始
[coroid/inqubus.git] / frontend / src / saccubus / net / Cookie.java
1 package saccubus.net;
2
3 import java.io.IOException;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6
7 /**
8  *
9  * @author yuki
10  */
11 public abstract class Cookie {
12
13     private static final Pattern USER_SESSION_PATTERN = Pattern.compile("user_session_[\\d_]+");
14
15     public enum BrowserType {
16
17         NONE, MSIE, IE6, FIREFOX, CHROME,
18         OPERA, CHROMIUM, OTHER
19     }
20
21     public static Cookie create(BrowserType type) {
22         switch (type) {
23             case CHROME:
24                 return new CookieWinCrome();
25             case FIREFOX:
26                 return new CookieWinFirefox4();
27             case MSIE:
28                 return new CookieWinMsIe();
29             default:
30                 throw new UnsupportedOperationException();
31         }
32     }
33
34     public abstract String getUserSessionString() throws IOException;
35
36     /**
37      * 文字列から user_session_ で始まる文字列を切り出して返す。数字とアンダーバー以外の文字で切れる。
38      * @param str 切り出す対象文字列
39      * @return user_session 文字列。見つからなければnull。
40      */
41     protected String cutUserSession(String str) {
42         final Matcher mather = USER_SESSION_PATTERN.matcher(str);
43         if (mather.lookingAt()) {
44             return mather.group(1);
45         }
46         return null;
47     }
48 }