Ignore:
Timestamp:
2013-03-19T20:46:10+01:00 (13 years ago)
Author:
zverik
Message:

another iteration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/IODBReader.java

    r29371 r29376  
    1111import javax.xml.parsers.SAXParserFactory;
    1212import 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;
    1613import org.openstreetmap.josm.io.UTFInputStreamReader;
    1714import org.xml.sax.Attributes;
     
    3330        private IOFields fields;
    3431        private boolean parsingOffset;
     32        private boolean parsingDeprecate;
    3533        private SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd");
    3634
     
    5149        public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    5250            if( !parsingOffset ) {
    53                 if( qName.equals("offset") || qName.equals("calibration-object") ) {
     51                if( qName.equals("offset") || qName.equals("calibration") ) {
    5452                    parsingOffset = true;
     53                    parsingDeprecate = false;
    5554                    fields.clear();
    5655                    fields.position = parseLatLon(attributes);
     56                    fields.id = Integer.parseInt(attributes.getValue("id"));
    5757                }
    5858            } 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));
    6361                } else if( qName.equals("imagery-position") ) {
    6462                    fields.imageryPos = parseLatLon(attributes);
     
    7068                    if( maxZoom != null )
    7169                        fields.maxZoom = Integer.parseInt(maxZoom);
     70                } else if( qName.equals("deprecated") ) {
     71                    parsingDeprecate = true;
    7272                }
    7373            }
     
    8585            if( parsingOffset ) {
    8686                if( qName.equals("author") ) {
    87                     fields.author = accumulator.toString();
     87                    if( !parsingDeprecate )
     88                        fields.author = accumulator.toString();
     89                    else
     90                        fields.abandonAuthor = accumulator.toString();
    8891                } else if( qName.equals("description") ) {
    8992                    fields.description = accumulator.toString();
     93                } else if( qName.equals("reason") && parsingDeprecate ) {
     94                    fields.abandonReason = accumulator.toString();
    9095                } else if( qName.equals("date") ) {
    9196                    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());
    93101                    } catch (ParseException ex) {
    94102                        throw new SAXException(ex);
    95103                    }
    96104                } 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;
    102106                } else if( qName.equals("imagery") ) {
    103107                    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") ) {
    107109                    // store offset
    108110                    try {
     
    136138   
    137139    private class IOFields {
     140        public int id;
    138141        public LatLon position;
    139142        public Date date;
     
    141144        public String description;
    142145        public Date abandonDate;
     146        public String abandonAuthor;
     147        public String abandonReason;
    143148        public LatLon imageryPos;
    144149        public String imagery;
    145150        public int minZoom, maxZoom;
    146         public boolean isNode;
    147         public long objectId;
    148         public long lastUserId;
     151        public List<LatLon> geometry;
    149152
    150153        public IOFields() {
     
    153156       
    154157        public void clear() {
     158            id = -1;
    155159            position = null;
    156160            date = null;
     
    158162            description = null;
    159163            abandonDate = null;
     164            abandonAuthor = null;
     165            abandonReason = null;
    160166            imageryPos = null;
    161167            imagery = null;
    162168            minZoom = -1;
    163169            maxZoom = -1;
    164             isNode = false;
    165             objectId = -1;
    166             lastUserId = -1;
     170            geometry = new ArrayList<LatLon>();
    167171        }
    168172
     
    170174            if( author == null || description == null || position == null || date == null )
    171175                throw new IllegalArgumentException("Not enought arguments to build an object");
    172             if( objectId < 0 ) {
     176            ImageryOffsetBase result;
     177            if( geometry.isEmpty() ) {
    173178                if( imagery == null || imageryPos == null )
    174179                    throw new IllegalArgumentException("Both imagery and imageryPos should be sepcified for the offset");
    175                 ImageryOffset result = new ImageryOffset(imagery, imageryPos);
     180                result = new ImageryOffset(imagery, imageryPos);
    176181                if( minZoom >= 0 )
    177                     result.setMinZoom(minZoom);
     182                    ((ImageryOffset)result).setMinZoom(minZoom);
    178183                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);
    183185            } 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]));
    189187            }
     188            if( id >= 0 )
     189                result.setId(id);
     190            result.setBasicInfo(position, author, description, date);
     191            result.setDeprecated(abandonDate, abandonAuthor, abandonReason);
     192            return result;
    190193        }
    191194    }
Note: See TracChangeset for help on using the changeset viewer.