OSDN Git Service

NGワード登録時, 登録した情報が見えるようにスクロールする
[coroid/inqubus.git] / frontend / src / yukihane / Util.java
index efff526..bb678fd 100644 (file)
@@ -1,16 +1,23 @@
 /* $Id$ */
 package yukihane;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
- * nicobrowser.util.Util\82æ\82è, \95K\97v\82È\82à\82Ì\82ð\83s\83b\83N\83A\83b\83v\82µ\82½\83N\83\89\83X.
+ * nicobrowser.util.Utilより, 必要なものをピックアップしたクラス.
+ * その後増えました.
  * @author yuki
  */
-public class Util {
+public final class Util {
+
+    private Util() {
+    }
 
     /**
-     * Content-Type \82©\82ç\8ag\92£\8eq\82ð\8c\88\92è\82·\82é.
-     * @param contentType Content-Type\95\8e\9a\97ñ.
-     * @return \90\84\91ª\82³\82ê\82é\8ag\92£\8eq.
+     * Content-Type から拡張子を決定する.
+     * @param contentType Content-Type文字列.
+     * @return 推測される拡張子.
      */
     public static String getExtention(String contentType) {
         if ("video/flv".equals(contentType) || "video/x-flv".equals(contentType)) {
@@ -22,4 +29,16 @@ public class Util {
         }
         return contentType.split("/")[1];
     }
+
+    public static String getVideoId(final String alterId) {
+        final int startIdIdx = alterId.lastIndexOf("/") + 1;
+        final String altId = alterId.substring(startIdIdx);
+        final Pattern idPattern = Pattern.compile("([a-z]*\\d+)");
+        final Matcher idMatcher = idPattern.matcher(altId);
+        if (!idMatcher.find()) {
+            throw new IllegalArgumentException("URL/IDの指定が不正です: " + alterId);
+        }
+
+        return idMatcher.group(1);
+    }
 }