diff --git a/importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java b/importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java index b1e64d8..404581a 100644 --- a/importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java +++ b/importPicture/src/osm/jp/gpx/ElementMapTRKSEG.java @@ -15,6 +15,20 @@ @SuppressWarnings("serial") public class ElementMapTRKSEG extends TreeMap { + /** + * TESTing + * @throws ParseException + * @throws ParserConfigurationException + * @throws IOException + * @throws SAXException + * @throws DOMException + */ + public static void main(String[] argv) throws DOMException, SAXException, IOException, ParserConfigurationException, ParseException { + ElementMapTRKSEG mapTRKSEG = null; + mapTRKSEG = new ElementMapTRKSEG(); + mapTRKSEG.parse(new File("testdata/cameradata/separate.gpx")); + mapTRKSEG.printinfo(); + } public ElementMapTRKSEG() { super(new TimeComparator()); @@ -50,15 +64,13 @@ factory.setIgnoringComments(true); factory.setValidating(true); - Element trk = null; - Node gpx = builder.parse(gpxFile).getFirstChild(); Document document = gpx.getOwnerDocument(); NodeList nodes = gpx.getChildNodes(); for (int i=0; i < nodes.getLength(); i++) { Node node2 = nodes.item(i); if (node2.getNodeName().equals("trk")) { - trk = (Element) node2; + Element trk = (Element) node2; NodeList nodes1 = trk.getChildNodes(); for (int i1=0; i1 < nodes1.getLength(); i1++) { @@ -83,7 +95,6 @@ if (nodeTRKSEG.getNodeName().equals("trkseg")) { NodeList nodes2 = nodeTRKSEG.getChildNodes(); - Date trksegStartTime = new Date(); // 対象とする開始時刻(現在時刻) ElementMapTRKPT mapTRKPT = new ElementMapTRKPT(); for (int i2 = 0; i2 < nodes2.getLength(); i2++) { Node nodeTRKPT = nodes2.item(i2); @@ -91,13 +102,10 @@ if (ImportPicture.param_GpxNoFirstNode && (i2 == 0)) { continue; } - Date time = mapTRKPT.put((Element)nodeTRKPT); - if (trksegStartTime.compareTo(time) < 0) { - trksegStartTime = time; - } + mapTRKPT.put((Element)nodeTRKPT); } } - this.put(trksegStartTime, mapTRKPT); + this.put(mapTRKPT); } } @@ -111,20 +119,21 @@ public void put(ElementMapTRKPT value) { for (Date key : value.keySet()) { this.put(key, value); + return; } } public void printinfo() { - System.out.println(" |--------------------|--------------------|"); + System.out.println(" +--------------------+--------------------|"); System.out.println(" GPS logging time | First Time | Last Time |"); + System.out.println("|--------------------------------+--------------------+--------------------|"); for (java.util.Map.Entry map : this.entrySet()) { - System.out.println("|--------------------------------|--------------------|--------------------|"); ElementMapTRKPT mapTRKPT = map.getValue(); mapTRKPT.printinfo(); } - System.out.println("|--------------------------------|--------------------|--------------------|"); + System.out.println("|--------------------------------+--------------------+--------------------|"); System.out.println(); } diff --git a/importPicture/src/osm/jp/gpx/ImportPicture.java b/importPicture/src/osm/jp/gpx/ImportPicture.java index 428006d..ac14872 100644 --- a/importPicture/src/osm/jp/gpx/ImportPicture.java +++ b/importPicture/src/osm/jp/gpx/ImportPicture.java @@ -294,7 +294,12 @@ public boolean param_GpxOutputWpt = true; public boolean param_ImgOutputAll = false; public String param_GpxSourceFolder = "."; + Document document; + public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss"; + public static final SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + public static final SimpleDateFormat dfuk = new SimpleDateFormat(TIME_FORMAT_STRING +"'Z'"); + @Override public void run() { /** @@ -341,8 +346,12 @@ * @throws TransformerException */ void procGPXfile(File gpxFile) throws ParserConfigurationException, SAXException, IOException, ParseException, ImageReadException, ImageWriteException, TransformerException { - DocumentBuilderFactory factory; - DocumentBuilder builder; + DocumentBuilderFactory factory = null; + DocumentBuilder builder = null; + ElementMapTRKSEG mapTRKSEG = null; + Node gpx = null; + + System.gc(); String fileName = gpxFile.getName(); String iStr = fileName.substring(0, fileName.length() - 4); @@ -361,14 +370,14 @@ factory.setValidating(true); // GPXファイルをパースする - ElementMapTRKSEG mapTRKSEG = new ElementMapTRKSEG(); + mapTRKSEG = new ElementMapTRKSEG(); document = mapTRKSEG.parse(gpxFile); // パースされた mapTRKSEG の中身を出力する mapTRKSEG.printinfo(); // GPX file --> Node root - Node gpx = builder.parse(gpxFile).getFirstChild(); + gpx = builder.parse(gpxFile).getFirstChild(); // imgDir内の画像ファイルを処理する System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); @@ -635,16 +644,6 @@ return ret; } - static Document document; - - - /** - * 2012-06-10T05:09:46Z (日本時間の'2012-06-10T14:09:46') - */ - public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss"; - public static SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - public static SimpleDateFormat dfuk = new SimpleDateFormat(TIME_FORMAT_STRING +"'Z'"); - /** * 対象は '*.JPG' のみ対象とする * @return @@ -758,7 +757,7 @@ wpt.appendChild(name); Element link = document.createElement("link"); - link.setAttribute("href", getShortPathName(imgDir, iFile)); + link.setAttribute("href", ImportPicture.getShortPathName(imgDir, iFile)); Element text = document.createElement("text"); text.setTextContent(iFile.getName()); link.appendChild(text); @@ -777,43 +776,13 @@ return filePath; } } - - public static Element getCopy(Document doc, Node node) { - Element root = doc.createElement(node.getNodeName()); - - NamedNodeMap nodeMap = node.getAttributes(); - if (null != nodeMap) { - for (int j=0; j < nodeMap.getLength(); j++ ) { - root.setAttribute(nodeMap.item(j).getNodeName(), nodeMap.item(j).getNodeValue()); - } - } - - NodeList nodes = node.getChildNodes(); - for (int i=0; i < nodes.getLength(); i++) { - Node node2 = nodes.item(i); - if (node2.getNodeType() == Node.ELEMENT_NODE) { - root.appendChild(getCopy(doc, node2)); - } - else if (node2.getNodeType() == Node.TEXT_NODE) { - String str = node2.getNodeValue(); - Text textContents = doc.createTextNode(str); - root.appendChild(textContents); - } - else if (node2.getNodeType() == Node.CDATA_SECTION_NODE) { - String str = node2.getNodeValue(); - CDATASection cdataSection = doc.createCDATASection(str); - root.appendChild(cdataSection); - } - } - return root; - } - + /** * ファイル名の順序に並び替えるためのソートクラス * * @author hayashi */ - static class FileSort implements Comparator{ + static class FileSort implements Comparator { @Override public int compare(File src, File target){ int diff = src.getName().compareTo(target.getName()); @@ -825,7 +794,7 @@ * JPEGファイルフィルター * @author yuu */ - class JpegFileFilter implements FilenameFilter{ + class JpegFileFilter implements FilenameFilter { public boolean accept(File dir, String name) { if (name.toUpperCase().matches(".*\\.JPG$")) { return true; diff --git a/importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java b/importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java index 4eb9e04..13b0a25 100644 --- a/importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java +++ b/importPicture/test/osm/jp/gpx/ElementMapTRKSEGTest.java @@ -57,7 +57,7 @@ ElementMapTRKSEG mapTRKSEG = new ElementMapTRKSEG(); mapTRKSEG.parse(new File(dataset.gpxSourcePath)); mapTRKSEG.printinfo(); - + System.out.println("GPX file: "+ dataset.gpxSourcePath); assertThat(mapTRKSEG.size(), is(dataset.segCount)); for (Date key : mapTRKSEG.keySet()) { assertThat(key, is(notNullValue())); diff --git a/importPicture/test/osm/jp/gpx/ImportPictureTest.java b/importPicture/test/osm/jp/gpx/ImportPictureTest.java index 0ad0be1..8120a2b 100644 --- a/importPicture/test/osm/jp/gpx/ImportPictureTest.java +++ b/importPicture/test/osm/jp/gpx/ImportPictureTest.java @@ -19,8 +19,6 @@ import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; -import hayashi.tools.files.DeleteDir; - @RunWith(Theories.class) public class ImportPictureTest { static class Expecter { @@ -206,7 +204,7 @@ "testdata/AdjustTime.M1c.separate.ini", new Expecter[] { // GPX file - new Expecter("separate_", true), + new Expecter("separate/separate_.gpx", true), // out of time ( - 2017-05-29T01:23:18) new Expecter("separate/20170529_102305A.jpg", false), @@ -242,7 +240,7 @@ "testdata/AdjustTime.M1d.separate.ini", new Expecter[] { // GPX file - new Expecter("separate_", true), + new Expecter("separate/separate_.gpx", true), // out of time ( - 2017-05-29T01:23:18) new Expecter("separate/20170529_102305A.jpg", true), @@ -563,8 +561,8 @@ @Theory public void パラメータテスト(Fixture dataset) throws Exception { - setup(dataset); - testdo(dataset.iniFilePath); + ImportPictureTest.setup(dataset); + ImportPictureTest.testdo(dataset.iniFilePath); Expecter[] es = dataset.expecters; AppParameters params = new AppParameters(dataset.iniFilePath); @@ -576,22 +574,22 @@ } } - public void setup(Fixture dataset) throws IOException { + static void setup(Fixture dataset) throws IOException { System.out.println(dataset.toString()); // カメラディレクトリを削除する File dir = new File("testdata/cameradata"); if (dir.exists()) { - DeleteDir.delete(dir); + ImportPictureTest.delete(dir); } File outDir = new File("testdata/output"); if (outDir.exists()) { - DeleteDir.delete(outDir); + ImportPictureTest.delete(outDir); } outDir.mkdir(); // カメラディレクトリを作成する - uncompress(new File(dataset.tarFilePath), new File("testdata/cameradata")); + ImportPictureTest.uncompress(new File(dataset.tarFilePath), new File("testdata/cameradata")); // GPXファイルをセット try ( FileInputStream inStream = new FileInputStream(new File(dataset.gpxSourcePath)); @@ -607,7 +605,7 @@ * 実行する * @throws Exception */ - public static void testdo(String iniFilePath) { + static void testdo(String iniFilePath) { try { String[] argv = new String[1]; argv[0] = new String(iniFilePath); @@ -635,7 +633,7 @@ TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); while (tarEntry != null) { File destPath = new File(dest, tarEntry.getName()); - System.out.println("uncompress: " + destPath.getCanonicalPath()); + //System.out.println("uncompress: " + destPath.getCanonicalPath()); if (tarEntry.isDirectory()) { destPath.mkdirs(); } @@ -661,4 +659,24 @@ } tarIn.close(); } + + public static void delete(File file) throws IOException { + if (!file.exists()) { + System.out.println("ERROR: ファイルまたはディレクトリが見つかりませんでした。"); + throw new IOException("File not found."); + } + + if (file.isDirectory()) { + File files[] = file.listFiles(); + if (files != null) { + for (int i=0; i < files.length; i++) { + delete(files[i]); // 再帰呼び出し + } + } + } + if (!file.delete()) { + System.out.println("ERROR: ファイルは削除できませんでした。 '" + file.getAbsolutePath() +"'"); + } + return; + } } diff --git a/importPicture/testdata/AdjustTime.M2b.separate.ini b/importPicture/testdata/AdjustTime.M2b.separate.ini new file mode 100644 index 0000000..8be595f --- /dev/null +++ b/importPicture/testdata/AdjustTime.M2b.separate.ini @@ -0,0 +1,16 @@ +#defuilt settings +#Tue Jun 27 19:19:34 JST 2017 +GPX.BASETIME=FILE_UPDATE +IMG.OUTPUT_EXIF=true +GPX.OUTPUT_SPEED=false +GPX.OUTPUT_WPT=false +IMG.OUTPUT_ALL=false +GPX.noFirstNode=true +IMG.OUTPUT=true +GPX.gpxSplit=true +GPX.REUSE=false +GPX.OVERWRITE_MAGVAR=false +IMG.BASE_FILE= +IMG.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/. +GPX.SOURCE_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/. +IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/.