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

Last change on this file since 6113 was 5874, checked in by Don-vip, 11 years ago

see #8570, #7406 - I/O refactorization:

  • Move different file copy functions to Utils.copyFile (to be replaced later by Files.copy when switching to Java 7)
  • Replace all Utils.close(XXX) by Utils.close(Closeable) -> impacted plugins: commandline, mirrored_download, opendata, piclayer
  • Add new Utils.close(ZipFile)
  • Use of Utils.close almost everywhere
  • Javadoc fixes
  • 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 StringBuffer sb = new StringBuffer();
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 HistoryDataSet data = reader.parse(progressMonitor.createSubTaskMonitor(1, true));
72 return data;
73 } catch(OsmTransferException e) {
74 throw e;
75 } catch (Exception e) {
76 if (cancel)
77 return null;
78 throw new OsmTransferException(e);
79 } finally {
80 progressMonitor.finishTask();
81 Utils.close(in);
82 activeConnection = null;
83 }
84 }
85}
Note: See TracBrowser for help on using the repository browser.