4 import java.io.IOException;
5 import java.text.ParseException;
7 import java.util.TreeMap;
9 import javax.xml.parsers.DocumentBuilder;
10 import javax.xml.parsers.DocumentBuilderFactory;
11 import javax.xml.parsers.ParserConfigurationException;
14 import org.xml.sax.SAXException;
16 @SuppressWarnings("serial")
17 public class ElementMapTRKSEG extends TreeMap<Date, ElementMapTRKPT> {
20 * @throws ParseException
21 * @throws ParserConfigurationException
23 * @throws SAXException
24 * @throws DOMException
26 public static void main(String[] argv) throws DOMException, SAXException, IOException, ParserConfigurationException, ParseException {
27 ElementMapTRKSEG mapTRKSEG = null;
28 mapTRKSEG = new ElementMapTRKSEG();
29 mapTRKSEG.parse(new File("testdata/cameradata/separate.gpx"));
30 mapTRKSEG.printinfo();
33 public ElementMapTRKSEG() {
34 super(new TimeComparator());
43 * <trkpt lat="35.32123832" lon="139.56965631">
44 * <ele>47.20000076293945</ele>
45 * <time>2012-06-15T03:00:29Z</time>
54 * @throws SAXException
56 * @throws ParserConfigurationException
57 * @throws DOMException
58 * @throws ParseException
60 public Document parse(File gpxFile) throws SAXException, IOException, ParserConfigurationException, DOMException, ParseException {
61 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
62 DocumentBuilder builder = factory.newDocumentBuilder();
63 factory.setIgnoringElementContentWhitespace(true);
64 factory.setIgnoringComments(true);
65 factory.setValidating(true);
67 Node gpx = builder.parse(gpxFile).getFirstChild();
68 Document document = gpx.getOwnerDocument();
69 NodeList nodes = gpx.getChildNodes();
70 for (int i=0; i < nodes.getLength(); i++) {
71 Node node2 = nodes.item(i);
72 if (node2.getNodeName().equals("trk")) {
73 Element trk = (Element) node2;
75 NodeList nodes1 = trk.getChildNodes();
76 for (int i1=0; i1 < nodes1.getLength(); i1++) {
77 Node nodeTRKSEG = nodes1.item(i1);
78 if (nodeTRKSEG.getNodeName().equals("trkseg")) {
88 * 拡張put value:Node<TRKSEG>をputするとNode<TRKSEG>内のNode<TRKSPT>を put(key,value)する。
90 * @return keyとして登録したtime:Date
91 * @throws ParseException
92 * @throws DOMException
94 public void put(Node nodeTRKSEG) throws DOMException, ParseException {
95 if (nodeTRKSEG.getNodeName().equals("trkseg")) {
96 NodeList nodes2 = nodeTRKSEG.getChildNodes();
98 ElementMapTRKPT mapTRKPT = new ElementMapTRKPT();
99 for (int i2 = 0; i2 < nodes2.getLength(); i2++) {
100 Node nodeTRKPT = nodes2.item(i2);
101 if (nodeTRKPT.getNodeName().equals("trkpt")) {
102 if (ImportPicture.param_GpxNoFirstNode && (i2 == 0)) {
105 mapTRKPT.put(new TagTrkpt((Element)nodeTRKPT));
113 * 拡張put value:ElementMapTRKPTをputするとElementMapTRKPT内の最初のエントリのtimeを読み取ってkeyとしてthis.put(key,value)する。
115 * @return keyとして登録したtime:Date
116 * @throws ParseException
117 * @throws DOMException
119 public void put(ElementMapTRKPT value) {
120 for (Date key : value.keySet()) {
121 this.put(key, value);
126 public void printinfo() {
127 System.out.println(" +--------------------+--------------------|");
128 System.out.println(" GPS logging time | First Time | Last Time |");
129 System.out.println("|--------------------------------+--------------------+--------------------|");
131 for (java.util.Map.Entry<Date, ElementMapTRKPT> map : this.entrySet()) {
132 ElementMapTRKPT mapTRKPT = map.getValue();
133 mapTRKPT.printinfo();
136 System.out.println("|--------------------------------+--------------------+--------------------|");
137 System.out.println();