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

Last change on this file since 2198 was 2181, checked in by stoecker, 15 years ago

lots of i18n fixes

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