Changeset 2242 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2009-10-04T00:37:05+02:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java
r2181 r2242 80 80 } 81 81 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 82 99 protected int getMandatoryAttributeInt(Attributes attr, String name) throws SAXException{ 83 100 String v = attr.getValue(name); … … 97 114 } 98 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; 122 try { 123 d = Double.parseDouble(v); 124 } catch(NumberFormatException e) { 125 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v)); 126 } 127 return d; 128 } 129 99 130 protected String getMandatoryAttributeString(Attributes attr, String name) throws SAXException{ 100 131 String v = attr.getValue(name); … … 102 133 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 103 134 } 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; 104 142 return v; 105 143 } … … 119 157 protected HistoryOsmPrimitive createPrimitive(Attributes atts, OsmPrimitiveType type) throws SAXException { 120 158 long id = getMandatoryAttributeLong(atts,"id"); 121 long version = getMandatoryAttributeLong(atts,"version"); 122 long changesetId = getMandatoryAttributeLong(atts,"changeset"); 123 boolean visible= getMandatoryAttributeBoolean(atts, "visible"); 124 long uid = get MandatoryAttributeLong(atts, "uid");125 String user = get MandatoryAttributeString(atts, "user");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>")); 126 164 String v = getMandatoryAttributeString(atts, "timestamp"); 127 165 Date timestamp = DateUtils.fromString(v); 128 166 HistoryOsmPrimitive primitive = null; 129 167 if (type.equals(OsmPrimitiveType.NODE)) { 168 double lat = getMandatoryAttributeDouble(atts, "lat"); 169 double lon = getMandatoryAttributeDouble(atts, "lon"); 130 170 primitive = new HistoryNode( 131 id,version,visible,user,uid,changesetId,timestamp 171 id,version,visible,user,uid,changesetId,timestamp,lat,lon 132 172 ); 133 173 } else if (type.equals(OsmPrimitiveType.WAY)) {
Note:
See TracChangeset
for help on using the changeset viewer.
