2.17.2: 2011-06-17

net.sf.basedb.core
Class FileStoreUtil

java.lang.Object
  extended by net.sf.basedb.core.FileStoreUtil

public class FileStoreUtil
extends Object

Utility class working with FileStoreEnabled items.

Version:
2.5
Author:
nicklas
Last modified
$Date: 2008-09-11 22:11:02 +0200 (Thu, 11 Sep 2008) $

Constructor Summary
FileStoreUtil()
           
 
Method Summary
static File getDataFile(DbControl dc, FileStoreEnabled item, String dataFileType)
          Get the file of the given data file type in the FileStoreEnabled item's file set.
static List<File> getGenericDataFiles(DbControl dc, FileStoreEnabled item, String genericType)
          Get all files with a specific generic FileType in a given item's file set.
static boolean hasDataFile(DbControl dc, FileStoreEnabled item, String dataFileType, boolean requireValid)
          Check if a file of the given data file type is present in a FileStoreEnabled item's file set.
static FileSetMember setDataFile(DbControl dc, FileStoreEnabled item, String dataFileType, File file)
          Set or remove a file to FileStoreEnabled item based on the file's DataFileType.
static FileSetMember setGenericDataFile(DbControl dc, FileStoreEnabled item, String genericType, String fallbackDataFileType, File file)
          Set or remove a file to FileStoreEnabled item based on the file's generic FileType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileStoreUtil

public FileStoreUtil()
Method Detail

hasDataFile

public static boolean hasDataFile(DbControl dc,
                                  FileStoreEnabled item,
                                  String dataFileType,
                                  boolean requireValid)
Check if a file of the given data file type is present in a FileStoreEnabled item's file set. Optionally, check if the file has been validated as a valid file.

Parameters:
dc - DbControl to use when accessing the database.
item - The FileStoreEnabled item to check
dataFileType - The external ID of the DataFileType to check for
requireValid - TRUE if the file must exist and be valid, FALSE if it must only exist. This parameter is ignored if the data file type doesn't have a validator
Returns:
TRUE if the file exists, FALSE otherwise

getDataFile

public static File getDataFile(DbControl dc,
                               FileStoreEnabled item,
                               String dataFileType)
Get the file of the given data file type in the FileStoreEnabled item's file set.

Parameters:
dc - DbControl used to access the database.
item - The FileStoreEnabled item to check
dataFileType - The external ID of the DataFileType to check for
Returns:
The file item, or null if no file of the given type exists
Throws:
PermissionDeniedException - If the logged in user doesn't have read permission to the file

getGenericDataFiles

public static List<File> getGenericDataFiles(DbControl dc,
                                             FileStoreEnabled item,
                                             String genericType)
Get all files with a specific generic FileType in a given item's file set. Note! This method will only return files that the logged in user has permission to read. Other files in the file set will be ignored. Note! This method checks the file type from DataFileType.getGenericType(), not the file type from File.getFileType().

Parameters:
dc - A DbControl to use for database access
item - The FileStoreEnabled item to check
genericType - The system ID of the FileType to check for
Returns:
A list of file items that matches

setDataFile

public static FileSetMember setDataFile(DbControl dc,
                                        FileStoreEnabled item,
                                        String dataFileType,
                                        File file)
Set or remove a file to FileStoreEnabled item based on the file's DataFileType.

Parameters:
dc - A DbControl to use for database access
item - The item to add/remove the file to/from
dataFileType - The external ID of the DataFileType of the file
file - The file, or null to remove an existing file
Returns:
The new FileSetMember item or null if a file was removed
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission to the item
InvalidUseOfNullException - If item is null

setGenericDataFile

public static FileSetMember setGenericDataFile(DbControl dc,
                                               FileStoreEnabled item,
                                               String genericType,
                                               String fallbackDataFileType,
                                               File file)
Set or remove a file to FileStoreEnabled item based on the file's generic FileType. Note! This method checks the file type from DataFileType.getGenericType(), not the file type from File.getFileType().

Parameters:
dc - A DbControl to use for database access
item - The item to add/remove the file to/from
genericType - The system ID of the generic FileType
fallbackDataFileType - The external ID of a DataFileType that is used if the specified generic file type isn't found among the file types registered for the platform
file - The file, or null to remove an existing file
Returns:
The new FileSetMember item or null if a file was removed
Throws:
PermissionDeniedException - If the logged in user doesn't have write permission to the item
InvalidUseOfNullException - If item is null

2.17.2: 2011-06-17