Accessing Filesystem Resources (org.apache.sling.fsresource)
Introduction
The Filesystem Resource Provider provides access to the operating system's filesystem through the Sling ResourceResolver. Multiple locations may be mapped into the resource tree by configuring the filesystem location and the resource tree root path for each location to be mapped.
To activate this feature, install the org.apache.sling.fsresource bundle. You can get it from the Sling downloads page or build it yourself from the source code
found under bundles/extensions/fsresource.
Resource Types
Files and directories are mapped into the resource tree as regular Resource instances whose resource type depends on the actual nature of the mapped filesystem resource:
- Regular files are assigned the
nt:fileresource type - Directories are assigned the
nt:folderresource type
Adapters
Filesystem resources extend from Sling's AbstractResource class and thus are adaptable to any type for which an AdapterFactory is registered supporting file system resources. In addition Filesystem Resources support the following adapters natively:
java.io.File-- The Java file object providing access to the filesystem filejava.net.URL-- A validfile://URL to the file. This URL is derived from thejava.io.Fileobject by calling theFile.toURI().toURL()sequence.java.io.InputStream-- If thejava.io.Filecan be read from (as perFile.canRead()anInputStreamto read from the file is returned.
Configuration
The Filesystem Resource Provider is configured with OSGi Configuration Admin factory configurtions whose factory PID is org.apache.sling.fsprovider.internal.FsResourceProvider. Configuration can be managed using the OSGi Configuration Admin API, through the Web Console or by any other means supporting Configuration Admin configurations.
The following configuration properties must be specified:
| Parameter | Name | Description |
|---|---|---|
| Provider Root | provider.roots |
Location in the virtual resource tree where the filesystem resources are mapped in. This property must not be an empty string. |
| Filesystem Root | provider.file |
Filesystem directory mapped to the virtual resource tree. This property must not be an empty string. If the path is relative it is resolved against sling.home or the current working directory. The path may be a file or folder. If the path does not address an existing file or folder, an empty folder is created. |