Package helper
Class DirectoryHelper
java.lang.Object
helper.DirectoryHelper
Contains helper methods for managing the directories of a ServletContext.
- Author:
- Afonso Caniço, Afonso Sampaio, Gustavo Ferreira, Samuel Correia
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
deleteOnExit
(File file) Schedules a file to be deleted when the virtual machine closes.static File
getDirectory
(jakarta.servlet.ServletContext context, String dirInitParameter) Gets the given context's directory specified in an init parameter.static int
getDirectoryFileCount
(jakarta.servlet.ServletContext context, String dirInitParameter) How many files are currently stored in the given context's specified directory?static String
getFileName
(String path) Gets the name of the file located at a given path.Gets a sorted (by last modification timestamp) set of all files in a given directory.static File
getMatchingHistoryFile
(jakarta.servlet.ServletContext context, String ontologyKbPath) Finds the history file of a given ontology, if it is present.static boolean
isDeleteOnExit
(File file) Is the specified file scheduled to be deleted when the virtual machine closes?static void
purgeUploadDirectoryIfFull
(jakarta.servlet.ServletContext context, String fileLimitInitParameter) Deletes the oldest file in the context's upload directory, but only if the number of files in this directory surpasses the limit defined in web.xml; Otherwise, does nothing.
-
Constructor Details
-
DirectoryHelper
public DirectoryHelper()
-
-
Method Details
-
deleteOnExit
Schedules a file to be deleted when the virtual machine closes.- Parameters:
file
- The file to be deleted.
-
isDeleteOnExit
Is the specified file scheduled to be deleted when the virtual machine closes?- Parameters:
file
- The file to check.- Returns:
- True if the file has been marked for deletion on exit; False, otherwise.
-
getDirectory
Gets the given context's directory specified in an init parameter.- Parameters:
context
- The current servlet context.dirInitParameter
- The init parameter for the directory, as specified in web.xml.- Returns:
- The full path of the directory given by the init parameter, as defined in web.xml
-
getFileName
Gets the name of the file located at a given path.- Parameters:
path
- The path to the file.- Returns:
- The name of the file stored at the given path.
-
getDirectoryFileCount
public static int getDirectoryFileCount(jakarta.servlet.ServletContext context, String dirInitParameter) How many files are currently stored in the given context's specified directory?- Parameters:
context
- The current servlet context.dirInitParameter
- The init parameter for the directory, as specified in web.xml.- Returns:
- The number of files in the directory, if applicable; 0 otherwise.
-
getFiles
public static SortedSet<File> getFiles(jakarta.servlet.ServletContext context, String dirInitParameter) Gets a sorted (by last modification timestamp) set of all files in a given directory.- Parameters:
context
- The current servlet context.dirInitParameter
- The init parameter for the directory, as specified in web.xml.- Returns:
- A set containing all non-marked (see
DirectoryHelper.deleteOnExit
) files in the given directory.
-
purgeUploadDirectoryIfFull
public static void purgeUploadDirectoryIfFull(jakarta.servlet.ServletContext context, String fileLimitInitParameter) Deletes the oldest file in the context's upload directory, but only if the number of files in this directory surpasses the limit defined in web.xml; Otherwise, does nothing.- Parameters:
context
- The current servlet context.fileLimitInitParameter
- The init parameter specifying the maximum number of files in a directory, as specified in web.xml.
-
getMatchingHistoryFile
public static File getMatchingHistoryFile(jakarta.servlet.ServletContext context, String ontologyKbPath) Finds the history file of a given ontology, if it is present. Otherwise, creates a history file for that ontology.- Parameters:
context
- The current servlet context.ontologyKbPath
- The path to the ontology's knowledge base.- Returns:
- The ontology's query history file, if present; Creates the file and returns it, otherwise.
-