Ticket #2545: relation-reading-1.patch

File relation-reading-1.patch, 5.6 KB (added by Gubaer, 15 years ago)
  • src/org/openstreetmap/josm/actions/OpenFileAction.java

     
    6565                openAsData(file);
    6666        } catch (SAXException x) {
    6767            x.printStackTrace();
    68             JOptionPane.showMessageDialog(Main.parent, tr("Error while parsing {0}",file.getName())+": "+x.getMessage());
     68            JOptionPane.showMessageDialog(Main.parent, tr("Error while parsing {0}",file.getName())+": "+x.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    6969        } catch (IOException x) {
    7070            x.printStackTrace();
    71             JOptionPane.showMessageDialog(Main.parent, tr("Could not read \"{0}\"",file.getName())+"\n"+x.getMessage());
     71            JOptionPane.showMessageDialog(Main.parent, tr("Could not read \"{0}\"",file.getName())+"\n"+x.getMessage(),"Error", JOptionPane.ERROR_MESSAGE);
    7272        }
    7373    }
    7474
  • 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                         if (value == null) {
     236                             System.out.println(tr("WARNING: no attribute \"role\" on member {0} in relation {1}, assuming empty role \"\"",Long.toString(emd.id), Long.toString(current.id)));
     237                             value = "";
     238                         }
     239                         emd.relationMember.role = value;
     240                         
    223241                         if (emd.id == 0)
    224242                              throw new SAXException(tr("Incomplete <member> specification with ref=0"));
    225243
     
    277295               current.visible = Boolean.parseBoolean(visible);
    278296          }
    279297
    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 
    287298          String version = atts.getValue("version");
     299          current.version = 0;
    288300          if (version != null) {
    289                current.version = Integer.parseInt(version);
     301              try {
     302                  current.version = Integer.parseInt(version);
     303              } catch(NumberFormatException e) {
     304                  throw new SAXException(tr("Illegal value for attribute \"version\" on OSM primitive with id {0}, got {1}", Long.toString(current.id), version));
     305              }
     306          } else {
     307              // version expected for OSM primitives with an id assigned by the server
     308              //
     309              if (current.id > 0) {
     310                  throw new SAXException(tr("Missing attribute \"version\" on OSM primitive with id {0}", Long.toString(current.id)));
     311              }
    290312          }
    291           version = atts.getValue("old_version");
    292           if (version != null) {
    293                current.version = Integer.parseInt(version);
    294           }
    295313
    296314          String action = atts.getValue("action");
    297315          if (action == null)