]> gitweb.fperrin.net Git - GpsPrune.git/commitdiff
Handling of 'cmt' tags in gpx files, thanks to Willy
authoractivityworkshop <mail@activityworkshop.net>
Fri, 17 Apr 2020 09:10:47 +0000 (11:10 +0200)
committeractivityworkshop <mail@activityworkshop.net>
Fri, 17 Apr 2020 09:10:47 +0000 (11:10 +0200)
src/tim/prune/data/Field.java
src/tim/prune/function/ShowFullDetails.java
src/tim/prune/load/xml/GpxHandler.java
src/tim/prune/save/GpxExporter.java

index 7b9d77925c1f39fbd4a1d842d63539245fe93b5b..399d931b5397ddfe4ae43cbcbdbf0a5f33588cea 100644 (file)
@@ -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;
        }
 
index 8f8289e4e0eb38b9523dcd4a8fcdb7549e37fb76..8bba3d0cb65b3e8a53b4146e8ebbe4942467b987 100644 (file)
@@ -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
index 6f63080ceb98461a89ada946fda0d9f35b4fc6f4..ebd106ab59cd77657a7ce7ec1b1943f863146679 100644 (file)
@@ -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<String[]> _pointList = new ArrayList<String[]>();
        private ArrayList<String> _linkList = new ArrayList<String>();
@@ -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;
        }
 
index 88ac7914c29a1b92a235ff426e782f07ca4fcae3..8bfd0905f857b5c744ca8a25c9455da656dbd516 100644 (file)
@@ -583,6 +583,7 @@ public class GpxExporter extends GenericFunction implements Runnable
                        }
                        source = replaceGpxTags(source, "<desc>", "</desc>",
                                XmlUtils.fixCdata(inPoint.getFieldValue(Field.DESCRIPTION)));
+                       source = replaceGpxTags(source, "<cmt>", "</cmt>", inPoint.getFieldValue(Field.COMMENT));
                }
                // photo / audio links
                if (source != null && (inPoint.hasMedia() || source.indexOf("</link>") > 0)) {
@@ -733,13 +734,21 @@ public class GpxExporter extends GenericFunction implements Runnable
                inWriter.write(XmlUtils.fixCdata(inPoint.getWaypointName().trim()));
                inWriter.write("</name>\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<desc>");
                        inWriter.write(desc);
                        inWriter.write("</desc>\n");
                }
+               // comment, if any
+               final String comment = XmlUtils.fixCdata(inPoint.getFieldValue(Field.COMMENT));
+               if (comment != null && !comment.equals(""))
+               {
+                       inWriter.write("\t\t<cmt>");
+                       inWriter.write(comment);
+                       inWriter.write("</cmt>\n");
+               }
                // Media links, if any
                if (inSettings.getExportPhotoPoints() && inPoint.getPhoto() != null)
                {