OSDN Git Service

ddf6e779f2ebf461bea7c3bc66290689bee77a66
[coroid/jnicoapi.git] / src / nicobrowser / util / Util.java
1 /*$Id$*/
2 package nicobrowser.util;
3
4 import java.io.InputStream;
5 import java.net.MalformedURLException;
6 import java.net.URL;
7 import java.util.List;
8 import java.util.logging.Level;
9 import java.util.logging.Logger;
10
11 public class Util {
12
13     static ResultParse rp = new ResultParse();
14     static UserInfo ui = new UserInfo();
15
16     public static String getExtention(String contentType) {
17         if ("video/flv".equals(contentType) || "video/x-flv".equals(contentType)) {
18             return "flv";
19         } else if ("video/mp4".equals(contentType)) {
20             return "mp4";
21         } else if ("application/x-shockwave-flash".equals(contentType)) {
22             return "swf";
23         }
24         return contentType.split("/")[1];
25     }
26
27     public static List<Result> parseSerchResult(InputStream is) {
28         return rp.parse(is);
29     }
30
31     public static String getNextPage(InputStream is) {
32         return rp.getNextPage(is);
33     }
34
35     /**
36      * ユーザIDを取得する
37      * @param is ニコニコ動画のウォッチページストリーム.
38      * @return ユーザID. 取得できなければnull.
39      */
40     public static String getUserId(InputStream is) {
41         return ui.getUserId(is);
42     }
43
44     /**
45      * 違反通報ページURLを取得する.
46      * @param is ニコニコ動画のウォッチページストリーム.
47      * @return 違反通報ページURL. 取得できなければnull.
48      */
49     public static URL getNotifierUrl(InputStream is) {
50         String res = ui.getNotifierUrl(is);
51         if (res == null) {
52             return null;
53         }
54
55         try {
56             return new URL(res);
57         } catch (MalformedURLException ex) {
58             Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
59             return null;
60         }
61     }
62
63     /**
64      * ユーザ名を取得する.
65      * @param is 違反通報ページストリーム.
66      * @return ユーザ名. 取得できなければnull.
67      */
68     public static String getUserName(InputStream is) {
69         String userName = ui.getUserName(is);
70         if ("".equals(userName)) {
71             userName = null;
72         }
73         return userName;
74     }
75 }