Class JarResourceModule

java.lang.Object
com.juliewoolie.delphi.resource.JarResourceModule
All Implemented Interfaces:
IoModule, ResourceModule

public class JarResourceModule extends Object implements IoModule
IO module that loads module files from a jar's resources
  • Constructor Details

    • JarResourceModule

      public JarResourceModule(ClassLoader loader, String directory)
      Constructs a new jar resource module.
      Parameters:
      loader - The class loader used for accessing resources
      directory - The path of the directory in the jar's resources to load from. Leave blank to use the jar's root directory.
  • Method Details

    • getLoader

      public ClassLoader getLoader()
    • getDirectory

      public String getDirectory()
    • setCharset

      public void setCharset(@NotNull @NotNull Charset charset)
      Sets the charset used to read resource files.
      Parameters:
      charset - Charset
      Throws:
      NullPointerException - If charset is null
    • getCharset

      public Charset getCharset()
    • getFilePaths

      @Nullable public @Nullable List<String> getFilePaths()
    • setFilePaths

      public void setFilePaths(@Nullable @Nullable List<String> filePaths)
      Sets the file paths returned by getModulePaths(ResourcePath).

      Since it's difficult to reliably get a list of files in a java class path (or plugin class path), this method sets the list of files getModulePaths(ResourcePath) will filter through.

      Parameters:
      filePaths - File path list.
    • loadString

      @NotNull public @NotNull StringBuffer loadString(@NotNull @NotNull ResourcePath path) throws IOException
      Description copied from interface: IoModule
      Load a string buffer from the file pointed to by the specified path.
      Specified by:
      loadString in interface IoModule
      Parameters:
      path - File path
      Returns:
      The read file contents
      Throws:
      IOException - If an IO exception ocurred while reading the file
    • getModulePaths

      @NotNull public @NotNull Collection<String> getModulePaths(@NotNull @NotNull ResourcePath pathSoFar)
      Description copied from interface: ResourceModule
      Gets a collection of files/documents contained in this module.

      The resulting file paths are used mainly for suggestions in the /delphi open <player> <path> command.

      Assuming we have the following files in the module:

      
       index.xml
       item-data.json
       global-style.scss
       admin-tab/index.xml
       admin-tab/head-item.json
       admin-tab/confirm/dialogue.xml
       admin-tab/confirm/style.scss
       spectator-tab/index.xml
       
      The following inputs should yield these results:
      Input Expected result
      Empty input Returns the entire file list
      admin-tab/ index.xml, head-item.json, confirm/dialogue.xml, confirm/style.scss
      admin-tab/confirm/ dialogue.xml, style.scss
      spectator-tab/ index.xml
      Specified by:
      getModulePaths in interface ResourceModule
      Parameters:
      pathSoFar - The current page path.
      Returns:
      A list of files contained in the directory specified by pathSoFar.