com.jalios.jcms.fileprocessor.repository
Class Repository

java.lang.Object
  extended by com.jalios.jcms.fileprocessor.repository.Repository

public class Repository
extends Object

Represent a configuration of a repository.

A repository is a directory in which a scan will be done.

A repository configuration is composed of :

A validate() method exists to see if all requirements are respected.

All registration of processors are done using the Class object of these processors. Instanciation of processorss is done lasily at a first call to getFileProcessorSet(String), after a modification in registration.

Version:
$Revision: 30539 $

Field Summary
static String CURRENT_REPOSITORY
          When a FileActionComponent (FileProcessor or FileParser) is invoked, the repository for which it is invoked is availble through the processing context using this attribute :
static String REVISION
           
 
Constructor Summary
Repository(String id, JProperties properties)
          The constructor set some default value and then read the specified properties.
 
Method Summary
 void addActionComponent(Class<? extends FileActionComponent> componentClazz, String[] extensions)
          Add the specified FileActionComponent (parser or processor) to this repository for the specified extensions.
 FileProcessingLog addFileProcessingLog(File file, FileActionComponent component, ProcessingType type, ProcessingStatus status, long duration, Exception exception)
          Create a new instance of FileProcessingLog with the specified parameters and store it.
 FileProcessingLog addFileProcessingLog(String filename, Class<? extends FileActionComponent> componentClass, ProcessingType type, ProcessingStatus status, long duration, String message)
           
static String applySubstitutions(String abstractFileName, Repository repository)
          Returns a String constructed from the abstractFileName in parameter where : <realpath> is replaced by the absolute real path of the webapp <uploadpath> is replaced by the absolute real path of the upload/ directory in the webapp <webinfpath> is replaced by the absolute real path of the WEB-INF/ directory in the webapp <datapath> is replaced by the absolute real path of the WEB-INF/data/ directory in the webapp <jcmsuploadindexpath> is replaced by the absolute real path of the WEB-INF/data/lucene/FilesIndex/ directory in the webapp <repositoryid> is replaced by the id of the repository <junit> is replaced by the -junit string
 void blacklistFile(String filename, Class<? extends FileActionComponent> actionComponentClass)
           
 void deleteAllNonBlacklistedLogs()
          Remove all successful logs from the database and update the remaining information.
 void deleteFileProcessingInfo(String filename)
          Delete the FileProcessingInfo for the specified filename
 void deleteFileProcessingLog(String filename, Class<? extends FileActionComponent> actionComponentClass)
          Remove all log and info for the specified filename and component.
 void deleteFileProcessingLog(String filename, String component)
           
 boolean directoryIgnored(File file)
          Tells if a directory under upload should be ignored given an exclusion pattern given by the property :
 FileActionComponent getActionComponent(Class<? extends FileActionComponent> componentClass)
          Retrieve any instance already created for the specified FileActionComponent class.
 Set<Class<? extends FileActionComponent>> getActionComponentClassSet()
          Retrieve a Set of all class FileActionComponent class registered for this repository
 String getAlarmManagerName()
           
 Object getAttribute(Object name)
          Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
 File getBaseDirectory()
           
 String getBaseDirectoryPath()
          Retrieve the base directory absolute path of this Repository
 Map<Class<? extends FileActionComponent>,SortedSet<String>> getComponentClassToExtensionSetMap()
          Retrieve a map of all component class to the extensions registered for them.
 DirectoryScanner getDirectoryScanner()
          Retrieve the DirectoryScanner instance used for repository scan
 List<ProcessingEvent> getEventList()
           
 String getExcludedDirRegExp()
           
 File getFile(String path)
          Retrieve a File instance from the specified relative path
 String getFilenameRelativeToBaseDirectory(File file)
          Retrieve the filename of the specified file relative to the base directory of this Repository.
 Set<Class<? extends FileParser>> getFileParserClassSet()
          Retrieve a Set of all FileParser class.
 SortedSet<String> getFileParserExtensionSet()
          Retrieve a Set of all extensions with at least one FileParser configured.
 SortedSet<? extends FileParser> getFileParserSet(String extension)
          Retrieve a Set of all FileParser configured for the specified extension.
 FileProcessingInfo getFileProcessingInfo(File file)
          Retrieve the FileProcessingInfo for the specified file in this repository and webapp instance (urid).
 FileProcessingInfo getFileProcessingInfo(String filename)
          Retrieve the FileProcessingInfo for the specified file in this repository and webapp instance (urid).
 List<FileProcessingLog> getFileProcessingLogs(File file)
          Retrieve all the FileProcessingLog for the specified file in this repository and webapp instance (urid).
 List<FileProcessingLog> getFileProcessingLogs(String filename)
          Retrieve all the FileProcessingLog for the specified file in this repository and webapp instance (urid).
 Set<Class<? extends FileProcessor>> getFileProcessorClassSet()
          Retrieve a Set of all FileProcessor class.
 SortedSet<String> getFileProcessorExtensionSet()
          Retrieve a Set of all extensions with at least one FileProcessor configured.
 SortedSet<? extends FileProcessor> getFileProcessorSet(String extension)
          Retrieve a Set of all FileProcessor configured for the specified extension.
 String getId()
           
 RepositoryIndexer getIndexer()
          For one repository, the way LuceneDocument are constructed from the content of a file and the file itself, is specific to the structure of the index.
 File getLuceneIndex()
           
 long getMaxFilesPerScan()
           
 String getName()
           
 int getProcessingLimitDuration()
           
 JProperties getRepositoryProperties()
           
 String getScheduleCron()
          Retrieve the cron defining rythm of scan of the directory.
 int getSchedulePeriod()
          Retrieve the period in minutes between scan of the directory.
 boolean hasSchedule()
          Check if this repository at a scanning scheduled defined.
 boolean isCreateAssociatedTextFile()
           
 boolean isIndexable()
           
 boolean isProcessedByActionComponentClass(File file, Class<? extends FileActionComponent> clazz)
          Test whether a file may be processed by a FileActionComponent.
 void logProcessingEvent(ProcessingEvent newAction)
           
 boolean removeActionComponent(Class<? extends FileActionComponent> componentClass)
          Remove the specified component class from this repository configuration.
 boolean removeActionComponent(Class<? extends FileActionComponent> componentClass, String[] extensions)
          Remove the specified component class from this repository configuration for the specified extension (if any).
 Object removeAttribute(String name)
          Removes an attribute from this repository.
 boolean scanNow()
          Trigger the repository scan now, in its specific thread (not in the current thread).
 void setAlarmManagerName(String alarmManagerName)
           
 Object setAttribute(String name, Object obj)
          Stores an attribute in this repository.
 void setBaseDirectory(File baseDirectory)
           
 void setCreateAssociatedTextFile(boolean createAssociatedTextFile)
           
 void setExcludedDirRegExp(String excludedDirRegExp)
           
 void setId(String id)
           
 void setIndexerClass(Class<? extends RepositoryIndexer> indexerClass)
           
 void setLuceneIndex(File luceneIndex)
           
 void setMaxFilesPerScan(long maxFilesPerScan)
           
 void setName(String name)
           
 void setProcessingLimitDuration(int processingLimitDuration)
           
 void setRepositoryProperties(JProperties properties)
           
 void setScheduleCron(String scheduleCron)
           
 void setSchedulePeriod(int schedulePeriod)
          Set the period in minutes between scan of the directory.
 String toStringConfiguration()
          Convenient method to display configuration informations in logs.
 void unBlacklistFile(String filename, Class<? extends FileActionComponent> actionComponentClass)
           
 void updateAllFileProcessingInfo()
          Create or Update all the FileProcessingInfo instance for this repository and webapp instance (urid).
 FileProcessingInfo updateFileProcessingInfo(File file, List<FileProcessingLog> logList)
          Create, Update or Delete the FileProcessingInfo instance for the specified file (in this repository and webapp instance, ie urid), from the specified list of FileProcessingLog
 FileProcessingInfo updateFileProcessingInfo(String filename, List<FileProcessingLog> logList)
           
 boolean validate()
          Validate the configuration is good for this repository.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values

CURRENT_REPOSITORY

public static final String CURRENT_REPOSITORY
When a FileActionComponent (FileProcessor or FileParser) is invoked, the repository for which it is invoked is availble through the processing context using this attribute :
 Repository repository = (Repository) ctxt.get(Repository.CURRENT_REPOSITORY);
 

See Also:
Constant Field Values
Constructor Detail

Repository

public Repository(String id,
                  JProperties properties)
The constructor set some default value and then read the specified properties.

Parameters:
id - the id of the repository to create
properties - the properties to be used by this Repository
Method Detail

directoryIgnored

public boolean directoryIgnored(File file)
Tells if a directory under upload should be ignored given an exclusion pattern given by the property :
    fileprocessor.repository.{repository-name}.excludedDirRegExp
 

Parameters:
file -
Returns:
true if the directory should be ignored

validate

public boolean validate()
Validate the configuration is good for this repository.

Returns:
true if the condition for the configuration is good

getIndexer

public RepositoryIndexer getIndexer()
For one repository, the way LuceneDocument are constructed from the content of a file and the file itself, is specific to the structure of the index. The implementation of the RepositoryIndexer knows the structure of the index for that repository.

Returns:
an instance of the indexer for that repository

isIndexable

public boolean isIndexable()

setIndexerClass

public void setIndexerClass(Class<? extends RepositoryIndexer> indexerClass)

getId

public String getId()

setId

public void setId(String id)

getName

public String getName()

setName

public void setName(String name)

getActionComponent

public FileActionComponent getActionComponent(Class<? extends FileActionComponent> componentClass)
Retrieve any instance already created for the specified FileActionComponent class.

Parameters:
componentClass - the FileActionComponent class
Returns:
null if the component has not been added previously to this Repository

addActionComponent

public void addActionComponent(Class<? extends FileActionComponent> componentClazz,
                               String[] extensions)
Add the specified FileActionComponent (parser or processor) to this repository for the specified extensions.

Parameters:
componentClazz - the class of the component to add, must not be null
extensions - the extension for which the FileActionComponent will be configured, must not be null or empty (otherwise method will have no effect)

removeActionComponent

public boolean removeActionComponent(Class<? extends FileActionComponent> componentClass)
Remove the specified component class from this repository configuration.

Parameters:
componentClass - the FileActionComponent class to remove
Returns:
true if the component was removed, false if their was no component of this class in this repository

removeActionComponent

public boolean removeActionComponent(Class<? extends FileActionComponent> componentClass,
                                     String[] extensions)
Remove the specified component class from this repository configuration for the specified extension (if any).

Parameters:
componentClass - the FileActionComponent class to remove
extensions - the extension for which the FileActionComponent will be removed, if null or empty, the component will be completely removed from repository
Returns:
true if the component was removed, false if their was no component of this class in this repository

isProcessedByActionComponentClass

public boolean isProcessedByActionComponentClass(File file,
                                                 Class<? extends FileActionComponent> clazz)
Test whether a file may be processed by a FileActionComponent.

Tested with the file's extension in this current implementation.

Parameters:
file - the File to test
clazz - the class of the FileActionComponent
Returns:
true if the FileActionComponent may process this file

getActionComponentClassSet

public Set<Class<? extends FileActionComponent>> getActionComponentClassSet()
Retrieve a Set of all class FileActionComponent class registered for this repository

Returns:
a Set of FileActionComponent's class

getFileProcessorSet

public SortedSet<? extends FileProcessor> getFileProcessorSet(String extension)
Retrieve a Set of all FileProcessor configured for the specified extension.

Parameters:
extension - a File extension, eg. "txt"
Returns:
a SortedSet of FileProcessor instances : may be null

getFileProcessorExtensionSet

public SortedSet<String> getFileProcessorExtensionSet()
Retrieve a Set of all extensions with at least one FileProcessor configured.

Returns:
a SortedSet of file extensions : may be null

getFileProcessorClassSet

public Set<Class<? extends FileProcessor>> getFileProcessorClassSet()
Retrieve a Set of all FileProcessor class.

Returns:
a Set of FileProcessor class : never return null

getFileParserSet

public SortedSet<? extends FileParser> getFileParserSet(String extension)
Retrieve a Set of all FileParser configured for the specified extension.

Parameters:
extension - a File extension, eg. "txt"
Returns:
a SortedSet of FileParser instances : may be null

getFileParserExtensionSet

public SortedSet<String> getFileParserExtensionSet()
Retrieve a Set of all extensions with at least one FileParser configured.

Returns:
a SortedSet of file extensions : may be null

getFileParserClassSet

public Set<Class<? extends FileParser>> getFileParserClassSet()
Retrieve a Set of all FileParser class.

Returns:
a Set of FileParser class : never return null

getComponentClassToExtensionSetMap

public Map<Class<? extends FileActionComponent>,SortedSet<String>> getComponentClassToExtensionSetMap()
Retrieve a map of all component class to the extensions registered for them.

Returns:
a Map of class to Set of String, never return null

getBaseDirectory

public File getBaseDirectory()

setBaseDirectory

public void setBaseDirectory(File baseDirectory)

getLuceneIndex

public File getLuceneIndex()

setLuceneIndex

public void setLuceneIndex(File luceneIndex)

getSchedulePeriod

public int getSchedulePeriod()
Retrieve the period in minutes between scan of the directory.

Returns:
a period in minutes (0 or negative if undefined)

setSchedulePeriod

public void setSchedulePeriod(int schedulePeriod)
Set the period in minutes between scan of the directory.

Parameters:
schedulePeriod - a period in minutes

getScheduleCron

public String getScheduleCron()
Retrieve the cron defining rythm of scan of the directory.

Returns:
a cron like schedule (empty or null if undefined)

setScheduleCron

public void setScheduleCron(String scheduleCron)

hasSchedule

public boolean hasSchedule()
Check if this repository at a scanning scheduled defined.

Returns:
true if a schedule cron or schedule period was set, false otherwise
Since:
jcms-7.0.0

getExcludedDirRegExp

public String getExcludedDirRegExp()

setExcludedDirRegExp

public void setExcludedDirRegExp(String excludedDirRegExp)

getMaxFilesPerScan

public long getMaxFilesPerScan()

setMaxFilesPerScan

public void setMaxFilesPerScan(long maxFilesPerScan)

toStringConfiguration

public String toStringConfiguration()
Convenient method to display configuration informations in logs.

Returns:
a convenient string to display configuration informations in logs

getRepositoryProperties

public JProperties getRepositoryProperties()

setRepositoryProperties

public void setRepositoryProperties(JProperties properties)

getAlarmManagerName

public String getAlarmManagerName()

setAlarmManagerName

public void setAlarmManagerName(String alarmManagerName)

getFilenameRelativeToBaseDirectory

public String getFilenameRelativeToBaseDirectory(File file)
Retrieve the filename of the specified file relative to the base directory of this Repository.

Parameters:
file - any file under
Returns:
a platform independant relative path, eg : docs/text/plain/foobar.txt or null if specified file was null or not inside repository base directory

getFile

public File getFile(String path)
Retrieve a File instance from the specified relative path

Parameters:
path - a platform independant path relative to the repository base directory, eg : docs/text/plain/foobar.txt
Returns:
a new File object or null if specified path was null.

getBaseDirectoryPath

public String getBaseDirectoryPath()
Retrieve the base directory absolute path of this Repository

Returns:
an absolute directory path

getProcessingLimitDuration

public int getProcessingLimitDuration()

setProcessingLimitDuration

public void setProcessingLimitDuration(int processingLimitDuration)

isCreateAssociatedTextFile

public boolean isCreateAssociatedTextFile()

setCreateAssociatedTextFile

public void setCreateAssociatedTextFile(boolean createAssociatedTextFile)

getFileProcessingLogs

public List<FileProcessingLog> getFileProcessingLogs(File file)
Retrieve all the FileProcessingLog for the specified file in this repository and webapp instance (urid).

Parameters:
file - the file for which logs are retrieved
Returns:
a list of FileProcessingLog instance corresponding to the specified file (never return null)

getFileProcessingLogs

public List<FileProcessingLog> getFileProcessingLogs(String filename)
Retrieve all the FileProcessingLog for the specified file in this repository and webapp instance (urid).

Parameters:
filename - the file path relative to the base directory of the repository
Returns:
a list of FileProcessingLog instance corresponding to the specified file (never return null)

updateAllFileProcessingInfo

public void updateAllFileProcessingInfo()
Create or Update all the FileProcessingInfo instance for this repository and webapp instance (urid).

WARNING: VERY EXPENSIVE METHODS WHICH ITERATES ALL THE DATABASE ENTRY.


updateFileProcessingInfo

public FileProcessingInfo updateFileProcessingInfo(File file,
                                                   List<FileProcessingLog> logList)
Create, Update or Delete the FileProcessingInfo instance for the specified file (in this repository and webapp instance, ie urid), from the specified list of FileProcessingLog

Parameters:
file - the file for which FileProcessingInfo should be updated
logList - the logList from which info will be updated
Returns:
the created/update info, or null if the processing was deleted or none was created

updateFileProcessingInfo

public FileProcessingInfo updateFileProcessingInfo(String filename,
                                                   List<FileProcessingLog> logList)

getFileProcessingInfo

public FileProcessingInfo getFileProcessingInfo(File file)
Retrieve the FileProcessingInfo for the specified file in this repository and webapp instance (urid).

Parameters:
file - the File for which FileProcessingInfo is being retrieved
Returns:
a FileProcessingInfo instance or null if none could be found

getFileProcessingInfo

public FileProcessingInfo getFileProcessingInfo(String filename)
Retrieve the FileProcessingInfo for the specified file in this repository and webapp instance (urid).

Parameters:
filename - the file path relative to the base directory of the repository
Returns:
a FileProcessingInfo instance or null if none could be found

deleteFileProcessingInfo

public void deleteFileProcessingInfo(String filename)
Delete the FileProcessingInfo for the specified filename

Parameters:
filename - the filename relative to the repository base directory

addFileProcessingLog

public FileProcessingLog addFileProcessingLog(File file,
                                              FileActionComponent component,
                                              ProcessingType type,
                                              ProcessingStatus status,
                                              long duration,
                                              Exception exception)
Create a new instance of FileProcessingLog with the specified parameters and store it.

The new instance will uses this repository and current webapp URID.

Parameters:
file - the file for which log must be added
component - the component for which log is added
type - the type of processing performed
status - the new processing status
duration - the duration it took to process
exception - any exception that might have occured during processing
Returns:
the newly created FileProcessingLog, never return null

addFileProcessingLog

public FileProcessingLog addFileProcessingLog(String filename,
                                              Class<? extends FileActionComponent> componentClass,
                                              ProcessingType type,
                                              ProcessingStatus status,
                                              long duration,
                                              String message)

deleteFileProcessingLog

public void deleteFileProcessingLog(String filename,
                                    Class<? extends FileActionComponent> actionComponentClass)
Remove all log and info for the specified filename and component.

Update the info if logs were partially deleted.

Parameters:
filename - the filename relative to the repository base directory
actionComponentClass - the FileActionComponent class concerned (optionnal)

deleteFileProcessingLog

public void deleteFileProcessingLog(String filename,
                                    String component)

blacklistFile

public void blacklistFile(String filename,
                          Class<? extends FileActionComponent> actionComponentClass)

unBlacklistFile

public void unBlacklistFile(String filename,
                            Class<? extends FileActionComponent> actionComponentClass)

deleteAllNonBlacklistedLogs

public void deleteAllNonBlacklistedLogs()
Remove all successful logs from the database and update the remaining information. WARNING: VERY EXPENSIVE METHODS WHICH ITERATES ALL THE DATABASE ENTRY.


setAttribute

public Object setAttribute(String name,
                           Object obj)
Stores an attribute in this repository.
If the object passed in is null, the effect is the same as calling removeAttribute(java.lang.String).

Parameters:
name - a String specifying the name of the attribute
obj - the Object to be stored
Returns:
previous value associated with specified name, or null if there was no mapping for name. A null return can also indicate that null was associated with the specified name.

getAttribute

public Object getAttribute(Object name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.

Parameters:
name - a String specifying the name of the attribute
Returns:
an Object containing the value of the attribute, or null if the attribute does not exist

removeAttribute

public Object removeAttribute(String name)
Removes an attribute from this repository.

Parameters:
name - a String specifying
Returns:
previous value associated with specified name, or null if there was no mapping for name. A null return can also indicate that null was associated with the specified name.

getEventList

public List<ProcessingEvent> getEventList()

logProcessingEvent

public void logProcessingEvent(ProcessingEvent newAction)

getDirectoryScanner

public DirectoryScanner getDirectoryScanner()
Retrieve the DirectoryScanner instance used for repository scan

Returns:
DirectoryScanner instance, never return null

scanNow

public boolean scanNow()
Trigger the repository scan now, in its specific thread (not in the current thread).

The scan will NOT be triggered if it already running.

Returns:
false if the scan was not started (due to scheduling not enabled or scan already running), true if the scan was successfully launched.

applySubstitutions

public static String applySubstitutions(String abstractFileName,
                                        Repository repository)
Returns a String constructed from the abstractFileName in parameter where :

Parameters:
abstractFileName -
repository -
Returns:
the replaced String


Copyright © 2001-2010 Jalios SA. All Rights Reserved.