X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fsave%2FGpxExporter.java;h=39b6a362589ce72150cdb4e8a56d85609618e92a;hp=fd4c869c03fac79608b194eb17ca3ffdf0720b08;hb=92dad5df664287acb51728e9ea599f150765d34a;hpb=eebbb64b5d63f9eea43a0dff908c30361a376768 diff --git a/tim/prune/save/GpxExporter.java b/tim/prune/save/GpxExporter.java index fd4c869..39b6a36 100644 --- a/tim/prune/save/GpxExporter.java +++ b/tim/prune/save/GpxExporter.java @@ -11,11 +11,11 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; -import java.nio.charset.Charset; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; @@ -24,26 +24,30 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JRadioButton; import javax.swing.JTextField; +import javax.swing.border.EtchedBorder; import tim.prune.App; import tim.prune.GenericFunction; -import tim.prune.GpsPruner; +import tim.prune.GpsPrune; import tim.prune.I18nManager; import tim.prune.UpdateMessageBroker; import tim.prune.config.Config; -import tim.prune.data.Altitude; -import tim.prune.data.AudioFile; +import tim.prune.data.AudioClip; import tim.prune.data.Coordinate; import tim.prune.data.DataPoint; import tim.prune.data.Field; -import tim.prune.data.MediaFile; +import tim.prune.data.MediaObject; import tim.prune.data.Photo; +import tim.prune.data.RecentFile; import tim.prune.data.Timestamp; import tim.prune.data.TrackInfo; +import tim.prune.data.UnitSetLibrary; import tim.prune.gui.DialogCloser; import tim.prune.load.GenericFileFilter; import tim.prune.save.xml.GpxCacherList; +import tim.prune.save.xml.XmlUtils; /** @@ -59,10 +63,12 @@ public class GpxExporter extends GenericFunction implements Runnable private PointTypeSelector _pointTypeSelector = null; private JCheckBox _timestampsCheckbox = null; private JCheckBox _copySourceCheckbox = null; + private JPanel _encodingsPanel = null; + private JRadioButton _useSystemRadio = null, _forceUtf8Radio = null; private File _exportFile = null; /** this program name */ - private static final String GPX_CREATOR = "Prune v" + GpsPruner.VERSION_NUMBER + " activityworkshop.net"; + private static final String GPX_CREATOR = "GpsPrune v" + GpsPrune.VERSION_NUMBER + " activityworkshop.net"; /** @@ -95,6 +101,13 @@ public class GpxExporter extends GenericFunction implements Runnable _dialog.pack(); } _pointTypeSelector.init(_app.getTrackInfo()); + _encodingsPanel.setVisible(!XmlUtils.isSystemUtf8()); + if (!XmlUtils.isSystemUtf8()) + { + String systemEncoding = XmlUtils.getSystemEncoding(); + _useSystemRadio.setText(I18nManager.getText("dialog.exportgpx.encoding.system") + + " (" + (systemEncoding == null ? "unknown" : systemEncoding) + ")"); + } _dialog.setVisible(true); } @@ -109,7 +122,7 @@ public class GpxExporter extends GenericFunction implements Runnable dialogPanel.setLayout(new BorderLayout()); JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); - // Make a central panel with the text boxes + // Make a panel for the name/desc text boxes JPanel descPanel = new JPanel(); descPanel.setLayout(new GridLayout(2, 2)); descPanel.add(new JLabel(I18nManager.getText("dialog.exportgpx.name"))); @@ -132,6 +145,28 @@ public class GpxExporter extends GenericFunction implements Runnable _copySourceCheckbox.setSelected(true); checkPanel.add(_copySourceCheckbox); mainPanel.add(checkPanel); + // panel for selecting character encoding + _encodingsPanel = new JPanel(); + if (!XmlUtils.isSystemUtf8()) + { + // only add this panel if system isn't utf8 (or can't be identified yet) + _encodingsPanel.setBorder(BorderFactory.createCompoundBorder( + BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(4, 4, 4, 4))); + _encodingsPanel.setLayout(new BorderLayout()); + _encodingsPanel.add(new JLabel(I18nManager.getText("dialog.exportgpx.encoding")), BorderLayout.NORTH); + JPanel radioPanel = new JPanel(); + radioPanel.setLayout(new FlowLayout()); + ButtonGroup radioGroup = new ButtonGroup(); + _useSystemRadio = new JRadioButton(I18nManager.getText("dialog.exportgpx.encoding.system")); + _forceUtf8Radio = new JRadioButton(I18nManager.getText("dialog.exportgpx.encoding.utf8")); + radioGroup.add(_useSystemRadio); + radioGroup.add(_forceUtf8Radio); + radioPanel.add(_useSystemRadio); + radioPanel.add(_forceUtf8Radio); + _useSystemRadio.setSelected(true); + _encodingsPanel.add(radioPanel, BorderLayout.CENTER); + mainPanel.add(_encodingsPanel); + } dialogPanel.add(mainPanel, BorderLayout.CENTER); // close dialog if escape pressed @@ -168,7 +203,8 @@ public class GpxExporter extends GenericFunction implements Runnable private void startExport() { // OK pressed, so check selections - if (!_pointTypeSelector.getAnythingSelected()) { + if (!_pointTypeSelector.getAnythingSelected()) + { JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("dialog.save.notypesselected"), I18nManager.getText("dialog.saveoptions.title"), JOptionPane.WARNING_MESSAGE); return; @@ -183,6 +219,7 @@ public class GpxExporter extends GenericFunction implements Runnable } } + /** * Select a GPX file to save to * @param inParentFrame parent frame for file chooser dialog @@ -234,28 +271,45 @@ public class GpxExporter extends GenericFunction implements Runnable return saveFile; } + /** * Run method for controlling separate thread for exporting */ public void run() { + // Instantiate source file cachers in case we want to copy output + GpxCacherList gpxCachers = null; + if (_copySourceCheckbox.isSelected()) { + gpxCachers = new GpxCacherList(_trackInfo.getFileInfo()); + } OutputStreamWriter writer = null; try { - // normal writing to file - writer = new OutputStreamWriter(new FileOutputStream(_exportFile)); - final boolean[] saveFlags = {_pointTypeSelector.getTrackpointsSelected(), _pointTypeSelector.getWaypointsSelected(), - _pointTypeSelector.getPhotopointsSelected(), _pointTypeSelector.getAudiopointsSelected(), - _pointTypeSelector.getJustSelection(), _timestampsCheckbox.isSelected()}; + // normal writing to file - firstly specify UTF8 encoding if requested + if (_forceUtf8Radio != null && _forceUtf8Radio.isSelected()) + writer = new OutputStreamWriter(new FileOutputStream(_exportFile), "UTF-8"); + else + writer = new OutputStreamWriter(new FileOutputStream(_exportFile)); + // TODO: Move to new method + SettingsForExport settings = new SettingsForExport(); + settings.setExportTrackPoints(_pointTypeSelector.getTrackpointsSelected()); + settings.setExportWaypoints(_pointTypeSelector.getWaypointsSelected()); + settings.setExportPhotoPoints(_pointTypeSelector.getPhotopointsSelected()); + settings.setExportAudiopoints(_pointTypeSelector.getAudiopointsSelected()); + settings.setExportJustSelection(_pointTypeSelector.getJustSelection()); + settings.setExportTimestamps(_timestampsCheckbox.isSelected()); // write file final int numPoints = exportData(writer, _trackInfo, _nameField.getText(), - _descriptionField.getText(), saveFlags, _copySourceCheckbox.isSelected()); + _descriptionField.getText(), settings, gpxCachers); // close file writer.close(); // Store directory in config for later Config.setConfigString(Config.KEY_TRACK_DIR, _exportFile.getParentFile().getAbsolutePath()); + // Add to recent file list + Config.getRecentFileList().addFile(new RecentFile(_exportFile, true)); // Show confirmation + UpdateMessageBroker.informSubscribers(); UpdateMessageBroker.informSubscribers(I18nManager.getText("confirm.save.ok1") + " " + numPoints + " " + I18nManager.getText("confirm.save.ok2") + " " + _exportFile.getAbsolutePath()); @@ -285,42 +339,28 @@ public class GpxExporter extends GenericFunction implements Runnable * @param inInfo track info object * @param inName name of track (optional) * @param inDesc description of track (optional) - * @param inSaveFlags array of booleans to export tracks, waypoints, photos, audios, selection, timestamps - * @param inUseCopy true to copy source if available + * @param inExportSettings flags for what to export and how + * @param inGpxCachers list of Gpx cachers containing input data * @return number of points written * @throws IOException if io errors occur on write */ public static int exportData(OutputStreamWriter inWriter, TrackInfo inInfo, String inName, - String inDesc, boolean[] inSaveFlags, boolean inUseCopy) throws IOException + String inDesc, SettingsForExport inSettings, GpxCacherList inGpxCachers) throws IOException { - // Instantiate source file cachers in case we want to copy output - GpxCacherList gpxCachers = null; - if (inUseCopy) gpxCachers = new GpxCacherList(inInfo.getFileInfo()); // Write or copy headers inWriter.write(getXmlHeaderString(inWriter)); - inWriter.write(getGpxHeaderString(gpxCachers)); - // Name field - String trackName = "PruneTrack"; - if (inName != null && !inName.equals("")) - { - trackName = inName; - inWriter.write("\t"); - inWriter.write(trackName); - inWriter.write("\n"); - } - // Description field - inWriter.write("\t"); - inWriter.write((inDesc != null && !inDesc.equals(""))?inDesc:"Export from Prune"); - inWriter.write("\n"); + 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); - int i = 0; DataPoint point = null; - final boolean exportTrackpoints = inSaveFlags[0]; - final boolean exportWaypoints = inSaveFlags[1]; - final boolean exportPhotos = inSaveFlags[2]; - final boolean exportAudios = inSaveFlags[3]; - final boolean exportSelection = inSaveFlags[4]; - final boolean exportTimestamps = inSaveFlags[5]; + final boolean exportWaypoints = inSettings.getExportWaypoints(); + final boolean exportSelection = inSettings.getExportJustSelection(); + final boolean exportTimestamps = inSettings.getExportTimestamps(); // Examine selection int selStart = -1, selEnd = -1; if (exportSelection) { @@ -330,54 +370,89 @@ public class GpxExporter extends GenericFunction implements Runnable // Loop over waypoints final int numPoints = inInfo.getTrack().getNumPoints(); int numSaved = 0; - for (i=0; i=selStart && i<=selEnd)) { + if (!exportSelection || (i>=selStart && i<=selEnd)) + { // Make a wpt element for each waypoint - if (point.isWaypoint()) { - if (exportWaypoints) + if (point.isWaypoint() && exportWaypoints) + { + String pointSource = (inGpxCachers == null? null : getPointSource(inGpxCachers, point)); + if (pointSource != null) { - String pointSource = (inUseCopy?getPointSource(gpxCachers, point):null); - if (pointSource != null) { - inWriter.write(pointSource); - inWriter.write('\n'); + // If timestamp checkbox is off, strip time + if (!exportTimestamps) { + pointSource = stripTime(pointSource); } - else { - exportWaypoint(point, inWriter, exportTimestamps, exportPhotos, exportAudios); - } - numSaved++; + inWriter.write('\t'); + inWriter.write(pointSource); + inWriter.write('\n'); } + else { + exportWaypoint(point, inWriter, inSettings); + } + numSaved++; } } } // Export both route points and then track points - if (exportTrackpoints || exportPhotos || exportAudios) + if (inSettings.getExportTrackPoints() || inSettings.getExportPhotoPoints() || inSettings.getExportAudioPoints()) { // Output all route points (if any) - numSaved += writeTrackPoints(inWriter, inInfo, exportSelection, exportTrackpoints, exportPhotos, - exportAudios, exportTimestamps, true, gpxCachers, "1\n", + numSaved += writeTrackPoints(inWriter, inInfo, inSettings, + true, inGpxCachers, "1\n", null, "\t\n"); // Output all track points, if any - String trackStart = "\t" + trackName + "1\n"; - numSaved += writeTrackPoints(inWriter, inInfo, exportSelection, exportTrackpoints, exportPhotos, - exportAudios, exportTimestamps, false, gpxCachers, "\n\t\n", "\t\n"); + String trackStart = "\t\n\t\t" + trackName + "\n\t\t1\n\t\t\n"; + numSaved += writeTrackPoints(inWriter, inInfo, inSettings, + false, inGpxCachers, "\n\t\n", "\t\t\n\t\n"); } inWriter.write("\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\n"); + } + if (inName != null && !inName.equals("")) + { + if (inIsVersion1_1) {inWriter.write('\t');} + inWriter.write("\t"); + inWriter.write(inName); + inWriter.write("\n"); + } + if (inIsVersion1_1) {inWriter.write('\t');} + inWriter.write("\t"); + inWriter.write(inDesc); + inWriter.write("\n"); + if (inIsVersion1_1) + { + inWriter.write("\t\n"); + } + } + /** * Loop through the track outputting the relevant track points * @param inWriter writer object for output * @param inInfo track info object containing track - * @param inExportSelection true to just output current selection - * @param inExportTrackpoints true to output track points - * @param inExportPhotos true to output photo points - * @param inExportAudios true to output audio points - * @param inExportTimestamps true to include timestamps in export + * @param inSettings export settings defining what should be exported * @param inOnlyCopies true to only export if source can be copied * @param inCachers list of GpxCachers * @param inPointTag tag to match for each point @@ -386,31 +461,37 @@ public class GpxExporter extends GenericFunction implements Runnable * @param inEndTag end tag to output */ private static int writeTrackPoints(OutputStreamWriter inWriter, - TrackInfo inInfo, boolean inExportSelection, boolean inExportTrackpoints, - boolean inExportPhotos, boolean inExportAudios, boolean exportTimestamps, + TrackInfo inInfo, SettingsForExport inSettings, boolean inOnlyCopies, GpxCacherList inCachers, String inPointTag, String inStartTag, String inSegmentTag, String inEndTag) throws IOException { - // Note: far too many input parameters to this method but avoids duplication + // Note: Too many input parameters to this method but avoids duplication // of output functionality for writing track points and route points int numPoints = inInfo.getTrack().getNumPoints(); int selStart = inInfo.getSelection().getStart(); int selEnd = inInfo.getSelection().getEnd(); int numSaved = 0; + final boolean exportSelection = inSettings.getExportJustSelection(); + final boolean exportTrackPoints = inSettings.getExportTrackPoints(); + final boolean exportPhotos = inSettings.getExportPhotoPoints(); + final boolean exportAudios = inSettings.getExportAudioPoints(); + final boolean exportTimestamps = inSettings.getExportTimestamps(); // Loop over track points for (int i=0; i=selStart && i<=selEnd)) && !point.isWaypoint()) + if ((!exportSelection || (i>=selStart && i<=selEnd)) && !point.isWaypoint()) { - if ((point.getPhoto()==null && inExportTrackpoints) || (point.getPhoto()!=null && inExportPhotos) - || (point.getAudio()!=null && inExportAudios)) + if ((point.getPhoto()==null && exportTrackPoints) || (point.getPhoto()!=null && exportPhotos) + || (point.getAudio()!=null && exportAudios)) { // get the source from the point (if any) String pointSource = getPointSource(inCachers, point); // Clear point source if it's the wrong type of point (eg changed from waypoint or route point) - if (pointSource != null && !pointSource.toLowerCase().startsWith(inPointTag)) {pointSource = null;} + if (pointSource != null && !pointSource.trim().toLowerCase().startsWith(inPointTag)) { + pointSource = null; + } if (pointSource != null || !inOnlyCopies) { // restart track segment if necessary @@ -418,19 +499,29 @@ public class GpxExporter extends GenericFunction implements Runnable inWriter.write(inSegmentTag); } if (numSaved == 0) {inWriter.write(inStartTag);} - if (pointSource != null) { + if (pointSource != null) + { + // If timestamps checkbox is off, strip the time + if (!exportTimestamps) { + pointSource = stripTime(pointSource); + } inWriter.write(pointSource); inWriter.write('\n'); } - else { - if (!inOnlyCopies) {exportTrackpoint(point, inWriter, exportTimestamps, inExportPhotos, inExportAudios);} + else + { + if (!inOnlyCopies) { + exportTrackpoint(point, inWriter, inSettings); + } } numSaved++; } } } } - if (numSaved > 0) {inWriter.write(inEndTag);} + if (numSaved > 0) { + inWriter.write(inEndTag); + } return numSaved; } @@ -449,9 +540,18 @@ public class GpxExporter extends GenericFunction implements Runnable // Point has been modified - maybe it's possible to modify the source source = replaceGpxTags(source, "lat=\"", "\"", inPoint.getLatitude().output(Coordinate.FORMAT_DECIMAL_FORCE_POINT)); source = replaceGpxTags(source, "lon=\"", "\"", inPoint.getLongitude().output(Coordinate.FORMAT_DECIMAL_FORCE_POINT)); - source = replaceGpxTags(source, "", "", inPoint.getAltitude().getStringValue(Altitude.Format.METRES)); - source = replaceGpxTags(source, "", inPoint.getTimestamp().getText(Timestamp.FORMAT_ISO_8601)); - if (inPoint.isWaypoint()) {source = replaceGpxTags(source, "", "", inPoint.getWaypointName());} // only for waypoints + source = replaceGpxTags(source, "", "", inPoint.getAltitude().getStringValue(UnitSetLibrary.UNITS_METRES)); + source = replaceGpxTags(source, "", inPoint.getTimestamp().getText(Timestamp.Format.ISO8601, null)); + if (inPoint.isWaypoint()) + { + source = replaceGpxTags(source, "", "", XmlUtils.fixCdata(inPoint.getWaypointName())); + if (source != null) + { + source = source.replaceAll("", "").replaceAll("", ""); + } + source = replaceGpxTags(source, "", "", + XmlUtils.fixCdata(inPoint.getFieldValue(Field.DESCRIPTION))); + } // photo / audio links if (source != null && (inPoint.hasMedia() || source.indexOf("") > 0)) { source = replaceMediaLinks(source, makeMediaLink(inPoint)); @@ -494,6 +594,7 @@ public class GpxExporter extends GenericFunction implements Runnable return null; } + /** * Replace the media tags in the given XML string * @param inSource source XML for point @@ -531,6 +632,7 @@ public class GpxExporter extends GenericFunction implements Runnable return null; } + /** * Get the header string for the xml document including encoding * @param inWriter writer object @@ -538,14 +640,10 @@ public class GpxExporter extends GenericFunction implements Runnable */ private static String getXmlHeaderString(OutputStreamWriter inWriter) { - String encoding = inWriter.getEncoding(); - try { - encoding = Charset.forName(encoding).name(); - } - catch (Exception e) {} // ignore failure to find encoding - return "\n"; + return "\n"; } + /** * Get the header string for the gpx tag * @param inCachers cacher list to ask for headers, if available @@ -557,6 +655,7 @@ public class GpxExporter extends GenericFunction implements Runnable if (inCachers != null) {gpxHeader = inCachers.getFirstHeader();} if (gpxHeader == null || gpxHeader.length() < 5) { + // TODO: Consider changing this to default to GPX 1.1 // Create default (1.0) header gpxHeader = "\n"); // altitude if available - if (inPoint.hasAltitude()) + if (inPoint.hasAltitude() || inSettings.getExportMissingAltitudesAsZero()) { inWriter.write("\t\t"); - inWriter.write("" + inPoint.getAltitude().getStringValue(Altitude.Format.METRES)); + inWriter.write(inPoint.hasAltitude() ? inPoint.getAltitude().getStringValue(UnitSetLibrary.UNITS_METRES) : "0"); inWriter.write("\n"); } - // timestamp if available (point might have timestamp and then be turned into a waypoint) - if (inPoint.hasTimestamp() && inTimestamps) + // timestamp if available (some waypoints have timestamps, some not) + if (inPoint.hasTimestamp() && inSettings.getExportTimestamps()) { inWriter.write("\t\t\n"); } // write waypoint name after elevation and time inWriter.write("\t\t"); - inWriter.write(inPoint.getWaypointName().trim()); + inWriter.write(XmlUtils.fixCdata(inPoint.getWaypointName().trim())); inWriter.write("\n"); + // description, if any + String desc = XmlUtils.fixCdata(inPoint.getFieldValue(Field.DESCRIPTION)); + if (desc != null && !desc.equals("")) + { + inWriter.write("\t\t"); + inWriter.write(desc); + inWriter.write("\n"); + } // Media links, if any - if (inPhoto && inPoint.getPhoto() != null) + if (inSettings.getExportPhotoPoints() && inPoint.getPhoto() != null) { inWriter.write("\t\t"); inWriter.write(makeMediaLink(inPoint.getPhoto())); inWriter.write('\n'); } - if (inAudio && inPoint.getAudio() != null) + if (inSettings.getExportAudioPoints() && inPoint.getAudio() != null) { inWriter.write("\t\t"); inWriter.write(makeMediaLink(inPoint.getAudio())); @@ -635,43 +741,41 @@ public class GpxExporter extends GenericFunction implements Runnable * Export the specified trackpoint into the file * @param inPoint trackpoint to export * @param inWriter writer object - * @param inTimestamps true to export timestamps too - * @param inExportPhoto true to export photo link - * @param inExportAudio true to export audio link + * @param inSettings export settings */ - private static void exportTrackpoint(DataPoint inPoint, Writer inWriter, boolean inTimestamps, - boolean inExportPhoto, boolean inExportAudio) + private static void exportTrackpoint(DataPoint inPoint, Writer inWriter, SettingsForExport inSettings) throws IOException { - inWriter.write("\t\t"); + inWriter.write("\">\n"); // altitude - if (inPoint.hasAltitude()) + if (inPoint.hasAltitude() || inSettings.getExportMissingAltitudesAsZero()) { - inWriter.write(""); - inWriter.write("" + inPoint.getAltitude().getStringValue(Altitude.Format.METRES)); - inWriter.write(""); + inWriter.write("\t\t\t\t"); + inWriter.write(inPoint.hasAltitude() ? inPoint.getAltitude().getStringValue(UnitSetLibrary.UNITS_METRES) : "0"); + inWriter.write("\n"); } // timestamp if available (and selected) - if (inPoint.hasTimestamp() && inTimestamps) + if (inPoint.hasTimestamp() && inSettings.getExportTimestamps()) { - inWriter.write(""); + inWriter.write("\t\t\t\t\n"); } // photo, audio - if (inPoint.getPhoto() != null && inExportPhoto) { + if (inPoint.getPhoto() != null && inSettings.getExportPhotoPoints()) { inWriter.write(makeMediaLink(inPoint.getPhoto())); } - if (inPoint.getAudio() != null && inExportAudio) { + if (inPoint.getAudio() != null && inSettings.getExportAudioPoints()) { inWriter.write(makeMediaLink(inPoint.getAudio())); } - inWriter.write("\n"); + inWriter.write("\t\t\t\n"); } + /** * Make the xml for the media link(s) * @param inPoint point to generate text for @@ -680,7 +784,7 @@ public class GpxExporter extends GenericFunction implements Runnable private static String makeMediaLink(DataPoint inPoint) { Photo photo = inPoint.getPhoto(); - AudioFile audio = inPoint.getAudio(); + AudioClip audio = inPoint.getAudio(); if (photo == null && audio == null) { return null; } @@ -699,8 +803,26 @@ public class GpxExporter extends GenericFunction implements Runnable * @param inMedia media item, either photo or audio * @return link for this media */ - private static String makeMediaLink(MediaFile inMedia) + private static String makeMediaLink(MediaObject inMedia) + { + if (inMedia.getFile() != null) + // file link + return "" + inMedia.getName() + ""; + if (inMedia.getUrl() != null) + // url link + return "" + inMedia.getName() + ""; + // No link available, must have been loaded from zip file - no link possible + return ""; + } + + + /** + * Strip the time from a GPX point source string + * @param inPointSource point source to copy + * @return point source with timestamp removed + */ + private static String stripTime(String inPointSource) { - return "" + inMedia.getFile().getName() + ""; + return inPointSource.replaceAll("[ \t]*", ""); } }