HomeDirectoryLocationStrategy (Apache Commons Configuration 2.15.1 API)
Description: declaration: package: org.apache.commons.configuration2.io, class: HomeDirectoryLocationStrategy

Package org.apache.commons.configuration2.io

# Class HomeDirectoryLocationStrategy

java.lang.Object
org.apache.commons.configuration2.io.AbstractFileLocationStrategy
org.apache.commons.configuration2.io.HomeDirectoryLocationStrategy

All Implemented Interfaces:
  `FileLocationStrategy`

public class HomeDirectoryLocationStrategy extends AbstractFileLocationStrategy
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.

See `AbstractFileLocationStrategy` learn how to grant an deny URL schemes and hosts.

See Also:
  - `AbstractFileLocationStrategy`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `HomeDirectoryLocationStrategy.Builder`
  Builds new instances of `HomeDirectoryLocationStrategy`.

  ## Nested classes/interfaces inherited from class org.apache.commons.configuration2.io.AbstractFileLocationStrategy

  `AbstractFileLocationStrategy.AbstractBuilder<T extends FileLocationStrategy,B extends AbstractFileLocationStrategy.AbstractBuilder<T,B>>, AbstractFileLocationStrategy.StrategyBuilder<T extends FileLocationStrategy>`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `HomeDirectoryLocationStrategy()`
  Creates a new instance of `HomeDirectoryLocationStrategy` with default settings.
  `HomeDirectoryLocationStrategy(boolean withBasePath)`
  Deprecated.
  Use `HomeDirectoryLocationStrategy.Builder.setEvaluateBasePath(boolean)`.
  `HomeDirectoryLocationStrategy(String homeDir, boolean withBasePath)`
  Deprecated.
  Use `HomeDirectoryLocationStrategy.Builder.setHomeDirectory(String)`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getHomeDirectory()`
  Gets 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.

  ### Methods inherited from class org.apache.commons.configuration2.io.AbstractFileLocationStrategy

  `toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### HomeDirectoryLocationStrategy

    public HomeDirectoryLocationStrategy()
    Creates a new instance of `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).

  - ### HomeDirectoryLocationStrategy

    @Deprecated public HomeDirectoryLocationStrategy(boolean withBasePath)
    Deprecated.
    Use `HomeDirectoryLocationStrategy.Builder.setEvaluateBasePath(boolean)`.
    Creates a new instance of `HomeDirectoryLocationStrategy` 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

    @Deprecated public HomeDirectoryLocationStrategy(String homeDir, boolean withBasePath)
    Deprecated.
    Use `HomeDirectoryLocationStrategy.Builder.setHomeDirectory(String)`.
    Creates a new instance of `HomeDirectoryLocationStrategy` and initializes it with the specified settings.
    Parameters:
      `homeDir` - the path to the home directory (may be `null`).
      `withBasePath` - a flag whether the base path should be evaluated.

- ## Method Details

  - ### getHomeDirectory

    public String getHomeDirectory()
    Gets the home directory. In this directory the strategy searches for files.
    Returns:
      the home directory used by this object.

  - ### isEvaluateBasePath

    public boolean 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

    public URL locate(FileSystem fileSystem, FileLocator locator)
    Tries to locate the specified file. The method also expects the `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.
    Parameters:
      `fileSystem` - the `FileSystem` to be used for this operation
      `locator` - 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