Changeset 4530 in josm for trunk/src/org
- Timestamp:
- 2011-10-20T04:45:57+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java
r4521 r4530 23 23 import org.openstreetmap.josm.Main; 24 24 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 25 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeTask; 25 26 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 26 27 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask; … … 51 52 addDownloadTaskClass(DownloadOsmTask.class); 52 53 addDownloadTaskClass(DownloadGpsTask.class); 54 addDownloadTaskClass(DownloadOsmChangeTask.class); 53 55 } 54 56 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r4523 r4530 33 33 protected DataSet downloadedData; 34 34 protected DownloadTask downloadTask; 35 36 protected OsmDataLayer targetLayer; 35 37 36 38 protected void rememberDownloadedData(DataSet ds) { … … 79 81 } 80 82 81 protectedclass DownloadTask extends PleaseWaitRunnable {83 protected class DownloadTask extends PleaseWaitRunnable { 82 84 protected OsmServerReader reader; 83 85 protected DataSet dataSet; … … 89 91 this.newLayer = newLayer; 90 92 } 93 94 protected DataSet parseDataSet() throws OsmTransferException { 95 return reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 96 } 91 97 92 98 @Override public void realRun() throws IOException, SAXException, OsmTransferException { … … 94 100 if (isCanceled()) 95 101 return; 96 dataSet = reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));102 dataSet = parseDataSet(); 97 103 } catch(Exception e) { 98 104 if (isCanceled()) { … … 161 167 // or it is not clear which layer to merge to 162 168 // 163 OsmDataLayer layer = createNewLayer();169 targetLayer = createNewLayer(); 164 170 final boolean isDisplayingMapView = Main.isDisplayingMapView(); 165 171 166 Main.main.addLayer( layer);172 Main.main.addLayer(targetLayer); 167 173 168 174 // If the mapView is not there yet, we cannot calculate the bounds (see constructor of MapView). 169 175 // Otherwise jump to the current download. 170 176 if (isDisplayingMapView) { 171 BoundingXYVisitor v = new BoundingXYVisitor(); 172 if (currentBounds != null) { 173 v.visit(currentBounds); 174 } else { 175 v.computeBoundingBox(dataSet.getNodes()); 176 } 177 Main.map.mapView.recalculateCenterScale(v); 177 computeBboxAndCenterScale(); 178 178 } 179 179 } else { 180 OsmDataLayer target; 181 target = getEditLayer(); 182 if (target == null) { 183 target = getFirstDataLayer(); 184 } 185 target.mergeFrom(dataSet); 186 BoundingXYVisitor v = new BoundingXYVisitor(); 187 if (currentBounds != null) { 188 v.visit(currentBounds); 189 } else { 190 v.computeBoundingBox(dataSet.getNodes()); 191 } 192 Main.map.mapView.recalculateCenterScale(v); 193 target.onPostDownloadFromServer(); 194 } 180 targetLayer = getEditLayer(); 181 if (targetLayer == null) { 182 targetLayer = getFirstDataLayer(); 183 } 184 targetLayer.mergeFrom(dataSet); 185 computeBboxAndCenterScale(); 186 targetLayer.onPostDownloadFromServer(); 187 } 188 } 189 190 protected void computeBboxAndCenterScale() { 191 BoundingXYVisitor v = new BoundingXYVisitor(); 192 if (currentBounds != null) { 193 v.visit(currentBounds); 194 } else { 195 v.computeBoundingBox(dataSet.getNodes()); 196 } 197 Main.map.mapView.recalculateCenterScale(v); 195 198 } 196 199 -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r4490 r4530 12 12 import java.util.regex.Pattern; 13 13 14 import javax.xml.stream.Location; 14 15 import javax.xml.stream.XMLInputFactory; 15 import javax.xml.stream.XMLStreamReader;16 16 import javax.xml.stream.XMLStreamConstants; 17 17 import javax.xml.stream.XMLStreamException; 18 import javax.xml.stream. Location;18 import javax.xml.stream.XMLStreamReader; 19 19 20 20 import org.openstreetmap.josm.data.Bounds; … … 48 48 public class OsmReader extends AbstractReader { 49 49 50 pr ivateXMLStreamReader parser;50 protected XMLStreamReader parser; 51 51 52 52 /** 53 * constructor (for private use only)53 * constructor (for private and subclasses use only) 54 54 * 55 55 * @see #parseDataSet(InputStream, DataSet, ProgressMonitor) 56 56 */ 57 pr ivateOsmReader() {58 } 59 60 p ublicvoid setParser(XMLStreamReader parser) {57 protected OsmReader() { 58 } 59 60 protected void setParser(XMLStreamReader parser) { 61 61 this.parser = parser; 62 62 } … … 66 66 } 67 67 68 p ublicvoid parse() throws XMLStreamException {68 protected void parse() throws XMLStreamException { 69 69 int event = parser.getEventType(); 70 70 while (true) { 71 71 if (event == XMLStreamConstants.START_ELEMENT) { 72 if (parser.getLocalName().equals("osm") || parser.getLocalName().equals("osmChange")) { 73 parseOsm(); 74 } else { 75 parseUnkown(); 76 } 72 parseRoot(); 77 73 } else if (event == XMLStreamConstants.END_ELEMENT) { 78 74 return; … … 85 81 } 86 82 parser.close(); 83 } 84 85 protected void parseRoot() throws XMLStreamException { 86 if (parser.getLocalName().equals("osm")) { 87 parseOsm(); 88 } else { 89 parseUnknown(); 90 } 87 91 } 88 92 … … 115 119 parseChangeset(uploadChangesetId); 116 120 } else { 117 parseUnk own();121 parseUnknown(); 118 122 } 119 123 } else if (event == XMLStreamConstants.END_ELEMENT) { … … 152 156 } 153 157 154 pr ivatevoid parseNode() throws XMLStreamException {158 protected void parseNode() throws XMLStreamException { 155 159 NodeData nd = new NodeData(); 156 160 nd.setCoor(new LatLon(Double.parseDouble(parser.getAttributeValue(null, "lat")), Double.parseDouble(parser.getAttributeValue(null, "lon")))); … … 166 170 parseTag(n); 167 171 } else { 168 parseUnk own();172 parseUnknown(); 169 173 } 170 174 } else if (event == XMLStreamConstants.END_ELEMENT) { … … 174 178 } 175 179 176 pr ivatevoid parseWay() throws XMLStreamException {180 protected void parseWay() throws XMLStreamException { 177 181 WayData wd = new WayData(); 178 182 readCommon(wd); … … 191 195 parseTag(w); 192 196 } else { 193 parseUnk own();197 parseUnknown(); 194 198 } 195 199 } else if (event == XMLStreamConstants.END_ELEMENT) { … … 220 224 } 221 225 222 pr ivatevoid parseRelation() throws XMLStreamException {226 protected void parseRelation() throws XMLStreamException { 223 227 RelationData rd = new RelationData(); 224 228 readCommon(rd); … … 237 241 parseTag(r); 238 242 } else { 239 parseUnk own();243 parseUnknown(); 240 244 } 241 245 } else if (event == XMLStreamConstants.END_ELEMENT) { … … 293 297 parseTag(uploadChangeset); 294 298 } else { 295 parseUnk own();299 parseUnknown(); 296 300 } 297 301 } else if (event == XMLStreamConstants.END_ELEMENT) { … … 314 318 } 315 319 316 pr ivate void parseUnkown(boolean printWarning) throws XMLStreamException {320 protected void parseUnknown(boolean printWarning) throws XMLStreamException { 317 321 if (printWarning) { 318 322 System.out.println(tr("Undefined element ''{0}'' found in input stream. Skipping.", parser.getLocalName())); … … 321 325 int event = parser.next(); 322 326 if (event == XMLStreamConstants.START_ELEMENT) { 323 parseUnk own(false); /* no more warning for inner elements */327 parseUnknown(false); /* no more warning for inner elements */ 324 328 } else if (event == XMLStreamConstants.END_ELEMENT) { 325 329 return; … … 328 332 } 329 333 330 pr ivate void parseUnkown() throws XMLStreamException {331 parseUnk own(true);334 protected void parseUnknown() throws XMLStreamException { 335 parseUnknown(true); 332 336 } 333 337 … … 343 347 int event = parser.next(); 344 348 if (event == XMLStreamConstants.START_ELEMENT) { 345 parseUnk own(printWarning);349 parseUnknown(printWarning); 346 350 } else if (event == XMLStreamConstants.END_ELEMENT) { 347 351 return; … … 531 535 } 532 536 537 protected DataSet doParseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { 538 if (progressMonitor == null) { 539 progressMonitor = NullProgressMonitor.INSTANCE; 540 } 541 CheckParameterUtil.ensureParameterNotNull(source, "source"); 542 try { 543 progressMonitor.beginTask(tr("Prepare OSM data...", 2)); 544 progressMonitor.indeterminateSubTask(tr("Parsing OSM data...")); 545 546 InputStreamReader ir = UTFInputStreamReader.create(source, "UTF-8"); 547 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ir); 548 setParser(parser); 549 parse(); 550 progressMonitor.worked(1); 551 552 progressMonitor.indeterminateSubTask(tr("Preparing data set...")); 553 prepareDataSet(); 554 progressMonitor.worked(1); 555 return getDataSet(); 556 } catch(IllegalDataException e) { 557 throw e; 558 } catch(OsmParsingException e) { 559 throw new IllegalDataException(e.getMessage(), e); 560 } catch(XMLStreamException e) { 561 String msg = e.getMessage(); 562 Pattern p = Pattern.compile("Message: (.+)"); 563 Matcher m = p.matcher(msg); 564 if (m.find()) { 565 msg = m.group(1); 566 } 567 if (e.getLocation() != null) { 568 throw new IllegalDataException(tr("Line {0} column {1}: ", e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()) + msg, e); 569 } else { 570 throw new IllegalDataException(msg, e); 571 } 572 } catch(Exception e) { 573 throw new IllegalDataException(e); 574 } finally { 575 progressMonitor.finishTask(); 576 } 577 } 578 533 579 /** 534 580 * Parse the given input source and return the dataset. … … 542 588 */ 543 589 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { 544 if (progressMonitor == null) { 545 progressMonitor = NullProgressMonitor.INSTANCE; 546 } 547 CheckParameterUtil.ensureParameterNotNull(source, "source"); 548 OsmReader reader = new OsmReader(); 549 try { 550 progressMonitor.beginTask(tr("Prepare OSM data...", 2)); 551 progressMonitor.indeterminateSubTask(tr("Parsing OSM data...")); 552 553 InputStreamReader ir = UTFInputStreamReader.create(source, "UTF-8"); 554 XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ir); 555 reader.setParser(parser); 556 reader.parse(); 557 progressMonitor.worked(1); 558 559 progressMonitor.indeterminateSubTask(tr("Preparing data set...")); 560 reader.prepareDataSet(); 561 progressMonitor.worked(1); 562 return reader.getDataSet(); 563 } catch(IllegalDataException e) { 564 throw e; 565 } catch(OsmParsingException e) { 566 throw new IllegalDataException(e.getMessage(), e); 567 } catch(XMLStreamException e) { 568 String msg = e.getMessage(); 569 Pattern p = Pattern.compile("Message: (.+)"); 570 Matcher m = p.matcher(msg); 571 if (m.find()) { 572 msg = m.group(1); 573 } 574 if (e.getLocation() != null) { 575 throw new IllegalDataException(tr("Line {0} column {1}: ", e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()) + msg, e); 576 } else { 577 throw new IllegalDataException(msg, e); 578 } 579 } catch(Exception e) { 580 throw new IllegalDataException(e); 581 } finally { 582 progressMonitor.finishTask(); 583 } 590 return new OsmReader().doParseDataSet(source, progressMonitor); 584 591 } 585 592 } -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r4521 r4530 48 48 } 49 49 50 /* (non-Javadoc) 51 * @see org.openstreetmap.josm.io.OsmServerReader#parseOsmChange(org.openstreetmap.josm.gui.progress.ProgressMonitor) 52 */ 53 @Override 54 public DataSet parseOsmChange(ProgressMonitor progressMonitor) 55 throws OsmTransferException { 56 InputStream in = null; 57 progressMonitor.beginTask(tr("Contacting Server...", 10)); 58 try { 59 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 60 if (in == null) 61 return null; 62 progressMonitor.subTask(tr("Downloading OSM data...")); 63 return OsmChangeReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 64 } catch(OsmTransferException e) { 65 throw e; 66 } catch (Exception e) { 67 if (cancel) 68 return null; 69 throw new OsmTransferException(e); 70 } finally { 71 progressMonitor.finishTask(); 72 try { 73 activeConnection = null; 74 if (in != null) { 75 in.close(); 76 } 77 } catch(Exception e) {/* ignore it */} 78 } 79 } 80 50 81 @Override 51 82 public GpxData parseRawGps(ProgressMonitor progressMonitor) throws OsmTransferException { -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r4521 r4530 142 142 public abstract DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException; 143 143 144 public DataSet parseOsmChange(ProgressMonitor progressMonitor) throws OsmTransferException { 145 return null; 146 } 147 144 148 public GpxData parseRawGps(ProgressMonitor progressMonitor) throws OsmTransferException { 145 149 return null;
Note:
See TracChangeset
for help on using the changeset viewer.