OSDN Git Service

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