Class FreemarkerTemplateRepository

java.lang.Object
com.pragma.archetype.infrastructure.adapter.out.template.FreemarkerTemplateRepository
All Implemented Interfaces:
TemplateRepository, TemplateContentProvider

public class FreemarkerTemplateRepository extends Object implements TemplateRepository, TemplateContentProvider
Adapter for template processing using Freemarker. Supports loading templates from: - Local filesystem (developer mode with localPath) - Remote GitHub repository (production mode or developer mode with repository) - Embedded resources (fallback)
  • Constructor Details

    • FreemarkerTemplateRepository

      public FreemarkerTemplateRepository(Path templatesBasePath)
      Creates a repository with templates from local filesystem.
      Parameters:
      templatesBasePath - base path where templates are located
    • FreemarkerTemplateRepository

      public FreemarkerTemplateRepository(TemplateConfig templateConfig)
      Creates a repository with template configuration. Supports local path, remote repository, or embedded templates. Uses TemplateSourceResolver to determine template source and configure caching.
      Parameters:
      templateConfig - template configuration
    • FreemarkerTemplateRepository

      public FreemarkerTemplateRepository(String templatesUrl)
      Creates a repository with templates from a URL. For Phase 1, we'll use local templates. Remote loading will be added later.
      Parameters:
      templatesUrl - URL to templates repository
  • Method Details

    • processTemplate

      public String processTemplate(String templatePath, Map<String,Object> context)
      Description copied from interface: TemplateRepository
      Loads and processes a template with the given context.
      Specified by:
      processTemplate in interface TemplateRepository
      Parameters:
      templatePath - path to the template file
      context - context data for template processing
      Returns:
      processed template content
    • templateExists

      public boolean templateExists(String templatePath)
      Description copied from interface: TemplateRepository
      Checks if a template exists.
      Specified by:
      templateExists in interface TemplateContentProvider
      Specified by:
      templateExists in interface TemplateRepository
      Parameters:
      templatePath - path to the template file
      Returns:
      true if template exists, false otherwise
    • getTemplateContent

      public String getTemplateContent(String templatePath)
      Description copied from interface: TemplateRepository
      Gets the raw content of a template without processing.
      Specified by:
      getTemplateContent in interface TemplateContentProvider
      Specified by:
      getTemplateContent in interface TemplateRepository
      Parameters:
      templatePath - path to the template file
      Returns:
      raw template content
    • getDownloader

      public GitHubTemplateDownloader getDownloader()
      Gets the downloader instance (for testing or cache management).
    • loadStructureMetadata

      public StructureMetadata loadStructureMetadata(ArchitectureType architecture)
      Description copied from interface: TemplateRepository
      Loads structure metadata for a given architecture type.
      Specified by:
      loadStructureMetadata in interface TemplateRepository
      Parameters:
      architecture - the architecture type
      Returns:
      structure metadata for the architecture
    • loadAdapterMetadata

      public AdapterMetadata loadAdapterMetadata(String adapterName)
      Description copied from interface: TemplateRepository
      Loads adapter metadata for a given adapter name (legacy method). This method uses the legacy flat structure: adapters/{adapterName}/metadata.yml
      Specified by:
      loadAdapterMetadata in interface TemplateRepository
      Parameters:
      adapterName - the name of the adapter
      Returns:
      adapter metadata for the adapter
    • loadAdapterMetadata

      public AdapterMetadata loadAdapterMetadata(String adapterName, String framework, String paradigm, String adapterType)
      Description copied from interface: TemplateRepository
      Loads adapter metadata for a given adapter using framework-aware structure. Path: frameworks/{framework}/{paradigm}/adapters/{adapterType}/{adapterName}/metadata.yml
      Specified by:
      loadAdapterMetadata in interface TemplateRepository
      Parameters:
      adapterName - the name of the adapter
      framework - the framework (e.g., "spring", "quarkus")
      paradigm - the paradigm (e.g., "reactive", "imperative")
      adapterType - the adapter type (e.g., "driven-adapters", "entry-points")
      Returns:
      adapter metadata for the adapter
    • validateTemplate

      public ValidationResult validateTemplate(String templatePath)
      Validates a template for FreeMarker syntax errors.
      Specified by:
      validateTemplate in interface TemplateRepository
      Parameters:
      templatePath - path to the template file
      Returns:
      ValidationResult indicating if template is valid
    • extractRequiredVariables

      public Set<String> extractRequiredVariables(String templatePath)
      Extracts required variables from a template by parsing FreeMarker expressions. Identifies variables used in ${...} and #{...} expressions.
      Specified by:
      extractRequiredVariables in interface TemplateRepository
      Parameters:
      templatePath - path to the template file
      Returns:
      set of variable names used in the template
    • validateTemplateVariables

      public ValidationResult validateTemplateVariables(String templatePath, Set<String> providedVariables)
      Validates a template against a set of required variables. Checks if all variables used in the template are provided in the required set.
      Parameters:
      templatePath - path to the template file
      providedVariables - set of variables that will be provided in the context
      Returns:
      ValidationResult indicating if all required variables are provided