Changeset 1790 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2009-07-15T17:22:56+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
r1772 r1790 62 62 private HashSet<Long> relations; 63 63 private HashSet<Long> missingPrimitives; 64 private HashSet<Long> skippedWayIds;65 64 private DataSet outputDataSet; 66 65 … … 320 319 try { 321 320 final OsmReader osm = OsmReader.parseDataSetOsm(in, Main.pleaseWaitDlg); 322 skippedWayIds.addAll(osm.getSkippedWayIds());323 321 merge(osm.getDs()); 324 } catch(IOException e) { 325 throw new OsmTransferException(e); 326 } catch(SAXException e) { 322 } catch(Exception e) { 327 323 throw new OsmTransferException(e); 328 324 } … … 346 342 try { 347 343 final OsmReader osm = OsmReader.parseDataSetOsm(in,Main.pleaseWaitDlg); 348 skippedWayIds.addAll(osm.getSkippedWayIds());349 344 merge(osm.getDs()); 350 } catch(IOException e) { 351 throw new OsmTransferException(e); 352 } catch(SAXException e) { 345 } catch(Exception e) { 353 346 throw new OsmTransferException(e); 354 347 } … … 440 433 @Override 441 434 public DataSet parseOsm() throws OsmTransferException { 442 skippedWayIds = new HashSet<Long>();443 435 missingPrimitives = new HashSet<Long>(); 444 436 … … 450 442 451 443 /** 452 * replies the set of {@see Way}s which were present in the data fetched from the453 * server but which were not included in the JOSM dataset because they referred454 * to nodes not present in the dataset455 *456 * @return the set of ids of skipped ways457 */458 public Set<Long> getSkippedWays() {459 return skippedWayIds;460 }461 462 /**463 444 * replies the set of ids of all primitives for which a fetch request to the 464 445 * server was submitted but which are not available from the server (the server -
trunk/src/org/openstreetmap/josm/io/OsmImporter.java
r1772 r1790 51 51 Main.main.addLayer(layer); 52 52 layer.fireDataChange(); 53 if (osm.getParseNotes().length() != 0) {54 /* display at most five lines */55 String notes = osm.getParseNotes();56 int j = 0;57 for (int i = 0; i < 5; i++) {58 j = notes.indexOf('\n', j + 1);59 }60 j = j >= 0 ? j : notes.length();61 JOptionPane.showMessageDialog(Main.parent, notes.substring(0, j));62 }63 53 } 64 54 } -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r1772 r1790 16 16 import java.util.Set; 17 17 import java.util.Map.Entry; 18 18 import java.util.logging.Logger; 19 20 import javax.swing.SwingUtilities; 19 21 import javax.xml.parsers.ParserConfigurationException; 20 22 import javax.xml.parsers.SAXParserFactory; 21 23 22 import org.openstreetmap.josm.Main;23 24 import org.openstreetmap.josm.data.Bounds; 24 25 import org.openstreetmap.josm.data.coor.LatLon; … … 50 51 */ 51 52 public class OsmReader { 53 static private final Logger logger = Logger.getLogger(OsmReader.class.getName()); 52 54 53 55 /** … … 56 58 private DataSet ds = new DataSet(); 57 59 public DataSet getDs() { return ds; } 58 59 /**60 * Record warnings. If there were any data inconsistencies, append61 * a newline-terminated string.62 */63 private String parseNotes = new String();64 private int parseNotesCount = 0;65 public String getParseNotes() {66 return parseNotes;67 }68 69 /** the list of ids of skipped {@see Way}s, i.e. ways which referred to nodes70 * not included in the parsed data71 */72 private Set<Long> skippedWayIds = new HashSet<Long>();73 60 74 61 /** … … 350 337 protected void createWays() { 351 338 for (Entry<OsmPrimitiveData, Collection<Long>> e : ways.entrySet()) { 352 Way w = new Way(); 339 Way w = new Way(e.getKey().id); 353 340 boolean failed = false; 354 341 for (long id : e.getValue()) { 355 342 Node n = findNode(id); 356 343 if (n == null) { 357 /* don't report ALL of them, just a few */358 if (parseNotesCount++ < 6) {359 parseNotes += tr("Skipping a way because it includes a node that doesn''t exist: {0}\n", id);360 } else if (parseNotesCount == 6) {361 parseNotes += "...\n";362 }363 344 failed = true; 364 345 break; … … 367 348 } 368 349 if (failed) { 369 skippedWayIds.add(e.getKey().id); 370 continue; 371 } 372 e.getKey().copyTo(w); 373 adder.visit(w); 374 } 375 350 logger.warning(tr("marked way {0} incomplete because referred nodes are missing in the loaded data", e.getKey().id)); 351 e.getKey().copyTo(w); 352 w.incomplete = true; 353 w.nodes.clear(); 354 } else { 355 e.getKey().copyTo(w); 356 w.incomplete = false; 357 adder.visit(w); 358 } 359 } 376 360 } 377 361 … … 475 459 } 476 460 477 public static OsmReader parseDataSetOsm(InputStream source,PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException { 461 public static OsmReader parseDataSetOsm(InputStream source, final PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException { 478 462 OsmReader osm = new OsmReader(); 479 463 … … 487 471 } 488 472 489 Main.pleaseWaitDlg.currentAction.setText(tr("Prepare OSM data...")); 490 Main.pleaseWaitDlg.setIndeterminate(true); 473 SwingUtilities.invokeLater( 474 new Runnable() { 475 public void run() { 476 pleaseWaitDlg.currentAction.setText(tr("Prepare OSM data...")); 477 pleaseWaitDlg.setIndeterminate(true); 478 } 479 } 480 ); 491 481 492 482 for (Node n : osm.nodes.values()) { … … 508 498 } 509 499 510 Main.pleaseWaitDlg.setIndeterminate(false); 511 Main.pleaseWaitDlg.progress.setValue(0); 500 SwingUtilities.invokeLater( 501 new Runnable() { 502 public void run() { 503 pleaseWaitDlg.setIndeterminate(false); 504 pleaseWaitDlg.progress.setValue(0); 505 } 506 } 507 ); 512 508 513 509 return osm; 514 510 } 515 516 /**517 * replies a set of ids of skipped {@see Way}s, i.e. ways which were included in the downloaded518 * data but which referred to nodes <strong>not</strong> available in the downloaded data519 *520 * @return the set of ids521 */522 public Set<Long> getSkippedWayIds() {523 return skippedWayIds;524 }525 511 } -
trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java
r1670 r1790 74 74 HistoryDataSet data = reader.parse(Main.pleaseWaitDlg); 75 75 return data; 76 } catch (IOException e) {77 if (cancel)78 return null;79 throw new OsmTransferException(e);80 } catch (SAXException e) {81 throw new OsmTransferException(e);82 76 } catch(OsmTransferException e) { 83 77 throw e; -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r1772 r1790 24 24 @Override 25 25 public DataSet parseOsm() throws OsmTransferException { 26 InputStream in = null; 26 27 try { 27 28 Main.pleaseWaitDlg.progress.setValue(0); 28 29 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting Server...")); 29 30 30 final InputStreamin = getInputStreamRaw(url, Main.pleaseWaitDlg);31 in = getInputStreamRaw(url, Main.pleaseWaitDlg); 31 32 if (in == null) 32 33 return null; 33 34 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 34 final DataSet data = OsmReader.parseDataSet(in, Main.pleaseWaitDlg); 35 in.close(); 36 activeConnection = null; 37 return data; 38 } catch (IOException e) { 39 if (cancel) 40 return null; 41 throw new OsmTransferException(e); 42 } catch (SAXException e) { 43 throw new OsmTransferException(e); 35 return OsmReader.parseDataSet(in, Main.pleaseWaitDlg); 44 36 } catch(OsmTransferException e) { 45 37 throw e; … … 48 40 return null; 49 41 throw new OsmTransferException(e); 42 } finally { 43 try { 44 if (in != null) { 45 in.close(); 46 } 47 activeConnection = null; 48 } catch(Exception e) {/* ignore it */} 50 49 } 51 50 } -
trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
r1772 r1790 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 9 import javax.swing.JOptionPane;10 8 11 9 import org.openstreetmap.josm.Main; … … 51 49 final DataSet data = osm.getDs(); 52 50 53 if (osm.getParseNotes().length() != 0) {54 JOptionPane.showMessageDialog(Main.parent, osm.getParseNotes());55 }56 51 in.close(); 57 52 activeConnection = null;
Note:
See TracChangeset
for help on using the changeset viewer.