source: josm/trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java@ 11320

Last change on this file since 11320 was 11262, checked in by simon04, 7 years ago

fix #13982 - Wrong links to OSM website if different API is used

  • Property svn:eol-style set to native
File size: 2.9 KB
RevLine 
[2512]1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
[10212]6import java.io.IOException;
[2512]7import java.io.InputStream;
[2852]8import java.text.MessageFormat;
[2512]9
10import org.openstreetmap.josm.data.osm.DataSet;
11import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
12import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
13import org.openstreetmap.josm.gui.progress.ProgressMonitor;
[2852]14import org.openstreetmap.josm.tools.CheckParameterUtil;
[10212]15import org.xml.sax.SAXException;
[2512]16
17/**
[5835]18 * Reads the history of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} from the OSM API server.
[2512]19 *
20 */
21public class OsmServerHistoryReader extends OsmServerReader {
22
[9078]23 private final OsmPrimitiveType primitiveType;
24 private final long id;
[2512]25
26 /**
27 * constructor
28 *
29 * @param type the type of the primitive whose history is to be fetched from the server.
30 * Must not be null.
31 * @param id the id of the primitive
32 *
[8291]33 * @throws IllegalArgumentException if type is null
[2512]34 */
[8291]35 public OsmServerHistoryReader(OsmPrimitiveType type, long id) {
[2852]36 CheckParameterUtil.ensureParameterNotNull(type, "type");
[2512]37 if (id < 0)
[2852]38 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' >= 0 expected. Got ''{1}''.", "id", id));
[2512]39 this.primitiveType = type;
40 this.id = id;
41 }
42
43 /**
44 * don't use - not implemented!
45 *
46 */
47 @Override
48 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
49 return null;
50 }
51
52 /**
53 * Fetches the history from the OSM API and parses it
[9231]54 * @param progressMonitor progress monitor
[2512]55 *
56 * @return the data set with the parsed history data
[8291]57 * @throws OsmTransferException if an exception occurs
[2512]58 */
59 public HistoryDataSet parseHistory(ProgressMonitor progressMonitor) throws OsmTransferException {
60 progressMonitor.beginTask("");
61 try {
62 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server..."));
[11262]63 final String urlStr = primitiveType.getAPIName() + '/' + id + "/history";
[2512]64
[11262]65 try (InputStream in = getInputStream(urlStr, progressMonitor.createSubTaskMonitor(1, true))) {
[7033]66 if (in == null)
67 return null;
68 progressMonitor.indeterminateSubTask(tr("Downloading history..."));
69 OsmHistoryReader reader = new OsmHistoryReader(in);
70 return reader.parse(progressMonitor.createSubTaskMonitor(1, true));
71 }
[8510]72 } catch (OsmTransferException e) {
[2512]73 throw e;
[10212]74 } catch (IOException | SAXException e) {
[2512]75 if (cancel)
76 return null;
77 throw new OsmTransferException(e);
78 } finally {
79 progressMonitor.finishTask();
[5874]80 activeConnection = null;
[2512]81 }
82 }
83}
Note: See TracBrowser for help on using the repository browser.