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

Last change on this file since 9646 was 9231, checked in by Don-vip, 8 years ago

javadoc update

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
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;
7import java.text.MessageFormat;
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;
13import org.openstreetmap.josm.tools.CheckParameterUtil;
14
15/**
16 * Reads the history of an {@link org.openstreetmap.josm.data.osm.OsmPrimitive} from the OSM API server.
17 *
18 */
19public class OsmServerHistoryReader extends OsmServerReader {
20
21 private final OsmPrimitiveType primitiveType;
22 private final 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 *
31 * @throws IllegalArgumentException if type is null
32 */
33 public OsmServerHistoryReader(OsmPrimitiveType type, long id) {
34 CheckParameterUtil.ensureParameterNotNull(type, "type");
35 if (id < 0)
36 throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' >= 0 expected. Got ''{1}''.", "id", id));
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 * @param progressMonitor progress monitor
53 *
54 * @return the data set with the parsed history data
55 * @throws OsmTransferException if an exception occurs
56 */
57 public HistoryDataSet parseHistory(ProgressMonitor progressMonitor) throws OsmTransferException {
58 progressMonitor.beginTask("");
59 try {
60 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server..."));
61 StringBuilder sb = new StringBuilder();
62 sb.append(primitiveType.getAPIName())
63 .append('/').append(id).append("/history");
64
65 try (InputStream in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true))) {
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 }
72 } catch (OsmTransferException e) {
73 throw e;
74 } catch (Exception e) {
75 if (cancel)
76 return null;
77 throw new OsmTransferException(e);
78 } finally {
79 progressMonitor.finishTask();
80 activeConnection = null;
81 }
82 }
83}
Note: See TracBrowser for help on using the repository browser.