Package org.openstreetmap.josm.io
Class OsmServerReader
java.lang.Object
org.openstreetmap.josm.io.OsmConnection
org.openstreetmap.josm.io.OsmServerReader
- Direct Known Subclasses:
BoundingBoxDownloader,MultiFetchServerObjectReader,MultiFetchServerObjectReader.Fetcher,OsmServerBackreferenceReader,OsmServerChangesetReader,OsmServerHistoryReader,OsmServerLocationReader,OsmServerObjectReader,OsmServerUserInfoReader,OsmServerUserPreferencesReader
This DataReader reads directly from the REST API of the osm server.
It supports plain text transfer as well as gzip or deflate encoded transfers;
if compressed transfers are unwanted, set property osm-server.use-compression
to false.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceDOM document parser.Nested classes/interfaces inherited from class org.openstreetmap.josm.io.OsmConnection
OsmConnection.OAuthAccessTokenFetcher -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final OsmApiprotected Stringprivate booleanprotected booleanFields inherited from class org.openstreetmap.josm.io.OsmConnection
activeConnection, cancel, fetcher, oAuth20Parameters -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a newOsmServerReader.protectedOsmServerReader(OsmApi osmApi) Constructs a newOsmServerReader. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidadaptRequest(HttpClient request) Allows subclasses to modify the request.<T> TfetchData(String api, String subtask, OsmServerReader.DomParser<T> parser, ProgressMonitor monitor, String reason) Fetches generic data from the DOM document resulting an API call.private static StringfetchResponseText(HttpClient.Response response) protected static StringgetAttribute(Node node, String name) Returns an attribute from the given DOM node.protected StringReturn the base URL for relative URL requestsprotected InputStreamgetInputStream(String urlStr, ProgressMonitor progressMonitor) Open a connection to the given url and return a reader on the input stream from that connection.protected InputStreamgetInputStream(String urlStr, ProgressMonitor progressMonitor, String reason) Open a connection to the given url and return a reader on the input stream from that connection.protected InputStreamgetInputStreamRaw(String urlStr, ProgressMonitor progressMonitor) Open a connection to the given url and return a reader on the input stream from that connection.protected InputStreamgetInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason) Open a connection to the given url and return a reader on the input stream from that connection.protected InputStreamgetInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason, boolean uncompressAccordingToContentDisposition) Open a connection to the given url (if HTTP, trough a GET request) and return a reader on the input stream from that connection.protected InputStreamgetInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason, boolean uncompressAccordingToContentDisposition, String httpMethod, byte[] requestBody) Open a connection to the given url (if HTTP, with the specified method) and return a reader on the input stream from that connection.booleanReturns true if this reader is adding authentication credentials to the read request sent to the server.final booleanDetermines if the GPX data has been parsed properly.parseNotes(int noteLimit, int daysClosed, ProgressMonitor progressMonitor) Downloads notes from the API, given API limit parametersabstract DataSetparseOsm(ProgressMonitor progressMonitor) Download OSM files from somewhereparseOsm(ProgressMonitor progressMonitor, Compression compression) Download compressed OSM files from somewhereparseOsmChange(ProgressMonitor progressMonitor) Download OSM Change uncompressed files from somewhereparseOsmChange(ProgressMonitor progressMonitor, Compression compression) Download OSM Change compressed files from somewhereparseRawGps(ProgressMonitor progressMonitor) Retrieve raw gps waypoints from the server API.parseRawGps(ProgressMonitor progressMonitor, Compression compression) Retrieve compressed GPX files from somewhere.parseRawNotes(ProgressMonitor progressMonitor) Downloads notes from a given raw URL.parseRawNotes(ProgressMonitor progressMonitor, Compression compression) Download notes from a URL that contains a compressed notes dump filevoidsetDoAuthenticate(boolean doAuthenticate) Sets whether this reader adds authentication credentials to the read request sent to the server.Methods inherited from class org.openstreetmap.josm.io.OsmConnection
addAuth, addBasicAuthorizationHeader, addOAuth20AuthorizationHeader, cancel, isCanceled, retrieveBasicAuthorizationLogin, setOAuthAccessTokenFetcher
-
Field Details
-
api
-
doAuthenticate
-
gpxParsedProperly
-
contentType
-
-
Constructor Details
-
OsmServerReader
protected OsmServerReader()Constructs a newOsmServerReader. -
OsmServerReader
Constructs a newOsmServerReader.- Parameters:
osmApi- The API to use for this call- Since:
- 18650
-
-
Method Details
-
getInputStream
protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException Open a connection to the given url and return a reader on the input stream from that connection. In case of user cancel, returnnull. Relative URL's are directed to API base URL.- Parameters:
urlStr- The url to connect to.progressMonitor- progress monitoring and abort handler- Returns:
- A reader reading the input stream (servers answer) or
null. - Throws:
OsmTransferException- if data transfer errors occur
-
getInputStream
protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor, String reason) throws OsmTransferException Open a connection to the given url and return a reader on the input stream from that connection. In case of user cancel, returnnull. Relative URL's are directed to API base URL.- Parameters:
urlStr- The url to connect to.progressMonitor- progress monitoring and abort handlerreason- The reason to show on console. Can benullif no reason is given- Returns:
- A reader reading the input stream (servers answer) or
null. - Throws:
OsmTransferException- if data transfer errors occur
-
getBaseUrl
Return the base URL for relative URL requests- Returns:
- base url of API
-
getInputStreamRaw
protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException Open a connection to the given url and return a reader on the input stream from that connection. In case of user cancel, returnnull.- Parameters:
urlStr- The exact url to connect to.progressMonitor- progress monitoring and abort handler- Returns:
- An reader reading the input stream (servers answer) or
null. - Throws:
OsmTransferException- if data transfer errors occur
-
getInputStreamRaw
protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason) throws OsmTransferException Open a connection to the given url and return a reader on the input stream from that connection. In case of user cancel, returnnull.- Parameters:
urlStr- The exact url to connect to.progressMonitor- progress monitoring and abort handlerreason- The reason to show on console. Can benullif no reason is given- Returns:
- An reader reading the input stream (servers answer) or
null. - Throws:
OsmTransferException- if data transfer errors occur
-
getInputStreamRaw
protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason, boolean uncompressAccordingToContentDisposition) throws OsmTransferException Open a connection to the given url (if HTTP, trough a GET request) and return a reader on the input stream from that connection. In case of user cancel, returnnull.- Parameters:
urlStr- The exact url to connect to.progressMonitor- progress monitoring and abort handlerreason- The reason to show on console. Can benullif no reason is givenuncompressAccordingToContentDisposition- Whether to inspect the HTTP headerContent-Dispositionforfilenameand uncompress a gzip/bzip2/xz/zip stream.- Returns:
- An reader reading the input stream (servers answer) or
null. - Throws:
OsmTransferException- if data transfer errors occur
-
getInputStreamRaw
protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason, boolean uncompressAccordingToContentDisposition, String httpMethod, byte[] requestBody) throws OsmTransferException Open a connection to the given url (if HTTP, with the specified method) and return a reader on the input stream from that connection. In case of user cancel, returnnull.- Parameters:
urlStr- The exact url to connect to.progressMonitor- progress monitoring and abort handlerreason- The reason to show on console. Can benullif no reason is givenuncompressAccordingToContentDisposition- Whether to inspect the HTTP headerContent-Dispositionforfilenameand uncompress a gzip/bzip2/xz/zip stream.httpMethod- HTTP method ("GET", "POST" or "PUT")requestBody- HTTP request body (for "POST" and "PUT" methods only). Must be null for "GET" method.- Returns:
- An reader reading the input stream (servers answer) or
null. - Throws:
OsmTransferException- if data transfer errors occur- Since:
- 12596
-
fetchResponseText
-
adaptRequest
Allows subclasses to modify the request.- Parameters:
request- the prepared request- Since:
- 9308
-
parseOsm
Download OSM files from somewhere- Parameters:
progressMonitor- The progress monitor- Returns:
- The corresponding dataset
- Throws:
OsmTransferException- if any error occurs
-
parseOsm
public DataSet parseOsm(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException Download compressed OSM files from somewhere- Parameters:
progressMonitor- The progress monitorcompression- compression to use- Returns:
- The corresponding dataset
- Throws:
OsmTransferException- if any error occurs- Since:
- 13352
-
parseOsmChange
Download OSM Change uncompressed files from somewhere- Parameters:
progressMonitor- The progress monitor- Returns:
- The corresponding dataset
- Throws:
OsmTransferException- if any error occurs
-
parseOsmChange
public DataSet parseOsmChange(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException Download OSM Change compressed files from somewhere- Parameters:
progressMonitor- The progress monitorcompression- compression to use- Returns:
- The corresponding dataset
- Throws:
OsmTransferException- if any error occurs- Since:
- 13352
-
parseRawGps
Retrieve raw gps waypoints from the server API.- Parameters:
progressMonitor- The progress monitor- Returns:
- The corresponding GPX tracks
- Throws:
OsmTransferException- if any error occurs
-
parseRawGps
public GpxData parseRawGps(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException Retrieve compressed GPX files from somewhere.- Parameters:
progressMonitor- The progress monitorcompression- compression to use- Returns:
- The corresponding GPX tracks
- Throws:
OsmTransferException- if any error occurs- Since:
- 13352
-
isDoAuthenticate
Returns true if this reader is adding authentication credentials to the read request sent to the server.- Returns:
- true if this reader is adding authentication credentials to the read request sent to the server
-
setDoAuthenticate
Sets whether this reader adds authentication credentials to the read request sent to the server.- Parameters:
doAuthenticate- true if this reader adds authentication credentials to the read request sent to the server
-
isGpxParsedProperly
Determines if the GPX data has been parsed properly.- Returns:
- true if the GPX data has been parsed properly, false otherwise
- See Also:
-
parseNotes
public List<Note> parseNotes(int noteLimit, int daysClosed, ProgressMonitor progressMonitor) throws OsmTransferException Downloads notes from the API, given API limit parameters- Parameters:
noteLimit- How many notes to download.daysClosed- Return notes closed this many days in the past. -1 means all notes, ever. 0 means only unresolved notes.progressMonitor- Progress monitor for user feedback- Returns:
- List of notes returned by the API
- Throws:
OsmTransferException- if any errors happen
-
parseRawNotes
Downloads notes from a given raw URL. The URL is assumed to be complete and no API limits are added- Parameters:
progressMonitor- progress monitor- Returns:
- A list of notes parsed from the URL
- Throws:
OsmTransferException- if any error occurs during dialog with OSM API
-
parseRawNotes
public List<Note> parseRawNotes(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException Download notes from a URL that contains a compressed notes dump file- Parameters:
progressMonitor- progress monitorcompression- compression to use- Returns:
- A list of notes parsed from the URL
- Throws:
OsmTransferException- if any error occurs during dialog with OSM API- Since:
- 13352
-
getAttribute
Returns an attribute from the given DOM node.- Parameters:
node- DOM nodename- attribute name- Returns:
- attribute value for the given attribute
- Since:
- 12510
-
fetchData
public <T> T fetchData(String api, String subtask, OsmServerReader.DomParser<T> parser, ProgressMonitor monitor, String reason) throws OsmTransferException Fetches generic data from the DOM document resulting an API call.- Type Parameters:
T- data type- Parameters:
api- the OSM API callsubtask- the subtask translated messageparser- the parser converting the DOM document (OSM API result)monitor- The progress monitorreason- The reason to show on console. Can benullif no reason is given- Returns:
- The converted data
- Throws:
OsmTransferException- if something goes wrong- Since:
- 12510
-