OSDN Git Service

31e711ef20fc39cf017a37c22f5a3eca73264c2c
[coroid/inqubus.git] / frontend / src / yukihane / Util.java
1 /* $Id$ */
2 package yukihane;
3
4 import static yukihane.inqubus.InqubusConstants.*;
5
6 import java.util.regex.Matcher;
7
8 /**
9  * nicobrowser.util.Utilより, 必要なものをピックアップしたクラス.
10  * その後増えました.
11  * @author yuki
12  */
13 public final class Util {
14
15     private Util() {
16     }
17
18     /**
19      * Content-Type から拡張子を決定する.
20      * @param contentType Content-Type文字列.
21      * @return 推測される拡張子.
22      */
23     public static String getExtention(String contentType) {
24         if ("video/flv".equals(contentType) || "video/x-flv".equals(contentType)) {
25             return "flv";
26         } else if ("video/mp4".equals(contentType)) {
27             return "mp4";
28         } else if ("application/x-shockwave-flash".equals(contentType)) {
29             return "swf";
30         }
31         return contentType.split("/")[1];
32     }
33
34     public static String getVideoId(final String alterId) {
35         final int startIdIdx = alterId.lastIndexOf("/") + 1;
36         final String altId = alterId.substring(startIdIdx);
37         final Matcher idMatcher = PATTERN_VIDEO_ID.matcher(altId);
38         if (!idMatcher.find()) {
39             throw new IllegalArgumentException("URL/IDの指定が不正です: " + alterId);
40         }
41
42         return idMatcher.group(1);
43     }
44 }