Changeset 5589 in josm for trunk


Ignore:
Timestamp:
2012-11-18T13:57:36+01:00 (11 years ago)
Author:
bastiK
Message:

drop unnecessary properties for upload to the OSM API in order to save bandwidth

The properties are: user, uid, visible, action and timestamp. In addition drop lat & lon for deleted nodes. (To undelete a primitive, it suffices to include it in a <modify> section, the 'visible' property is ignored by the server.)

Location:
trunk/src/org/openstreetmap/josm
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/APIDataSet.java

    r5266 r5589  
    5555    public void init(DataSet ds) {
    5656        if (ds == null) return;
     57        init(ds.allPrimitives());
     58    }
     59
     60    public void init(Collection<OsmPrimitive> primitives) {
    5761        toAdd.clear();
    5862        toUpdate.clear();
    5963        toDelete.clear();
    6064
    61         for (OsmPrimitive osm :ds.allPrimitives()) {
     65        for (OsmPrimitive osm :primitives) {
    6266            if (osm.get("josm/ignore") != null) {
    6367                continue;
     
    140144    public APIDataSet(Collection<OsmPrimitive> primitives) {
    141145        this();
    142         toAdd.clear();
    143         toUpdate.clear();
    144         toDelete.clear();
    145         for (OsmPrimitive osm: primitives) {
    146             if (osm.isNewOrUndeleted() && !osm.isDeleted()) {
    147                 toAdd.addLast(osm);
    148             } else if (osm.isModified() && !osm.isDeleted()) {
    149                 toUpdate.addLast(osm);
    150             } else if (osm.isDeleted() && !osm.isNew() && osm.isModified() && osm.isVisible()) {
    151                 toDelete.addFirst(osm);
    152             }
    153         }
    154         OsmPrimitiveComparator c = new OsmPrimitiveComparator();
    155         c.relationsFirst = true;
    156         Collections.sort(toDelete, c);
    157         Collections.sort(toAdd, c);
    158         Collections.sort(toUpdate, c);
     146        init(primitives);
    159147    }
    160148
  • trunk/src/org/openstreetmap/josm/data/osm/IPrimitive.java

    r4431 r5589  
    77
    88/**
    9  * IPrimitive captures the common functions of OsmPrimitive and PrimitiveData.
     9 * IPrimitive captures the common functions of {@link OsmPrimitive} and {@link PrimitiveData}.
    1010 */
    1111public interface IPrimitive extends Tagged, PrimitiveId {
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r5531 r5589  
    2828
    2929/**
    30  * An OSM primitive can be associated with a key/value pair. It can be created, deleted
    31  * and updated within the OSM-Server.
     30 * The base class for OSM objects ({@link Node}, {@link Way}, {@link Relation}).
     31 *
     32 * It can be created, deleted and uploaded to the OSM-Server.
    3233 *
    3334 * Although OsmPrimitive is designed as a base class, it is not to be meant to subclass
  • trunk/src/org/openstreetmap/josm/data/osm/PrimitiveData.java

    r5170 r5589  
    99
    1010/**
     11 * This class can be used to save properties of OsmPrimitive.
    1112 *
    12  * This class can be used to save properties of OsmPrimitive. The main difference between PrimitiveData
     13 * The main difference between PrimitiveData
    1314 * and OsmPrimitive is that PrimitiveData is not part of the dataset and changes in PrimitiveData are not
    1415 * reported by events
    15  *
    1616 */
    1717public abstract class PrimitiveData extends AbstractPrimitive {
  • trunk/src/org/openstreetmap/josm/io/OsmChangeBuilder.java

    r4645 r5589  
    3636        osmwriter = OsmWriterFactory.createOsmWriter(writer, false, apiVersion);
    3737        osmwriter.setChangeset(changeset);
     38        osmwriter.setIsOsmChange(true);
    3839    }
    3940
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r5497 r5589  
    4040    private boolean osmConform;
    4141    private boolean withBody = true;
     42    private boolean isOsmChange;
    4243    private String version;
    4344    private Changeset changeset;
     
    5556        this.withBody = wb;
    5657    }
     58
     59    public void setIsOsmChange(boolean isOsmChange) {
     60        this.isOsmChange = isOsmChange;
     61    }
     62
    5763    public void setChangeset(Changeset cs) {
    5864        this.changeset = cs;
     
    136142        if (n.isIncomplete()) return;
    137143        addCommon(n, "node");
    138         if (n.getCoor() != null) {
    139             out.print(" lat='"+n.getCoor().lat()+"' lon='"+n.getCoor().lon()+"'");
    140         }
    141144        if (!withBody) {
    142145            out.println("/>");
    143146        } else {
     147            if (n.getCoor() != null) {
     148                out.print(" lat='"+n.getCoor().lat()+"' lon='"+n.getCoor().lon()+"'");
     149            }
    144150            addTags(n, "node", true);
    145151        }
     
    240246        } else
    241247            throw new IllegalStateException(tr("Unexpected id 0 for osm primitive found"));
    242         if (!osmConform) {
    243             String action = null;
    244             if (osm.isDeleted()) {
    245                 action = "delete";
    246             } else if (osm.isModified()) {
    247                 action = "modify";
    248             }
    249             if (action != null) {
    250                 out.print(" action='"+action+"'");
    251             }
    252         }
    253         if (!osm.isTimestampEmpty()) {
    254             out.print(" timestamp='"+DateUtils.fromDate(osm.getTimestamp())+"'");
    255         }
    256         // user and visible added with 0.4 API
    257         if (osm.getUser() != null) {
    258             if(osm.getUser().isLocalUser()) {
    259                 out.print(" user='"+XmlWriter.encode(osm.getUser().getName())+"'");
    260             } else if (osm.getUser().isOsmUser()) {
    261                 // uid added with 0.6
    262                 out.print(" uid='"+ osm.getUser().getId()+"'");
    263                 out.print(" user='"+XmlWriter.encode(osm.getUser().getName())+"'");
    264             }
    265         }
    266         out.print(" visible='"+osm.isVisible()+"'");
     248        if (!isOsmChange) {
     249            if (!osmConform) {
     250                String action = null;
     251                if (osm.isDeleted()) {
     252                    action = "delete";
     253                } else if (osm.isModified()) {
     254                    action = "modify";
     255                }
     256                if (action != null) {
     257                    out.print(" action='"+action+"'");
     258                }
     259            }
     260            if (!osm.isTimestampEmpty()) {
     261                out.print(" timestamp='"+DateUtils.fromDate(osm.getTimestamp())+"'");
     262            }
     263            // user and visible added with 0.4 API
     264            if (osm.getUser() != null) {
     265                if(osm.getUser().isLocalUser()) {
     266                    out.print(" user='"+XmlWriter.encode(osm.getUser().getName())+"'");
     267                } else if (osm.getUser().isOsmUser()) {
     268                    // uid added with 0.6
     269                    out.print(" uid='"+ osm.getUser().getId()+"'");
     270                    out.print(" user='"+XmlWriter.encode(osm.getUser().getName())+"'");
     271                }
     272            }
     273            out.print(" visible='"+osm.isVisible()+"'");
     274        }
    267275        if (osm.getVersion() != 0) {
    268276            out.print(" version='"+osm.getVersion()+"'");
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r5587 r5589  
    362362    /**
    363363     * Calculate MD5 hash of a string and output in hexadecimal format.
    364      * Output has length 32 with characters in range [0-9a-f]
     364     * @param data arbitrary String
     365     * @return MD5 hash of data, string of length 32 with characters in range [0-9a-f]
    365366     */
    366367    public static String md5Hex(String data) {
     
    382383
    383384    /**
    384      * Converts a byte array to a string of hexadecimal characters. Preserves leading zeros, so the
    385      * size of the output string is always twice the number of input bytes.
     385     * Converts a byte array to a string of hexadecimal characters.
     386     * Preserves leading zeros, so the size of the output string is always twice
     387     * the number of input bytes.
     388     * @param bytes the byte array
     389     * @return hexadecimal representation
    386390     */
    387391    public static String toHexString(byte[] bytes) {
Note: See TracChangeset for help on using the changeset viewer.