Changeset 2243 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2009-10-04T12:07:16+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java
r2242 r2243 12 12 import javax.xml.parsers.SAXParserFactory; 13 13 14 import org.openstreetmap.josm.data.coor.LatLon; 14 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 15 16 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; … … 80 81 } 81 82 82 protected long getAttributeLong(Attributes attr, String name, long defaultValue) throws SAXException{ 83 String v = attr.getValue(name); 84 if (v == null) { 85 return defaultValue; 86 } 87 Long l = 0l; 88 try { 89 l = Long.parseLong(v); 90 } catch(NumberFormatException e) { 91 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long. Got ''{1}''.", name, v)); 92 } 93 if (l < 0) { 94 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long (>=0). Got ''{1}''.", name, v)); 95 } 96 return l; 97 } 98 99 protected int getMandatoryAttributeInt(Attributes attr, String name) throws SAXException{ 100 String v = attr.getValue(name); 101 if (v == null) { 102 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 103 } 104 Integer i = 0; 105 try { 106 i = Integer.parseInt(v); 107 } catch(NumberFormatException e) { 108 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type int. Got ''{1}''.", name, v)); 109 } 110 if (i < 0) { 111 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type int (>=0). Got ''{1}''.", name, v)); 112 } 113 return i; 114 } 115 116 protected double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{ 117 String v = attr.getValue(name); 118 if (v == null) { 119 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 120 } 121 double d = 0.0; 83 protected Double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{ 84 String v = attr.getValue(name); 85 if (v == null) { 86 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 87 } 88 double d = 0; 122 89 try { 123 90 d = Double.parseDouble(v); … … 125 92 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v)); 126 93 } 94 if (d < 0) { 95 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double (>=0). Got ''{1}''.", name, v)); 96 } 127 97 return d; 128 98 } … … 133 103 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 134 104 } 135 return v;136 }137 138 protected String getAttributeString(Attributes attr, String name, String defaultValue) {139 String v = attr.getValue(name);140 if (v == null)141 v = defaultValue;142 105 return v; 143 106 } … … 157 120 protected HistoryOsmPrimitive createPrimitive(Attributes atts, OsmPrimitiveType type) throws SAXException { 158 121 long id = getMandatoryAttributeLong(atts,"id"); 159 long version = getMandatoryAttributeLong(atts, "version");160 long changesetId = getMandatoryAttributeLong(atts, "changeset");161 boolean visible = getMandatoryAttributeBoolean(atts, "visible");162 long uid = getAttributeLong(atts, "uid" , -1);163 String user = getAttributeString(atts, "user" , tr("<anonymous>"));122 long version = getMandatoryAttributeLong(atts,"version"); 123 long changesetId = getMandatoryAttributeLong(atts,"changeset"); 124 boolean visible= getMandatoryAttributeBoolean(atts, "visible"); 125 long uid = getMandatoryAttributeLong(atts, "uid"); 126 String user = getMandatoryAttributeString(atts, "user"); 164 127 String v = getMandatoryAttributeString(atts, "timestamp"); 165 128 Date timestamp = DateUtils.fromString(v); … … 169 132 double lon = getMandatoryAttributeDouble(atts, "lon"); 170 133 primitive = new HistoryNode( 171 id,version,visible,user,uid,changesetId,timestamp, lat,lon134 id,version,visible,user,uid,changesetId,timestamp, new LatLon(lat,lon) 172 135 ); 136 173 137 } else if (type.equals(OsmPrimitiveType.WAY)) { 174 138 primitive = new HistoryWay(
Note:
See TracChangeset
for help on using the changeset viewer.
