]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/load/xml/GpxHandler.java
Version 8, September 2009
[GpsPrune.git] / tim / prune / load / xml / GpxHandler.java
index 771621b57f75b98ca1d5229704dda7b63e3a446b..8ab3e17978b878dca0221d8c80c9156fa9b5d1d4 100644 (file)
@@ -17,11 +17,15 @@ 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[]>();
 
+       // FIXME: Read waypoint type too
 
        /**
         * Receive the start of a tag
@@ -57,6 +61,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);
        }
 
@@ -122,10 +134,14 @@ 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[6];
                values[0] = _latitude; values[1] = _longitude;
                values[2] = _elevation; values[3] = _name;
                values[4] = _time;
+               if (_startSegment && !_insideWaypoint) {
+                       values[5] = "1";
+                       _startSegment = false;
+               }
                _pointList.add(values);
        }
 
@@ -136,7 +152,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};
                return fields;
        }
 
@@ -152,7 +168,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;
        }