Class UrlResourceDescriptor

    • Constructor Detail

      • UrlResourceDescriptor

        public UrlResourceDescriptor​(URL url,
                                     Charset charset)
                              throws URISyntaxException
        Creates a new resource descriptor that reads the data from the given URL.
        Parameters:
        url - URL pointing to the data. Must be an absolute URL.
        charset - Charset for plain text resources. Use NullPointerException for binary resources.
        Throws:
        URISyntaxException - When the URL is invalid.
        IllegalArgumentException - When the URL is not absolute.
      • UrlResourceDescriptor

        public UrlResourceDescriptor​(URL url,
                                     URI uri,
                                     Charset charset)
                              throws URISyntaxException
        Creates a new resource descriptor that reads the data from the given URL.
        Parameters:
        url - URL pointing to the data. Must be an absolute URL.
        uri - URI identifying to the resource, which may be different from the URL.
        charset - Charset for plain text resources. Use NullPointerException for binary resources.
        Throws:
        URISyntaxException - When the URL is invalid.
        IllegalArgumentException - When the URL is not absolute.
    • Method Detail

      • getAbsoluteUri

        public URI getAbsoluteUri()
        Description copied from interface: IResourceDescriptor
        Gets the absolute URI that identifies this resource. The URI should be unique for each resource. If there are different versions of the same resource, they should have different URIs, e.g. by including a version number in the URI. The URI is not used to access the binary data, but may be used e.g. for caching purposes.

        The URI must be unique globally, i.e. also across different plugins. It is recommended to use a URI scheme that is unlikely to be used by other plugins, e.g. by including the Maven group and artifact ID.

        It is an error for this method to return a URI where URI.isAbsolute() yields false.

        Specified by:
        getAbsoluteUri in interface IResourceDescriptor
        Returns:
        An absolute URI that identifies this resource.
      • getCharset

        public Charset getCharset()
        Specified by:
        getCharset in interface IResourceDescriptor
        Returns:
        When this resource is a plain text resource: the charset or encoding of the text. Defaults to UTF_8.
      • forClasspathResource

        public static IResourceDescriptor forClasspathResource​(Class<?> clazz,
                                                               String path,
                                                               Charset charset)
                                                        throws URISyntaxException
        Creates a new resource descriptor that reads the data from the given classpath.
        Parameters:
        clazz - Class with a class loader for reading the resource.
        path - Path of the resource. Always interpreted as an absolute path, may or may not start with a slash.
        charset - Charset for plain text files. null for binary files.
        Returns:
        A new resource descriptor that reads the data from the given classpath.
        Throws:
        URISyntaxException - When no URI was given and the URL obtained from the class loader cannot be converted to a URI.
        IllegalArgumentException - When the path cannot be loaded by the class loader.
      • forClasspathResource

        public static IResourceDescriptor forClasspathResource​(ClassLoader loader,
                                                               String path,
                                                               Charset charset)
                                                        throws URISyntaxException
        Creates a new resource descriptor that reads the data from the given classpath.
        Parameters:
        loader - Class loader for reading the resource.
        path - Path of the resource. Always interpreted as an absolute path, may or may not start with a slash.
        charset - Charset for plain text files. null for binary files.
        Returns:
        A new resource descriptor that reads the data from the given classpath.
        Throws:
        URISyntaxException - When no URI was given and the URL obtained from the class loader cannot be converted to a URI.
        IllegalArgumentException - When the path cannot be loaded by the class loader.
      • forClasspathResource

        public static IResourceDescriptor forClasspathResource​(Class<?> clazz,
                                                               String path,
                                                               URI uri,
                                                               Charset charset)
                                                        throws URISyntaxException
        Creates a new resource descriptor that reads the data from the given classpath.
        Parameters:
        clazz - Class with a class loader for reading the resource.
        path - Path of the resource. Always interpreted as an absolute path, may or may not start with a slash.
        uri - Identifier of the resource.
        charset - Charset for plain text files. null for binary files.
        Returns:
        A new resource descriptor that reads the data from the given classpath.
        Throws:
        URISyntaxException - When no URI was given and the URL obtained from the class loader cannot be converted to a URI.
        IllegalArgumentException - When the path cannot be loaded by the class loader.
      • forClasspathResource

        public static IResourceDescriptor forClasspathResource​(ClassLoader loader,
                                                               String path,
                                                               URI uri,
                                                               Charset charset)
                                                        throws URISyntaxException
        Creates a new resource descriptor that reads the data from the given classpath.
        Parameters:
        loader - Class loader for reading the resource.
        path - Path of the resource. Always interpreted as an absolute path, may or may not start with a slash.
        uri - Identifier of the resource.
        charset - Charset for plain text files. null for binary files.
        Returns:
        A new resource descriptor that reads the data from the given classpath.
        Throws:
        URISyntaxException - When no URI was given and the URL obtained from the class loader cannot be converted to a URI.
        IllegalArgumentException - When the path cannot be loaded by the class loader.