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.
  • Field Details

  • Constructor Details

    • OsmServerReader

      protected OsmServerReader()
      Constructs a new OsmServerReader.
    • OsmServerReader

      protected OsmServerReader(OsmApi osmApi)
      Constructs a new OsmServerReader.
      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, return null. 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, return null. Relative URL's are directed to API base URL.
      Parameters:
      urlStr - The url to connect to.
      progressMonitor - progress monitoring and abort handler
      reason - The reason to show on console. Can be null 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 String 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, return null.
      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, return null.
      Parameters:
      urlStr - The exact url to connect to.
      progressMonitor - progress monitoring and abort handler
      reason - The reason to show on console. Can be null 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 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, return null.
      Parameters:
      urlStr - The exact url to connect to.
      progressMonitor - progress monitoring and abort handler
      reason - The reason to show on console. Can be null if no reason is given
      uncompressAccordingToContentDisposition - Whether to inspect the HTTP header Content-Disposition for filename 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 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, return null.
      Parameters:
      urlStr - The exact url to connect to.
      progressMonitor - progress monitoring and abort handler
      reason - The reason to show on console. Can be null if no reason is given
      uncompressAccordingToContentDisposition - Whether to inspect the HTTP header Content-Disposition for filename 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 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 monitor
      compression - 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 monitor
      compression - 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 monitor
      compression - 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:
    • 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

      public 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 List<Note> parseRawNotes(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException
      Download notes from a URL that contains a compressed notes dump file
      Parameters:
      progressMonitor - progress monitor
      compression - 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 String getAttribute(Node node, String name)
      Returns an attribute from the given DOM node.
      Parameters:
      node - DOM node
      name - 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 call
      subtask - the subtask translated message
      parser - the parser converting the DOM document (OSM API result)
      monitor - The progress monitor
      reason - The reason to show on console. Can be null if no reason is given
      Returns:
      The converted data
      Throws:
      OsmTransferException - if something goes wrong
      Since:
      12510