Ticket #6742: changeset_try4.diff

File changeset_try4.diff, 9.0 KB (added by brycenesbitt, 13 years ago)

Patch to prevent node/way/relation damage in case of extra tags.

  • src/org/openstreetmap/josm/actions/UploadAction.java

     
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
    99import java.util.LinkedList;
     10import java.util.logging.Logger;
    1011
    1112import javax.swing.JOptionPane;
    1213
     
    3536 * @author imi
    3637 */
    3738public class UploadAction extends JosmAction{
     39    private static Logger logger = Logger.getLogger(UploadAction.class.getName());
     40
    3841    /**
    3942     * The list of upload hooks. These hooks will be called one after the other
    4043     * when the user wants to upload data. Plugins can insert their own hooks here
     
    160163            return;
    161164
    162165        final UploadDialog dialog = UploadDialog.getUploadDialog();
     166        dialog.setDefaultChangesetTags(layer.data.getChangeSetTags());
    163167        dialog.setUploadedPrimitives(apiData);
    164168        dialog.setVisible(true);
    165169        if (dialog.isCanceled())
  • src/org/openstreetmap/josm/tools/PlatformHookOsx.java

     
    3030        // Here we register callbacks for the menu entries in the system menu
    3131        try {
    3232            Class Ccom_apple_eawt_Application = Class.forName("com.apple.eawt.Application");
     33            @SuppressWarnings("unchecked")
    3334            Object Ocom_apple_eawt_Application = Ccom_apple_eawt_Application.getConstructor((Class[])null).newInstance((Object[])null);
    3435            Class Ccom_apple_eawt_ApplicationListener = Class.forName("com.apple.eawt.ApplicationListener");
     36            @SuppressWarnings("unchecked")
    3537            Method MaddApplicationListener = Ccom_apple_eawt_Application.getDeclaredMethod("addApplicationListener", new Class[] { Ccom_apple_eawt_ApplicationListener });
    3638            Object Oproxy = Proxy.newProxyInstance(PlatformHookOsx.class.getClassLoader(), new Class[] { Ccom_apple_eawt_ApplicationListener }, ivhandler);
    3739            MaddApplicationListener.invoke(Ocom_apple_eawt_Application, new Object[] { Oproxy });
     40            @SuppressWarnings("unchecked")
    3841            Method MsetEnabledPreferencesMenu = Ccom_apple_eawt_Application.getDeclaredMethod("setEnabledPreferencesMenu", new Class[] { boolean.class });
    3942            MsetEnabledPreferencesMenu.invoke(Ocom_apple_eawt_Application, new Object[] { Boolean.TRUE });
    4043        } catch (Exception ex) {
  • src/org/openstreetmap/josm/gui/io/UploadDialog.java

     
    1717import java.util.Collections;
    1818import java.util.List;
    1919import java.util.Map;
     20import java.util.logging.Logger;
    2021
    2122import javax.swing.AbstractAction;
    2223import javax.swing.BorderFactory;
     
    5253 *
    5354 */
    5455public class UploadDialog extends JDialog implements PropertyChangeListener, PreferenceChangedListener{
     56    private static Logger logger = Logger.getLogger(UploadDialog.class.getName());
     57
    5558    /**  the unique instance of the upload dialog */
    5659    static private UploadDialog uploadDialog;
    5760
     
    300303
    301304    public void setDefaultChangesetTags(Map<String, String> tags) {
    302305        pnlTagSettings.setDefaultTags(tags);
     306
     307        // The following code does not seem to actually work.  JOSM ignores the comment given.
     308        for (String key: tags.keySet()) {
     309            if( key.equals("comment")) {
     310                logger.info("TODO: bug, this tag is not working. comment=" +tags.get(key));
     311                pnlTagSettings.setUploadComment(tags.get(key));
     312            }
     313        }
    303314    }
    304315
    305316    /**
  • src/org/openstreetmap/josm/io/OsmImporter.java

     
    88import java.io.FileNotFoundException;
    99import java.io.IOException;
    1010import java.io.InputStream;
     11import java.util.logging.Logger;
    1112
    1213import javax.swing.SwingUtilities;
    1314
     
    1920import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2021
    2122public class OsmImporter extends FileImporter {
     23    private static Logger logger = Logger.getLogger(OsmImporter.class.getName());
    2224
    2325    public OsmImporter() {
    2426        super(new ExtensionFileFilter("osm,xml", "osm", tr("OSM Server Files") + " (*.osm *.xml)"));
     
    4143    protected void importData(InputStream in, File associatedFile) throws IllegalDataException {
    4244        DataSet dataSet = OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE);
    4345        final OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile);
     46
    4447        // FIXME: remove UI stuff from IO subsystem
    4548        //
    4649        Runnable uiStuff = new Runnable() {
  • src/org/openstreetmap/josm/io/OsmReader.java

     
    112112        /**
    113113         * The current osm primitive to be read.
    114114         */
    115         private OsmPrimitive currentPrimitive;
     115        private OsmPrimitive currentPrimitive = null;
    116116        private long currentExternalId;
    117117        private String generator;
    118118
     
    134134                    generator = atts.getValue("generator");
    135135                    ds.setVersion(v);
    136136
     137                    // JOSM specific extension to the file format.  This is for scripts or bots that build
     138                    // a .osm file for human review.  Here the script or bot can pre-set values for
     139                    // later upload in the changeset.
     140                } else if (qName.equals("changeset")) {
     141                    currentPrimitive = null;    // flag for tag parser below
     142
    137143                } else if (qName.equals("bounds")) {
    138144                    // new style bounds.
    139145                    String minlon = atts.getValue("minlon");
     
    259265                        list.add(emd);
    260266                    }
    261267
    262                     // ---- PARSING TAGS (applicable to all objects) ----
    263 
     268                    // ---- PARSING TAGS (applicable to all objects & changesets) ----
    264269                } else if (qName.equals("tag")) {
    265270                    String key = atts.getValue("k");
    266271                    String value = atts.getValue("v");
    267272                    if (key == null || value == null) {
    268273                        throwException(tr("Missing key or value attribute in tag."));
    269274                    }
    270                     currentPrimitive.put(key.intern(), value.intern());
     275                    if( currentPrimitive == null) {
     276                        ds.addChangeSetTag(key.intern(), value.intern() );  // changeset
     277                    } else {
     278                        currentPrimitive.put(key.intern(), value.intern()); // node/way/relation
     279                    }
    271280
    272281                } else {
    273282                    System.out.println(tr("Undefined element ''{0}'' found in input stream. Skipping.", qName));
     283                    currentPrimitive = null;
    274284                }
    275285            } catch (Exception e) {
    276286                throw new SAXParseException(e.getMessage(), locator, e);
     
    452462            }
    453463            w.setNodes(wayNodes);
    454464            if (w.hasIncompleteNodes()) {
    455                   System.out.println(tr("Way {0} with {1} nodes has incomplete nodes because at least one node was missing in the loaded data.",
    456                           externalWayId, w.getNodesCount()));
     465                System.out.println(tr("Way {0} with {1} nodes has incomplete nodes because at least one node was missing in the loaded data.",
     466                        externalWayId, w.getNodesCount()));
    457467            }
    458468            ds.addPrimitive(w);
    459469        }
  • src/org/openstreetmap/josm/data/osm/DataSet.java

     
    206206        this.version = version;
    207207    }
    208208
     209    /*
     210     * Holding bin for changeset tag information, to be applied when or if this is ever uploaded.
     211     */
     212    //private HashMap changeSetTags = new HashMap();
     213    private Map<String, String> changeSetTags = new HashMap<String, String>();
     214    public Map<String, String> getChangeSetTags() {
     215        return changeSetTags;
     216    }
     217    public void addChangeSetTag(String k, String v) {
     218        this.changeSetTags.put(k,v);
     219    }
     220
    209221    /**
    210222     * All nodes goes here, even when included in other data (ways etc). This enables the instant
    211223     * conversion of the whole DataSet by iterating over this data structure.