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

Last change on this file since 7001 was 6822, checked in by bastiK, 10 years ago

see #8902 - Small performance enhancements / coding style (patch by shinigami, updated, modified)

stringbuilder.diff: StringBuffer => StringBuilder

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