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

Last change on this file since 3217 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
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;
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 {@see OsmPrimitive} from the OSM API server.
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 *
31 * @exception IllegalArgumentException thrown, if type is null
32 */
33 public OsmServerHistoryReader(OsmPrimitiveType type, long id) throws IllegalArgumentException {
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 *
53 * @return the data set with the parsed history data
54 * @throws OsmTransferException thrown, if an exception occurs
55 */
56 public HistoryDataSet parseHistory(ProgressMonitor progressMonitor) throws OsmTransferException {
57 InputStream in = null;
58 progressMonitor.beginTask("");
59 try {
60 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server..."));
61 StringBuffer sb = new StringBuffer();
62 sb.append(primitiveType.getAPIName())
63 .append("/").append(id).append("/history");
64
65 in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true));
66 if (in == null)
67 return null;
68 progressMonitor.indeterminateSubTask(tr("Downloading history..."));
69 final OsmHistoryReader reader = new OsmHistoryReader(in);
70 HistoryDataSet data = reader.parse(progressMonitor.createSubTaskMonitor(1, true));
71 return data;
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 if (in != null) {
81 try {
82 in.close();
83 } catch(Exception e) {}
84 activeConnection = null;
85 }
86 }
87 }
88}
Note: See TracBrowser for help on using the repository browser.