From: activityworkshop Date: Fri, 17 Apr 2020 09:10:47 +0000 (+0200) Subject: Handling of 'cmt' tags in gpx files, thanks to Willy X-Git-Tag: v20.1.fp1~25 X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=commitdiff_plain;h=890ec6fb37d62c8bfa172094c837424bef550854 Handling of 'cmt' tags in gpx files, thanks to Willy --- diff --git a/src/tim/prune/data/Field.java b/src/tim/prune/data/Field.java index 7b9d779..399d931 100644 --- a/src/tim/prune/data/Field.java +++ b/src/tim/prune/data/Field.java @@ -18,6 +18,7 @@ public class Field public static final Field WAYPT_NAME = new Field("fieldname.waypointname", true); public static final Field WAYPT_TYPE = new Field("fieldname.waypointtype", true); public static final Field DESCRIPTION = new Field("fieldname.description", true); + public static final Field COMMENT = new Field("fieldname.comment", true); public static final Field NEW_SEGMENT = new Field("fieldname.newsegment", true); public static final Field SPEED = new Field("fieldname.speed", true); @@ -66,8 +67,9 @@ public class Field */ public String getName() { - if (_labelKey != null) + if (_labelKey != null) { return I18nManager.getText(_labelKey); + } return _customLabel; } diff --git a/src/tim/prune/function/ShowFullDetails.java b/src/tim/prune/function/ShowFullDetails.java index 8f8289e..8bba3d0 100644 --- a/src/tim/prune/function/ShowFullDetails.java +++ b/src/tim/prune/function/ShowFullDetails.java @@ -239,6 +239,8 @@ public class ShowFullDetails extends GenericFunction addTextPair(result, "fieldname.description", point.getFieldValue(Field.DESCRIPTION)); + addTextPair(result, "fieldname.comment", point.getFieldValue(Field.COMMENT)); + addTextPair(result, "fieldname.waypointtype", point.getFieldValue(Field.WAYPT_TYPE)); // Speed can come from either timestamps and distances, or speed values in data diff --git a/src/tim/prune/load/xml/GpxHandler.java b/src/tim/prune/load/xml/GpxHandler.java index 6f63080..ebd106a 100644 --- a/src/tim/prune/load/xml/GpxHandler.java +++ b/src/tim/prune/load/xml/GpxHandler.java @@ -24,7 +24,7 @@ public class GpxHandler extends XmlHandler private String _latitude = null, _longitude = null; private GpxTag _elevation = new GpxTag(), _time = new GpxTag(); private GpxTag _type = new GpxTag(), _description = new GpxTag(); - private GpxTag _link = new GpxTag(); + private GpxTag _link = new GpxTag(), _comment = new GpxTag(); private GpxTag _currentTag = null; private ArrayList _pointList = new ArrayList(); private ArrayList _linkList = new ArrayList(); @@ -58,6 +58,7 @@ public class GpxHandler extends XmlHandler _type.setValue(null); _link.setValue(null); _description.setValue(null); + _comment.setValue(null); } else if (tag.equals("ele")) { _currentTag = _elevation; @@ -84,6 +85,9 @@ public class GpxHandler extends XmlHandler else if (tag.equals("description") || tag.equals("desc")) { _currentTag = _description; } + else if (tag.equals("cmt")) { + _currentTag = _comment; + } else if (tag.equals("link")) { _link.setValue(attributes.getValue("href")); } @@ -153,7 +157,7 @@ public class GpxHandler extends XmlHandler private void processPoint() { // Put the values into a String array matching the order in getFieldArray() - String[] values = new String[8]; + String[] values = new String[9]; values[0] = _latitude; values[1] = _longitude; values[2] = _elevation.getValue(); @@ -166,6 +170,7 @@ public class GpxHandler extends XmlHandler } values[6] = _type.getValue(); values[7] = _description.getValue(); + values[8] = _comment.getValue(); _pointList.add(values); _trackNameList.addPoint(_trackNum, _trackName.getValue(), _isTrackPoint); _linkList.add(_link.getValue()); @@ -179,7 +184,7 @@ public class GpxHandler extends XmlHandler { final Field[] fields = {Field.LATITUDE, Field.LONGITUDE, Field.ALTITUDE, Field.WAYPT_NAME, Field.TIMESTAMP, Field.NEW_SEGMENT, - Field.WAYPT_TYPE, Field.DESCRIPTION}; + Field.WAYPT_TYPE, Field.DESCRIPTION, Field.COMMENT}; return fields; } diff --git a/src/tim/prune/save/GpxExporter.java b/src/tim/prune/save/GpxExporter.java index 88ac791..8bfd090 100644 --- a/src/tim/prune/save/GpxExporter.java +++ b/src/tim/prune/save/GpxExporter.java @@ -583,6 +583,7 @@ public class GpxExporter extends GenericFunction implements Runnable } source = replaceGpxTags(source, "", "", XmlUtils.fixCdata(inPoint.getFieldValue(Field.DESCRIPTION))); + source = replaceGpxTags(source, "", "", inPoint.getFieldValue(Field.COMMENT)); } // photo / audio links if (source != null && (inPoint.hasMedia() || source.indexOf("") > 0)) { @@ -733,13 +734,21 @@ public class GpxExporter extends GenericFunction implements Runnable inWriter.write(XmlUtils.fixCdata(inPoint.getWaypointName().trim())); inWriter.write("\n"); // description, if any - String desc = XmlUtils.fixCdata(inPoint.getFieldValue(Field.DESCRIPTION)); + final String desc = XmlUtils.fixCdata(inPoint.getFieldValue(Field.DESCRIPTION)); if (desc != null && !desc.equals("")) { inWriter.write("\t\t"); inWriter.write(desc); inWriter.write("\n"); } + // comment, if any + final String comment = XmlUtils.fixCdata(inPoint.getFieldValue(Field.COMMENT)); + if (comment != null && !comment.equals("")) + { + inWriter.write("\t\t"); + inWriter.write(comment); + inWriter.write("\n"); + } // Media links, if any if (inSettings.getExportPhotoPoints() && inPoint.getPhoto() != null) {