Package fr.paris.lutece.plugins.resource
Class DefaultResourceManager
java.lang.Object
fr.paris.lutece.plugins.resource.DefaultResourceManager
- All Implemented Interfaces:
ResourceManager
- Version:
- $Id$
- Author:
- Trygve Laugstøl, Jason van Zyl
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSearchPath(String id, String path) 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 outputPath) 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. voidvoidsetOutputDirectory(File outputDirectory) Sets the output directory where resources will be stored.
-
Constructor Details
-
DefaultResourceManager
public DefaultResourceManager()
-
-
Method Details
-
produceResourceLoaders
@PostConstruct public void produceResourceLoaders() -
getResourceAsInputStream
Description copied from interface:ResourceManagerRetrieves a resource as an InputStream using the specified resource name.- Specified by:
getResourceAsInputStreamin interfaceResourceManager- 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
public File getResourceAsFile(String name) throws ResourceNotFoundException, FileResourceCreationException Description copied from interface:ResourceManagerRetrieves a resource as a File using the specified resource name.- Specified by:
getResourceAsFilein interfaceResourceManager- 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
public File getResourceAsFile(String name, String outputPath) throws ResourceNotFoundException, FileResourceCreationException Description copied from interface:ResourceManagerRetrieves a resource as a File and saves it with the specified output filename.- Specified by:
getResourceAsFilein interfaceResourceManager- Parameters:
name- the name of the resource to retrieveoutputPath- 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
Description copied from interface:ResourceManagerSets the output directory where resources will be stored.- Specified by:
setOutputDirectoryin interfaceResourceManager- Parameters:
outputDirectory- the directory to set as the output location for resources
-
addSearchPath
Description copied from interface:ResourceManagerAdds a search path for the resource loader with the specified ID.- Specified by:
addSearchPathin interfaceResourceManager- Parameters:
id- the ID of the resource loaderpath- the path to add to the resource loader's search paths
-
getResource
Description copied from interface:ResourceManagerSearches for a resource with the given name and returns a corresponding LuteceResource object.- Specified by:
getResourcein interfaceResourceManager- 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
Description copied from interface:ResourceManagerRetrieves 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.- Specified by:
getResourceAsFilein interfaceResourceManager- 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
public void createResourceAsFile(LuteceResource resource, File outputFile) throws FileResourceCreationException Description copied from interface:ResourceManagerDownloads the specified resource to the given output file.- Specified by:
createResourceAsFilein interfaceResourceManager- 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
Description copied from interface:ResourceManagerRetrieves 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.- Specified by:
getResourceURLin interfaceResourceManager- 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.
-