Ignore:
Timestamp:
2009-04-06T20:18:48+02:00 (15 years ago)
Author:
framm
Message:
  • Major redesign of how JOSM talks to the OSM server. Connections now all go through a new OsmApi class that finds out which version the server uses. JOSM should now be able to handle 0.5 and 0.6 without configuration change. Config options osm-server.version and osm-server.additional-versions now obsolete. Handling of error and cancel situations might still need some improvement.
File:
1 edited

Legend:

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

    r1499 r1523  
    88import java.io.InputStreamReader;
    99import java.util.ArrayList;
    10 import java.util.Arrays;
    1110import java.util.Collection;
    1211import java.util.HashMap;
    13 import java.util.HashSet;
    1412import java.util.LinkedList;
    1513import java.util.Map;
     
    130128     private Map<OsmPrimitiveData, Collection<RelationMemberData>> relations = new HashMap<OsmPrimitiveData, Collection<RelationMemberData>>();
    131129
    132      /**
    133       * List of protocol versions that will be accepted on reading
    134       */
    135      private HashSet<String> allowedVersions = new HashSet<String>();
    136 
    137130     private class Parser extends DefaultHandler {
    138131          /**
     
    164157                         if (atts == null)
    165158                              throw new SAXException(tr("Unknown version"));
    166                          if (!allowedVersions.contains(atts.getValue("version")))
    167                               throw new SAXException(tr("Unknown version")+": "+atts.getValue("version"));
     159                         String v = atts.getValue("version");
     160                         if (v == null)
     161                             throw new SAXException(tr("Version number missing from OSM data"));
     162                         if (!(v.equals("0.5") || v.equals("0.6")))
     163                             throw new SAXException(tr("Unknown version: {0}", v));
    168164                         // save generator attribute for later use when creating DataSource objects
    169165                         generator = atts.getValue("generator");
    170 
    171 
    172                     } else if (qName.equals("bound")) {
    173                          // old style bounds.
    174                          // TODO: remove this around 1st October 2008.
    175                          // - this is a bit of a hack; since we still write out old style bound objects,
    176                          // we don't want to load them both. so when writing, we add a "note" tag the our
    177                          // old-style bound, and when reading, ignore those with a "note".
    178                          String note = atts.getValue("note");
    179                          if (note == null) {
    180                              System.out.println("Notice: old style <bound> element detected; support for these will be dropped in a future release.");
    181                              String bbox = atts.getValue("box");
    182                              String origin = atts.getValue("origin");
    183                              if (origin == null) origin = "";
    184                              if (bbox != null) {
    185                                   String[] b = bbox.split(",");
    186                                   Bounds bounds = new Bounds();
    187                                   if (b.length == 4)
    188                                        bounds = new Bounds(
    189                                                  new LatLon(Double.parseDouble(b[0]),Double.parseDouble(b[1])),
    190                                                  new LatLon(Double.parseDouble(b[2]),Double.parseDouble(b[3])));
    191                                   DataSource src = new DataSource(bounds, origin);
    192                                   ds.dataSources.add(src);
    193                              }
    194                          }
     166                         ds.version = v;
     167                         
    195168                    } else if (qName.equals("bounds")) {
    196169                         // new style bounds.
     
    277250               return Double.parseDouble(atts.getValue(value));
    278251          }
    279      }
    280 
    281      /**
    282       * Constructor initializes list of allowed protocol versions.
    283       */
    284      public OsmReader() {
    285           // first add the main server version
    286           allowedVersions.add(Main.pref.get("osm-server.version", "0.5"));
    287           // now also add all compatible versions
    288           String[] additionalVersions =
    289                Main.pref.get("osm-server.additional-versions", "").split("/,/");
    290           if (additionalVersions.length == 1 && additionalVersions[0].length() == 0)
    291                additionalVersions = new String[] {};
    292           allowedVersions.addAll(Arrays.asList(additionalVersions));
    293252     }
    294253
     
    491450          osm.references = ref == null ? new DataSet() : ref;
    492451
    493 
    494452          currSource = source;
    495453
Note: See TracChangeset for help on using the changeset viewer.