Class UrlRequester

java.lang.Object
org.codehaus.mojo.license.utils.UrlRequester

public class UrlRequester extends Object
This class should be used to load the content from a URL.

Supported URL protocols are those standards plus classpath protocol.

  • Field Details

  • Constructor Details

    • UrlRequester

      public UrlRequester()
  • Method Details

    • setProxy

      public static void setProxy(org.apache.maven.settings.Proxy proxy)
      Sets the proxy used by the http and https requests of this class. The mojos set the active proxy of settings.xml before they download anything.
      Parameters:
      proxy - the proxy, or null to connect directly
    • isStringUrl

      public static boolean isStringUrl(String data)
      Checks if the given input is a URL value.
      Parameters:
      data - the license string or a URL
      Returns:
      true if URL, false else
    • toUrl

      public static URL toUrl(String url) throws MalformedURLException
      Converts the given string to a URL.

      A file: URL that is not a valid URI, such as file:///${project.build.directory}/file.txt with a Windows path, is built from its path instead: backslashes become slashes and characters such as spaces are quoted. java.net.URL accepted these strings before 2.5.0.

      Parameters:
      url - the URL as a string
      Returns:
      the URL
      Throws:
      MalformedURLException - if the string is not a URL
      IllegalArgumentException - if the string is not a URI and not a file: URL
    • isExternalUrl

      public static boolean isExternalUrl(String url)
      Check if URL point to external resource.
      Parameters:
      url - the URL as a string
      Returns:
      true if URL use external protocol
    • getFromUrl

      public static String getFromUrl(String url) throws IOException
      Returns the content of the resource pointed by the given URL as a string.
      Parameters:
      url - the resource destination that is expected to contain pure text
      Returns:
      the string representation of the resource at the given URL
      Throws:
      IOException - If an I/O error occurs when retrieve of the content URL
    • findProtocol

      public static String findProtocol(String url)
      Returns the protocol of the given URL as a string. The RFC specifies that the url is composed by :invalid input: '<'schema-part>.
      Parameters:
      url - the URL as a string.
      Returns:
      the protocol from the URL.
    • getFromUrl

      public static String getFromUrl(String url, String encoding) throws IOException
      Returns the content of the resource pointed by the given URL as a string.
      Parameters:
      url - the resource destination that is expected to contain pure text
      encoding - the resource content encoding
      Returns:
      the string representation of the resource at the given URL
      Throws:
      IOException - If an I/O error occurs when retrieve of the content URL
    • downloadList

      public static List<String> downloadList(String url) throws org.apache.maven.plugin.MojoExecutionException
      will download a external resource and read the content of the file that will then be translated into a new list.
      Lines starting with the character '#' will be omitted from the list

      NOTE:
      certificate checking for this request will be disabled because some resources might be present on some local servers in the internal network that do not use a safe connection
      Parameters:
      url - the URL to the external resource
      Returns:
      a new list with all license entries from the remote resource
      Throws:
      org.apache.maven.plugin.MojoExecutionException