Changeset 29376 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/IODBReader.java
- Timestamp:
- 2013-03-19T20:46:10+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/IODBReader.java
r29371 r29376 11 11 import javax.xml.parsers.SAXParserFactory; 12 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.data.osm.Node;14 import org.openstreetmap.josm.data.osm.OsmPrimitive;15 import org.openstreetmap.josm.data.osm.Way;16 13 import org.openstreetmap.josm.io.UTFInputStreamReader; 17 14 import org.xml.sax.Attributes; … … 33 30 private IOFields fields; 34 31 private boolean parsingOffset; 32 private boolean parsingDeprecate; 35 33 private SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd"); 36 34 … … 51 49 public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { 52 50 if( !parsingOffset ) { 53 if( qName.equals("offset") || qName.equals("calibration -object") ) {51 if( qName.equals("offset") || qName.equals("calibration") ) { 54 52 parsingOffset = true; 53 parsingDeprecate = false; 55 54 fields.clear(); 56 55 fields.position = parseLatLon(attributes); 56 fields.id = Integer.parseInt(attributes.getValue("id")); 57 57 } 58 58 } else { 59 if( qName.equals("object") ) { 60 fields.isNode = attributes.getValue("type").equals("node"); 61 } else if( qName.equals("last-user") ) { 62 fields.lastUserId = Integer.parseInt(attributes.getValue("id")); 59 if( qName.equals("node") ) { 60 fields.geometry.add(parseLatLon(attributes)); 63 61 } else if( qName.equals("imagery-position") ) { 64 62 fields.imageryPos = parseLatLon(attributes); … … 70 68 if( maxZoom != null ) 71 69 fields.maxZoom = Integer.parseInt(maxZoom); 70 } else if( qName.equals("deprecated") ) { 71 parsingDeprecate = true; 72 72 } 73 73 } … … 85 85 if( parsingOffset ) { 86 86 if( qName.equals("author") ) { 87 fields.author = accumulator.toString(); 87 if( !parsingDeprecate ) 88 fields.author = accumulator.toString(); 89 else 90 fields.abandonAuthor = accumulator.toString(); 88 91 } else if( qName.equals("description") ) { 89 92 fields.description = accumulator.toString(); 93 } else if( qName.equals("reason") && parsingDeprecate ) { 94 fields.abandonReason = accumulator.toString(); 90 95 } else if( qName.equals("date") ) { 91 96 try { 92 fields.date = dateParser.parse(accumulator.toString()); 97 if( !parsingDeprecate ) 98 fields.date = dateParser.parse(accumulator.toString()); 99 else 100 fields.abandonDate = dateParser.parse(accumulator.toString()); 93 101 } catch (ParseException ex) { 94 102 throw new SAXException(ex); 95 103 } 96 104 } else if( qName.equals("deprecated") ) { 97 try { 98 fields.abandonDate = dateParser.parse(accumulator.toString()); 99 } catch (ParseException ex) { 100 throw new SAXException(ex); 101 } 105 parsingDeprecate = false; 102 106 } else if( qName.equals("imagery") ) { 103 107 fields.imagery = accumulator.toString(); 104 } else if( qName.equals("object") ) { 105 fields.objectId = Integer.parseInt(accumulator.toString()); 106 } else if( qName.equals("offset") || qName.equals("calibration-object") ) { 108 } else if( qName.equals("offset") || qName.equals("calibration") ) { 107 109 // store offset 108 110 try { … … 136 138 137 139 private class IOFields { 140 public int id; 138 141 public LatLon position; 139 142 public Date date; … … 141 144 public String description; 142 145 public Date abandonDate; 146 public String abandonAuthor; 147 public String abandonReason; 143 148 public LatLon imageryPos; 144 149 public String imagery; 145 150 public int minZoom, maxZoom; 146 public boolean isNode; 147 public long objectId; 148 public long lastUserId; 151 public List<LatLon> geometry; 149 152 150 153 public IOFields() { … … 153 156 154 157 public void clear() { 158 id = -1; 155 159 position = null; 156 160 date = null; … … 158 162 description = null; 159 163 abandonDate = null; 164 abandonAuthor = null; 165 abandonReason = null; 160 166 imageryPos = null; 161 167 imagery = null; 162 168 minZoom = -1; 163 169 maxZoom = -1; 164 isNode = false; 165 objectId = -1; 166 lastUserId = -1; 170 geometry = new ArrayList<LatLon>(); 167 171 } 168 172 … … 170 174 if( author == null || description == null || position == null || date == null ) 171 175 throw new IllegalArgumentException("Not enought arguments to build an object"); 172 if( objectId < 0 ) { 176 ImageryOffsetBase result; 177 if( geometry.isEmpty() ) { 173 178 if( imagery == null || imageryPos == null ) 174 179 throw new IllegalArgumentException("Both imagery and imageryPos should be sepcified for the offset"); 175 ImageryOffsetresult = new ImageryOffset(imagery, imageryPos);180 result = new ImageryOffset(imagery, imageryPos); 176 181 if( minZoom >= 0 ) 177 result.setMinZoom(minZoom);182 ((ImageryOffset)result).setMinZoom(minZoom); 178 183 if( maxZoom >= 0 ) 179 result.setMaxZoom(maxZoom); 180 result.setBasicInfo(position, author, description, date); 181 result.setAbandonDate(abandonDate); 182 return result; 184 ((ImageryOffset)result).setMaxZoom(maxZoom); 183 185 } else { 184 OsmPrimitive p = isNode ? new Node(objectId) : new Way(objectId); 185 CalibrationObject result = new CalibrationObject(p, lastUserId); 186 result.setBasicInfo(position, author, description, date); 187 result.setAbandonDate(abandonDate); 188 return result; 186 result = new CalibrationObject(geometry.toArray(new LatLon[0])); 189 187 } 188 if( id >= 0 ) 189 result.setId(id); 190 result.setBasicInfo(position, author, description, date); 191 result.setDeprecated(abandonDate, abandonAuthor, abandonReason); 192 return result; 190 193 } 191 194 }
Note:
See TracChangeset
for help on using the changeset viewer.
