@SuppressWarnings("serial")
public class ElementMapTRKSEG extends TreeMap<Date, ElementMapTRKPT> {
+ /**
+ * 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());
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++) {
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);
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);
}
}
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<Date, ElementMapTRKPT> map : this.entrySet()) {
- System.out.println("|--------------------------------|--------------------|--------------------|");
ElementMapTRKPT mapTRKPT = map.getValue();
mapTRKPT.printinfo();
}
- System.out.println("|--------------------------------|--------------------|--------------------|");
+ System.out.println("|--------------------------------+--------------------+--------------------|");
System.out.println();
}
public boolean param_GpxOutputWpt = true;\r
public boolean param_ImgOutputAll = false;\r
public String param_GpxSourceFolder = ".";\r
+ Document document;\r
\r
+ public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss";\r
+ public static final SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
+ public static final SimpleDateFormat dfuk = new SimpleDateFormat(TIME_FORMAT_STRING +"'Z'");\r
+\r
@Override\r
public void run() {\r
/**\r
* @throws TransformerException \r
*/\r
void procGPXfile(File gpxFile) throws ParserConfigurationException, SAXException, IOException, ParseException, ImageReadException, ImageWriteException, TransformerException {\r
- DocumentBuilderFactory factory;\r
- DocumentBuilder builder;\r
+ DocumentBuilderFactory factory = null;\r
+ DocumentBuilder builder = null;\r
+ ElementMapTRKSEG mapTRKSEG = null;\r
+ Node gpx = null;\r
+ \r
+ System.gc();\r
\r
String fileName = gpxFile.getName();\r
String iStr = fileName.substring(0, fileName.length() - 4);\r
factory.setValidating(true);\r
\r
// GPXファイルをパースする\r
- ElementMapTRKSEG mapTRKSEG = new ElementMapTRKSEG();\r
+ mapTRKSEG = new ElementMapTRKSEG();\r
document = mapTRKSEG.parse(gpxFile);\r
\r
// パースされた mapTRKSEG の中身を出力する\r
mapTRKSEG.printinfo();\r
\r
// GPX file --> Node root\r
- Node gpx = builder.parse(gpxFile).getFirstChild();\r
+ gpx = builder.parse(gpxFile).getFirstChild();\r
\r
// imgDir内の画像ファイルを処理する\r
System.out.println("|--------------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|");\r
return ret;\r
}\r
\r
- static Document document;\r
-\r
-\r
- /**\r
- * 2012-06-10T05:09:46Z (日本時間の'2012-06-10T14:09:46')\r
- */\r
- public static final String TIME_FORMAT_STRING = "yyyy-MM-dd'T'HH:mm:ss";\r
- public static SimpleDateFormat dfjp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");\r
- public static SimpleDateFormat dfuk = new SimpleDateFormat(TIME_FORMAT_STRING +"'Z'");\r
-\r
/**\r
* 対象は '*.JPG' のみ対象とする\r
* @return \r
wpt.appendChild(name);\r
\r
Element link = document.createElement("link");\r
- link.setAttribute("href", getShortPathName(imgDir, iFile));\r
+ link.setAttribute("href", ImportPicture.getShortPathName(imgDir, iFile));\r
Element text = document.createElement("text");\r
text.setTextContent(iFile.getName());\r
link.appendChild(text);\r
return filePath;\r
}\r
}\r
-\r
- public static Element getCopy(Document doc, Node node) {\r
- Element root = doc.createElement(node.getNodeName());\r
-\r
- NamedNodeMap nodeMap = node.getAttributes();\r
- if (null != nodeMap) {\r
- for (int j=0; j < nodeMap.getLength(); j++ ) {\r
- root.setAttribute(nodeMap.item(j).getNodeName(), nodeMap.item(j).getNodeValue());\r
- }\r
- }\r
-\r
- NodeList nodes = node.getChildNodes();\r
- for (int i=0; i < nodes.getLength(); i++) {\r
- Node node2 = nodes.item(i);\r
- if (node2.getNodeType() == Node.ELEMENT_NODE) {\r
- root.appendChild(getCopy(doc, node2));\r
- }\r
- else if (node2.getNodeType() == Node.TEXT_NODE) {\r
- String str = node2.getNodeValue();\r
- Text textContents = doc.createTextNode(str);\r
- root.appendChild(textContents);\r
- }\r
- else if (node2.getNodeType() == Node.CDATA_SECTION_NODE) {\r
- String str = node2.getNodeValue();\r
- CDATASection cdataSection = doc.createCDATASection(str);\r
- root.appendChild(cdataSection);\r
- }\r
- }\r
- return root;\r
- }\r
- \r
+ \r
/**\r
* ファイル名の順序に並び替えるためのソートクラス\r
* \r
* @author hayashi\r
*/\r
- static class FileSort implements Comparator<File>{\r
+ static class FileSort implements Comparator<File> {\r
@Override\r
public int compare(File src, File target){\r
int diff = src.getName().compareTo(target.getName());\r
* JPEGファイルフィルター\r
* @author yuu\r
*/\r
- class JpegFileFilter implements FilenameFilter{\r
+ class JpegFileFilter implements FilenameFilter {\r
public boolean accept(File dir, String name) {\r
if (name.toUpperCase().matches(".*\\.JPG$")) {\r
return true;\r
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()));
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 {
"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),
"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),
@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);
}
}
- 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));
* 実行する
* @throws Exception
*/
- public static void testdo(String iniFilePath) {
+ static void testdo(String iniFilePath) {
try {
String[] argv = new String[1];
argv[0] = new String(iniFilePath);
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();
}
}
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;
+ }
}
--- /dev/null
+#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/.