Package org.apache.sis.console
Class ResourcesDownloader
- Object
-
- InstallationResources
-
- ResourcesDownloader
-
public class ResourcesDownloader extends InstallationResources
A provider for data licensed under different terms of use than the Apache license. This class is in charge of downloading the data if necessary and asking user's agreement before to install them. Authorities managed by the current implementation are:"EPSG"
for the EPSG geodetic dataset.
- Since:
- 0.7
Defined in the
sis-console
module
-
-
Constructor Summary
Constructors Constructor Description ResourcesDownloader()
Creates a new installation scripts provider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>
getAuthorities()
Returns the name of the authority who provides data under non-Apache terms of use.String
getLicense(String authority, Locale locale, String mimeType)
Returns the terms of use of the dataset provided by the given authority, ornull
if none.Object
getResource(String authority, int index)
Returns an installation resource for the given authority.String[]
getResourceNames(String authority)
Returns the names of installation scripts provided by the given authority.BufferedReader
openScript(String authority, int resource)
Returns a reader for the installation script at the given index.
-
-
-
Method Detail
-
getAuthorities
public Set<String> getAuthorities()
Returns the name of the authority who provides data under non-Apache terms of use. If thisResourcesDownloader
can not ask user's agreement because there is noConsole
attached to the current Java virtual machine, then this method returns an empty set.- Specified by:
getAuthorities
in classInstallationResources
- Returns:
"EPSG"
or an empty set.
-
getLicense
public String getLicense(String authority, Locale locale, String mimeType) throws IOException
Returns the terms of use of the dataset provided by the given authority, ornull
if none. The terms of use can be returned in either plain text or HTML.- Specified by:
getLicense
in classInstallationResources
- Parameters:
authority
- one of the values returned bygetAuthorities()
.mimeType
- either"text/plain"
or"text/html"
.locale
- the preferred locale for the terms of use.- Returns:
- the terms of use in plain text or HTML, or
null
if none. - Throws:
IllegalArgumentException
- if the givenauthority
argument is not one of the expected values.IOException
- if an error occurred while reading the license file.
-
getResourceNames
public String[] getResourceNames(String authority) throws IOException
Returns the names of installation scripts provided by the given authority. This method is invoked byEPSGFactory.install(Connection)
for listing the SQL scripts to execute during EPSG dataset installation.If that question has not already been asked, this method asks to the user if (s)he accepts EPSG terms of use. If (s)he refuses, an
AccessDeniedException
will be thrown.- Specified by:
getResourceNames
in classInstallationResources
- Parameters:
authority
- one of the values returned bygetAuthorities()
.- Returns:
- the names of all SQL scripts to execute.
- Throws:
IllegalArgumentException
- if the givenauthority
argument is not one of the expected values.IOException
- if an error occurred while fetching the script names.
-
getResource
public Object getResource(String authority, int index) throws IOException
Returns an installation resource for the given authority. If that question has not already been asked, this method asks to the user if (s)he accepts EPSG terms of use. If (s)he refuses, anAccessDeniedException
will be thrown.- Overrides:
getResource
in classInstallationResources
- Parameters:
authority
- one of the values returned bygetAuthorities()
.index
- index of the resource to get, from 0 inclusive togetResourceNames(authority).length
exclusive.- Returns:
- the resource as an URL or any other type, at implementation choice.
- Throws:
IllegalArgumentException
- if the givenauthority
argument is not one of the expected values.IndexOutOfBoundsException
- if the givenresource
argument is out of bounds.IOException
- if an error occurred while fetching the resource.- Since:
- 0.8
- See Also:
ClassLoader.getResource(String)
-
openScript
public BufferedReader openScript(String authority, int resource) throws IOException
Returns a reader for the installation script at the given index. This method is invoked byEPSGFactory.install(Connection)
for getting the SQL scripts to execute during EPSG dataset installation.If that question has not already been asked, this method asks to the user if (s)he accepts EPSG terms of use. If (s)he refuses, an
AccessDeniedException
will be thrown.- Specified by:
openScript
in classInstallationResources
- Parameters:
authority
- one of the values returned bygetAuthorities()
.resource
- index of the script to open, from 0 inclusive togetResourceNames(authority).length
exclusive.- Returns:
- a reader for the installation script content.
- Throws:
IllegalArgumentException
- if the givenauthority
argument is not one of the expected values.IndexOutOfBoundsException
- if the givenresource
argument is out of bounds.FileNotFoundException
- if the SQL script of the given name has not been found.IOException
- if an error occurred while creating the reader.
-
-