OSDN Git Service

FIX: JOSMでのファイルパスを修正
authoryuuhayashi <hayashi.yuu@gmail.com>
Sun, 26 Jan 2014 15:04:20 +0000 (00:04 +0900)
committeryuuhayashi <hayashi.yuu@gmail.com>
Sun, 26 Jan 2014 15:04:20 +0000 (00:04 +0900)
importPicture/.gitignore [new file with mode: 0644]
importPicture/.settings/org.eclipse.core.resources.prefs [new file with mode: 0644]
importPicture/src/osm/jp/gpx/ImportPicture.java

diff --git a/importPicture/.gitignore b/importPicture/.gitignore
new file mode 100644 (file)
index 0000000..8ba548b
--- /dev/null
@@ -0,0 +1 @@
+/classes
diff --git a/importPicture/.settings/org.eclipse.core.resources.prefs b/importPicture/.settings/org.eclipse.core.resources.prefs
new file mode 100644 (file)
index 0000000..ed2ca4a
--- /dev/null
@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+encoding//src/osm/jp/gpx/ImportPicture.java=UTF-8
+encoding/<project>=UTF-8
index bf454d2..c3ae229 100644 (file)
@@ -24,6 +24,7 @@ import org.w3c.dom.*;
 import org.xml.sax.SAXException;\r
 \r
 public class ImportPicture {\r
+       public static File gpxDir = new File(".");\r
 \r
        /** メイン\r
         * 画像ファイルをGPXファイルに取り込みます。\r
@@ -49,9 +50,8 @@ public class ImportPicture {
                        csvfile = new File(argv[0]);\r
                }\r
 \r
-               File dir = new File(".");\r
                if (argv.length > 1) {\r
-                       dir = new File(argv[1]);\r
+                       gpxDir = new File(argv[1]);\r
                }\r
 \r
                if (argv.length < 4) {\r
@@ -62,10 +62,10 @@ public class ImportPicture {
                // 第5引数が指定されなければ、指定されたディレクトリ内のGPXファイルすべてを対象とする\r
                ArrayList<File> gpxFiles = new ArrayList<File>();\r
                if (argv.length > 4) {\r
-                       gpxFiles.add(new File(dir, argv[4]));\r
+                       gpxFiles.add(new File(gpxDir, argv[4]));\r
                }\r
                else {\r
-                       File[] files = dir.listFiles();\r
+                       File[] files = gpxDir.listFiles();\r
                        for (int i=0; i < files.length; i++) {\r
                                if (files[i].isFile()) {\r
                                        String filename = files[i].getName().toUpperCase();\r
@@ -144,7 +144,7 @@ public class ImportPicture {
 \r
                                if (trk != null) {\r
                                        HashMap<Long,Element> map = trkptMap(trk);\r
-                                       File baseFile = new File(dir, argv[2]);\r
+                                       File baseFile = new File(gpxDir, argv[2]);\r
                                        Date jptime = new Date(baseFile.lastModified());\r
 \r
                                        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(csvfile)));\r
@@ -177,27 +177,7 @@ public class ImportPicture {
                                                pw.println("  GPX end time: "+ dfjp.format(new Date(gpxEndTime).getTime()));\r
 \r
                                                pw.println("\"name\",\"orignal\",\"gpstime\"");\r
-                                               File[] files = dir.listFiles();\r
-                                               Arrays.sort(files, new FileSort());\r
-                                               for (File image : files) {\r
-                                                       String imageName = image.getName();\r
-                                                       if (checkFile(imageName)) {\r
-                                                               Date itime = new Date(image.lastModified());\r
-                                                               Date uktime = new Date(itime.getTime() + delta);\r
-                                                               if ((uktime.getTime() >= gpxStartTime) && (uktime.getTime() <= gpxEndTime)) {\r
-                                                                       Element trkpt = trkpt(map, uktime);\r
-                                                                       if (trkpt != null) {\r
-                                                                               pw.print("\""+ image.getName() +"\",");\r
-                                                                               pw.print("\""+ dfjp.format(itime) +"\",");\r
-                                                                               pw.println("\""+ dfjp.format(uktime) +"\"");\r
-\r
-                                                                               Element wpt = createWptTag(dir, image, uktime.getTime(), trkpt);\r
-                                                                               Element temp = getCopy(gpx.getOwnerDocument(), wpt);\r
-                                                                               gpx.appendChild(temp);\r
-                                                                       }\r
-                                                               }\r
-                                                       }\r
-                                               }\r
+                                               proc(gpxDir, delta, gpxStartTime, gpxEndTime, map, pw, gpx);\r
                                        }\r
                                        catch (ParseException e) {\r
                                                System.out.println("'"+ timeStr +"' の書式が違います(yyyy-MM-dd'T'HH:mm:ss)");\r
@@ -235,6 +215,40 @@ public class ImportPicture {
                finally {\r
                }\r
        }\r
+       \r
+       /**\r
+        * 再帰メソッド\r
+        * @throws ParseException \r
+        */\r
+       static void proc(File dir, long delta, long gpxStartTime, long gpxEndTime, HashMap<Long,Element> map, PrintWriter pw, Node gpx) throws ParseException {\r
+               File[] files = dir.listFiles();\r
+               Arrays.sort(files, new FileSort());\r
+               for (File image : files) {\r
+                       if (image.isDirectory()) {\r
+                               proc(image, delta, gpxStartTime, gpxEndTime, map, pw, gpx);\r
+                       }\r
+                       else {\r
+                               String imageName = image.getName();\r
+                               if (checkFile(imageName)) {\r
+                                       Date itime = new Date(image.lastModified());\r
+                                       Date uktime = new Date(itime.getTime() + delta);\r
+                                       if ((uktime.getTime() >= gpxStartTime) && (uktime.getTime() <= gpxEndTime)) {\r
+                                               Element trkpt = trkpt(map, uktime);\r
+                                               if (trkpt != null) {\r
+                                                       pw.print("\""+ image.getName() +"\",");\r
+                                                       pw.print("\""+ dfjp.format(itime) +"\",");\r
+                                                       pw.println("\""+ dfjp.format(uktime) +"\"");\r
+\r
+                                                       Element wpt = createWptTag(image, uktime.getTime(), trkpt);\r
+                                                       Element temp = getCopy(gpx.getOwnerDocument(), wpt);\r
+                                                       gpx.appendChild(temp);\r
+                                               }\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+       }\r
 \r
        static Document document;\r
 \r
@@ -345,7 +359,7 @@ public class ImportPicture {
         * @param delta\r
         * @throws IOException\r
         */\r
-       public static Element createWptTag(File dir, File iFile, long timestamp, Element trkpt) {\r
+       public static Element createWptTag(File iFile, long timestamp, Element trkpt) {\r
                Element wpt = document.createElement("wpt");\r
 \r
                NamedNodeMap nodeMap = trkpt.getAttributes();\r
@@ -400,7 +414,7 @@ public class ImportPicture {
                wpt.appendChild(name);\r
 \r
                Element link = document.createElement("link");\r
-               link.setAttribute("href", dir.getName() + "/"+ iFile.getName());\r
+               link.setAttribute("href", getShortPathName(gpxDir, iFile));\r
                Element text = document.createElement("text");\r
                text.setTextContent(iFile.getName());\r
                link.appendChild(text);\r
@@ -408,6 +422,17 @@ public class ImportPicture {
 \r
                return wpt;\r
        }\r
+       \r
+       static String getShortPathName(File dir, File iFile) {\r
+               String dirPath = dir.getAbsolutePath();\r
+               String filePath = iFile.getAbsolutePath();\r
+               if (filePath.startsWith(dirPath)) {\r
+                       return filePath.substring(dirPath.length()+1);\r
+               }\r
+               else {\r
+                       return filePath;\r
+               }\r
+       }\r
 \r
        public static Element getCopy(Document doc, Node node) {\r
                Element root = doc.createElement(node.getNodeName());\r