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

Last change on this file since 1670 was 1670, checked in by Gubaer, 15 years ago

fixed: bug in OsmApi.getOsmApi()
cleanup: exception handling in interfacing with OSM API
new: new action for updating individual elements with the their current state on the server (including new menu item in the file menu)
new: improved user feedback in case of conflicts
new: handles 410 Gone conflicts when uploading a changeset
new: undoable command for "purging" a primitive from the current dataset (necessary if the primitive is already deleted on the server and the user wants to remove it from its local dataset)
new: undoable command for "undeleting" an already deleted primitive on the server (kind of "cloning")
new: after a full upload, checks whether there are primitives in the local dataset which might be deleted on the server.
new: data structures for history data
new: history download support in io package

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