Changeset 227 in josm


Ignore:
Timestamp:
2007-05-07T23:17:41+02:00 (17 years ago)
Author:
framm
Message:

Support new 0.4 attributes "user" and "visible"; support config option "osm-server.additional-versions" containig a comma separated list of version numbers that should be accepted when reading OSM files - defaults to 0.3 to allow reading 0.3 files.

Location:
src/org/openstreetmap/josm
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r220 r227  
    5656
    5757        /**
     58         * Visibility status as specified by the server. The visible attribute was
     59         * introduced with the 0.4 API to be able to communicate deleted objects
     60         * (they will have visible=false). Currently JOSM does never deal with
     61         * these, so this is really for future use only.
     62         */
     63        public boolean visible = true;
     64       
     65        /**
     66         * User that last modified this primitive, as specified by the server.
     67         * Never changed by JOSM.
     68         */
     69        public User user = null;
     70       
     71        /**
    5872         * <code>true</code>, if the object has been shown. This property is not used
    5973         * internally by JOSM, but can be used by plugins that take over the object
     
    182196                        deleted == osm.deleted &&
    183197                        (semanticOnly || (timestamp == null ? osm.timestamp==null : timestamp.equals(osm.timestamp))) &&
     198                        (semanticOnly || (user == null ? osm.user==null : user==osm.user)) &&
     199                        (semanticOnly || (visible == osm.visible)) &&
    184200                        (keys == null ? osm.keys==null : keys.equals(osm.keys));
    185201        }
  • src/org/openstreetmap/josm/io/OsmReader.java

    r225 r227  
    66import java.io.InputStream;
    77import java.io.InputStreamReader;
     8import java.lang.reflect.Array;
    89import java.text.ParseException;
     10import java.util.Arrays;
    911import java.util.Collection;
    1012import java.util.HashMap;
     13import java.util.HashSet;
    1114import java.util.LinkedList;
    1215import java.util.Map;
     
    2023import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2124import org.openstreetmap.josm.data.osm.Segment;
     25import org.openstreetmap.josm.data.osm.User;
    2226import org.openstreetmap.josm.data.osm.Way;
    2327import org.openstreetmap.josm.data.osm.visitor.AddVisitor;
     
    7680                        osm.deleted = deleted;
    7781                        osm.timestamp = timestamp;
     82                        osm.user = user;
     83                        osm.visible = visible;
    7884                }
    7985        }
     
    8490         */
    8591        private Map<OsmPrimitiveData, long[]> segs = new HashMap<OsmPrimitiveData, long[]>();
     92
    8693        /**
    8794         * Data structure for the remaining way objects
     
    8996        private Map<OsmPrimitiveData, Collection<Long>> ways = new HashMap<OsmPrimitiveData, Collection<Long>>();
    9097
     98        /**
     99         * List of protocol versions that will be accepted on reading
     100         */
     101        private HashSet<String> allowedVersions = new HashSet<String>();
    91102
    92103        private class Parser extends MinML2 {
     
    101112                                        if (atts == null)
    102113                                                throw new SAXException(tr("Unknown version"));
    103                                         if (!Main.pref.get("osm-server.version", "0.4").equals(atts.getValue("version")))
     114                                        if (!allowedVersions.contains(atts.getValue("version")))
    104115                                                throw new SAXException(tr("Unknown version")+": "+atts.getValue("version"));
    105116                                } else if (qName.equals("node")) {
     
    138149                }
    139150        }
     151       
     152        /**
     153         * Constructor initializes list of allowed protocol versions.
     154         */
     155        public OsmReader() {
     156                // first add the main server version
     157                allowedVersions.add(Main.pref.get("osm-server.version", "0.4"));
     158                // now also add all compatible versions
     159                String[] additionalVersions =
     160                        Main.pref.get("osm-server.additional-versions", "0.3").split("/,/");
     161                allowedVersions.addAll(Arrays.asList(additionalVersions));     
     162        }
    140163
    141164        /**
     
    155178                                throw new SAXException(tr("Couldn''t read time format \"{0}\".",time));
    156179                        }
     180                }
     181               
     182                // user attribute added in 0.4 API
     183                String user = atts.getValue("user");
     184                if (user != null) {
     185                        // do not store literally; get object reference for string
     186                        current.user = User.get(user);
     187                }
     188               
     189                // visible attribute added in 0.4 API
     190                String visible = atts.getValue("visible");
     191                if (visible != null) {
     192                        current.visible = Boolean.parseBoolean(visible);
    157193                }
    158194
  • src/org/openstreetmap/josm/io/OsmWriter.java

    r225 r227  
    153153
    154154        /**
    155          * Add the common part as the from of the tag as well as the id or the action tag.
     155         * Add the common part as the form of the tag as well as the XML attributes
     156         * id, action, user, and visible.
    156157         */
    157158        private void addCommon(OsmPrimitive osm, String tagname) {
     
    170171                        out.print(" timestamp='"+time+"'");
    171172                }
     173                // user and visible added with 0.4 API
     174                if (osm.user != null) {
     175                        out.print(" user='"+XmlWriter.encode(osm.user.name)+"'");
     176                }
     177                out.print(" visible='"+osm.visible+"'");
     178               
    172179        }
    173180}
Note: See TracChangeset for help on using the changeset viewer.