Package fr.paris.lutece.plugins.resource
Interface ResourceManager
- All Known Implementing Classes:
DefaultResourceManager
public interface ResourceManager
- Version:
- $Id$
- Author:
- Trygve Laugstøl, Jason van Zyl
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddSearchPath(String resourceLoaderId, String searchPath) Adds a search path for the resource loader with the specified ID.voidcreateResourceAsFile(LuteceResource resource, File outputFile) Downloads the specified resource to the given output file.getResource(String name) Searches for a resource with the given name and returns a corresponding LuteceResource object.getResourceAsFile(LuteceResource resource) Retrieves a file with the given resource's contents.getResourceAsFile(String name) Retrieves a resource as a File using the specified resource name.getResourceAsFile(String name, String outputFile) Retrieves a resource as a File and saves it with the specified output filename.Retrieves a resource as an InputStream using the specified resource name.getResourceURL(String path) Retrieves the resource paths as a Setfrom a given directory. voidsetOutputDirectory(File outputDirectory) Sets the output directory where resources will be stored.
-
Method Details
-
getResourceAsInputStream
Retrieves a resource as an InputStream using the specified resource name.- Parameters:
name- the name of the resource to retrieve- Returns:
- an InputStream representing the resource's contents
- Throws:
ResourceNotFoundException- if the resource cannot be found
-
getResourceAsFile
Retrieves a resource as a File using the specified resource name.- Parameters:
name- the name of the resource to retrieve- Returns:
- a File object representing the resource's contents
- Throws:
ResourceNotFoundException- if the resource cannot be foundFileResourceCreationException- if there is an error creating the File
-
getResourceAsFile
File getResourceAsFile(String name, String outputFile) throws ResourceNotFoundException, FileResourceCreationException Retrieves a resource as a File and saves it with the specified output filename.- Parameters:
name- the name of the resource to retrieveoutputFile- the name to save the resource as- Returns:
- a File object representing the resource's contents
- Throws:
ResourceNotFoundException- if the resource cannot be foundFileResourceCreationException- if there is an error creating the File
-
setOutputDirectory
Sets the output directory where resources will be stored.- Parameters:
outputDirectory- the directory to set as the output location for resources
-
addSearchPath
Adds a search path for the resource loader with the specified ID.- Parameters:
resourceLoaderId- the ID of the resource loadersearchPath- the path to add to the resource loader's search paths
-
getResource
Searches for a resource with the given name and returns a corresponding LuteceResource object.- Parameters:
name- the name of the resource to search for- Returns:
- the LuteceResource found with the specified name
- Throws:
ResourceNotFoundException- if the resource cannot be found
-
getResourceAsFile
Retrieves a file with the given resource's contents. If the resource is already available as a file, returns that file. Otherwise, a file in the resource manager's output directory is created, and the resource is downloaded to that file.- Parameters:
resource- the LuteceResource to retrieve as a file- Returns:
- a File object representing the resource's contents
- Throws:
FileResourceCreationException- if there is an error creating the File
-
createResourceAsFile
void createResourceAsFile(LuteceResource resource, File outputFile) throws FileResourceCreationException Downloads the specified resource to the given output file.- Parameters:
resource- the LuteceResource to downloadoutputFile- the File to which the resource will be downloaded- Throws:
FileResourceCreationException- if there is an error creating the File
-
getResourceURL
Retrieves the resource paths as a Setfrom a given directory. This method reads the files in the specified directory, converts their paths to URLs, and returns them in a Set. If no resources are found, a ResourceNotFoundExceptionwill be thrown.- Parameters:
path- The base path in the file system, which can be either relative or absolute. This path is used to locate the directory containing the resources. The path must start with a "/".- Returns:
- A Set containing the URLs of the resources found in the directory.
- Throws:
ResourceNotFoundException- If no resources are found or if an error occurs while reading the directory or converting paths to URLs.
-