Dirk Stöcker writes:
 > On Sun, 28 Dec 2008, Russ Nelson wrote:
 > 
 > > Potential improvements:
 > >  o convert all invocations of OsmReader.parseDataSet() to
 > >    OsmReader.parseDataSetOsm() to gain access to getParseNotes().
 > 
 > When useful, do it, but be aware of potential problems with plugins when 
 > changing the interface :-). The drawback of our open plugin interface.

Understood.  That's why I didn't change the interface, but instead
added a new call.

I'm not certain it's correct to change the other calls:

In io/OsmServerObjectReader.java, it's reading from the API.  Will the
API ever hand out ways without their nodes?

Same for io/OsmServerLocationReader.java and io/BoundingBoxDownloader.java.

 > >  o Doing something more sensible with the output presentation if
 > >    there are too many warnings than can fit on the screen (or will it
 > >    switch to a scrollbox?)
 > 
 > Cut after a certain number of lines and add "..."?

Fixed.  5 lines.

 > >  o It's possible that DataSet ought to be the entity that has
 > >    parseNotes.  That would make for a simpler patch, but not
 > >    necessarily more correct.
 > 
 > I don't think this is a good idea. The DataSet remains during lifetime, 
 > but these notes are only related to import.

Agreed.

 > Never construct string or use them without tr() or there is no 
 > translation.

OOPS!

 > Do you provide an updated patch?

Index: src/org/openstreetmap/josm/actions/OpenFileAction.java
===================================================================
--- src/org/openstreetmap/josm/actions/OpenFileAction.java      (revision 1180)
+++ src/org/openstreetmap/josm/actions/OpenFileAction.java      (working copy)
@@ -74,10 +74,20 @@
     private void openAsData(File file) throws SAXException, IOException, 
FileNotFoundException {
         String fn = file.getName();
         if 
(ExtensionFileFilter.filters[ExtensionFileFilter.OSM].acceptName(fn)) {
-            DataSet dataSet = OsmReader.parseDataSet(new 
FileInputStream(file), null, Main.pleaseWaitDlg);
+            OsmReader osm = OsmReader.parseDataSetOsm(new 
FileInputStream(file), null, Main.pleaseWaitDlg);
+            DataSet dataSet = osm.getDs();
             OsmDataLayer layer = new OsmDataLayer(dataSet, file.getName(), 
file);
             Main.main.addLayer(layer);
             layer.fireDataChange();
+            if (osm.getParseNotes().length() != 0) {
+                /* display at most five lines */
+                String notes = osm.getParseNotes();
+                int j = 0;
+                for (int i = 0; i < 5; i++) {
+                    j = notes.indexOf('\n', j + 1);
+                }
+                JOptionPane.showMessageDialog(Main.parent, notes.substring(0, 
j));
+            }
         }
         else
             JOptionPane.showMessageDialog(Main.parent, fn+": "+tr("Unknown 
file extension: {0}", fn.substring(file.getName().lastIndexOf('.')+1)));
Index: src/org/openstreetmap/josm/io/OsmReader.java
===================================================================
--- src/org/openstreetmap/josm/io/OsmReader.java        (revision 1180)
+++ src/org/openstreetmap/josm/io/OsmReader.java        (working copy)
@@ -59,8 +59,18 @@
       * The dataset to add parsed objects to.
       */
      private DataSet ds = new DataSet();
+     public DataSet getDs() { return ds; }
 
      /**
+      * Record warnings.  If there were any data inconsistencies, append
+      * a newline-terminated string.
+      */
+     private String parseNotes = new String();
+     public String getParseNotes() {
+         return parseNotes;
+     }
+
+     /**
       * The visitor to use to add the data to the set.
       */
      private AddVisitor adder = new AddVisitor(ds);
@@ -332,6 +342,7 @@
                for (long id : e.getValue()) {
                     Node n = findNode(id);
                     if (n == null) {
+                         parseNotes += tr("Skipping a way because it includes 
a node that doesn't exist: {0}\n", id);
                          failed = true;
                          break;
                     }
@@ -434,6 +445,10 @@
       *  elemet found there is returned.
       */
      public static DataSet parseDataSet(InputStream source, DataSet ref, 
PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {
+          return parseDataSetOsm(source, ref, pleaseWaitDlg).ds;
+     }
+
+     public static OsmReader parseDataSetOsm(InputStream source, DataSet ref, 
PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {
           OsmReader osm = new OsmReader();
           osm.references = ref == null ? new DataSet() : ref;
 
@@ -467,6 +482,6 @@
                if (o.id < 0)
                     o.id = 0;
 
-          return osm.ds;
+          return osm;
      }
 }

-- 
--my blog is at    http://blog.russnelson.com   | Delegislation is a slippery
Crynwr sells support for free software  | PGPok | slope to prosperity.
521 Pleasant Valley Rd. | +1 315-323-1241       | Fewer laws, more freedom.
Potsdam, NY 13676-3213  |     Sheepdog          | (Not a GOP supporter).

_______________________________________________
josm-dev mailing list
josm-dev@openstreetmap.org
http://lists.openstreetmap.org/listinfo/josm-dev

Reply via email to