Class ResourceFactory

java.lang.Object
lib.aide.resource.content.ResourceFactory

public class ResourceFactory extends Object
  • Field Details

    • DEFAULT_DELIMITER_PATTERN

      public static final Pattern DEFAULT_DELIMITER_PATTERN
    • DEFAULT_ASSEMBLER_TEXT

      public static final String DEFAULT_ASSEMBLER_TEXT
      See Also:
  • Constructor Details

    • ResourceFactory

      public ResourceFactory()
  • Method Details

    • textResourceFactoryFromSuffix

      public Optional<ResourceFactory.SuffixedTextResourceFactory<String,TextResource<? extends Nature>>> textResourceFactoryFromSuffix(String suffixesSrc, Optional<Pattern> delimiter)
      Detect the nature of a resource from the suffixes supplied. This method processes the source path to extract suffixes using the provided delimiter or a default delimiter. Based on the most significant suffix (the last one in the path), it attempts to determine the nature of the resource. If no suffixes are found, or if the nature cannot be determined, it returns an empty Optional. Examples:
      • For the source path "my-file.md" with the default delimiter ".", it might detect a markdown nature.
      • For the source path "my-file.special-type.md" with the default delimiter ".", it might detect a special markdown nature.
      Parameters:
      suffixesSrc - the source path in which suffixes are found
      delimiter - an optional delimiter to use for suffixes, defaults to the pattern "\\."
      Returns:
      an Optional containing SuffixedTextResourceFactory if the nature can be determined, otherwise Optional.empty()
    • textResourceFromSuffix

      public Optional<TextResource<? extends Nature>> textResourceFromSuffix(String suffixesSrc, Supplier<String> content, Optional<Pattern> delimiter)
      Determine if a suffix has a text resource factory and return an Optional.
      Parameters:
      suffixesSrc - the source path in which suffixes are found
      content - the supplier of the content to be used for the resource
      delimiter - an optional delimiter to use for suffixes, defaults to the pattern "\\."
      Returns:
      an Optional containing TextResource if the resource can be created, otherwise Optional.empty()
    • resourceFromSuffix

      public <T> Optional<Resource<? extends Nature,T>> resourceFromSuffix(String suffixesSrc, Supplier<T> content, Optional<Pattern> delimiter, Optional<String> assembler)
      Determine if a suffix has a resource factory and return an Optional. After parsing suffixes it looks in the ResourceFactory for the match with the most suffixes to the least suffixes. For example, if a suffixesSrc is `a.b.c.d` then we search for `.b.c.d` first, then `.c.d` and finally `.d`.
      Type Parameters:
      T - the type of the content
      Parameters:
      suffixesSrc - the source path in which suffixes are found
      content - the supplier of the content to be used for the resource
      delimiter - an optional delimiter to use for suffixes, defaults to the pattern "\\."
      assembler - an optional delimiter to use for reassembling suffixes, defaults to string "."
      Returns:
      an Optional containing Resource if the resource can be created, otherwise Optional.empty()
    • mapFromText

      public static ResourceFactory.MapFromTextResult mapFromText(String fileName, Optional<Supplier<String>> textSupplier)
      Maps the content of a file or a provided text supplier to a Mapinvalid input: '<'String, Object>. Supports JSON and YAML files based on the file extension.
      Parameters:
      fileName - The name of the file to read from if no text supplier is provided.
      textSupplier - An optional supplier that provides the text content to be mapped.
      Returns:
      A MapFromTextResult containing the resulting map, validity status, any issues encountered, the original text content, and the type of content parsed.