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