forked from upstream-mirrors/OpenTracks
code format
This commit is contained in:
@@ -114,9 +114,8 @@ public class GpxSaxImporter extends DefaultHandler {
|
|||||||
private MyTracksProviderUtils providerUtils;
|
private MyTracksProviderUtils providerUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* flag to indicate if we in a track xml element
|
* flag to indicate if we in a track xml element some sub elements like name
|
||||||
* some sub elements like name may be used in other
|
* may be used in other parts of the gpx file - ignore them
|
||||||
* parts of the gpx file - ignore them
|
|
||||||
*/
|
*/
|
||||||
private boolean isInTrackElement;
|
private boolean isInTrackElement;
|
||||||
|
|
||||||
@@ -124,19 +123,27 @@ public class GpxSaxImporter extends DefaultHandler {
|
|||||||
* Reads GPS tracks from a GPX file and append tracks and their coordinates to
|
* Reads GPS tracks from a GPX file and append tracks and their coordinates to
|
||||||
* the given list of tracks.
|
* the given list of tracks.
|
||||||
*
|
*
|
||||||
* Callers must execute <pre>rollbackUnfinishedTrack</pre> in case of
|
* Callers must execute
|
||||||
* an exception to avoid inconsistent data
|
*
|
||||||
|
* <pre>
|
||||||
|
* rollbackUnfinishedTrack
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* in case of an exception to avoid inconsistent data
|
||||||
*
|
*
|
||||||
* @param tracks
|
* @param tracks
|
||||||
* a list of tracks
|
* a list of tracks
|
||||||
* @param is
|
* @param is
|
||||||
* a input steam with gpx-xml data
|
* a input steam with gpx-xml data
|
||||||
* @throws SAXException a parsing error
|
* @throws SAXException
|
||||||
* @throws ParserConfigurationException internal error
|
* a parsing error
|
||||||
* @throws IOException a file reading problem
|
* @throws ParserConfigurationException
|
||||||
|
* internal error
|
||||||
|
* @throws IOException
|
||||||
|
* a file reading problem
|
||||||
*/
|
*/
|
||||||
public static long[] importGPXFile(
|
public static long[] importGPXFile(final InputStream is,
|
||||||
final InputStream is,final MyTracksProviderUtils providerUtils)
|
final MyTracksProviderUtils providerUtils)
|
||||||
throws ParserConfigurationException, SAXException, IOException {
|
throws ParserConfigurationException, SAXException, IOException {
|
||||||
|
|
||||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
@@ -186,7 +193,6 @@ public class GpxSaxImporter extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endElement(String uri, String localName, String name)
|
public void endElement(String uri, String localName, String name)
|
||||||
throws SAXException {
|
throws SAXException {
|
||||||
@@ -259,7 +265,6 @@ public class GpxSaxImporter extends DefaultHandler {
|
|||||||
return loc;
|
return loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void onDescriptionElementEnd() {
|
private void onDescriptionElementEnd() {
|
||||||
track.setDescription(content.toString().trim());
|
track.setDescription(content.toString().trim());
|
||||||
}
|
}
|
||||||
@@ -278,7 +283,8 @@ public class GpxSaxImporter extends DefaultHandler {
|
|||||||
stats.addLocation(location, location.getTime());
|
stats.addLocation(location, location.getTime());
|
||||||
|
|
||||||
// insert in db
|
// insert in db
|
||||||
Uri trackPointIdUri = providerUtils.insertTrackPoint(location, track.getId());
|
Uri trackPointIdUri = providerUtils.insertTrackPoint(location, track
|
||||||
|
.getId());
|
||||||
|
|
||||||
// set start and stop id for track
|
// set start and stop id for track
|
||||||
long trackPointId = Long.parseLong(trackPointIdUri.getLastPathSegment());
|
long trackPointId = Long.parseLong(trackPointIdUri.getLastPathSegment());
|
||||||
@@ -322,10 +328,9 @@ public class GpxSaxImporter extends DefaultHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setting time and doing additional calculations
|
* setting time and doing additional calculations as this is the last value
|
||||||
* as this is the last value required. Also sets the
|
* required. Also sets the start time for track and statistics as there is no
|
||||||
* start time for track and statistics as there is
|
* start time in the track root element
|
||||||
* no start time in the track root element
|
|
||||||
*/
|
*/
|
||||||
private void onTimeElementEnd() {
|
private void onTimeElementEnd() {
|
||||||
|
|
||||||
|
|||||||
@@ -54,22 +54,25 @@ public class GpxImporterTest extends AndroidTestCase {
|
|||||||
private static final String TRACK_TIME_2 = "2010-04-22T18:21:50Z";
|
private static final String TRACK_TIME_2 = "2010-04-22T18:21:50Z";
|
||||||
|
|
||||||
// TODO use real files from different sources with more track points
|
// TODO use real files from different sources with more track points
|
||||||
private static final String VALID_TEST_GPX =
|
private static final String VALID_TEST_GPX = "<gpx><trk><name><![CDATA["
|
||||||
"<gpx><trk><name><![CDATA[" + TRACK_NAME + "]]></name><desc><![CDATA[" + TRACK_DESC + "]]></desc><trkseg>" +
|
+ TRACK_NAME + "]]></name><desc><![CDATA[" + TRACK_DESC
|
||||||
"<trkpt lat=\"" + TRACK_LAT_1 + "\" lon=\"" + TRACK_LON_1 + "\"><ele>" + TRACK_ELE_1 + "</ele><time>" + TRACK_TIME_1 + "</time></trkpt> +" +
|
+ "]]></desc><trkseg>" + "<trkpt lat=\"" + TRACK_LAT_1 + "\" lon=\""
|
||||||
"<trkpt lat=\"" + TRACK_LAT_2 + "\" lon=\"" + TRACK_LON_2 + "\"><ele>" + TRACK_ELE_2 + "</ele><time>" + TRACK_TIME_2 + "</time></trkpt>" +
|
+ TRACK_LON_1 + "\"><ele>" + TRACK_ELE_1 + "</ele><time>" + TRACK_TIME_1
|
||||||
"</trkseg></trk></gpx>";
|
+ "</time></trkpt> +" + "<trkpt lat=\"" + TRACK_LAT_2 + "\" lon=\""
|
||||||
|
+ TRACK_LON_2 + "\"><ele>" + TRACK_ELE_2 + "</ele><time>" + TRACK_TIME_2
|
||||||
|
+ "</time></trkpt>" + "</trkseg></trk></gpx>";
|
||||||
|
|
||||||
// invalid xml
|
// invalid xml
|
||||||
private static final String INVALID_TEST_GPX = VALID_TEST_GPX.substring(0,VALID_TEST_GPX.length() - 50);
|
private static final String INVALID_TEST_GPX = VALID_TEST_GPX.substring(0,
|
||||||
|
VALID_TEST_GPX.length() - 50);
|
||||||
|
|
||||||
private static final long TRACK_ID = 1;
|
private static final long TRACK_ID = 1;
|
||||||
private static final long TRACK_POINT_ID = 1;
|
private static final long TRACK_POINT_ID = 1;
|
||||||
|
|
||||||
private static final Uri TRACK_ID_URI =
|
private static final Uri TRACK_ID_URI = ContentUris.appendId(
|
||||||
ContentUris.appendId( TracksColumns.CONTENT_URI.buildUpon(), TRACK_ID).build();
|
TracksColumns.CONTENT_URI.buildUpon(), TRACK_ID).build();
|
||||||
private static final Uri TRACK_POINT_ID_URI =
|
private static final Uri TRACK_POINT_ID_URI = ContentUris.appendId(
|
||||||
ContentUris.appendId( TrackPointsColumns.CONTENT_URI.buildUpon(), TRACK_POINT_ID).build();
|
TrackPointsColumns.CONTENT_URI.buildUpon(), TRACK_POINT_ID).build();
|
||||||
|
|
||||||
private MyTracksProviderUtils providerUtils;
|
private MyTracksProviderUtils providerUtils;
|
||||||
|
|
||||||
@@ -98,12 +101,10 @@ public class GpxImporterTest extends AndroidTestCase {
|
|||||||
Capture<Location> locParam = new Capture<Location>();
|
Capture<Location> locParam = new Capture<Location>();
|
||||||
Capture<Long> idParam = new Capture<Long>();
|
Capture<Long> idParam = new Capture<Long>();
|
||||||
|
|
||||||
expect(
|
expect(providerUtils.insertTrack(capture(trackParam))).andReturn(
|
||||||
providerUtils.insertTrack(capture(trackParam)))
|
TRACK_ID_URI);
|
||||||
.andReturn(TRACK_ID_URI);
|
|
||||||
|
|
||||||
expect(
|
expect(providerUtils.insertTrackPoint(capture(locParam), capture(idParam)))
|
||||||
providerUtils.insertTrackPoint(capture(locParam),capture(idParam)))
|
|
||||||
.andReturn(TRACK_POINT_ID_URI);
|
.andReturn(TRACK_POINT_ID_URI);
|
||||||
expectLastCall().times(2);
|
expectLastCall().times(2);
|
||||||
|
|
||||||
@@ -120,7 +121,8 @@ public class GpxImporterTest extends AndroidTestCase {
|
|||||||
Track track = trackParam.getValue();
|
Track track = trackParam.getValue();
|
||||||
assertEquals(TRACK_NAME, track.getName());
|
assertEquals(TRACK_NAME, track.getName());
|
||||||
assertEquals(TRACK_DESC, track.getDescription());
|
assertEquals(TRACK_DESC, track.getDescription());
|
||||||
assertEquals(DATE_FORMAT.parse(TRACK_TIME_1).getTime(), track.getStartTime());
|
assertEquals(DATE_FORMAT.parse(TRACK_TIME_1).getTime(), track
|
||||||
|
.getStartTime());
|
||||||
assertNotSame(-1, track.getStartId());
|
assertNotSame(-1, track.getStartId());
|
||||||
assertNotSame(-1, track.getStopId());
|
assertNotSame(-1, track.getStopId());
|
||||||
|
|
||||||
@@ -134,17 +136,15 @@ public class GpxImporterTest extends AndroidTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if created track will be deleted on
|
* Test if created track will be deleted on parsing errors
|
||||||
* parsing errors
|
|
||||||
*/
|
*/
|
||||||
public void testImportFailure() throws ParserConfigurationException,
|
public void testImportFailure() throws ParserConfigurationException,
|
||||||
SAXException, IOException {
|
SAXException, IOException {
|
||||||
|
|
||||||
|
expect(providerUtils.insertTrack((Track) EasyMock.anyObject())).andReturn(
|
||||||
|
TRACK_ID_URI);
|
||||||
expect(
|
expect(
|
||||||
providerUtils.insertTrack((Track) EasyMock.anyObject())).andReturn(TRACK_ID_URI);
|
providerUtils.insertTrackPoint((Location) EasyMock.anyObject(),
|
||||||
expect(
|
|
||||||
providerUtils.insertTrackPoint(
|
|
||||||
(Location) EasyMock.anyObject(),
|
|
||||||
EasyMock.anyLong())).andReturn(TRACK_POINT_ID_URI);
|
EasyMock.anyLong())).andReturn(TRACK_POINT_ID_URI);
|
||||||
|
|
||||||
expectLastCall().anyTimes();
|
expectLastCall().anyTimes();
|
||||||
|
|||||||
Reference in New Issue
Block a user