]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/load/xml/GpxHandler.java
Version 9, February 2010
[GpsPrune.git] / tim / prune / load / xml / GpxHandler.java
index 771621b57f75b98ca1d5229704dda7b63e3a446b..b4ae07a4e662c719d80b7b242be0519cbc532472 100644 (file)
@@ -17,11 +17,13 @@ public class GpxHandler extends XmlHandler
        private boolean _insideName = false;
        private boolean _insideElevation = false;
        private boolean _insideTime = false;
+       private boolean _insideType = false;
+       private boolean _startSegment = true;
        private String _name = null, _latitude = null, _longitude = null;
        private String _elevation = null;
        private String _time = null;
-       private ArrayList _pointList = new ArrayList();
-
+       private String _type = null;
+       private ArrayList<String[]> _pointList = new ArrayList<String[]>();
 
        /**
         * Receive the start of a tag
@@ -31,7 +33,7 @@ public class GpxHandler extends XmlHandler
                Attributes attributes) throws SAXException
        {
                // Read the parameters for waypoints and track points
-               if (qName.equalsIgnoreCase("wpt") || qName.equalsIgnoreCase("trkpt"))
+               if (qName.equalsIgnoreCase("wpt") || qName.equalsIgnoreCase("trkpt") || qName.equalsIgnoreCase("rtept"))
                {
                        _insideWaypoint = qName.equalsIgnoreCase("wpt");
                        int numAttributes = attributes.getLength();
@@ -44,6 +46,7 @@ public class GpxHandler extends XmlHandler
                        _elevation = null;
                        _name = null;
                        _time = null;
+                       _type = null;
                }
                else if (qName.equalsIgnoreCase("ele"))
                {
@@ -57,6 +60,14 @@ public class GpxHandler extends XmlHandler
                {
                        _insideTime = true;
                }
+               else if (qName.equalsIgnoreCase("type"))
+               {
+                       _insideType = true;
+               }
+               else if (qName.equalsIgnoreCase("trkseg"))
+               {
+                       _startSegment = true;
+               }
                super.startElement(uri, localName, qName, attributes);
        }
 
@@ -68,7 +79,7 @@ public class GpxHandler extends XmlHandler
        public void endElement(String uri, String localName, String qName)
                throws SAXException
        {
-               if (qName.equalsIgnoreCase("wpt") || qName.equalsIgnoreCase("trkpt"))
+               if (qName.equalsIgnoreCase("wpt") || qName.equalsIgnoreCase("trkpt") || qName.equalsIgnoreCase("rtept"))
                {
                        processPoint();
                }
@@ -84,6 +95,10 @@ public class GpxHandler extends XmlHandler
                {
                        _insideTime = false;
                }
+               else if (qName.equalsIgnoreCase("type"))
+               {
+                       _insideType = false;
+               }
                super.endElement(uri, localName, qName);
        }
 
@@ -99,6 +114,7 @@ public class GpxHandler extends XmlHandler
                if (_insideName && _insideWaypoint) {_name = checkCharacters(_name, value);}
                else if (_insideElevation) {_elevation = checkCharacters(_elevation, value);}
                else if (_insideTime) {_time = checkCharacters(_time, value);}
+               else if (_insideType) {_type = checkCharacters(_type, value);}
                super.characters(ch, start, length);
        }
 
@@ -122,10 +138,15 @@ public class GpxHandler extends XmlHandler
        private void processPoint()
        {
                // Put the values into a String array matching the order in getFieldArray()
-               String[] values = new String[5];
+               String[] values = new String[7];
                values[0] = _latitude; values[1] = _longitude;
                values[2] = _elevation; values[3] = _name;
                values[4] = _time;
+               if (_startSegment && !_insideWaypoint) {
+                       values[5] = "1";
+                       _startSegment = false;
+               }
+               values[6] = _type;
                _pointList.add(values);
        }
 
@@ -136,7 +157,7 @@ public class GpxHandler extends XmlHandler
        public Field[] getFieldArray()
        {
                final Field[] fields = {Field.LATITUDE, Field.LONGITUDE, Field.ALTITUDE,
-                       Field.WAYPT_NAME, Field.TIMESTAMP};
+                       Field.WAYPT_NAME, Field.TIMESTAMP, Field.NEW_SEGMENT, Field.WAYPT_TYPE};
                return fields;
        }
 
@@ -152,7 +173,7 @@ public class GpxHandler extends XmlHandler
                String[][] result = new String[numPoints][];
                for (int i=0; i<numPoints; i++)
                {
-                       result[i] = (String[]) _pointList.get(i);
+                       result[i] = _pointList.get(i);
                }
                return result;
        }