Changeset 5397 in josm


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

fix element ordering when writing gpx (see #7927)

Location:
trunk/src/org/openstreetmap/josm/io
Files:
3 edited

Legend:

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

    r5396 r5397  
    3333import org.openstreetmap.josm.gui.layer.Layer;
    3434import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    35 import org.openstreetmap.josm.io.auth.CredentialsManager;
    3635import org.openstreetmap.josm.tools.CheckParameterUtil;
    3736import org.openstreetmap.josm.tools.GBC;
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r5395 r5397  
    9393                currentData.creator = atts.getValue("creator");
    9494                version = atts.getValue("version");
    95                 if (!equal(version, "1.0") && !equal(version, "1.1")) {
     95                if (version != null && version.startsWith("1.0")) {
     96                    version = "1.0";
     97                } else if (!"1.1".equals(version)) {
     98                    // unknown version, assume 1.1
    9699                    version = "1.1";
    97100                }
    98                 System.err.println("Version: "+version);
     101                break;
    99102            case gpx:
    100103                if (qName.equals("metadata")) {
     
    229232            elements.pop();
    230233            switch (currentState) {
    231             case metadata:
     234            case gpx:       // GPX 1.0
     235            case metadata:  // GPX 1.1
    232236                if (qName.equals("name")) {
    233237                    currentData.attr.put(GpxData.META_NAME, accumulator.toString());
     
    238242                } else if (qName.equals("keywords")) {
    239243                    currentData.attr.put(GpxData.META_KEYWORDS, accumulator.toString());
    240                 } else if (qName.equals("metadata")) {
     244                } else if (version.equals("1.0") && qName.equals("author")) {
     245                    // author is a string in 1.0, but complex element in 1.1
     246                    currentData.attr.put(GpxData.META_AUTHOR_NAME, accumulator.toString());
     247                } else if (version.equals("1.0") && qName.equals("email")) {
     248                    currentData.attr.put(GpxData.META_AUTHOR_EMAIL, accumulator.toString());
     249                } else if ((currentState == State.metadata && qName.equals("metadata")) ||
     250                        (currentState == State.gpx && qName.equals("gpx"))) {
    241251                    currentState = states.pop();
    242252                }
     
    334344                    currentState = states.pop();
    335345                }
    336                 break;
    337             case gpx:
    338                 currentState = states.pop();
    339346                break;
    340347            default:
  • 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.