Class FileSystemIncludeResolver

java.lang.Object
dev.jcputney.mjml.FileSystemIncludeResolver
All Implemented Interfaces:
IncludeResolver

public final class FileSystemIncludeResolver extends Object implements IncludeResolver
Resolves mj-include paths from the file system relative to a base directory.

Usage

MjmlConfiguration config = MjmlConfiguration.builder()
    .includeResolver(new FileSystemIncludeResolver(Path.of("/templates")))
    .build();
  • Constructor Details

    • FileSystemIncludeResolver

      public FileSystemIncludeResolver(Path baseDir)
      Creates a resolver that resolves paths relative to the given base directory.
      Parameters:
      baseDir - the base directory for relative include paths
  • Method Details

    • resolve

      public String resolve(String path, ResolverContext context)
      Description copied from interface: IncludeResolver
      Resolves the given path to its content.

      Security note: Implementations should validate paths to prevent directory traversal attacks (e.g., paths containing "../" sequences).

      Specified by:
      resolve in interface IncludeResolver
      Parameters:
      path - the include path from the mj-include element
      context - metadata about the include chain (including path, type, depth)
      Returns:
      the resolved content string