OSDN Git Service

merge.
[coroid/inqubus.git] / frontend / src / saccubus / converter / filegetter / FileLocator.java
1 /* $Id$ */
2 package saccubus.converter.filegetter;
3
4 import java.io.File;
5 import java.io.FilenameFilter;
6
7 /**
8  *
9  * @author yuki
10  */
11 class FileLocator {
12
13     private final boolean autoFileName;
14     private final File initFile;
15     private final String prefix;
16     private final String title;
17     private final String suffix;
18
19     FileLocator(boolean autoFileName, File initFile, String prefix, String title, String suffix) {
20         this.autoFileName = autoFileName;
21         this.initFile = initFile;
22         this.prefix = prefix;
23         this.title = title;
24         this.suffix = suffix;
25     }
26
27     /**
28      * \83R\83\93\83X\83g\83\89\83N\83^\82Å\8ew\92è\82µ\82½\8fð\8c\8f\82Å\83t\83@\83C\83\8b\82ð\8c\9f\8dõ\82·\82é\81B
29      * autoFileName\82ªfalse\82Ì\8fê\8d\87\81A\92¼\90Ú\96¼\91O\8ew\92è\82Å\82 \82é\82½\82ß\8ew\92è\82³\82ê\82½\83t\83@\83C\83\8b\82ð\82»\82Ì\82Ü\82Ü\95Ô\82·\81B
30      * autoFileName\82ªtrue\82Ì\8fê\8d\87\81AinitFile\83f\83B\83\8c\83N\83g\83\8a\82Éprefix\82Å\8en\82Ü\82é\83t\83@\83C\83\8b\82ª\91\8dÝ\82·\82é\82©\8c\9f\8dõ\82µ
31      * \82 \82ê\82Î\82»\82ê\82ð\95Ô\82·\81B
32      * \82±\82Ì\83t\83@\83C\83\8b\82à\96³\82¢\8fê\8d\87\81A\8ew\92è\82³\82ê\82½\83p\83\89\83\81\81[\83^\82É\8f]\82Á\82½\83t\83@\83C\83\8b\96¼\82ð\95Ô\82·\81B
33      * @return \8f\8a\96]\82Ì\83t\83@\83C\83\8b\81B\83t\83@\83C\83\8b\82Í\91\8dÝ\82·\82é\8fê\8d\87\82à\82 \82è\81A\91\8dÝ\82µ\82È\82¢\8fê\8d\87\82à\82 \82é\82±\82Æ\82É\92\8d\88Ó\81B
34      */
35     File getFile() {
36         if (!isAutoNaming()) {
37             return initFile;
38         } else {
39             File res = searchFile();
40             if (res != null) {
41                 return res;
42             }
43             return new File(initFile, prefix + title + suffix);
44         }
45     }
46
47     private final File searchFile() {
48         FilenameFilter filter = new FilenameFilter() {
49
50             public boolean accept(File dir, String name) {
51                 return (name.startsWith(prefix)) ? true : false;
52             }
53         };
54         File[] res = initFile.listFiles(filter);
55         if (res == null || res.length == 0) {
56             return null;
57         }
58         return res[0];
59     }
60
61     protected boolean isAutoNaming() {
62         return autoFileName;
63     }
64
65     protected final boolean getAutoFileName() {
66         return autoFileName;
67     }
68 }