Ticket #2545: relation-reading-2.patch

File relation-reading-2.patch, 6.0 KB (added by Gubaer, 4 years ago)
  • src/org/openstreetmap/josm/data/osm/User.java

     
    2020 
    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. */ 
    2528    private User(String name) { 
  • src/org/openstreetmap/josm/io/OsmReader.java

     
    205205                    // ---- PARSING RELATIONS ---- 
    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) 
    216214                              throw new SAXException(tr("Found <member> element in non-relation.")); 
    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")); 
    225239 
     
    270284               // do not store literally; get object reference for string 
    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 
    275297          String visible = atts.getValue("visible"); 
     
    277299               current.visible = Boolean.parseBoolean(visible); 
    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); 
     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              } 
    290316          } 
    291           version = atts.getValue("old_version"); 
    292           if (version != null) { 
    293                current.version = Integer.parseInt(version); 
    294           } 
    295317 
    296318          String action = atts.getValue("action"); 
    297319          if (action == null) 
  • src/org/openstreetmap/josm/io/OsmWriter.java

     
    129129                out.print("    <member type='"); 
    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); 
    135135        }