forked from upstream-mirrors/OpenTracks
Added check for negative time changes and bugfix for files with multiple tracks
This commit is contained in:
@@ -122,6 +122,11 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
*/
|
*/
|
||||||
private boolean isInTrackElement;
|
private boolean isInTrackElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counter to find out which child level of track we are processing
|
||||||
|
*/
|
||||||
|
private int trackChildDepth;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SAX-Locator to get current line information
|
* SAX-Locator to get current line information
|
||||||
*/
|
*/
|
||||||
@@ -193,11 +198,13 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isInTrackElement = true;
|
isInTrackElement = true;
|
||||||
|
trackChildDepth = 0;
|
||||||
onTrackElementStart();
|
onTrackElementStart();
|
||||||
|
|
||||||
// process this element only as sub-elements of track
|
// process this element only as sub-elements of track
|
||||||
} else if (isInTrackElement) {
|
} else if (isInTrackElement) {
|
||||||
|
|
||||||
|
trackChildDepth++;
|
||||||
if (localName.equalsIgnoreCase(TAG_TRACK_POINT)) {
|
if (localName.equalsIgnoreCase(TAG_TRACK_POINT)) {
|
||||||
onTrackPointElementStart(attributes);
|
onTrackPointElementStart(attributes);
|
||||||
}
|
}
|
||||||
@@ -211,6 +218,7 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
if (localName.equalsIgnoreCase(TAG_TRACK)) {
|
if (localName.equalsIgnoreCase(TAG_TRACK)) {
|
||||||
onTrackElementEnd();
|
onTrackElementEnd();
|
||||||
isInTrackElement = false;
|
isInTrackElement = false;
|
||||||
|
trackChildDepth = 0;
|
||||||
|
|
||||||
// process these elements only as sub-elements of track
|
// process these elements only as sub-elements of track
|
||||||
} else if (isInTrackElement) {
|
} else if (isInTrackElement) {
|
||||||
@@ -222,10 +230,17 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
} else if (localName.equalsIgnoreCase(TAG_TIME)) {
|
} else if (localName.equalsIgnoreCase(TAG_TIME)) {
|
||||||
onTimeElementEnd();
|
onTimeElementEnd();
|
||||||
} else if (localName.equalsIgnoreCase(TAG_NAME)) {
|
} else if (localName.equalsIgnoreCase(TAG_NAME)) {
|
||||||
onNameElementEnd();
|
// we are only interested in the first level name element
|
||||||
|
if (trackChildDepth == 1) {
|
||||||
|
onNameElementEnd();
|
||||||
|
}
|
||||||
} else if (localName.equalsIgnoreCase(TAG_DESCRIPTION)) {
|
} else if (localName.equalsIgnoreCase(TAG_DESCRIPTION)) {
|
||||||
onDescriptionElementEnd();
|
// we are only interested in the first level description element
|
||||||
|
if (trackChildDepth == 1) {
|
||||||
|
onDescriptionElementEnd();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
trackChildDepth--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset element content
|
// reset element content
|
||||||
@@ -342,6 +357,7 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
tracksWritten.add(track.getId());
|
tracksWritten.add(track.getId());
|
||||||
isCurrentTrackRollbackable = false;
|
isCurrentTrackRollbackable = false;
|
||||||
lastLocation = null;
|
lastLocation = null;
|
||||||
|
stats = null;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -366,6 +382,15 @@ public class GpxImporter extends DefaultHandler {
|
|||||||
|
|
||||||
if (location != null) {
|
if (location != null) {
|
||||||
|
|
||||||
|
// check for negative time change
|
||||||
|
if (lastLocation != null) {
|
||||||
|
long timeDifference = time - lastLocation.getTime();
|
||||||
|
if (timeDifference < 0) {
|
||||||
|
String msg = createErrorMessage("Found negative time change.");
|
||||||
|
throw new SAXException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
location.setTime(time);
|
location.setTime(time);
|
||||||
// initialize start time with time of first track point
|
// initialize start time with time of first track point
|
||||||
if (stats == null) {
|
if (stats == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user