OSDN Git Service

メソッド名の誤字修正
[coroid/inqubus.git] / frontend / src / saccubus / converter / filegetter / FileInstanciator.java
index 195cbe8..b1750d3 100644 (file)
@@ -2,15 +2,15 @@
 package saccubus.converter.filegetter;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import org.apache.commons.io.FilenameUtils;
 import saccubus.ConvertStopFlag;
-import saccubus.converter.FileSetting;
-import saccubus.converter.Profile;
+import saccubus.converter.profile.InputFileSetting;
 import saccubus.net.TextProgressListener;
 
 /**
- * \83_\83E\83\93\83\8d\81[\83h\8f\88\97\9d\82ð\91S\82­\95K\97v\82Æ\82µ\82È\82¢\8fê\8d\87\82Ì\83t\83@\83C\83\8b\83C\83\93\83X\83^\83\93\83X\89»\83N\83\89\83X.
+ * ダウンロード処理を全く必要としない場合のファイルインスタンス化クラス.
  * @author yuki
  */
 public class FileInstanciator {
@@ -44,7 +44,7 @@ public class FileInstanciator {
             String tag, String time) throws
             IOException {
         FileInstanciator getter;
-        if (videoType.isDoanload() || commentType.isDoanload() || tcommType.isDoanload()) {
+        if (videoType.isDownload() || commentType.isDownload() || tcommType.isDownload()) {
             getter = new WebFileInstanciator(stopFlag, videoType, commentType, tcommType, li, tag, time);
         } else {
             getter = new FileInstanciator(videoType, commentType, tcommType, tag);
@@ -67,14 +67,17 @@ public class FileInstanciator {
         setTcommFileGetter(getter);
     }
 
-    /** @return \93®\89æ\82Ì\83^\83C\83g\83\8b\95ª\82©\82ç\82È\82¢\8fê\8d\87\82Ínull. */
-    public String getVideoTitle() {
+    /**
+     * @return 動画のタイトル.
+     * @throws FileNotFoundException ビデオタイトルの自動命名時、参考となるファイルが見つからなかった。
+     */
+    public String getVideoTitle() throws FileNotFoundException {
         String fileName = null;
         if (!videoType.isAutoFileName()) {
-            // \93®\89æ\83t\83@\83C\83\8b\96¼\82ð\92¼\90Ú\8ew\92è\82µ\82Ä\82¢\82é\8fê\8d\87\82Í\81A\82»\82Ì\83t\83@\83C\83\8b\96¼\82ð\8aî\82É\83^\83C\83g\83\8b\82ð\8eæ\93¾\82·\82é.
+            // 動画ファイル名を直接指定している場合は、そのファイル名を基にタイトルを取得する.
             fileName = videoType.getInitFile().toString();
         } else {
-            // \8e©\93®\96½\96¼\82Ì\8fê\8d\87\82Í\81A\83f\83B\83\8c\83N\83g\83\8a\93à\82É\82 \82é\83t\83@\83C\83\8b\82©\82ç\83^\83C\83g\83\8b\96¼\82ð\97Þ\90\84\81B
+            // 自動命名の場合は、ディレクトリ内にあるファイルからタイトル名を類推。
             String[] files = videoType.getInitFile().list();
             if (files != null) {
                 for (String file : files) {
@@ -84,36 +87,36 @@ public class FileInstanciator {
                     }
                 }
             }
+            if (fileName == null) {
+                throw new FileNotFoundException(getVideoIdWithBracket() + "のファイルを特定できませんでした。");
+            }
         }
 
-        if (fileName == null) {
-            return null;
-        }
         String baseName = FilenameUtils.getBaseName(fileName);
         int s = baseName.indexOf(getVideoIdWithBracket());
-        return baseName.substring(s + 1);
+        return baseName.replace(getVideoIdWithBracket(), "");
     }
 
     /**
-     * \93®\89æ\83t\83@\83C\83\8b\82ð\8eæ\93¾\82µ\82Ü\82·.
-     * @param listener \90i\92»\92Ê\92m\82ð\8eó\82¯\8eæ\82é\82½\82ß\82Ì\83\8a\83X\83i.
-     * @return \93®\89æ\83t\83@\83C\83\8b.
-     * @throws IOException \93®\89æ\83t\83@\83C\83\8b\82ª\91\8dÝ\82µ\82È\82¢, \8eæ\93¾\82É\8e¸\94s\82µ\82½.
+     * 動画ファイルを取得します.
+     * @param listener 進捗通知を受け取るためのリスナ.
+     * @return 動画ファイル.
+     * @throws IOException 動画ファイルが存在しない, 取得に失敗した.
      */
-    public final File getVideoFile(TextProgressListener listener) {
+    public final File getVideoFile(TextProgressListener listener) throws IOException {
         File file = new FileLocator(videoType.isAutoFileName(), videoType.getInitFile(), getVideoIdWithBracket(),
-                getVideoTitle(), ".flv").getFile();
+                getVideoTitle(), ".flv", ".mp4", ".swf").getFile();
         file = videoFileGetter.get(file, listener);
         return file;
     }
 
     /**
-     * \83R\83\81\83\93\83g\83t\83@\83C\83\8b\82ð\8eæ\93¾\82µ\82Ü\82·.
-     * @param listener \90i\92»\92Ê\92m\82ð\8eó\82¯\8eæ\82é\82½\82ß\82Ì\83\8a\83X\83i.
-     * @return \83R\83\81\83\93\83g\83t\83@\83C\83\8b.
-     * @throws IOException \83R\83\81\83\93\83g\83t\83@\83C\83\8b\82ª\91\8dÝ\82µ\82È\82¢, \8eæ\93¾\82É\8e¸\94s\82µ\82½.
+     * コメントファイルを取得します.
+     * @param listener 進捗通知を受け取るためのリスナ.
+     * @return コメントファイル.
+     * @throws IOException コメントファイルが存在しない, 取得に失敗した.
      */
-    public final File getCommentFile(TextProgressListener listener) {
+    public final File getCommentFile(TextProgressListener listener) throws IOException {
         File file = new FileLocator(commentType.isAutoFileName(), commentType.getInitFile(), getVideoIdWithBracket(),
                 getVideoTitle(), ".xml").getFile();
         file = commentFileGetter.get(file, listener);
@@ -121,12 +124,12 @@ public class FileInstanciator {
     }
 
     /**
-     * \93\8a\8de\8eÒ\83R\83\81\83\93\83g\83t\83@\83C\83\8b\82ð\8eæ\93¾\82µ\82Ü\82·.
-     * @param listener \90i\92»\92Ê\92m\82ð\8eó\82¯\8eæ\82é\82½\82ß\82Ì\83\8a\83X\83i.
-     * @return \93\8a\8de\8eÒ\83R\83\81\83\93\83g\83t\83@\83C\83\8b.
-     * @throws IOException \83R\83\81\83\93\83g\83t\83@\83C\83\8b\82ª\91\8dÝ\82µ\82È\82¢, \8eæ\93¾\82É\8e¸\94s\82µ\82½.
+     * 投稿者コメントファイルを取得します.
+     * @param listener 進捗通知を受け取るためのリスナ.
+     * @return 投稿者コメントファイル.
+     * @throws IOException コメントファイルが存在しない, 取得に失敗した.
      */
-    public final File getTcommFile(TextProgressListener listener) {
+    public final File getTcommFile(TextProgressListener listener) throws IOException {
         File file = new FileLocator(tcommType.isAutoFileName(), tcommType.getInitFile(), getVideoIdWithBracket(),
                 getVideoTitle(), ".xml").getFile();
         file = tcommFileGetter.get(file, listener);
@@ -144,15 +147,15 @@ public class FileInstanciator {
         private final File initFile;
 
         /**
-         * \83t\83@\83C\83\8b\82ð\83C\83\93\83X\83^\83\93\83X\89»\82·\82é\95û\96@\82ð\8ew\92è\82·\82é\83N\83\89\83X.
+         * ファイルをインスタンス化する方法を指定するクラス.
          */
-        public InstanciationType(FileSetting fileSetting) {
+        public InstanciationType(InputFileSetting fileSetting) {
             this.download = fileSetting.isDownload();
             this.autoFileName = !fileSetting.getFile().isFile();
             this.initFile = fileSetting.getFile().getFile();
         }
 
-        public boolean isDoanload() {
+        public boolean isDownload() {
             return download;
         }
 
@@ -170,7 +173,7 @@ public class FileInstanciator {
         private final boolean autoCommentNum;
         private final int backComment;
 
-        public CommentInstanciationType(FileSetting fileSetting, boolean autoCommentNum, int backComment) {
+        public CommentInstanciationType(InputFileSetting fileSetting, boolean autoCommentNum, int backComment) {
             super(fileSetting);
             this.autoCommentNum = autoCommentNum;
             this.backComment = backComment;