Interface FileLocationStrategy
- All Known Implementing Classes:
AbsoluteNameLocationStrategy
,BasePathLocationStrategy
,ClasspathLocationStrategy
,CombinedLocationStrategy
,FileSystemLocationStrategy
,HomeDirectoryLocationStrategy
,ProvidedURLLocationStrategy
An interface allowing applications to customize the process of locating a file.
FileHandler
uses FileLocator
objects for referencing files. These objects are not guaranteed to
identify a file in a unique way. For instance, if only a file name is defined, this could mean a relative file name
in the current directory, the name of a resource to be loaded from the class path, or something else. Before the file
described by a FileLocator
can be actually accessed, an unambiguous URL pointing to this file has to be
obtained. This is the job of a FileLocationStrategy
.
This interface defines a method for locating a file provided as a FileLocator
object. If location is
successful, a URL is returned. A concrete implementation can perform arbitrary actions to search for the file in
question at various places. There will also be an implementation allowing the combination of multiple
FileLocationStrategy
implementations; so a file can be searched using multiple strategies until one of them
is successful.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionlocate
(FileSystem fileSystem, FileLocator locator) Tries to locate the specified file.
-
Method Details
-
locate
Tries to locate the specified file. The method also expects theFileSystem
to be used. Note that theFileLocator
object may also contain aFileSystem
, but this is optional. The passed inFileSystem
should be used, and callers must not pass a null reference for this argument. A concrete implementation has to evaluate the properties stored in theFileLocator
object and try to match them to an existing file. If this can be done, a corresponding URL is returned. Otherwise, result is null. Implementations should not throw an exception (unless parameters are null) as there might be alternative strategies which can find the file in question.- Parameters:
fileSystem
- theFileSystem
to be used for this operationlocator
- the object describing the file to be located- Returns:
- a URL pointing to the referenced file if location was successful; null if the file could not be resolved
-