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-consolemodule
-
-
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.StringgetLicense(String authority, Locale locale, String mimeType)Returns the terms of use of the dataset provided by the given authority, ornullif none.ObjectgetResource(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.BufferedReaderopenScript(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 thisResourcesDownloadercan not ask user's agreement because there is noConsoleattached to the current Java virtual machine, then this method returns an empty set.- Specified by:
getAuthoritiesin 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, ornullif none. The terms of use can be returned in either plain text or HTML.- Specified by:
getLicensein 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
nullif none. - Throws:
IllegalArgumentException- if the givenauthorityargument 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
AccessDeniedExceptionwill be thrown.- Specified by:
getResourceNamesin classInstallationResources- Parameters:
authority- one of the values returned bygetAuthorities().- Returns:
- the names of all SQL scripts to execute.
- Throws:
IllegalArgumentException- if the givenauthorityargument 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, anAccessDeniedExceptionwill be thrown.- Overrides:
getResourcein classInstallationResources- Parameters:
authority- one of the values returned bygetAuthorities().index- index of the resource to get, from 0 inclusive togetResourceNames(authority).lengthexclusive.- Returns:
- the resource as an URL or any other type, at implementation choice.
- Throws:
IllegalArgumentException- if the givenauthorityargument is not one of the expected values.IndexOutOfBoundsException- if the givenresourceargument 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
AccessDeniedExceptionwill be thrown.- Specified by:
openScriptin classInstallationResources- Parameters:
authority- one of the values returned bygetAuthorities().resource- index of the script to open, from 0 inclusive togetResourceNames(authority).lengthexclusive.- Returns:
- a reader for the installation script content.
- Throws:
IllegalArgumentException- if the givenauthorityargument is not one of the expected values.IndexOutOfBoundsException- if the givenresourceargument 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.
-
-