Changeset 1604 in josm for trunk/src/org


Ignore:
Timestamp:
2009-05-19T19:05:10+02:00 (15 years ago)
Author:
stoecker
Message:

fixed #2545 - patch by Gubaer - JOSM has problems with files from XAPI

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/User.java

    r1169 r1604  
    2121    /** the username. */
    2222    public String name;
     23   
     24    /** the user ID (since API 0.6) */
     25    public String uid;
    2326
    2427    /** private constructor, only called from get method. */
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r1523 r1604  
    206206
    207207                    } else if (qName.equals("relation")) {
    208 //                         relationsN++;
    209208                         current = new OsmPrimitiveData();
    210209                         readCommon(atts, current);
    211210                         relations.put((OsmPrimitiveData)current, new LinkedList<RelationMemberData>());
    212211                    } else if (qName.equals("member")) {
    213 //                         membersN++;
    214212                         Collection<RelationMemberData> list = relations.get(current);
    215213                         if (list == null)
     
    217215                         RelationMemberData emd = new RelationMemberData();
    218216                         emd.relationMember = new RelationMember();
    219                          emd.id = getLong(atts, "ref");
    220                          emd.type=atts.getValue("type");
    221                          emd.relationMember.role = atts.getValue("role");
    222 
     217                         String value = atts.getValue("ref");
     218                         if (value == null) {
     219                             throw new SAXException(tr("Missing attribute \"ref\" on member in relation {0}",current.id));
     220                         }
     221                         try {
     222                             emd.id = Long.parseLong(value);
     223                         } catch(NumberFormatException e) {
     224                             throw new SAXException(tr("Illegal value for attribute \"ref\" on member in relation {0}, got {1}", Long.toString(current.id),value));
     225                         }
     226                         value = atts.getValue("type");
     227                         if (value == null) {
     228                             throw new SAXException(tr("Missing attribute \"type\" on member {0} in relation {1}", Long.toString(emd.id), Long.toString(current.id)));
     229                         }
     230                         if (! (value.equals("way") || value.equals("node") || value.equals("relation"))) {
     231                             throw new SAXException(tr("Unexpected \"type\" on member {0} in relation {1}, got {2}.", Long.toString(emd.id), Long.toString(current.id), value));
     232                         }
     233                         emd.type= value;
     234                         value = atts.getValue("role");
     235                         emd.relationMember.role = value;
     236                         
    223237                         if (emd.id == 0)
    224238                              throw new SAXException(tr("Incomplete <member> specification with ref=0"));
     
    271285               current.user = User.get(user);
    272286          }
     287         
     288          // uid attribute added in 0.6 API
     289          String uid = atts.getValue("uid");
     290          if (uid != null) {
     291              if (current.user != null) {
     292                  current.user.uid = uid;
     293              }
     294         }
    273295
    274296          // visible attribute added in 0.4 API
     
    278300          }
    279301
    280           // oldversion attribute added in 0.6 API
    281 
    282           // Note there is an asymmetry here: the server will send
    283           // the version as "version" the client sends it as
    284           // "oldversion". So we take both since which we receive will
    285           // depend on reading from a file or reading from the server
    286 
    287302          String version = atts.getValue("version");
     303          current.version = 0;
    288304          if (version != null) {
    289                current.version = Integer.parseInt(version);
    290           }
    291           version = atts.getValue("old_version");
    292           if (version != null) {
    293                current.version = Integer.parseInt(version);
     305              try {
     306                  current.version = Integer.parseInt(version);
     307              } catch(NumberFormatException e) {
     308                  throw new SAXException(tr("Illegal value for attribute \"version\" on OSM primitive with id {0}, got {1}", Long.toString(current.id), version));
     309              }
     310          } else {
     311              // version expected for OSM primitives with an id assigned by the server (id > 0), since API 0.6
     312              //
     313              if (current.id > 0 && ds.version != null && ds.version.equals("0.6")) {
     314                  throw new SAXException(tr("Missing attribute \"version\" on OSM primitive with id {0}", Long.toString(current.id)));
     315              }
    294316          }
    295317
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r1587 r1604  
    130130                out.print(OsmApi.which(em.member));
    131131                out.println("' ref='"+getUsedId(em.member)+"' role='" +
    132                         XmlWriter.encode(em.role) + "' />");
     132                        XmlWriter.encode(em.role == null ? "" : em.role) + "' />");
    133133            }
    134134            addTags(e, "relation", false);
Note: See TracChangeset for help on using the changeset viewer.