Class HomeDirectoryLocationStrategy
- All Implemented Interfaces:
FileLocationStrategy
A specialized implementation of FileLocationStrategy
which searches for files in the user's home directory or
another special configurable directory.
This strategy implementation ignores the URL stored in the passed in FileLocator
. It constructs a file path
from the configured home directory (which is the user's home directory per default, but can be changed to another
path), optionally the base path, and the file name. If the resulting path points to an existing file, its URL is
returned.
When constructing an instance it can be configured whether the base path should be taken into account. If this option is set, the base path is appended to the home directory if it is not null. This is useful for instance to select a specific sub directory of the user's home directory. If this option is set to false, the base path is always ignored, and only the file name is evaluated.
-
Constructor Summary
ConstructorDescriptionCreates a new instance ofHomeDirectoryLocationStrategy
with default settings.HomeDirectoryLocationStrategy
(boolean withBasePath) Creates a new instance ofHomeDirectoryLocationStrategy
and initializes the base path flag.HomeDirectoryLocationStrategy
(String homeDir, boolean withBasePath) Creates a new instance ofHomeDirectoryLocationStrategy
and initializes it with the specified settings. -
Method Summary
Modifier and TypeMethodDescriptionGets the home directory.boolean
Returns a flag whether the base path is to be taken into account when searching for a file.locate
(FileSystem fileSystem, FileLocator locator) Tries to locate the specified file.
-
Constructor Details
-
HomeDirectoryLocationStrategy
public HomeDirectoryLocationStrategy()Creates a new instance ofHomeDirectoryLocationStrategy
with default settings. The home directory is set to the user's home directory. The base path flag is set to false (which means that the base path is ignored). -
HomeDirectoryLocationStrategy
Creates a new instance ofHomeDirectoryLocationStrategy
and initializes the base path flag. The home directory is set to the user's home directory.- Parameters:
withBasePath
- a flag whether the base path should be evaluated
-
HomeDirectoryLocationStrategy
Creates a new instance ofHomeDirectoryLocationStrategy
and initializes it with the specified settings.- Parameters:
homeDir
- the path to the home directory (can be null)withBasePath
- a flag whether the base path should be evaluated
-
-
Method Details
-
getHomeDirectory
Gets the home directory. In this directory the strategy searches for files.- Returns:
- the home directory used by this object
-
isEvaluateBasePath
Returns a flag whether the base path is to be taken into account when searching for a file.- Returns:
- the flag whether the base path is evaluated
-
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. This implementation searches in the home directory for a file described by the passed inFileLocator
. If the locator defines a base path and theevaluateBasePath
property is true, a sub directory of the home directory is searched.- Specified by:
locate
in interfaceFileLocationStrategy
- 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
-