Ignore:
Timestamp:
2012-08-05T22:40:52+02:00 (12 years ago)
Author:
bastiK
Message:

fix element ordering when writing gpx (see #7927)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/GpxWriter.java

    r5393 r5397  
    99import java.io.PrintWriter;
    1010import java.io.UnsupportedEncodingException;
     11import java.util.Arrays;
    1112import java.util.Collection;
     13import java.util.List;
    1214import java.util.Map;
    1315
     
    6163    }
    6264
     65    public static List<String> WPT_KEYS = Arrays.asList("ele", "time", "magvar", "geoidheight",
     66            "name", "cmt", "desc", "src", GpxData.META_LINKS, "sym", "number", "type",
     67            "fix", "sat", "hdop", "vdop", "pdop", "ageofdgpsdata", "dgpsid");
    6368    @SuppressWarnings("unchecked")
    6469    private void writeAttr(Map<String, Object> attr) {
    65         // FIXME this loop is evil, because it does not assure the
    66         // correct element order specified by the xml schema.
    67         // for now it works, but future extension could get very complex and unmaintainable
    68         for (Map.Entry<String, Object> ent : attr.entrySet()) {
    69             String k = ent.getKey();
    70             if (k.equals(GpxData.META_LINKS)) {
    71                 for (GpxLink link : (Collection<GpxLink>) ent.getValue()) {
    72                     gpxLink(link);
     70        for (String key : WPT_KEYS) {
     71            Object value = attr.get(key);
     72            if (value != null) {
     73                if (key.equals(GpxData.META_LINKS)) {
     74                    for (GpxLink link : (Collection<GpxLink>) value) {
     75                        gpxLink(link);
     76                    }
     77                } else {
     78                    simpleTag(key, value.toString());
    7379                }
    74             } else {
    75                 simpleTag(k, ent.getValue().toString());
    7680            }
    7781        }
Note: See TracChangeset for help on using the changeset viewer.