Ignore:
Timestamp:
2009-06-15T20:22:46+02:00 (17 years ago)
Author:
Gubaer
Message:

fixed: bug in OsmApi.getOsmApi()
cleanup: exception handling in interfacing with OSM API
new: new action for updating individual elements with the their current state on the server (including new menu item in the file menu)
new: improved user feedback in case of conflicts
new: handles 410 Gone conflicts when uploading a changeset
new: undoable command for "purging" a primitive from the current dataset (necessary if the primitive is already deleted on the server and the user wants to remove it from its local dataset)
new: undoable command for "undeleting" an already deleted primitive on the server (kind of "cloning")
new: after a full upload, checks whether there are primitives in the local dataset which might be deleted on the server.
new: data structures for history data
new: history download support in io package

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r1640 r1670  
    1111import org.openstreetmap.josm.data.osm.Node;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
     13import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1314import org.openstreetmap.josm.data.osm.Relation;
    1415import org.openstreetmap.josm.data.osm.RelationMember;
     
    2526
    2627    public final String DEFAULT_API_VERSION = "0.6";
    27    
     28
    2829    /**
    2930     * The counter for newly created objects. Starts at -1 and goes down.
    3031     */
    3132    private long newIdCounter = -1;
    32  
     33
    3334    /**
    3435     * All newly created ids and their primitive that uses it. This is a back reference
     
    4142    private String version;
    4243    private Changeset changeset;
    43    
     44
    4445    public OsmWriter(PrintWriter out, boolean osmConform, String version) {
    4546        super(out);
     
    4748        this.version = (version == null ? DEFAULT_API_VERSION : version);
    4849    }
    49    
     50
    5051    public void setWithBody(boolean wb) {
    5152        this.withBody = wb;
     
    5758        this.version = v;
    5859    }
    59    
     60
    6061    public void header() {
    6162        out.println("<?xml version='1.0' encoding='UTF-8'?>");
     
    7071    public void writeContent(DataSet ds) {
    7172        for (Node n : ds.nodes)
    72             if (shouldWrite(n))
     73            if (shouldWrite(n)) {
    7374                visit(n);
     75            }
    7476        for (Way w : ds.ways)
    75             if (shouldWrite(w))
     77            if (shouldWrite(w)) {
    7678                visit(w);
     79            }
    7780        for (Relation e : ds.relations)
    78             if (shouldWrite(e))
     81            if (shouldWrite(e)) {
    7982                visit(e);
     83            }
    8084    }
    8185
     
    100104        out.print(" lat='"+n.getCoor().lat()+"' lon='"+n.getCoor().lon()+"'");
    101105        if (!withBody) {
    102             out.println("/>"); 
     106            out.println("/>");
    103107        } else {
    104108            addTags(n, "node", true);
     
    110114        addCommon(w, "way");
    111115        if (!withBody) {
    112             out.println("/>"); 
     116            out.println("/>");
    113117        } else {
    114118            out.println(">");
    115             for (Node n : w.nodes)
     119            for (Node n : w.nodes) {
    116120                out.println("    <nd ref='"+getUsedId(n)+"' />");
     121            }
    117122            addTags(w, "way", false);
    118123        }
     
    123128        addCommon(e, "relation");
    124129        if (!withBody) {
    125             out.println("/>"); 
     130            out.println("/>");
    126131        } else {
    127132            out.println(">");
    128133            for (RelationMember em : e.members) {
    129134                out.print("    <member type='");
    130                 out.print(OsmApi.which(em.member));
     135                out.print(OsmPrimitiveType.from(em.member).getAPIName());
    131136                out.println("' ref='"+getUsedId(em.member)+"' role='" +
    132137                        XmlWriter.encode(em.role == null ? "" : em.role) + "' />");
     
    160165    private void addTags(OsmPrimitive osm, String tagname, boolean tagOpen) {
    161166        if (osm.keys != null) {
    162             if (tagOpen)
     167            if (tagOpen) {
    163168                out.println(">");
    164             for (Entry<String, String> e : osm.keys.entrySet())
     169            }
     170            for (Entry<String, String> e : osm.keys.entrySet()) {
    165171                out.println("    <tag k='"+ XmlWriter.encode(e.getKey()) +
    166172                        "' v='"+XmlWriter.encode(e.getValue())+ "' />");
     173            }
    167174            out.println("  </" + tagname + ">");
    168         } else if (tagOpen)
     175        } else if (tagOpen) {
    169176            out.println(" />");
    170         else
     177        } else {
    171178            out.println("  </" + tagname + ">");
     179        }
    172180    }
    173181
     
    180188        out.print("  <"+tagname);
    181189        if (id != 0) {
    182              out.print(" id='"+getUsedId(osm)+"'");
     190            out.print(" id='"+getUsedId(osm)+"'");
    183191        }
    184192        if (!osmConform) {
    185193            String action = null;
    186             if (osm.deleted)
     194            if (osm.deleted) {
    187195                action = "delete";
    188             else if (osm.modified)
     196            } else if (osm.modified) {
    189197                action = "modify";
    190             if (action != null)
     198            }
     199            if (action != null) {
    191200                out.print(" action='"+action+"'");
     201            }
    192202        }
    193203        if (!osm.isTimestampEmpty()) {
     
    199209        }
    200210        out.print(" visible='"+osm.visible+"'");
    201         if (osm.version != -1)
     211        if (osm.version != -1) {
    202212            out.print(" version='"+osm.version+"'");
    203         if (this.changeset != null && this.changeset.id != 0)
     213        }
     214        if (this.changeset != null && this.changeset.id != 0) {
    204215            out.print(" changeset='"+this.changeset.id+"'" );
    205     }
    206    
     216        }
     217    }
     218
    207219    public void close() {
    208220        out.close();
    209221    }
    210    
     222
    211223    public void flush() {
    212224        out.flush();
Note: See TracChangeset for help on using the changeset viewer.