Class SilverpeasFileProvider
- java.lang.Object
-
- org.silverpeas.core.io.file.SilverpeasFileProvider
-
public class SilverpeasFileProvider extends Object
A provider of Silverpeas files. This provider aims to provide a single point to simply retrieve files managed in Silverpeas in the form of aSilverpeasFile
instances. TheSilverpeasFile
class provides useful methods to manage the files in Silverpeas. BothSilverpeasFileProvider
andSilverpeasFile
classes support a mechanism of pre and post operations processing permitting to hook additional treatments on the files handled in Silverpeas.Unlike the IO Processing API in Silverpeas, it is not dedicated to be used within a transactional file processing; for a such use, please see the
FileHandler
class that offers a higher level access to the files managed in Silverpeas. This class is dedicated to provide a low-level and a single and unique point to access the files in Silverpeas with a support for an additional computing in order to hook parallel behaviours on the handled file.The Silverpeas File Provider provides two extensions points to hook additional computations with the file operations. For example, a process can be hooked to resize automatically the images on the demand (see
ImageResizingProcessor
for a such example of processors). To hook such processors, they have to implement theSilverpeasFileProcessor
interface.- Author:
- mmoquillon
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addProcessor(SilverpeasFileProcessor processor)
Adds a processor of SilverpeasFile.static SilverpeasFile
getFile(String absolutePath)
Gets aSilverpeasFile
instance for the file located at the specified absolute path.static SilverpeasFile
getFile(SilverpeasFileDescriptor descriptor)
Gets aSilverpeasFile
instance matching the description provided by the specified file descriptor.static SilverpeasFile
newFile(String absolutePath)
Gets a newSilverpeasFile
instance for the file located at the specified absolute path.static SilverpeasFile
newFile(SilverpeasFileDescriptor descriptor)
Gets a newSilverpeasFile
instance for the file described by the specified file descriptor.protected static SilverpeasFile
processAfter(SilverpeasFile file, SilverpeasFileProcessor.ProcessingContext context)
Triggers the chain of post-processors against the specified file and according to the specified processing context.
-
-
-
Method Detail
-
newFile
public static SilverpeasFile newFile(String absolutePath)
Gets a newSilverpeasFile
instance for the file located at the specified absolute path. If the file already exists, it is this file that will be returned. No chain of pre and post processing are performed against the new Silverpeas file.- Parameters:
absolutePath
- the absolute path at which will be located the file.- Returns:
- a new SilverpeasFile that will be created (if not already) at the specified location.
-
newFile
public static SilverpeasFile newFile(SilverpeasFileDescriptor descriptor)
Gets a newSilverpeasFile
instance for the file described by the specified file descriptor. If the file already exists, it is this file that will be returned. No chain of pre and post processing are performed against the new Silverpeas file.- Parameters:
descriptor
- a descriptor of a SilverpeasFile.- Returns:
- a new SilverpeasFile that will be created (if not already) at the specified location.
-
getFile
public static SilverpeasFile getFile(SilverpeasFileDescriptor descriptor)
Gets aSilverpeasFile
instance matching the description provided by the specified file descriptor.A chain of pre and post file processing will be performed against the file to retrieve; in this case, the returned file can be a modified version of the targeted file:
- The chain of pre-processors are ran; the first processor will have as argument the absolute path of the asked file, generated from the specified descriptor, and then the returned path of each processor is passed as argument to the next processor. By this way additional treatments can be performed against the path itself; the path can be altered according to the treatment and the next processor will work on this modified path.
- Once the pre-processing chain is done, the file located by the resulted absolute path is fetched from the filesystem.
- The chain of post-processors are ran; the first processor will have as argument the fetched Silverpeas file. Each further processors will have as argument the returned Silverpeas file by the previous processor. By this way, additional treatments can be performed against the Silverpeas file itself. One of the pre-defined post processor is a checker of the fetched file existence.
- The Silverpeas file processed by the last chain of processors is then returned by the method.
- Parameters:
descriptor
- a descriptor of a SilverpeasFile.- Returns:
- the SilverpeasFile with the content of the file identified by the specified descriptor and after filtering by pre and post file processing.
-
getFile
public static SilverpeasFile getFile(String absolutePath)
Gets aSilverpeasFile
instance for the file located at the specified absolute path.A chain of pre and post file processing will be performed against the file to retrieve; in this case, the returned file can be a modified version of the targeted file:
- The chain of pre-processors are ran; the first processor will have as argument the specified absolute path of the asked file and then the returned path of each processor is passed as argument to the next processor. By this way additional treatments can be performed against the path itself; the path can be altered according to the treatment and the next processor will work on this modified path.
- Once the pre-processing chain is done, the file located by the resulted absolute path is fetched from the filesystem.
- The chain of post-processors are ran; the first processor will have as argument the fetched Silverpeas file. Each further processors will have as argument the returned Silverpeas file by the previous processor. By this way, additional treatments can be performed against the Silverpeas file itself. One of the pre-defined post processor is a checker of the fetched file existence.
- The Silverpeas file processed by the last chain of processors is then returned by the method.
- Parameters:
absolutePath
- the absolute path of a file.- Returns:
- the SilverpeasFile with the content of the file located at the specified path and after filtering by pre and post file processing.
-
addProcessor
public static void addProcessor(SilverpeasFileProcessor processor)
Adds a processor of SilverpeasFile. A processor can perform some additional treatments on the path of a SilverpeasFile or on the SilverpeasFile itself. According to the file operation performed, both a pre and a post processing can be triggered or only a post-processing. For instance, getting a Silverpeas file will trigger both a chain of pre and a chain of post processing; the first one on the path of the file and the last one on the fetched Silverpeas file. For others operations (like deletion, update, ...) only the chain of post processing is ran against the Silverpeas file once the operation done, as the Silverpeas file was already get. Each processor are triggered in the order they are added and the output of one processor acts as an input for the second processor.
The chained execution of the processors is established according to the priority of a processor, provided bySilverpeasFileProcessor.getPriority()
method.{@see SilverpeasFileProcessor}
- Parameters:
processor
- a SilverpeasFile processor to add.
-
processAfter
protected static SilverpeasFile processAfter(SilverpeasFile file, SilverpeasFileProcessor.ProcessingContext context)
Triggers the chain of post-processors against the specified file and according to the specified processing context. The processing context indicates the file operation on which the processing will behave.- Parameters:
file
- the Silverpeas file on which the post-processors will work.context
- the file operation context.- Returns:
- the Silverpeas file resulting from the post-processors chain execution.
-
-