Changeset 2094 in josm
- Timestamp:
- 2009-09-11T10:24:41+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r2092 r2094 36 36 37 37 /** 38 * Parser for the Osm Api. Read from an input stream and construct a dataset out of it. 38 * Parser for the Osm Api. Read from an input stream and constructs a dataset out of it. 39 39 * 40 40 */ … … 80 80 } 81 81 82 private static class OsmPrimitiveData {83 public long id = 0;84 public boolean modified = false;85 public boolean deleted = false;86 public Date timestamp = new Date();87 public User user = null;88 public boolean visible = true;89 public int version = 0;90 public LatLon latlon = new LatLon(0,0);91 private OsmPrimitive primitive;92 93 public void copyTo(OsmPrimitive osm) {94 osm.setModified(modified);95 osm.setDeleted(deleted);96 // id < 0 possible if read from a file97 if (id <= 0) {98 osm.clearOsmId();99 } else {100 osm.setOsmId(id, version);101 }102 osm.setTimestamp(timestamp);103 osm.user = user;104 osm.setVisible(visible);105 osm.mappaintStyle = null;106 }107 108 public Node createNode() {109 Node node = new Node();110 node.setCoor(latlon);111 copyTo(node);112 primitive = node;113 return node;114 }115 116 public Way createWay() {117 Way way = new Way();118 copyTo(way);119 primitive = way;120 return way;121 }122 public Relation createRelation() {123 Relation relation= new Relation();124 copyTo(relation);125 primitive = relation;126 return relation;127 }128 129 public void rememberTag(String key, String value) {130 primitive.put(key, value);131 }132 }133 82 134 83 /** … … 152 101 private Map<Long, Collection<RelationMemberData>> relations = new HashMap<Long, Collection<RelationMemberData>>(); 153 102 154 static public class OsmDataParsingException extends SAXException {155 private int columnNumber;156 private int lineNumber;157 158 public OsmDataParsingException() {159 super();160 }161 162 public OsmDataParsingException(Exception e) {163 super(e);164 }165 166 public OsmDataParsingException(String message, Exception e) {167 super(message, e);168 }169 170 public OsmDataParsingException(String message) {171 super(message);172 }173 174 public OsmDataParsingException rememberLocation(Locator locator) {175 if (locator == null) return this;176 this.columnNumber = locator.getColumnNumber();177 this.lineNumber = locator.getLineNumber();178 return this;179 }180 181 @Override182 public String getMessage() {183 String msg = super.getMessage();184 if (lineNumber == 0 && columnNumber == 0)185 return msg;186 if (msg == null) {187 msg = getClass().getName();188 }189 msg = msg + " " + tr("(at line {0}, column {1})", lineNumber, columnNumber);190 return msg;191 }192 193 public int getColumnNumber() {194 return columnNumber;195 }196 197 public int getLineNumber() {198 return lineNumber;199 }200 }201 103 202 104 private class Parser extends DefaultHandler { … … 601 503 } 602 504 } 505 506 /** 507 * Temporarily holds data for a parsed {@see OsmPrimitive} and provides 508 * methods for creating an {@see OsmPrimitive} based on this data. 509 */ 510 private static class OsmPrimitiveData { 511 public long id = 0; 512 public boolean modified = false; 513 public boolean deleted = false; 514 public Date timestamp = new Date(); 515 public User user = null; 516 public boolean visible = true; 517 public int version = 0; 518 public LatLon latlon = new LatLon(0,0); 519 private OsmPrimitive primitive; 520 521 public void copyTo(OsmPrimitive osm) { 522 // id < 0 possible if read from a file 523 if (id <= 0) { 524 osm.clearOsmId(); 525 } else { 526 osm.setOsmId(id, version); 527 } 528 osm.setDeleted(deleted); 529 osm.setModified(modified); 530 osm.setTimestamp(timestamp); 531 osm.user = user; 532 osm.setVisible(visible); 533 osm.mappaintStyle = null; 534 } 535 536 public Node createNode() { 537 Node node = new Node(); 538 node.setCoor(latlon); 539 copyTo(node); 540 primitive = node; 541 return node; 542 } 543 544 public Way createWay() { 545 Way way = new Way(); 546 copyTo(way); 547 primitive = way; 548 return way; 549 } 550 public Relation createRelation() { 551 Relation relation= new Relation(); 552 copyTo(relation); 553 primitive = relation; 554 return relation; 555 } 556 557 public void rememberTag(String key, String value) { 558 primitive.put(key, value); 559 } 560 } 603 561 }
Note:
See TracChangeset
for help on using the changeset viewer.