net.larsan.urd.util.fileset
Class FileSet

java.lang.Object
  |
  +--net.larsan.urd.util.fileset.FileSet
All Implemented Interfaces:
ResourceLocator
Direct Known Subclasses:
JarFileSet, RegexpFileSet, TrivialFileSet

public abstract class FileSet
extends java.lang.Object
implements ResourceLocator

A file set is an base class for monitored group of files. A file set is based on a folder and can recurse through subfolders if needed. A file set can created with a regular expression filter. Subclasses of this class is expected to be able to handle archives as well as plain files.

All paths to resources should be relative to their roots, e.g 'path/name' as opposed to '/path/name'.

FileSet inplements the ResourceLocator interface which is used by the Norna class loader.

All path uses the '/' as separator.

Version:
Alpha-0.1 / 2002-10-06 21:37
Author:
Lars J. Nilsson

Field Summary
protected  java.io.File root
          File set root folder, this folder will be checked on initiation so that it exists and is accessible.
 
Constructor Summary
protected FileSet(java.io.File root)
          Construct a file set using a root folder.
 
Method Summary
abstract  java.security.cert.Certificate[] getCertificates(Resource resource)
          Get the certificates for a resource.
 ErrorHandler getErrorHandler()
          Get the error handler for this file set.
abstract  Resource getResource(java.lang.String filePath)
          Get a resource from the set.
abstract  java.lang.String[] getResourcePaths()
          Get all available resources ids.
 boolean isRecursive()
          Check if the file set recurses into subfolders or not.
protected  boolean matches(java.lang.String filePath)
          Check if a given file name matches the provided regular expression pattern.
protected  java.lang.String resolvePath(java.io.File file)
          Attempt to resolve a relative file path from the root of the file set.
abstract  void scan()
          Perform a scan of available files for the set.
 void setErrorHandler(ErrorHandler errorHandler)
          Set the error handler for this file set.
 void setIsRecursive(boolean isRecursive)
          Determine if this file set should recurse into subfolders or not.
protected  void setRegexpPattern(java.lang.String pattern)
          Set the regular expression pattern to filter this fileset by.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

protected java.io.File root
File set root folder, this folder will be checked on initiation so that it exists and is accessible.

Constructor Detail

FileSet

protected FileSet(java.io.File root)
           throws java.io.IOException
Construct a file set using a root folder. Should the folder not exist or denote a file as opposed to a folder an IOException will be thrown.

Throws:
java.io.IOException - If the root file does not exist, or is a file and not a folder
Method Detail

scan

public abstract void scan()
                   throws java.io.IOException
Perform a scan of available files for the set. This method can be called at any time and it is up to subclasses to take steps to synchronize resources.

Throws:
java.io.IOException - If the scan fails

getResourcePaths

public abstract java.lang.String[] getResourcePaths()
Get all available resources ids. This arrays should be empty if the file set is empty. Every path should be reported by their relative path to the file set root folder, e.g. 'path/name' as opposed to '/path/name'.

Returns:
A string array of relative paths, an empty array will be returned if the set is empty

getResource

public abstract Resource getResource(java.lang.String filePath)
Get a resource from the set. This should return a Resource if the resource is found or null if not. The parameter should be a relative path as reparted by getResourcePaths.

Subclasses should hash resources by path for maximum speed.

Specified by:
getResource in interface ResourceLocator
Parameters:
filePath - A relative path to the resource to get
Returns:
A FileSet.Resource object representing the resource or null if not found

getCertificates

public abstract java.security.cert.Certificate[] getCertificates(Resource resource)
Get the certificates for a resource. This method should return null if the resource is not signed.

Parameters:
resource - The resource to check for signing certificates
Returns:
An arraya of signing certificates or null if not signed

resolvePath

protected java.lang.String resolvePath(java.io.File file)
                                throws java.io.IOException
Attempt to resolve a relative file path from the root of the file set. This method resolves on absolute file paths.

Parameters:
file - File to resolve relative path for
Returns:
The relative path of the file, including name
Throws:
java.io.IOException - On IO Errors

setIsRecursive

public void setIsRecursive(boolean isRecursive)
Determine if this file set should recurse into subfolders or not. This property defaules into false. If set to true the file set will garther resources from subfolders to the current folders.

Parameters:
isRecursive - True if the file set should recurse into subfolders.

isRecursive

public boolean isRecursive()
Check if the file set recurses into subfolders or not. Recursive file set looks into subfolders of the root folder as well as the root itself.

Returns:
True if the file set recurses into subfolders

setRegexpPattern

protected void setRegexpPattern(java.lang.String pattern)
                         throws java.util.regex.PatternSyntaxException
Set the regular expression pattern to filter this fileset by. This method will throw a PatternSyntaxException if the pattern is invalid. All patterns are case sensitive.

Parameters:
pattern - Perl 5 regexp pattern
Throws:
java.util.regex.PatternSyntaxException - If the regular expression pattern is invalid

matches

protected boolean matches(java.lang.String filePath)
Check if a given file name matches the provided regular expression pattern. Should no pattern have been set this method always returns true.

Returns:
True if the path matches, false otherwise

getErrorHandler

public ErrorHandler getErrorHandler()
Get the error handler for this file set. If no error handle is specified this method return null.

Returns:
An error handler for the file set

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
Set the error handler for this file set. The error handler will be used on IO errors when reading resources.

Parameters:
errorHandler - Error handler for this file set