import org.xml.sax.SAXException;
import tim.prune.data.Field;
+import tim.prune.load.TrackNameList;
/**
*/
public class GpxHandler extends XmlHandler
{
+ private boolean _insidePoint = false;
private boolean _insideWaypoint = false;
private boolean _insideName = false;
private boolean _insideElevation = false;
private boolean _insideTime = false;
+ private boolean _insideType = false;
+ private boolean _startSegment = true;
+ private boolean _isTrackPoint = false;
+ private int _trackNum = -1;
+ private String _trackName = null;
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[]>();
+ private TrackNameList _trackNameList = new TrackNameList();
/**
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"))
{
+ _insidePoint = true;
_insideWaypoint = qName.equalsIgnoreCase("wpt");
+ _isTrackPoint = qName.equalsIgnoreCase("trkpt");
int numAttributes = attributes.getLength();
for (int i=0; i<numAttributes; i++)
{
_elevation = null;
_name = null;
_time = null;
+ _type = null;
}
else if (qName.equalsIgnoreCase("ele"))
{
}
else if (qName.equalsIgnoreCase("name"))
{
+ _name = null;
_insideName = true;
}
else if (qName.equalsIgnoreCase("time"))
{
_insideTime = true;
}
+ else if (qName.equalsIgnoreCase("type"))
+ {
+ _insideType = true;
+ }
+ else if (qName.equalsIgnoreCase("trkseg"))
+ {
+ _startSegment = true;
+ }
+ else if (qName.equalsIgnoreCase("trk"))
+ {
+ _trackNum++;
+ _trackName = null;
+ }
super.startElement(uri, localName, qName, attributes);
}
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();
+ _insidePoint = false;
}
else if (qName.equalsIgnoreCase("ele"))
{
{
_insideTime = false;
}
+ else if (qName.equalsIgnoreCase("type"))
+ {
+ _insideType = false;
+ }
super.endElement(uri, localName, qName);
}
{
String value = new String(ch, start, length);
if (_insideName && _insideWaypoint) {_name = checkCharacters(_name, value);}
+ if (_insideName && !_insidePoint) {_trackName = checkCharacters(_trackName, 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);
}
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);
+ _trackNameList.addPoint(_trackNum, _trackName, _isTrackPoint);
}
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;
}
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;
}
+
+
+ /**
+ * @return track name list
+ */
+ public TrackNameList getTrackNameList() {
+ return _trackNameList;
+ }
}