diff options
author | Marco Jacob <mjacob@union06.de> | 2012-06-11 22:10:52 +0200 |
---|---|---|
committer | Marco Jacob <mjacob@union06.de> | 2012-06-11 22:10:52 +0200 |
commit | ade487e941987fd6569d3cec05290dad385efbf3 (patch) | |
tree | 43797826a2a68435612fb67bac2701e5928195f9 /main/src/cgeo/geocaching | |
parent | b335983a2a9ceef86af0d60ced2cd84397899281 (diff) | |
download | cgeo-ade487e941987fd6569d3cec05290dad385efbf3.zip cgeo-ade487e941987fd6569d3cec05290dad385efbf3.tar.gz cgeo-ade487e941987fd6569d3cec05290dad385efbf3.tar.bz2 |
fixes #1740: correct prefix for user defined waypoints
Diffstat (limited to 'main/src/cgeo/geocaching')
-rw-r--r-- | main/src/cgeo/geocaching/export/GpxExport.java | 97 |
1 files changed, 69 insertions, 28 deletions
diff --git a/main/src/cgeo/geocaching/export/GpxExport.java b/main/src/cgeo/geocaching/export/GpxExport.java index afae7ae..5dd98e4 100644 --- a/main/src/cgeo/geocaching/export/GpxExport.java +++ b/main/src/cgeo/geocaching/export/GpxExport.java @@ -26,6 +26,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -122,7 +123,9 @@ class GpxExport extends AbstractExport { gpx.write("</type>"); gpx.write("<groundspeak:cache "); - gpx.write("available=\""); + gpx.write("id=\""); + gpx.write(cache.getCacheId()); + gpx.write("\" available=\""); gpx.write(!cache.isDisabled() ? "True" : "False"); gpx.write("\" archived=\""); gpx.write(cache.isArchived() ? "True" : "False"); @@ -225,35 +228,73 @@ class GpxExport extends AbstractExport { } private void writeWaypoints(final cgCache cache) throws IOException { + List<cgWaypoint> waypoints = cache.getWaypoints(); + List<cgWaypoint> ownWaypoints = new ArrayList<cgWaypoint>(waypoints.size()); + List<cgWaypoint> originWaypoints = new ArrayList<cgWaypoint>(waypoints.size()); for (cgWaypoint wp : cache.getWaypoints()) { - gpx.write("<wpt lat=\""); - final Geopoint coords = wp.getCoords(); - gpx.write(coords != null ? Double.toString(coords.getLatitude()) : ""); // TODO: check whether is the best way to handle unknown waypoint coordinates - gpx.write("\" lon=\""); - gpx.write(coords != null ? Double.toString(coords.getLongitude()) : ""); - gpx.write("\">"); - - gpx.write("<name>"); - gpx.write(StringEscapeUtils.escapeXml(wp.getPrefix())); - gpx.write(StringEscapeUtils.escapeXml(cache.getGeocode().substring(2))); - gpx.write("</name>"); - - gpx.write("<cmt />"); - - gpx.write("<desc>"); - gpx.write(StringEscapeUtils.escapeXml(wp.getNote())); - gpx.write("</desc>"); - - gpx.write("<sym>"); - gpx.write(StringEscapeUtils.escapeXml(wp.getWaypointType().toString())); //TODO: Correct identifier string - gpx.write("</sym>"); - - gpx.write("<type>Waypoint|"); - gpx.write(StringEscapeUtils.escapeXml(wp.getWaypointType().toString())); //TODO: Correct identifier string - gpx.write("</type>"); - - gpx.write("</wpt>"); + if (wp.isUserDefined()) { + ownWaypoints.add(wp); + } else { + originWaypoints.add(wp); + } } + int maxPrefix = 0; + for (cgWaypoint wp : originWaypoints) { + String prefix = wp.getPrefix(); + try { + maxPrefix = Math.max(Integer.parseInt(prefix), maxPrefix); + } catch (NumberFormatException ex) { + Log.e("Unexpected origin waypoint prefix='" + prefix + "'", ex); + } + writeCacheWaypoint(wp, prefix); + } + for (cgWaypoint wp : ownWaypoints) { + maxPrefix++; + String prefix = String.valueOf(maxPrefix); + if (prefix.length() == 1) { + prefix = "0" + prefix; + } + writeCacheWaypoint(wp, prefix); + } + } + + /** + * Writes one waypoint entry for cache waypoint. + * + * @param cache + * The + * @param wp + * @param prefix + * @throws IOException + */ + private void writeCacheWaypoint(final cgWaypoint wp, final String prefix) throws IOException { + gpx.write("<wpt lat=\""); + final Geopoint coords = wp.getCoords(); + gpx.write(coords != null ? Double.toString(coords.getLatitude()) : ""); // TODO: check whether is the best way to handle unknown waypoint coordinates + gpx.write("\" lon=\""); + gpx.write(coords != null ? Double.toString(coords.getLongitude()) : ""); + gpx.write("\">"); + + gpx.write("<name>"); + gpx.write(StringEscapeUtils.escapeXml(prefix)); + gpx.write(StringEscapeUtils.escapeXml(wp.getGeocode().substring(2))); + gpx.write("</name>"); + + gpx.write("<cmt />"); + + gpx.write("<desc>"); + gpx.write(StringEscapeUtils.escapeXml(wp.getNote())); + gpx.write("</desc>"); + + gpx.write("<sym>"); + gpx.write(StringEscapeUtils.escapeXml(wp.getWaypointType().toString())); //TODO: Correct identifier string + gpx.write("</sym>"); + + gpx.write("<type>Waypoint|"); + gpx.write(StringEscapeUtils.escapeXml(wp.getWaypointType().toString())); //TODO: Correct identifier string + gpx.write("</type>"); + + gpx.write("</wpt>"); } private void writeLogs(final cgCache cache) throws IOException { |