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

Last change on this file since 8854 was 8510, checked in by Don-vip, 9 years ago

checkstyle: enable relevant whitespace checks and fix them

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