OSDN Git Service

r57に含まれる変更.
authoryuki <yuki@c066991c-cf13-ec4a-a49a-846e61667af5>
Sat, 2 May 2009 10:20:41 +0000 (10:20 +0000)
committeryuki <yuki@c066991c-cf13-ec4a-a49a-846e61667af5>
Sat, 2 May 2009 10:20:41 +0000 (10:20 +0000)
ユーティリティメソッドを外部クラスFileUtilへ委譲.

git-svn-id: http://192.168.11.7/svn/saccubus/trunk@15 c066991c-cf13-ec4a-a49a-846e61667af5

frontend/src/saccubus/net/NicoClient.java
frontend/src/saccubus/util/FileUtil.java [new file with mode: 0644]

index c57bfe5..c21d539 100644 (file)
@@ -12,10 +12,10 @@ import javax.swing.JLabel;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.regex.Pattern;
 import java.text.*;
 import javax.net.ssl.HttpsURLConnection;
 import saccubus.ConvertStopFlag;
+import saccubus.util.FileUtil;
 
 /**
  * <p>
@@ -127,47 +127,12 @@ public class NicoClient {
                return VideoTitle;
        }
 
-       private static Pattern safeFileName_SPACE = Pattern.compile(" {2}+");
-       private static String safeFileName(String str) {
-               //\8eÀ\91Ì\8eQ\8fÆ\82Ì\83p\81[\83X
-               int old_index = 0;
-               int new_index = 0;
-               StringBuffer sb = new StringBuffer();
-               String ch;
-               while((new_index = str.indexOf("&#",old_index)) >= 0){
-                       sb.append(str,old_index,new_index);
-                       old_index = str.indexOf(";",new_index);
-                       ch = str.substring(new_index+2,old_index);
-                       sb.append(new String(new char[]{(char) Integer.parseInt(ch)}));
-                       old_index++;
-               }
-               //\8dÅ\8cã\82É\92Ç\89Á
-               sb.append(str,old_index,str.length());
-               str = sb.toString();
-               //\83t\83@\83C\83\8b\83V\83X\83e\83\80\82Å\88µ\82¦\82é\8c`\82É
-               str = str.replace('/', '\81^');
-               str = str.replace('\\', '\81\8f');
-               str = str.replace('?', '\81H');
-               str = str.replace('*', '\81\96');
-               str = str.replace(':', '\81F');
-               str = str.replace('|', '\81b');
-               str = str.replace('\"', '\81h');
-               str = str.replace('<', '\81\83');
-               str = str.replace('>', '\81\84');
-               str = str.replace('.', '\81D');
-               str = safeFileName_SPACE.matcher(str).replaceAll(" ");
-               return str;
-       }
-
        private String VideoTitle = null;
 
        private int VideoLength = -1;
 
        private static final String TITLE_PARSE_STR_START = "<title>";
 
-       //RC2\82É\82È\82Á\82Ä\83^\83C\83g\83\8b\82ª\95Ï\8dX\81A\8eg\82í\82È\82­\82È\82Á\82½\81B
-       //private static final String TITLE_PARSE_STR_END = "</title>";
-
        public boolean getVideoHistoryAndTitle(String tag) {
                String url = "http://www.nicovideo.jp/watch/" + tag;
                System.out.print("Getting video history...");
@@ -203,7 +168,7 @@ public class NicoClient {
                        while ((ret = br.readLine()) != null && index < 0) {
                                if ((index = ret.indexOf(TITLE_PARSE_STR_START)) >= 0) {
                                        VideoTitle = ret.substring(index+TITLE_PARSE_STR_START.length(), ret.indexOf("\81]", index));
-                                       VideoTitle = safeFileName(VideoTitle);
+                                       VideoTitle = FileUtil.safeFileName(VideoTitle);
                                }
                        }
                        br.close();
diff --git a/frontend/src/saccubus/util/FileUtil.java b/frontend/src/saccubus/util/FileUtil.java
new file mode 100644 (file)
index 0000000..ad3cf2c
--- /dev/null
@@ -0,0 +1,38 @@
+package saccubus.util;
+
+import java.util.regex.Pattern;
+
+public class FileUtil {
+       private static Pattern safeFileName_SPACE = Pattern.compile(" {2}+");
+       public static String safeFileName(String str) {
+               //\8eÀ\91Ì\8eQ\8fÆ\82Ì\83p\81[\83X
+               int old_index = 0;
+               int new_index = 0;
+               StringBuffer sb = new StringBuffer();
+               String ch;
+               while((new_index = str.indexOf("&#",old_index)) >= 0){
+                       sb.append(str,old_index,new_index);
+                       old_index = str.indexOf(";",new_index);
+                       ch = str.substring(new_index+2,old_index);
+                       sb.append(new String(new char[]{(char) Integer.parseInt(ch)}));
+                       old_index++;
+               }
+               //\8dÅ\8cã\82É\92Ç\89Á
+               sb.append(str,old_index,str.length());
+               str = sb.toString();
+               //\83t\83@\83C\83\8b\83V\83X\83e\83\80\82Å\88µ\82¦\82é\8c`\82É
+               str = str.replace('/', '\81^');
+               str = str.replace('\\', '\81\8f');
+               str = str.replace('?', '\81H');
+               str = str.replace('*', '\81\96');
+               str = str.replace(':', '\81F');
+               str = str.replace('|', '\81b');
+               str = str.replace('\"', '\81h');
+               str = str.replace('<', '\81\83');
+               str = str.replace('>', '\81\84');
+               str = str.replace('.', '\81D');
+               str = safeFileName_SPACE.matcher(str).replaceAll(" ");
+               return str;
+       }
+
+}