Changeset 4414 in josm


Ignore:
Timestamp:
2011-09-11T20:22:26+02:00 (13 years ago)
Author:
bastiK
Message:

applied #6742 - allow script generated files to set default changeset info (based on patch by brycenesbitt)

To set a default upload comment and other tags, include a changeset element in the osm file like this:
<osm version='0.6' upload-changeset='-1'>

<changeset id='-1'>

<tag k='comment' v='suggested upload comment'/>
<tag k='source' v='the source'/>

</changeset>
<node .../>
...

</osm>

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r4191 r4414  
    1010
    1111import javax.swing.JOptionPane;
     12import javax.swing.SwingUtilities;
    1213
    1314import org.openstreetmap.josm.Main;
     
    147148     * @param apiData the primitives to be added, updated, or deleted
    148149     */
    149     public void uploadData(OsmDataLayer layer, APIDataSet apiData) {
     150    public void uploadData(final OsmDataLayer layer, APIDataSet apiData) {
    150151        if (apiData.isEmpty()) {
    151152            JOptionPane.showMessageDialog(
     
    161162
    162163        final UploadDialog dialog = UploadDialog.getUploadDialog();
     164        // If we simply set the changeset comment here, it would be
     165        // overridden by subsequent events in EDT that are caused by
     166        // dialog creation. The current solution is to queue this operation
     167        // after these events.
     168        // TODO: find better way to initialize the comment field
     169        SwingUtilities.invokeLater(new Runnable() {
     170            public void run() {
     171                dialog.setDefaultChangesetTags(layer.data.getChangeSetTags());
     172            }
     173        });
    163174        dialog.setUploadedPrimitives(apiData);
    164175        dialog.setVisible(true);
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r4327 r4414  
    8181 * Note that it is not necessary to call beginUpdate/endUpdate for every dataset modification - dataset will get locked
    8282 * automatically.
    83  * 
     83 *
    8484 * Note that locks cannot be upgraded - if one threads use read lock and and then write lock, dead lock will occur - see #5814 for
    8585 * sample ticket
     
    205205    public void setVersion(String version) {
    206206        this.version = version;
     207    }
     208
     209    /*
     210    * Holding bin for changeset tag information, to be applied when or if this is ever uploaded.
     211    */
     212    private Map<String, String> changeSetTags = new HashMap<String, String>();
     213
     214    public Map<String, String> getChangeSetTags() {
     215        return changeSetTags;
     216    }
     217
     218    public void addChangeSetTag(String k, String v) {
     219        this.changeSetTags.put(k,v);
    207220    }
    208221
     
    438451     * nodes should be highlighted. WaySegments are used to avoid having
    439452     * to create a VirtualNode class that wouldn't have much purpose otherwise.
    440      * 
     453     *
    441454     * @return unmodifiable collection of WaySegments
    442455     */
     
    448461     * returns an unmodifiable collection of WaySegments that should be
    449462     * highlighted.
    450      * 
     463     *
    451464     * @return unmodifiable collection of WaySegments
    452465     */
     
    10561069    /**
    10571070     * Invalidates the internal cache of projected east/north coordinates.
    1058      * 
     1071     *
    10591072     * This method can be invoked after the globally configured projection method
    10601073     * changed. In contrast to {@link DataSet#reproject()} it only invalidates the
     
    11431156    /**
    11441157     * <p>Replies the list of data source bounds.</p>
    1145      * 
     1158     *
    11461159     * <p>Dataset maintains a list of data sources which have been merged into the
    11471160     * data set. Each of these sources can optionally declare a bounding box of the
    11481161     * data it supplied to the dataset.</p>
    1149      * 
     1162     *
    11501163     * <p>This method replies the list of defined (non {@code null}) bounding boxes.</p>
    1151      * 
     1164     *
    11521165     * @return the list of data source bounds. An empty list, if no non-null data source
    11531166     * bounds are defined.
  • trunk/src/org/openstreetmap/josm/gui/io/ChangesetCommentModel.java

    r3720 r4414  
    99 *
    1010 */
    11 public class ChangesetCommentModel extends Observable{
     11public class ChangesetCommentModel extends Observable {
    1212    private String comment = "";
    1313
     
    1818     * @param comment the new upload comment. Empty string assumed if null.
    1919     */
    20     public void setComment(String comment){
     20    public void setComment(String comment) {
    2121        String oldValue = this.comment;
    2222        this.comment = comment == null ? "" : comment;
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r4310 r4414  
    301301    public void setDefaultChangesetTags(Map<String, String> tags) {
    302302        pnlTagSettings.setDefaultTags(tags);
     303         for (String key: tags.keySet()) {
     304            if (key.equals("comment")) {
     305                changesetCommentModel.setComment(tags.get(key));
     306            }
     307        }
    303308    }
    304309
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r4413 r4414  
    2424import org.openstreetmap.josm.data.Bounds;
    2525import org.openstreetmap.josm.data.coor.LatLon;
     26import org.openstreetmap.josm.data.osm.Changeset;
    2627import org.openstreetmap.josm.data.osm.DataSet;
    2728import org.openstreetmap.josm.data.osm.DataSource;
     
    3637import org.openstreetmap.josm.data.osm.RelationMember;
    3738import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
     39import org.openstreetmap.josm.data.osm.Tagged;
    3840import org.openstreetmap.josm.data.osm.User;
    3941import org.openstreetmap.josm.data.osm.Way;
     
    8688    private Map<Long, Collection<RelationMemberData>> relations = new HashMap<Long, Collection<RelationMemberData>>();
    8789
     90    private Changeset uploadChangeset;
     91
    8892    /**
    8993     * constructor (for private use only)
     
    141145            throwException(tr("Unsupported version: {0}", v));
    142146        }
     147        ds.setVersion(v);
    143148        String generator = parser.getAttributeValue(null, "generator");
    144         ds.setVersion(v);
     149        Long uploadChangesetId = null;
     150        if (parser.getAttributeValue(null, "upload-changeset") != null) {
     151            uploadChangesetId = getLong("upload-changeset");
     152        }
    145153        while (true) {
    146154            int event = parser.next();
     
    154162                } else if (parser.getLocalName().equals("relation")) {
    155163                    parseRelation();
     164                } else if (parser.getLocalName().equals("changeset")) {
     165                    parseChangeset(uploadChangesetId);
    156166                } else {
    157167                    parseUnkown();
     
    320330    }
    321331
    322     private void parseTag(OsmPrimitive osm) throws XMLStreamException {
     332    private void parseChangeset(Long uploadChangesetId) throws XMLStreamException {
     333        long id = getLong("id");
     334
     335        if (id == uploadChangesetId) {
     336            uploadChangeset = new Changeset((int) getLong("id"));
     337            while (true) {
     338                int event = parser.next();
     339                if (event == XMLStreamConstants.START_ELEMENT) {
     340                    if (parser.getLocalName().equals("tag")) {
     341                        parseTag(uploadChangeset);
     342                    } else {
     343                        parseUnkown();
     344                    }
     345                } else if (event == XMLStreamConstants.END_ELEMENT) {
     346                    return;
     347                }
     348            }
     349        } else {
     350            jumpToEnd(false);
     351        }
     352    }
     353
     354    private void parseTag(Tagged t) throws XMLStreamException {
    323355        String key = parser.getAttributeValue(null, "k");
    324356        String value = parser.getAttributeValue(null, "v");
     
    326358            throwException(tr("Missing key or value attribute in tag."));
    327359        }
    328         osm.put(key.intern(), value.intern());
     360        t.put(key.intern(), value.intern());
    329361        jumpToEnd();
    330     }
    331 
    332     /**
    333      * When cursor is at the start of an element, moves it to the end tag of that element.
    334      * Nested content is skipped.
    335      *
    336      * This is basically the same code as parseUnkown(), except for the warnings, which
    337      * are displayed for inner elements and not at top level.
    338      */
    339     private void jumpToEnd() throws XMLStreamException {
    340         while (true) {
    341             int event = parser.next();
    342             if (event == XMLStreamConstants.START_ELEMENT) {
    343                 parseUnkown();
    344             } else if (event == XMLStreamConstants.END_ELEMENT) {
    345                 return;
    346             }
    347         }
    348     }
    349 
    350     private void parseUnkown() throws XMLStreamException {
    351         parseUnkown(true);
    352362    }
    353363
     
    364374            }
    365375        }
     376    }
     377
     378    private void parseUnkown() throws XMLStreamException {
     379        parseUnkown(true);
     380    }
     381
     382    /**
     383     * When cursor is at the start of an element, moves it to the end tag of that element.
     384     * Nested content is skipped.
     385     *
     386     * This is basically the same code as parseUnkown(), except for the warnings, which
     387     * are displayed for inner elements and not at top level.
     388     */
     389    private void jumpToEnd(boolean printWarning) throws XMLStreamException {
     390        while (true) {
     391            int event = parser.next();
     392            if (event == XMLStreamConstants.START_ELEMENT) {
     393                parseUnkown(printWarning);
     394            } else if (event == XMLStreamConstants.END_ELEMENT) {
     395                return;
     396            }
     397        }
     398    }
     399
     400    private void jumpToEnd() throws XMLStreamException {
     401        jumpToEnd(true);
    366402    }
    367403
     
    665701    }
    666702
     703    private void processChangesetAfterParsing() {
     704        if (uploadChangeset != null) {
     705            for (Map.Entry<String, String> e : uploadChangeset.getKeys().entrySet()) {
     706                ds.addChangeSetTag(e.getKey(), e.getValue());
     707            }
     708        }
     709    }
     710
    667711    /**
    668712     * Parse the given input source and return the dataset.
     
    697741                reader.processWaysAfterParsing();
    698742                reader.processRelationsAfterParsing();
     743                reader.processChangesetAfterParsing();
    699744            } finally {
    700745                reader.ds.endUpdate();
Note: See TracChangeset for help on using the changeset viewer.