Changeset 2795 in josm for trunk/src/org
- Timestamp:
- 2010-01-09T21:16:03+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r2247 r2795 79 79 } 80 80 81 public boolean isEmpty() { 82 return !hasRoutePoints() && !hasTrackPoints() && waypoints.isEmpty(); 83 } 84 81 85 // FIXME might perhaps use visitor pattern? 82 86 public Bounds recalculateBounds() { -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r2786 r2795 179 179 iStream = new FileInputStream(sel); 180 180 } 181 data = new GpxReader(iStream, sel).data; 181 GpxReader reader = new GpxReader(iStream); 182 reader.parse(false); 183 data = reader.data; 182 184 data.storageFile = sel; 183 185 … … 874 876 875 877 tfTimezone.setText(formatTimezone(timezone)); 876 tfOffset.setText(Long.toString(delta + dayOffset*24*60*60l)); // add the day offset to the offset field878 tfOffset.setText(Long.toString(delta + 24*60*60L*dayOffset)); // add the day offset to the offset field 877 879 878 880 tfTimezone.getDocument().addDocumentListener(statusBarListener); -
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r2676 r2795 51 51 } 52 52 progressMonitor.setTicks(0); 53 GpxData currentGpx = new GpxReader(in, null).data; 53 GpxReader reader = new GpxReader(in); 54 reader.parse(false); 55 GpxData currentGpx = reader.data; 54 56 if (result == null) { 55 57 result = currentGpx; -
trunk/src/org/openstreetmap/josm/io/GpxImporter.java
r2235 r2795 11 11 import java.util.zip.GZIPInputStream; 12 12 13 import javax.swing.JOptionPane; 13 14 import javax.swing.SwingUtilities; 14 15 … … 45 46 } 46 47 } 47 final GpxReader r = new GpxReader(is, file.getAbsoluteFile().getParentFile()); 48 final GpxReader r = new GpxReader(is); 49 final boolean parsedProperly = r.parse(true); 48 50 r.data.storageFile = file; 49 51 final GpxLayer gpxLayer = new GpxLayer(r.data, fn, true); … … 61 63 Main.main.addLayer(ml); 62 64 } 65 } 66 if (!parsedProperly) { 67 JOptionPane.showMessageDialog(null, tr("Error occured while parsing gpx file {0}. Only part of the file will be available", file.getName())); 63 68 } 64 69 } -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r2789 r2795 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 8 import java.io.File;9 8 import java.io.IOException; 10 9 import java.io.InputStream; … … 13 12 import java.util.Collection; 14 13 import java.util.LinkedList; 14 import java.util.List; 15 15 import java.util.Map; 16 16 import java.util.Stack; … … 41 41 */ 42 42 public GpxData data; 43 public enum State { init, metadata, wpt, rte, trk, ext, author, link, trkseg, copyright} 43 private enum State { init, metadata, wpt, rte, trk, ext, author, link, trkseg, copyright} 44 private InputSource inputSource; 44 45 45 46 private class Parser extends DefaultHandler { … … 55 56 private GpxLink currentLink; 56 57 private Stack<State> states; 58 private final Stack<String> elements = new Stack<String>(); 57 59 58 60 private StringBuffer accumulator = new StringBuffer(); … … 81 83 82 84 @Override public void startElement(String namespaceURI, String qName, String rqName, Attributes atts) throws SAXException { 85 elements.push(qName); 83 86 switch(currentState) { 84 87 case init: … … 211 214 @SuppressWarnings("unchecked") 212 215 @Override public void endElement(String namespaceURI, String qName, String rqName) { 216 elements.pop(); 213 217 switch (currentState) { 214 218 case metadata: … … 333 337 data = currentData; 334 338 } 339 340 public void tryToFinish() throws SAXException { 341 List<String> remainingElements = new ArrayList<String>(elements); 342 for (int i=remainingElements.size() - 1; i >= 0; i--) { 343 endElement(null, remainingElements.get(i), null); 344 } 345 endDocument(); 346 } 335 347 } 336 348 … … 338 350 * Parse the input stream and store the result in trackData and markerData 339 351 * 340 * @param relativeMarkerPath The directory to use as relative path for all <wpt>341 * marker tags. Maybe <code>null</code>, in which case no relative urls are constructed for the markers.342 352 */ 343 public GpxReader(InputStream source, File relativeMarkerPath) throws SAXException, IOException { 344 353 public GpxReader(InputStream source) throws IOException { 354 this.inputSource = new InputSource(new InputStreamReader(source, "UTF-8")); 355 } 356 357 /** 358 * 359 * @return True if file was properly parsed, false if there was error during parsing but some data were parsed anyway 360 * @throws SAXException 361 * @throws IOException 362 */ 363 public boolean parse(boolean tryToFinish) throws SAXException, IOException { 345 364 Parser parser = new Parser(); 346 InputSource inputSource = new InputSource(new InputStreamReader(source, "UTF-8"));347 365 try { 348 366 SAXParserFactory factory = SAXParserFactory.newInstance(); 349 367 factory.setNamespaceAware(true); 350 368 factory.newSAXParser().parse(inputSource, parser); 369 return true; 370 } catch (SAXException e) { 371 if (tryToFinish) { 372 parser.tryToFinish(); 373 if (parser.currentData.isEmpty()) 374 throw e; 375 return false; 376 } else 377 throw e; 351 378 } catch (ParserConfigurationException e) { 352 379 e.printStackTrace(); // broken SAXException chaining
Note:
See TracChangeset
for help on using the changeset viewer.