import org.xml.sax.SAXException;\r
\r
public class ImportPicture {\r
+ public static File gpxDir = new File(".");\r
\r
/** メイン\r
* 画像ファイルをGPXファイルに取り込みます。\r
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
// 第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
\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
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
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
* @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
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
\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