public class HomeDirectoryLocationStrategy extends Object implements 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 and Description |
---|
HomeDirectoryLocationStrategy()
Creates a new instance of
HomeDirectoryLocationStrategy with default settings. |
HomeDirectoryLocationStrategy(boolean withBasePath)
Creates a new instance of
HomeDirectoryLocationStrategy and initializes the base path flag. |
HomeDirectoryLocationStrategy(String homeDir,
boolean withBasePath)
Creates a new instance of
HomeDirectoryLocationStrategy and initializes it with the specified settings. |
Modifier and Type | Method and Description |
---|---|
String |
getHomeDirectory()
Returns the home directory.
|
boolean |
isEvaluateBasePath()
Returns a flag whether the base path is to be taken into account when searching for a file.
|
URL |
locate(FileSystem fileSystem,
FileLocator locator)
Tries to locate the specified file.
|
public HomeDirectoryLocationStrategy(String homeDir, boolean withBasePath)
HomeDirectoryLocationStrategy
and initializes it with the specified settings.homeDir
- the path to the home directory (can be null)withBasePath
- a flag whether the base path should be evaluatedpublic HomeDirectoryLocationStrategy(boolean withBasePath)
HomeDirectoryLocationStrategy
and initializes the base path flag. The home
directory is set to the user's home directory.withBasePath
- a flag whether the base path should be evaluatedpublic HomeDirectoryLocationStrategy()
HomeDirectoryLocationStrategy
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).public String getHomeDirectory()
public boolean isEvaluateBasePath()
public URL locate(FileSystem fileSystem, FileLocator locator)
FileSystem
to be used. Note that the
FileLocator
object may also contain a FileSystem
, but this is optional. The passed in
FileSystem
should be used, and callers must not pass a null reference for this argument. A concrete
implementation has to evaluate the properties stored in the FileLocator
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 in
FileLocator
. If the locator defines a base path and the evaluateBasePath
property is true, a
sub directory of the home directory is searched.locate
in interface FileLocationStrategy
fileSystem
- the FileSystem
to be used for this operationlocator
- the object describing the file to be locatedCopyright © 2001–2022 The Apache Software Foundation. All rights reserved.