Package org.openapitools.codegen
Class TemplateManager
- java.lang.Object
-
- org.openapitools.codegen.TemplateManager
-
- All Implemented Interfaces:
TemplateProcessor,TemplatingExecutor
public class TemplateManager extends Object implements TemplatingExecutor, TemplateProcessor
Manages the lookup, compilation, and writing of template files
-
-
Constructor Summary
Constructors Constructor Description TemplateManager(TemplateManagerOptions options, TemplatingEngineAdapter engineAdapter, TemplatePathLocator[] templateLoaders)Constructs a new instance of aTemplateManager
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringgetCPResourcePath(String name)Gets a normalized classpath resource location according to OS-specific file separatorStringgetFullTemplateContents(String name)returns the template content by namePathgetFullTemplatePath(String name)Returns the path of a template, allowing access to the template where consuming literal contents aren't desirable or possible.ReadergetTemplateReader(String name)voidignore(Path path, String context)StringreadTemplate(String name)Reads a template's contents from the specified locationvoidskip(Path path, String context)Filewrite(Map<String,Object> data, String template, File target)Writes data to a compiled templateFilewriteToFile(String filename, byte[] contents)Write bytes to a fileFilewriteToFile(String filename, String contents)Write String to a file, formatting as UTF-8-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openapitools.codegen.api.TemplateProcessor
error
-
-
-
-
Constructor Detail
-
TemplateManager
public TemplateManager(TemplateManagerOptions options, TemplatingEngineAdapter engineAdapter, TemplatePathLocator[] templateLoaders)
Constructs a new instance of aTemplateManager- Parameters:
options- TheTemplateManagerOptionsfor reading and writing templatesengineAdapter- The adaptor to underlying templating enginetemplateLoaders- Loaders which define where we look for templates
-
-
Method Detail
-
getFullTemplateContents
public String getFullTemplateContents(String name)
returns the template content by name- Specified by:
getFullTemplateContentsin interfaceTemplatingExecutor- Parameters:
name- the template name (e.g. model.mustache)- Returns:
- the contents of that template
-
getFullTemplatePath
public Path getFullTemplatePath(String name)
Returns the path of a template, allowing access to the template where consuming literal contents aren't desirable or possible.- Specified by:
getFullTemplatePathin interfaceTemplatingExecutor- Parameters:
name- the template name (e.g. model.mustache)- Returns:
- The
Pathto the template
-
getCPResourcePath
public static String getCPResourcePath(String name)
Gets a normalized classpath resource location according to OS-specific file separator- Parameters:
name- The name of the resource file/directory to find- Returns:
- A normalized string according to OS-specific file separator
-
readTemplate
public String readTemplate(String name)
Reads a template's contents from the specified location- Parameters:
name- The location of the template- Returns:
- The raw template contents
-
write
public File write(Map<String,Object> data, String template, File target) throws IOException
Writes data to a compiled template- Specified by:
writein interfaceTemplateProcessor- Parameters:
data- Input datatemplate- Input template locationtarget- The targeted file output location- Returns:
- The actual file
- Throws:
IOException
-
ignore
public void ignore(Path path, String context)
- Specified by:
ignorein interfaceTemplateProcessor
-
skip
public void skip(Path path, String context)
- Specified by:
skipin interfaceTemplateProcessor
-
writeToFile
public File writeToFile(String filename, String contents) throws IOException
Write String to a file, formatting as UTF-8- Parameters:
filename- The name of file to writecontents- The contents string.- Returns:
- File representing the written file.
- Throws:
IOException- If file cannot be written.
-
writeToFile
public File writeToFile(String filename, byte[] contents) throws IOException
Write bytes to a file- Specified by:
writeToFilein interfaceTemplateProcessor- Parameters:
filename- The name of file to writecontents- The contents bytes. Typically, this is a UTF-8 formatted string.- Returns:
- File representing the written file.
- Throws:
IOException- If file cannot be written.
-
-