Class URLs

java.lang.Object
uk.ac.starlink.ttools.func.URLs

public class URLs extends Object
Functions that construct URLs for external services. Most of the functions here just do string manipulation to build up URL strings, using knowledge of the parameters required for various services.
Since:
18 Oct 2019
Author:
Mark Taylor
  • Method Details

    • urlEncode

      public static String urlEncode(String txt)
      Performs necessary quoting of a string for it to be included safely in the data part of a URL. Alphanumeric characters and the characters underscore ("_"), minus sign ("-"), period (".") and tilde ("~") are passed through unchanged, and any other 7-bit ASCII character is represented by a percent sign ("%") followed by its 2-digit hexadecimal code. Characters with values of 128 or greater are simply dropped.
      Parameters:
      txt - input (unencoded) string
      Returns:
      output (encoded) string
      See Also:
      Examples:
      urlEncode("RR Lyr") = "RR%20Lyr"
    • urlDecode

      public static String urlDecode(String txt)
      Reverses the quoting performed by urlEncode. Percent-encoded sequences (%xx) are replaced by the ASCII character with the hexadecimal code xx.
      Parameters:
      txt - input (encoded) string
      Returns:
      output (unencoded) string
      See Also:
      Examples:
      urlDecode("RR%20Lyr") = "RR Lyr"
    • paramsUrl

      public static String paramsUrl(String baseUrl, String... nameValuePairs)
      Builds a query-type URL string given a base URL and a list of name, value pairs.

      The parameters are encoded on the command line according to the "application/x-www-form-urlencoded" convention, which appends a "?" to the base URL, and then adds name=value pairs separated by "&" characters, with percent-encoding of non-URL-friendly characters. This format is used by many services that require a list of parameters to be conveyed on the URL.

      Parameters:
      baseUrl - basic URL (may or may not already contain a "?")
      nameValuePairs - an even number of arguments (or an even-length string array) giving parameter name1,value1,name2,value2,...nameN,valueN
      Returns:
      form-encoded URL
      Examples:
      paramsUrl("http://x.org/", "a", "1", "b", "two", "c", "3&4") = "http://x.org/?a=1&b=two&c=3%264"
    • bibcodeUrl

      public static String bibcodeUrl(String bibcode)
      Maps a bibcode to the URL that will display the relevant entry in ADS. If the supplied string does not appear to be a bibcode, null will be returned.

      If the supplied string appears to be a bibcode, it just prepends the string "https://ui.adsabs.harvard.edu/abs/" and performs any character escaping that is required.

      Parameters:
      bibcode - ADS-style bibcode string
      Returns:
      display URL pointing at bibcode record, or null if it doesn't look like a bibcode
      See Also:
      Examples:
      bibcodeUrl("2018A&A...616A...2L") = "https://ui.adsabs.harvard.edu/abs/2018A%26A...616A...2L"
    • doiUrl

      public static String doiUrl(String doi)
      Maps a DOI (Digital Object Identifier) to its dislay URL. If the supplied string does not appear to be a DOI, null will be returned.

      If the supplied string appears to be a DOI, it strips any "doi:" prefix if present, prepends the string "https://doi.org/", and performs any character escaping that is required.

      Parameters:
      doi - DOI string, with or without "doi:" prefix
      Returns:
      display URL pointing at DOI content, or null if it doesn't look like a DOI
      See Also:
      Examples:
      doiUrl("10.3390/informatics4030018") = "https://doi.org/10.3390/informatics4030018"
    • arxivUrl

      public static String arxivUrl(String arxivId)
      Maps an arXiv identifier to the URL that will display its arXiv web page. If the supplied string does not appear to be an arXiv identifier, null will be returned.

      If the supplied string appears to be an arXiv identifier, it strips any "arXiv: prefix and prepends the string "https://arxiv.org/abs/".

      Parameters:
      arxivId - arXiv identifier, with or without "arXiv:" prefix
      Returns:
      display URL pointing at bibcode record, or null if it doesn't look like a bibcode
      See Also:
      Examples:
      arxivUrl("arXiv:1804.09379") = "https://arxiv.org/abs/1804.09381"
    • simbadUrl

      public static String simbadUrl(String sourceId)
      Maps a source identifier to the URL of its SIMBAD web page. SIMBAD is the astronomical source information service run by the Centre de Données astronomiques de Strasbourg.

      The string "http://simbad.u-strasbg.fr/simbad/sim-id?Ident=" is prepended to the given id string, and any necessary character escaping is applied. No attempt is made to validate whether the supplied string is a real source identifier, so there is no guarantee that the returned URL will contain actual results.

      Parameters:
      sourceId - free text assumed to represent a source identifier known by SIMBAD
      Returns:
      URL of the Simbad web page describing the identified source
      Examples:
      simbadUrl("Beta Pictoris") = "http://simbad.u-strasbg.fr/simbad/sim-id?Ident=Beta%20Pictoris"
    • nedUrl

      public static String nedUrl(String sourceId)
      Maps a source identifier to the URL of its NED web page. NED is the NASA/IPAC Extragalactic Database.

      The string "http://ned.ipac.caltech.edu/byname?objname=" is prepended to the given id string, and any necessary character escaping is applied. No attempt is made to validate whether the supplied string is a real source identifier, so there is no guarantee that the returned URL will contain actual results.

      Parameters:
      sourceId - free text assumed to represent a source identifier known by NED
      Returns:
      URL of the NED web page describing the identified source
      Examples:
      nedUrl("NGC 3952") = "http://ned.ipac.caltech.edu/byname?objname=NGC%203952"
    • hips2fitsUrl

      public static String hips2fitsUrl(String hipsId, String fmt, double raDeg, double decDeg, double fovDeg, int npix)
      Returns the URL of a cutout from the Hips2Fits service operated by CDS. The result will be the URL of a FITS or image file resampled to order from one of the HiPS surveys available at CDS.

      This function requests a square cutout using the SIN projection, which is suitable for small cutouts. If the details of this function don't suit your purposes, you can construct the URL yourself.

      Parameters:
      hipsId - identifier or partial identifier for the HiPS survey
      fmt - required output format, for instance "fits", "png", "jpg"
      raDeg - central Right Ascension (longitude) in degrees
      decDeg - central Declination (latitude) in degrees
      fovDeg - field of view; extent of the cutout in degrees
      npix - extent of the cutout in pixels (width=height=npix)
      Returns:
      URL of the required cutout
      See Also: