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> {
21 * @throws ParseException
22 * @throws ParserConfigurationException
24 * @throws SAXException
25 * @throws DOMException
27 public static void main(String[] argv) throws DOMException, SAXException, IOException, ParserConfigurationException, ParseException {
28 ElementMapTRKSEG mapTRKSEG = null;
29 mapTRKSEG = new ElementMapTRKSEG();
30 mapTRKSEG.parse(new File("testdata/cameradata/separate.gpx"));
31 mapTRKSEG.printinfo();
34 public ElementMapTRKSEG() {
35 super(new TimeComparator());
44 * <trkpt lat="35.32123832" lon="139.56965631">
45 * <ele>47.20000076293945</ele>
46 * <time>2012-06-15T03:00:29Z</time>
56 * @throws SAXException
58 * @throws ParserConfigurationException
59 * @throws DOMException
60 * @throws ParseException
62 public Document parse(File gpxFile) throws SAXException, IOException, ParserConfigurationException, DOMException, ParseException {
63 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
64 DocumentBuilder builder = factory.newDocumentBuilder();
65 factory.setIgnoringElementContentWhitespace(true);
66 factory.setIgnoringComments(true);
67 factory.setValidating(true);
69 Node gpx = builder.parse(gpxFile).getFirstChild();
70 Document document = gpx.getOwnerDocument();
71 NodeList nodes = gpx.getChildNodes();
72 for (int i=0; i < nodes.getLength(); i++) {
73 Node node2 = nodes.item(i);
74 if (node2.getNodeName().equals("trk")) {
75 Element trk = (Element) node2;
77 NodeList nodes1 = trk.getChildNodes();
78 for (int i1=0; i1 < nodes1.getLength(); i1++) {
79 Node nodeTRKSEG = nodes1.item(i1);
80 if (nodeTRKSEG.getNodeName().equals("trkseg")) {
91 * 拡張put value:Node<TRKSEG>をputするとNode<TRKSEG>内のNode<TRKSPT>を put(key,value)する。
94 * @throws ParseException
95 * @throws DOMException
97 public void put(Node nodeTRKSEG) throws DOMException, ParseException {
98 if (nodeTRKSEG.getNodeName().equals("trkseg")) {
99 NodeList nodes2 = nodeTRKSEG.getChildNodes();
101 ElementMapTRKPT mapTRKPT = new ElementMapTRKPT();
102 for (int i2 = 0; i2 < nodes2.getLength(); i2++) {
103 Node nodeTRKPT = nodes2.item(i2);
104 if (nodeTRKPT.getNodeName().equals("trkpt")) {
105 if (ImportPicture.param_GpxNoFirstNode && (i2 == 0)) {
108 mapTRKPT.put(new TagTrkpt((Element)nodeTRKPT));
116 * 拡張put value:ElementMapTRKPTをputするとElementMapTRKPT内の最初のエントリのtimeを読み取ってkeyとしてthis.put(key,value)する。
118 * @throws DOMException
120 public void put(ElementMapTRKPT value) {
121 for (Date key : value.keySet()) {
122 this.put(key, value);
127 public void printinfo() {
128 System.out.println(" +--------------------+--------------------|");
129 System.out.println(" GPS logging time | First Time | Last Time |");
130 System.out.println("|--------------------------------+--------------------+--------------------|");
131 for (java.util.Map.Entry<Date, ElementMapTRKPT> map : this.entrySet()) {
132 ElementMapTRKPT mapTRKPT = map.getValue();
133 mapTRKPT.printinfo();
135 System.out.println("|--------------------------------+--------------------+--------------------|");
136 System.out.println();