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
public abstract class OsmServerReader extends OsmConnection
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 Classes Modifier and Type Class Description protected static interface
OsmServerReader.DomParser<R>
DOM document parser.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.io.OsmConnection
OsmConnection.OAuthAccessTokenFetcher
-
-
Field Summary
Fields Modifier and Type Field Description private OsmApi
api
protected java.lang.String
contentType
private boolean
doAuthenticate
protected boolean
gpxParsedProperly
-
Fields inherited from class org.openstreetmap.josm.io.OsmConnection
activeConnection, cancel, fetcher, oAuth20Parameters
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
OsmServerReader()
Constructs a newOsmServerReader
.protected
OsmServerReader(OsmApi osmApi)
Constructs a newOsmServerReader
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
adaptRequest(HttpClient request)
Allows subclasses to modify the request.<T> T
fetchData(java.lang.String api, java.lang.String subtask, OsmServerReader.DomParser<T> parser, ProgressMonitor monitor, java.lang.String reason)
Fetches generic data from the DOM document resulting an API call.private static java.lang.String
fetchResponseText(HttpClient.Response response)
protected static java.lang.String
getAttribute(org.w3c.dom.Node node, java.lang.String name)
Returns an attribute from the given DOM node.protected java.lang.String
getBaseUrl()
Return the base URL for relative URL requestsprotected java.io.InputStream
getInputStream(java.lang.String urlStr, ProgressMonitor progressMonitor)
Open a connection to the given url and return a reader on the input stream from that connection.protected java.io.InputStream
getInputStream(java.lang.String urlStr, ProgressMonitor progressMonitor, java.lang.String reason)
Open a connection to the given url and return a reader on the input stream from that connection.protected java.io.InputStream
getInputStreamRaw(java.lang.String urlStr, ProgressMonitor progressMonitor)
Open a connection to the given url and return a reader on the input stream from that connection.protected java.io.InputStream
getInputStreamRaw(java.lang.String urlStr, ProgressMonitor progressMonitor, java.lang.String reason)
Open a connection to the given url and return a reader on the input stream from that connection.protected java.io.InputStream
getInputStreamRaw(java.lang.String urlStr, ProgressMonitor progressMonitor, java.lang.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 java.io.InputStream
getInputStreamRaw(java.lang.String urlStr, ProgressMonitor progressMonitor, java.lang.String reason, boolean uncompressAccordingToContentDisposition, java.lang.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.boolean
isDoAuthenticate()
Returns true if this reader is adding authentication credentials to the read request sent to the server.boolean
isGpxParsedProperly()
Determines if the GPX data has been parsed properly.java.util.List<Note>
parseNotes(int noteLimit, int daysClosed, ProgressMonitor progressMonitor)
Downloads notes from the API, given API limit parametersabstract DataSet
parseOsm(ProgressMonitor progressMonitor)
Download OSM files from somewhereDataSet
parseOsm(ProgressMonitor progressMonitor, Compression compression)
Download compressed OSM files from somewhereDataSet
parseOsmChange(ProgressMonitor progressMonitor)
Download OSM Change uncompressed files from somewhereDataSet
parseOsmChange(ProgressMonitor progressMonitor, Compression compression)
Download OSM Change compressed files from somewhereGpxData
parseRawGps(ProgressMonitor progressMonitor)
Retrieve raw gps waypoints from the server API.GpxData
parseRawGps(ProgressMonitor progressMonitor, Compression compression)
Retrieve compressed GPX files from somewhere.java.util.List<Note>
parseRawNotes(ProgressMonitor progressMonitor)
Downloads notes from a given raw URL.java.util.List<Note>
parseRawNotes(ProgressMonitor progressMonitor, Compression compression)
Download notes from a URL that contains a compressed notes dump filevoid
setDoAuthenticate(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 Detail
-
doAuthenticate
private boolean doAuthenticate
-
gpxParsedProperly
protected boolean gpxParsedProperly
-
contentType
protected java.lang.String contentType
-
-
Constructor Detail
-
OsmServerReader
protected OsmServerReader()
Constructs a newOsmServerReader
.
-
OsmServerReader
protected OsmServerReader(OsmApi osmApi)
Constructs a newOsmServerReader
.- Parameters:
osmApi
- The API to use for this call- Since:
- 18650
-
-
Method Detail
-
getInputStream
protected java.io.InputStream getInputStream(java.lang.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 java.io.InputStream getInputStream(java.lang.String urlStr, ProgressMonitor progressMonitor, java.lang.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 benull
if no reason is given- Returns:
- A reader reading the input stream (servers answer) or
null
. - Throws:
OsmTransferException
- if data transfer errors occur
-
getBaseUrl
protected java.lang.String getBaseUrl()
Return the base URL for relative URL requests- Returns:
- base url of API
-
getInputStreamRaw
protected java.io.InputStream getInputStreamRaw(java.lang.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 java.io.InputStream getInputStreamRaw(java.lang.String urlStr, ProgressMonitor progressMonitor, java.lang.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 benull
if no reason is given- Returns:
- An reader reading the input stream (servers answer) or
null
. - Throws:
OsmTransferException
- if data transfer errors occur
-
getInputStreamRaw
protected java.io.InputStream getInputStreamRaw(java.lang.String urlStr, ProgressMonitor progressMonitor, java.lang.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 benull
if no reason is givenuncompressAccordingToContentDisposition
- Whether to inspect the HTTP headerContent-Disposition
forfilename
and 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 java.io.InputStream getInputStreamRaw(java.lang.String urlStr, ProgressMonitor progressMonitor, java.lang.String reason, boolean uncompressAccordingToContentDisposition, java.lang.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 benull
if no reason is givenuncompressAccordingToContentDisposition
- Whether to inspect the HTTP headerContent-Disposition
forfilename
and 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
private static java.lang.String fetchResponseText(HttpClient.Response response)
-
adaptRequest
protected void adaptRequest(HttpClient request)
Allows subclasses to modify the request.- Parameters:
request
- the prepared request- Since:
- 9308
-
parseOsm
public abstract DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException
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
public DataSet parseOsmChange(ProgressMonitor progressMonitor) throws OsmTransferException
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
public GpxData parseRawGps(ProgressMonitor progressMonitor) throws OsmTransferException
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
public boolean 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
public void setDoAuthenticate(boolean doAuthenticate)
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
public final boolean isGpxParsedProperly()
Determines if the GPX data has been parsed properly.- Returns:
- true if the GPX data has been parsed properly, false otherwise
- See Also:
GpxReader.parse(boolean)
-
parseNotes
public java.util.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
public java.util.List<Note> parseRawNotes(ProgressMonitor progressMonitor) throws OsmTransferException
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 java.util.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
protected static java.lang.String getAttribute(org.w3c.dom.Node node, java.lang.String name)
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(java.lang.String api, java.lang.String subtask, OsmServerReader.DomParser<T> parser, ProgressMonitor monitor, java.lang.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 benull
if no reason is given- Returns:
- The converted data
- Throws:
OsmTransferException
- if something goes wrong- Since:
- 12510
-
-