4 import java.io.FileNotFoundException;
5 import java.io.FilenameFilter;
6 import java.io.IOException;
7 import java.text.ParseException;
8 import java.util.ArrayList;
9 import java.util.Arrays;
10 import java.util.Comparator;
11 import java.util.List;
13 import javax.xml.parsers.ParserConfigurationException;
15 import org.xml.sax.SAXException;
17 public class GpxFolder extends ArrayList<GpxFile> {
18 private static final long serialVersionUID = 6178901459948163548L;
21 public GpxFolder(AppParameters params) throws ParserConfigurationException, SAXException, IOException, ParseException {
25 File gpxDir = params.getGpxSourceFolder();
27 // GPXファイルまたはディレクトリが存在しません。('%s')
28 throw new FileNotFoundException(String.format(ImportPicture.i18n.getString("msg.100"), "null"));
30 if (!gpxDir.exists()) {
31 // GPXファイルまたはディレクトリが存在しません。('%s')
32 throw new FileNotFoundException(String.format(ImportPicture.i18n.getString("msg.100"), gpxDir.getAbsolutePath()));
35 if (gpxDir.isFile()) {
36 if (accept(params, gpxDir.getName())) {
37 List<File> fileList = new ArrayList<>();
39 gpxfiles = fileList.toArray(new File[fileList.size()]);
42 // GPXファイルまたはディレクトリが存在しません。('%s')
43 throw new FileNotFoundException(String.format(ImportPicture.i18n.getString("msg.100"), gpxDir.getAbsolutePath()));
46 else if (gpxDir.isDirectory()) {
47 // 指定されたディレクトリ内のGPXファイルすべてを対象とする
48 gpxfiles = gpxDir.listFiles(new GpxFileFilter());
49 if (gpxfiles == null) {
50 // 対象となるGPXファイルがありませんでした。('%s')
51 throw new FileNotFoundException(
52 String.format(ImportPicture.i18n.getString("msg.110"), gpxDir.getAbsolutePath())
55 if (params.isImgOutputAll() && (gpxfiles.length > 1)) {
56 // "複数のGPXファイルがあるときには、'IMG.OUTPUT_ALL'オプションは指定できません。"
57 throw new FileNotFoundException(
58 String.format(ImportPicture.i18n.getString("msg.120"))
63 // GPXファイルまたはディレクトリが存在しません。('%s')
64 throw new FileNotFoundException(String.format(ImportPicture.i18n.getString("msg.100"), gpxDir.getAbsolutePath()));
67 Arrays.sort(gpxfiles, new FileSort());
68 for (File file : gpxfiles) {
69 this.add(new GpxFile(params, file));
76 public static boolean accept(AppParameters params, String name) {
77 String filename = name.toUpperCase();
78 if (filename.endsWith(".GPX")) {
79 if (!filename.endsWith("_.GPX") || params.isGpxReuse()) {
87 * ファイル名の順序に並び替えるためのソートクラス
90 static class FileSort implements Comparator<File> {
92 public int compare(File src, File target){
93 int diff = src.getName().compareTo(target.getName());
101 class GpxFileFilter implements FilenameFilter {
103 public boolean accept(File dir, String name) {
104 return GpxFolder.accept(params, name);