Ticket #2545: relation-reading-2.patch
| File relation-reading-2.patch, 6.0 KB (added by , 17 years ago) |
|---|
-
src/org/openstreetmap/josm/data/osm/User.java
20 20 21 21 /** the username. */ 22 22 public String name; 23 24 /** the user ID (since API 0.6) */ 25 public String uid; 23 26 24 27 /** private constructor, only called from get method. */ 25 28 private User(String name) { -
src/org/openstreetmap/josm/io/OsmReader.java
205 205 // ---- PARSING RELATIONS ---- 206 206 207 207 } else if (qName.equals("relation")) { 208 // relationsN++;209 208 current = new OsmPrimitiveData(); 210 209 readCommon(atts, current); 211 210 relations.put((OsmPrimitiveData)current, new LinkedList<RelationMemberData>()); 212 211 } else if (qName.equals("member")) { 213 // membersN++;214 212 Collection<RelationMemberData> list = relations.get(current); 215 213 if (list == null) 216 214 throw new SAXException(tr("Found <member> element in non-relation.")); 217 215 RelationMemberData emd = new RelationMemberData(); 218 216 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 223 237 if (emd.id == 0) 224 238 throw new SAXException(tr("Incomplete <member> specification with ref=0")); 225 239 … … 270 284 // do not store literally; get object reference for string 271 285 current.user = User.get(user); 272 286 } 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 } 273 295 274 296 // visible attribute added in 0.4 API 275 297 String visible = atts.getValue("visible"); … … 277 299 current.visible = Boolean.parseBoolean(visible); 278 300 } 279 301 280 // oldversion attribute added in 0.6 API281 282 // Note there is an asymmetry here: the server will send283 // the version as "version" the client sends it as284 // "oldversion". So we take both since which we receive will285 // depend on reading from a file or reading from the server286 287 302 String version = atts.getValue("version"); 303 current.version = 0; 288 304 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 } 290 316 } 291 version = atts.getValue("old_version");292 if (version != null) {293 current.version = Integer.parseInt(version);294 }295 317 296 318 String action = atts.getValue("action"); 297 319 if (action == null) -
src/org/openstreetmap/josm/io/OsmWriter.java
129 129 out.print(" <member type='"); 130 130 out.print(OsmApi.which(em.member)); 131 131 out.println("' ref='"+getUsedId(em.member)+"' role='" + 132 XmlWriter.encode(em.role ) + "' />");132 XmlWriter.encode(em.role == null ? "" : em.role) + "' />"); 133 133 } 134 134 addTags(e, "relation", false); 135 135 }
