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)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when template processing fails.Nested classes/interfaces inherited from interface com.pragma.archetype.domain.port.out.TemplateRepository
TemplateRepository.TemplateNotFoundException -
Constructor Summary
ConstructorsConstructorDescriptionFreemarkerTemplateRepository(TemplateConfig templateConfig) Creates a repository with template configuration.FreemarkerTemplateRepository(String templatesUrl) Creates a repository with templates from a URL.FreemarkerTemplateRepository(Path templatesBasePath) Creates a repository with templates from local filesystem. -
Method Summary
Modifier and TypeMethodDescriptionextractRequiredVariables(String templatePath) Extracts required variables from a template by parsing FreeMarker expressions.Gets the downloader instance (for testing or cache management).getTemplateContent(String templatePath) Gets the raw content of a template without processing.loadAdapterMetadata(String adapterName) Loads adapter metadata for a given adapter name (legacy method).loadAdapterMetadata(String adapterName, String framework, String paradigm, String adapterType) Loads adapter metadata for a given adapter using framework-aware structure.loadStructureMetadata(ArchitectureType architecture) Loads structure metadata for a given architecture type.processTemplate(String templatePath, Map<String, Object> context) Loads and processes a template with the given context.booleantemplateExists(String templatePath) Checks if a template exists.validateTemplate(String templatePath) Validates a template for FreeMarker syntax errors.validateTemplateVariables(String templatePath, Set<String> providedVariables) Validates a template against a set of required variables.
-
Constructor Details
-
FreemarkerTemplateRepository
Creates a repository with templates from local filesystem.- Parameters:
templatesBasePath- base path where templates are located
-
FreemarkerTemplateRepository
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
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
Description copied from interface:TemplateRepositoryLoads and processes a template with the given context.- Specified by:
processTemplatein interfaceTemplateRepository- Parameters:
templatePath- path to the template filecontext- context data for template processing- Returns:
- processed template content
-
templateExists
Description copied from interface:TemplateRepositoryChecks if a template exists.- Specified by:
templateExistsin interfaceTemplateContentProvider- Specified by:
templateExistsin interfaceTemplateRepository- Parameters:
templatePath- path to the template file- Returns:
- true if template exists, false otherwise
-
getTemplateContent
Description copied from interface:TemplateRepositoryGets the raw content of a template without processing.- Specified by:
getTemplateContentin interfaceTemplateContentProvider- Specified by:
getTemplateContentin interfaceTemplateRepository- Parameters:
templatePath- path to the template file- Returns:
- raw template content
-
getDownloader
Gets the downloader instance (for testing or cache management). -
loadStructureMetadata
Description copied from interface:TemplateRepositoryLoads structure metadata for a given architecture type.- Specified by:
loadStructureMetadatain interfaceTemplateRepository- Parameters:
architecture- the architecture type- Returns:
- structure metadata for the architecture
-
loadAdapterMetadata
Description copied from interface:TemplateRepositoryLoads adapter metadata for a given adapter name (legacy method). This method uses the legacy flat structure: adapters/{adapterName}/metadata.yml- Specified by:
loadAdapterMetadatain interfaceTemplateRepository- 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:TemplateRepositoryLoads adapter metadata for a given adapter using framework-aware structure. Path: frameworks/{framework}/{paradigm}/adapters/{adapterType}/{adapterName}/metadata.yml- Specified by:
loadAdapterMetadatain interfaceTemplateRepository- Parameters:
adapterName- the name of the adapterframework- 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
Validates a template for FreeMarker syntax errors.- Specified by:
validateTemplatein interfaceTemplateRepository- Parameters:
templatePath- path to the template file- Returns:
- ValidationResult indicating if template is valid
-
extractRequiredVariables
Extracts required variables from a template by parsing FreeMarker expressions. Identifies variables used in ${...} and #{...} expressions.- Specified by:
extractRequiredVariablesin interfaceTemplateRepository- 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 fileprovidedVariables- set of variables that will be provided in the context- Returns:
- ValidationResult indicating if all required variables are provided
-