Class DefaultModuleFileProvider

java.lang.Object
dev.jcputney.elearning.parser.impl.provider.DefaultModuleFileProvider
All Implemented Interfaces:
ModuleFileProvider

public class DefaultModuleFileProvider extends Object implements ModuleFileProvider
Default implementation of the ModuleFileProvider interface.

This class delegates file access operations to an underlying FileAccess instance, providing a consistent interface for parsers to use without directly depending on the FileAccess interface.

  • Field Details

    • XAPI_JS_FILE

      public static final String XAPI_JS_FILE
      The name of the xAPI JavaScript file.
      See Also:
    • XAPI_SEND_STATEMENT_FILE

      public static final String XAPI_SEND_STATEMENT_FILE
      The name of the xAPI send statement file.
      See Also:
  • Constructor Details

    • DefaultModuleFileProvider

      public DefaultModuleFileProvider(FileAccess fileAccess)
      Constructs a DefaultModuleFileProvider with the specified FileAccess instance.
      Parameters:
      fileAccess - An instance of FileAccess for reading files in the module package.
      Throws:
      IllegalArgumentException - if fileAccess is null
  • Method Details

    • getFileContents

      public InputStream getFileContents(String path) throws IOException
      Gets the contents of a file as an InputStream.
      Specified by:
      getFileContents in interface ModuleFileProvider
      Parameters:
      path - The path to the file.
      Returns:
      An InputStream containing the file contents.
      Throws:
      IOException - If an error occurs while reading the file.
      IllegalArgumentException - if a path is null
    • fileExists

      public boolean fileExists(String path)
      Checks if a file exists at the specified path.
      Specified by:
      fileExists in interface ModuleFileProvider
      Parameters:
      path - The path to check.
      Returns:
      true if the file exists, false otherwise.
      Throws:
      IllegalArgumentException - if a path is null
    • getRootPath

      public String getRootPath()
      Gets the root path of the module.
      Specified by:
      getRootPath in interface ModuleFileProvider
      Returns:
      The root path of the module.
    • hasXapiSupport

      public boolean hasXapiSupport()
      Checks if the module contains xAPI-related files.
      Specified by:
      hasXapiSupport in interface ModuleFileProvider
      Returns:
      true if xAPI is enabled, false otherwise.
    • listFiles

      public List<String> listFiles(String directory) throws IOException
      Lists all files in the specified directory.
      Specified by:
      listFiles in interface ModuleFileProvider
      Parameters:
      directory - The directory to list files from.
      Returns:
      A list of file names in the directory.
      Throws:
      IOException - If an error occurs while listing the files.
      IllegalArgumentException - if the directory is null
    • fileExistsBatch

      public Map<String,Boolean> fileExistsBatch(List<String> paths)
      Checks if multiple files exist in a batch operation.

      This implementation delegates to the underlying FileAccess implementation.

      Specified by:
      fileExistsBatch in interface ModuleFileProvider
      Parameters:
      paths - List of file paths to check
      Returns:
      Map where keys are the file paths and values indicate whether the file exists
      Throws:
      IllegalArgumentException - if paths is null or contains null elements
    • prefetchCommonFiles

      public void prefetchCommonFiles()
      Prefetches common module files for faster subsequent access.

      This implementation delegates to the underlying FileAccess implementation.

      Specified by:
      prefetchCommonFiles in interface ModuleFileProvider
    • getTotalSize

      public long getTotalSize() throws IOException
      Gets the total size of all files in the module.

      This implementation delegates to the underlying FileAccess implementation.

      Specified by:
      getTotalSize in interface ModuleFileProvider
      Returns:
      Total size of all files in bytes, or -1 if not supported
      Throws:
      IOException - if there's an error accessing file sizes