Package helper

Class DirectoryHelper

java.lang.Object
helper.DirectoryHelper

public class DirectoryHelper extends Object
Contains helper methods for managing the directories of a ServletContext.
Author:
Afonso Caniço, Afonso Sampaio, Gustavo Ferreira, Samuel Correia
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    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
    Gets the name of the file located at a given path.
    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.
    static File
    getMatchingHistoryFile(jakarta.servlet.ServletContext context, String ontologyKbPath)
    Finds the history file of a given ontology, if it is present.
    static boolean
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DirectoryHelper

      public DirectoryHelper()
  • Method Details

    • deleteOnExit

      public static void deleteOnExit(File file)
      Schedules a file to be deleted when the virtual machine closes.
      Parameters:
      file - The file to be deleted.
    • isDeleteOnExit

      public static boolean isDeleteOnExit(File file)
      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

      public static File getDirectory(jakarta.servlet.ServletContext context, String dirInitParameter)
      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

      public static String getFileName(String path)
      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.