X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fload%2Fxml%2FGpxHandler.java;h=6f63080ceb98461a89ada946fda0d9f35b4fc6f4;hb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465;hp=ec52f8b5b4b81c54cadb5976a0ed4633d528f494;hpb=f35b6d628f68e3b5ef19965ad8988d0dd1eb8efa;p=GpsPrune.git diff --git a/tim/prune/load/xml/GpxHandler.java b/tim/prune/load/xml/GpxHandler.java index ec52f8b..6f63080 100644 --- a/tim/prune/load/xml/GpxHandler.java +++ b/tim/prune/load/xml/GpxHandler.java @@ -19,10 +19,12 @@ public class GpxHandler extends XmlHandler private boolean _startSegment = true; private boolean _isTrackPoint = false; private int _trackNum = -1; - private GpxTag _name = new GpxTag(), _trackName = new GpxTag(); + private GpxTag _fileTitle = new GpxTag(); + private GpxTag _pointName = new GpxTag(), _trackName = new GpxTag(); private String _latitude = null, _longitude = null; private GpxTag _elevation = new GpxTag(), _time = new GpxTag(); - private GpxTag _type = new GpxTag(), _link = new GpxTag(); + private GpxTag _type = new GpxTag(), _description = new GpxTag(); + private GpxTag _link = new GpxTag(); private GpxTag _currentTag = null; private ArrayList _pointList = new ArrayList(); private ArrayList _linkList = new ArrayList(); @@ -51,16 +53,27 @@ public class GpxHandler extends XmlHandler else if (att.equals("lon")) {_longitude = attributes.getValue(i);} } _elevation.setValue(null); - _name.setValue(null); + _pointName.setValue(null); _time.setValue(null); _type.setValue(null); _link.setValue(null); + _description.setValue(null); } else if (tag.equals("ele")) { _currentTag = _elevation; } - else if (tag.equals("name")) { - _currentTag = (_insidePoint?_name:_trackName); + else if (tag.equals("name")) + { + if (_insidePoint) { + _currentTag = _pointName; + } + else if (_trackNum < 0) + { + _currentTag = _fileTitle; + } + else { + _currentTag = _trackName; + } } else if (tag.equals("time")) { _currentTag = _time; @@ -68,6 +81,9 @@ public class GpxHandler extends XmlHandler else if (tag.equals("type")) { _currentTag = _type; } + else if (tag.equals("description") || tag.equals("desc")) { + _currentTag = _description; + } else if (tag.equals("link")) { _link.setValue(attributes.getValue("href")); } @@ -137,17 +153,19 @@ public class GpxHandler extends XmlHandler private void processPoint() { // Put the values into a String array matching the order in getFieldArray() - String[] values = new String[7]; + String[] values = new String[8]; values[0] = _latitude; values[1] = _longitude; values[2] = _elevation.getValue(); - if (_insideWaypoint) {values[3] = _name.getValue();} + if (_insideWaypoint) {values[3] = _pointName.getValue();} values[4] = _time.getValue(); - if (_startSegment && !_insideWaypoint) { + if (_startSegment && !_insideWaypoint) + { values[5] = "1"; _startSegment = false; } values[6] = _type.getValue(); + values[7] = _description.getValue(); _pointList.add(values); _trackNameList.addPoint(_trackNum, _trackName.getValue(), _isTrackPoint); _linkList.add(_link.getValue()); @@ -160,7 +178,8 @@ public class GpxHandler extends XmlHandler public Field[] getFieldArray() { final Field[] fields = {Field.LATITUDE, Field.LONGITUDE, Field.ALTITUDE, - Field.WAYPT_NAME, Field.TIMESTAMP, Field.NEW_SEGMENT, Field.WAYPT_TYPE}; + Field.WAYPT_NAME, Field.TIMESTAMP, Field.NEW_SEGMENT, + Field.WAYPT_TYPE, Field.DESCRIPTION}; return fields; } @@ -204,4 +223,11 @@ public class GpxHandler extends XmlHandler public TrackNameList getTrackNameList() { return _trackNameList; } + + /** + * @return file title + */ + public String getFileTitle() { + return _fileTitle.getValue(); + } }