+ // Write or copy headers
+ inWriter.write(getXmlHeaderString(inWriter));
+ final String gpxHeader = getGpxHeaderString(inGpxCachers);
+ final boolean isVersion1_1 = (gpxHeader.toUpperCase().indexOf("GPX/1/1") > 0);
+ inWriter.write(gpxHeader);
+ // name and description
+ String trackName = (inName != null && !inName.equals("")) ? XmlUtils.fixCdata(inName) : "GpsPruneTrack";
+ String desc = (inDesc != null && !inDesc.equals("")) ? XmlUtils.fixCdata(inDesc) : "Export from GpsPrune";
+ writeNameAndDescription(inWriter, trackName, desc, isVersion1_1);
+
+ DataPoint point = null;
+ final boolean exportWaypoints = inSettings.getExportWaypoints();
+ final boolean exportSelection = inSettings.getExportJustSelection();
+ final boolean exportTimestamps = inSettings.getExportTimestamps();
+ // Examine selection
+ int selStart = -1, selEnd = -1;
+ if (exportSelection) {
+ selStart = inInfo.getSelection().getStart();
+ selEnd = inInfo.getSelection().getEnd();
+ }
+ // Loop over waypoints
+ final int numPoints = inInfo.getTrack().getNumPoints();
+ int numSaved = 0;
+ for (int i=0; i<numPoints; i++)
+ {
+ point = inInfo.getTrack().getPoint(i);
+ if (!exportSelection || (i>=selStart && i<=selEnd))
+ {
+ // Make a wpt element for each waypoint
+ if (point.isWaypoint() && exportWaypoints)
+ {
+ String pointSource = (inGpxCachers == null? null : getPointSource(inGpxCachers, point));
+ if (pointSource != null)
+ {
+ // If timestamp checkbox is off, strip time
+ if (!exportTimestamps) {
+ pointSource = stripTime(pointSource);
+ }
+ inWriter.write('\t');
+ inWriter.write(pointSource);
+ inWriter.write('\n');
+ }
+ else {
+ exportWaypoint(point, inWriter, inSettings);
+ }
+ numSaved++;
+ }
+ }
+ }
+ // Export both route points and then track points
+ if (inSettings.getExportTrackPoints() || inSettings.getExportPhotoPoints() || inSettings.getExportAudioPoints())
+ {
+ // Output all route points (if any)
+ numSaved += writeTrackPoints(inWriter, inInfo, inSettings,
+ true, inGpxCachers, "<rtept", "\t<rte><number>1</number>\n",
+ null, "\t</rte>\n");
+ // Output all track points, if any
+ String trackStart = "\t<trk>\n\t\t<name>" + trackName + "</name>\n\t\t<number>1</number>\n\t\t<trkseg>\n";
+ numSaved += writeTrackPoints(inWriter, inInfo, inSettings,
+ false, inGpxCachers, "<trkpt", trackStart,
+ "\t</trkseg>\n\t<trkseg>\n", "\t\t</trkseg>\n\t</trk>\n");
+ }
+
+ inWriter.write("</gpx>\n");
+ return numSaved;
+ }
+
+
+ /**
+ * Write the name and description according to the GPX version number
+ * @param inWriter writer object
+ * @param inName name, or null if none supplied
+ * @param inDesc description, or null if none supplied
+ * @param inIsVersion1_1 true if gpx version 1.1, false for version 1.0
+ */
+ private static void writeNameAndDescription(OutputStreamWriter inWriter,
+ String inName, String inDesc, boolean inIsVersion1_1) throws IOException
+ {
+ // Position of name and description fields needs to be different for GPX1.0 and GPX1.1
+ if (inIsVersion1_1)
+ {
+ // GPX 1.1 has the name and description inside a metadata tag
+ inWriter.write("\t<metadata>\n");
+ }
+ if (inName != null && !inName.equals(""))