org.silverpeas.file
Class SilverpeasFileProvider

java.lang.Object
  extended by org.silverpeas.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 a SilverpeasFile instances. The SilverpeasFile class provides useful methods to manage the files in Silverpeas. Both and SilverpeasFile 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 the SilverpeasFileProcessor interface.

Author:
mmoquillon

Method Summary
 void addProcessor(SilverpeasFileProcessor processor)
          Adds a processor of SilverpeasFile.
static SilverpeasFile getFile(SilverpeasFileDescriptor descriptor)
           
static SilverpeasFile getFile(String absolutePath)
           
static SilverpeasFileProvider getInstance()
           
 SilverpeasFile getSilverpeasFile(SilverpeasFileDescriptor descriptor)
          Gets a SilverpeasFile instance matching the description provided by the specified file descriptor.
 SilverpeasFile getSilverpeasFile(String absolutePath)
          Gets a SilverpeasFile instance for the file located at the specified absolute path.
static SilverpeasFile newFile(SilverpeasFileDescriptor descriptor)
           
static SilverpeasFile newFile(String absolutePath)
           
 SilverpeasFile newSilverpeasFile(SilverpeasFileDescriptor descriptor)
          Gets a new SilverpeasFile instance for the file described by the specified file descriptor.
 SilverpeasFile newSilverpeasFile(String absolutePath)
          Gets a new SilverpeasFile instance for the file located at the specified absolute path.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static SilverpeasFileProvider getInstance()

getFile

public static SilverpeasFile getFile(SilverpeasFileDescriptor descriptor)
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.
See Also:
getSilverpeasFile(SilverpeasFileDescriptor)

getFile

public static SilverpeasFile getFile(String absolutePath)
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.
See Also:
getSilverpeasFile(String)

newFile

public static SilverpeasFile newFile(String absolutePath)
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.
See Also:
newSilverpeasFile(String)

newFile

public static SilverpeasFile newFile(SilverpeasFileDescriptor descriptor)
Parameters:
descriptor - a descriptor of a SilverpeasFile.
Returns:
a new SilverpeasFile that will be created (if not already) at the location described by the specified descriptor.
See Also:
newSilverpeasFile(org.silverpeas.file.SilverpeasFileDescriptor)

newSilverpeasFile

public SilverpeasFile newSilverpeasFile(String absolutePath)
Gets a new SilverpeasFile 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.

newSilverpeasFile

public SilverpeasFile newSilverpeasFile(SilverpeasFileDescriptor descriptor)
Gets a new SilverpeasFile 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.

getSilverpeasFile

public SilverpeasFile getSilverpeasFile(SilverpeasFileDescriptor descriptor)
Gets a SilverpeasFile 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:

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.

getSilverpeasFile

public SilverpeasFile getSilverpeasFile(String absolutePath)
Gets a SilverpeasFile 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:

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 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 by SilverpeasFileProcessor.getPriority() method.

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.


Copyright © 2016 Silverpeas. All Rights Reserved.