uk.org.ogsadai.dataresource.conx
Class FileSystemConnectionManager

java.lang.Object
  |
  +--uk.org.ogsadai.dataresource.conx.ConnectionManager
        |
        +--uk.org.ogsadai.dataresource.conx.FileSystemConnectionManager

public class FileSystemConnectionManager
extends ConnectionManager


Field Summary
 
Fields inherited from class uk.org.ogsadai.dataresource.conx.ConnectionManager
mDriverClass, mLog, mRoleMapClass, mRoleMapper, mURI
 
Constructor Summary
FileSystemConnectionManager(ConnectionConfig config)
          Configure this connection manager by initialising its top-level directory and confirming that it exists.
 
Method Summary
static void assertDirectoryExists(java.io.File dir)
          A utility method to test whether a given File object, representing a directory, exists.
static void assertDirectoryReadable(java.io.File dir)
          A utility method to test whether a directory is readable.
static void assertFileDoesntExist(java.io.File file)
          A utility method to test whether a file does not exist.
static void assertFileExists(java.io.File file)
          A utility method to test whether a file exists.
static void assertFileIsDirectory(java.io.File file)
          A utility method to test whether a given File object represents a directory.
static void assertFileReadable(java.io.File file)
          A utility method to test whether a file is readable.
static void assertFileWriteable(java.io.File file)
          A utility method to test whether a file is writeable.
static java.io.File getCanonicalFile(java.io.File file)
          A utility method to obtain a canonical File object for a given file.
 java.io.File getDirectory()
          Return a File object representing the top-level directory.
 java.io.File getFile(java.lang.String filename)
          A utility method to obtain a canonical File object for a file specified as a path relative to the top-level directory.
 java.lang.String getPath()
          Return the filename of the top-level directory.
 void validateFile(java.lang.String filename)
          A utility method which checks whether a given pathname specified relative to the top-level directory is contained below that directory in the file system directory hierarchy.
 boolean verifyFileIsInsideDirectory(java.lang.String filename, java.io.File directory)
          A utility method which checks whether a given pathname specified relative to a given directory is contained below that directory in the file system directory hierarchy.
 
Methods inherited from class uk.org.ogsadai.dataresource.conx.ConnectionManager
mapCertificate, setRoleMapsFile, setupRoleMapping, updateRoleMaps
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystemConnectionManager

public FileSystemConnectionManager(ConnectionConfig config)
                            throws CoreSystemException,
                                   CoreUserException
Configure this connection manager by initialising its top-level directory and confirming that it exists.

Parameters:
config - the configuration
Throws:
CoreSystemException - if there is a problem reading from the directory
CoreUserException - if the directory doesn't exist
Method Detail

getPath

public java.lang.String getPath()
Return the filename of the top-level directory.

Returns:
the top-level directory's filename

getDirectory

public java.io.File getDirectory()
Return a File object representing the top-level directory.

Returns:
the top-level directory

validateFile

public void validateFile(java.lang.String filename)
                  throws CoreUserException,
                         CoreSystemException
A utility method which checks whether a given pathname specified relative to the top-level directory is contained below that directory in the file system directory hierarchy. If this is not the case then a CoreUserException is thrown.

For example,

validateFile("src/java/.classpath")
will return normally, even if the .classpath file does not actually exist.

But

validateFile("src/../../private/config.xml", new File("c:/project"))
will throw an exception, since the c:/project/src/../../private/config.xml resolves to c:/private/config.xml, which is not below c:/project in the directory hierarchy.

Parameters:
filename - the relative pathname to test
Throws:
CoreUserException - if the filename is outside the directory, or another user-related problem occurs
CoreSystemException - if a system-related problem occurs

getFile

public java.io.File getFile(java.lang.String filename)
                     throws CoreUserException,
                            CoreSystemException
A utility method to obtain a canonical File object for a file specified as a path relative to the top-level directory. If the file is outside of the top-level directory's directory hierarchy, a CoreUserException is thrown.

Note that the path need not specify an existing file.

Parameters:
filename - the path, relative to the top-level directory, to return the canonical form of
Returns:
the canonical File object
Throws:
CoreSystemException - if an I/O error occurs whilst obtaining the canonical pathname.
CoreUserException - if the filename is outside the top-level directory

getCanonicalFile

public static java.io.File getCanonicalFile(java.io.File file)
                                     throws CoreSystemException
A utility method to obtain a canonical File object for a given file.

Note that the path need not specify an existing file.

Parameters:
file - the path to return the canonical form of
Returns:
the canonical File object
Throws:
CoreSystemException - if an I/O error occurs whilst obtaining the canonical pathname.

assertFileExists

public static void assertFileExists(java.io.File file)
                             throws CoreUserException
A utility method to test whether a file exists. If it does not, then an CoreUserException is thrown.

Parameters:
file - the file to test for existence
Throws:
CoreUserException - if the file does not exist

assertFileDoesntExist

public static void assertFileDoesntExist(java.io.File file)
                                  throws CoreUserException
A utility method to test whether a file does not exist. If it does, then an CoreUserException is thrown.

Parameters:
file - the file to test for non-existence
Throws:
CoreUserException - if the file does exist

assertFileReadable

public static void assertFileReadable(java.io.File file)
                               throws CoreUserException
A utility method to test whether a file is readable. If it is not, then an CoreUserException is thrown.

Parameters:
file - the file to test for readability
Throws:
CoreUserException - if the file is not readable

assertFileWriteable

public static void assertFileWriteable(java.io.File file)
                                throws CoreUserException
A utility method to test whether a file is writeable. If it is not, then an CoreUserException is thrown.

Parameters:
file - the file to test for writeability
Throws:
CoreUserException - if the file is not writeable

assertFileIsDirectory

public static void assertFileIsDirectory(java.io.File file)
                                  throws CoreUserException
A utility method to test whether a given File object represents a directory. If it is not, then an CoreUserException is thrown.

Parameters:
file - the file to test for directoryness
Throws:
CoreUserException - if the File object is not a directory

assertDirectoryExists

public static void assertDirectoryExists(java.io.File dir)
                                  throws CoreUserException
A utility method to test whether a given File object, representing a directory, exists. If it does not, then an CoreUserException is thrown.

Parameters:
dir - the directory to test
Throws:
CoreUserException - if the directory does not exist

assertDirectoryReadable

public static void assertDirectoryReadable(java.io.File dir)
                                    throws CoreUserException
A utility method to test whether a directory is readable. If it is not, then an CoreUserException is thrown.

Parameters:
dir - the directory to test for readability
Throws:
CoreUserException - if the file is not readable

verifyFileIsInsideDirectory

public boolean verifyFileIsInsideDirectory(java.lang.String filename,
                                           java.io.File directory)
                                    throws CoreUserException,
                                           CoreSystemException
A utility method which checks whether a given pathname specified relative to a given directory is contained below that directory in the file system directory hierarchy.

Parameters:
filename - the relative pathname to test
directory - the directory we are testing within
Returns:
true iff the file exists below the directory
Throws:
CoreUserException - if a user-related problem occurs
CoreSystemException - if a system-related problem occurs