Class WebMapper


  • public abstract class WebMapper
    extends java.lang.Object
    Object that can map some particular sort of string to a URL referencing a web page. "Web page" here is generally intended to mean a resource that it's reasonable to try viewing in a web browser.
    Since:
    20 Jun 2019
    Author:
    Mark Taylor
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static WebMapper ARXIV
      Mapper for an arXiv identifier.
      static WebMapper AUTO
      Mapper that tries various strategies to turn a string into a URL.
      static WebMapper BIBCODE
      Mapper for a Bibcode.
      static WebMapper BIBCODE_OLD
      Mapper for a Bibcode, using the Classic web pages (deprecated by ADS).
      static WebMapper DOI
      Mapper for a DOI (Digital Object Identifier).
      static WebMapper FILE
      Mapper for pathname of a file in the local filesystem.
      static WebMapper NED
      Maps a source identifier to its NED web page.
      static WebMapper NED_CLASSIC
      Maps a source identifier to its classic NED web page.
      static WebMapper SIMBAD
      Maps a source identifier to its Simbad web page.
      static WebMapper URL
      Mapper for a string that's already a URL.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected WebMapper​(java.lang.String name)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static WebMapper createMultiMapper​(java.lang.String name, WebMapper[] others)
      Returns a mapper that combines others to come up with a result if any of them can turn a string into a URL.
      static WebMapper createPrefixMapper​(java.lang.String name, java.lang.String urlPrefix)
      Returns a mapper that blindly appends the given location string to a supplied prefix URL, pausing only to URL-encode it.
      static WebMapper[] getMappers()
      Returns a list of all the known useful mappers.
      java.lang.String getName()
      Returns the user-visible name for this mapper.
      java.lang.String toString()  
      abstract java.net.URL toUrl​(java.lang.String txt)
      Returns a URL constructed from the given text according to the knowledge of this WebMapper, if it looks suitable.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • FILE

        public static final WebMapper FILE
        Mapper for pathname of a file in the local filesystem.
      • URL

        public static final WebMapper URL
        Mapper for a string that's already a URL.
      • BIBCODE

        public static final WebMapper BIBCODE
        Mapper for a Bibcode.
      • DOI

        public static final WebMapper DOI
        Mapper for a DOI (Digital Object Identifier).
      • ARXIV

        public static final WebMapper ARXIV
        Mapper for an arXiv identifier.
      • SIMBAD

        public static final WebMapper SIMBAD
        Maps a source identifier to its Simbad web page.
      • NED

        public static final WebMapper NED
        Maps a source identifier to its NED web page.
      • BIBCODE_OLD

        public static final WebMapper BIBCODE_OLD
        Mapper for a Bibcode, using the Classic web pages (deprecated by ADS).
      • NED_CLASSIC

        public static final WebMapper NED_CLASSIC
        Maps a source identifier to its classic NED web page.
      • AUTO

        public static final WebMapper AUTO
        Mapper that tries various strategies to turn a string into a URL.
    • Constructor Detail

      • WebMapper

        protected WebMapper​(java.lang.String name)
        Constructor.
        Parameters:
        name - user-visible name for this mapper
    • Method Detail

      • toUrl

        public abstract java.net.URL toUrl​(java.lang.String txt)
        Returns a URL constructed from the given text according to the knowledge of this WebMapper, if it looks suitable. If the supplied string does not look like the kind of input this mapper is expecting, it should return null.

        Where possible, implementations should do enough checking of the format to tell whether the result is likely to be a resolvable URL (though without taking significant time to do it), rather than just making a best effort to come up with a URL that's unlikely to work.

        Parameters:
        txt - location string
        Returns:
        URL, or null
      • getName

        public java.lang.String getName()
        Returns the user-visible name for this mapper.
        Returns:
        name
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getMappers

        public static WebMapper[] getMappers()
        Returns a list of all the known useful mappers. The AUTO mapper will be first in the list.
        Returns:
        mapper list
      • createPrefixMapper

        public static WebMapper createPrefixMapper​(java.lang.String name,
                                                   java.lang.String urlPrefix)
        Returns a mapper that blindly appends the given location string to a supplied prefix URL, pausing only to URL-encode it. This implementation does not attempt to assess the supplied URL for suitability, so it never returns null except in case of a blank input string.
        Parameters:
        name - mapper name
        Returns:
        new mapper
      • createMultiMapper

        public static WebMapper createMultiMapper​(java.lang.String name,
                                                  WebMapper[] others)
        Returns a mapper that combines others to come up with a result if any of them can turn a string into a URL.
        Parameters:
        name - mapper name
        others - list of WebMappers to which this one will try delegating in turn
        Returns:
        new mapper