[2115] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.io;
|
---|
| 3 |
|
---|
| 4 | import java.io.InputStream;
|
---|
| 5 | import java.util.List;
|
---|
| 6 |
|
---|
| 7 | import org.openstreetmap.josm.data.osm.Changeset;
|
---|
| 8 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
[2124] | 9 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
[2115] | 10 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
| 11 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * Reads the history of an {@see OsmPrimitive} from the OSM API server.
|
---|
| 15 | *
|
---|
| 16 | */
|
---|
| 17 | public class OsmServerChangesetReader extends OsmServerReader {
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * constructor
|
---|
| 21 | *
|
---|
| 22 | */
|
---|
| 23 | public OsmServerChangesetReader(){
|
---|
[2124] | 24 | setDoAuthenticate(false);
|
---|
[2115] | 25 | }
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | * don't use - not implemented!
|
---|
| 29 | *
|
---|
| 30 | */
|
---|
| 31 | @Override
|
---|
| 32 | public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
|
---|
| 33 | return null;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[2124] | 36 | /**
|
---|
| 37 | * Queries a list
|
---|
| 38 | * @param query the query specification. Must not be null.
|
---|
| 39 | * @param monitor a progress monitor. Set to {@see NullProgressMonitor#INSTANCE} if null
|
---|
| 40 | * @return the list of changesets read from the server
|
---|
| 41 | * @throws IllegalArgumentException thrown if query is null
|
---|
| 42 | * @throws OsmTransferException
|
---|
| 43 | */
|
---|
[2115] | 44 | public List<Changeset> queryChangesets(ChangesetQuery query, ProgressMonitor monitor) throws OsmTransferException {
|
---|
[2124] | 45 | if (query == null)
|
---|
[2181] | 46 | throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "query"));
|
---|
[2124] | 47 | if (monitor == null) {
|
---|
| 48 | monitor = NullProgressMonitor.INSTANCE;
|
---|
| 49 | }
|
---|
[2115] | 50 | try {
|
---|
[2124] | 51 | monitor.beginTask(tr("Reading changesets..."));
|
---|
[2115] | 52 | StringBuffer sb = new StringBuffer();
|
---|
| 53 | sb.append("changesets?").append(query.getQueryString());
|
---|
| 54 | InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true));
|
---|
| 55 | if (in == null)
|
---|
| 56 | return null;
|
---|
| 57 | monitor.indeterminateSubTask(tr("Downloading changesets ..."));
|
---|
| 58 | List<Changeset> changesets = OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true));
|
---|
| 59 | return changesets;
|
---|
| 60 | } catch(OsmTransferException e) {
|
---|
| 61 | throw e;
|
---|
| 62 | } catch(IllegalDataException e) {
|
---|
| 63 | throw new OsmTransferException(e);
|
---|
| 64 | } finally {
|
---|
| 65 | monitor.finishTask();
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[2124] | 69 | /**
|
---|
| 70 | * Reads teh changeset with id <code>id</code> from the server
|
---|
| 71 | *
|
---|
| 72 | * @param id the changeset id. id > 0 required.
|
---|
| 73 | * @param monitor the progress monitor. Set to {@see NullProgressMonitor#INSTANCE} if null
|
---|
| 74 | * @return the changeset read
|
---|
| 75 | * @throws OsmTransferException thrown if something goes wrong
|
---|
| 76 | * @throws IllegalArgumentException if id <= 0
|
---|
| 77 | */
|
---|
[2115] | 78 | public Changeset readChangeset(long id, ProgressMonitor monitor) throws OsmTransferException {
|
---|
[2124] | 79 | if (id <= 0)
|
---|
[2181] | 80 | throw new IllegalArgumentException(tr("Parameter ''{0}'' > 0 expected. Got ''{1}''.", "id", id));
|
---|
[2124] | 81 | if (monitor == null) {
|
---|
| 82 | monitor = NullProgressMonitor.INSTANCE;
|
---|
| 83 | }
|
---|
[2115] | 84 | try {
|
---|
| 85 | monitor.beginTask(tr("Reading changeset {0} ...",id));
|
---|
| 86 | StringBuffer sb = new StringBuffer();
|
---|
| 87 | sb.append("changeset/").append(id);
|
---|
| 88 | InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true));
|
---|
| 89 | if (in == null)
|
---|
| 90 | return null;
|
---|
[2124] | 91 | monitor.indeterminateSubTask(tr("Downloading changeset {0} ...", id));
|
---|
[2115] | 92 | List<Changeset> changesets = OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true));
|
---|
| 93 | if (changesets == null || changesets.isEmpty())
|
---|
| 94 | return null;
|
---|
| 95 | return changesets.get(0);
|
---|
| 96 | } catch(OsmTransferException e) {
|
---|
| 97 | throw e;
|
---|
| 98 | } catch(IllegalDataException e) {
|
---|
| 99 | throw new OsmTransferException(e);
|
---|
| 100 | } finally {
|
---|
| 101 | monitor.finishTask();
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[2124] | 105 | /**
|
---|
| 106 | * not implemented yet
|
---|
| 107 | *
|
---|
| 108 | * @param id
|
---|
| 109 | * @param monitor
|
---|
| 110 | * @return
|
---|
| 111 | * @throws OsmTransferException
|
---|
| 112 | */
|
---|
[2115] | 113 | public Changeset downloadChangeset(long id, ProgressMonitor monitor) throws OsmTransferException {
|
---|
| 114 | return null;
|
---|
| 115 | }
|
---|
| 116 | }
|
---|