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 String
getCPResourcePath(String name)
Gets a normalized classpath resource location according to OS-specific file separatorString
getFullTemplateContents(String name)
returns the template content by namePath
getFullTemplatePath(String name)
Returns the path of a template, allowing access to the template where consuming literal contents aren't desirable or possible.Reader
getTemplateReader(String name)
void
ignore(Path path, String context)
String
readTemplate(String name)
Reads a template's contents from the specified locationvoid
skip(Path path, String context)
File
write(Map<String,Object> data, String template, File target)
Writes data to a compiled templateFile
writeToFile(String filename, byte[] contents)
Write bytes to a fileFile
writeToFile(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
- TheTemplateManagerOptions
for 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:
getFullTemplateContents
in 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:
getFullTemplatePath
in interfaceTemplatingExecutor
- Parameters:
name
- the template name (e.g. model.mustache)- Returns:
- The
Path
to 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:
write
in 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:
ignore
in interfaceTemplateProcessor
-
skip
public void skip(Path path, String context)
- Specified by:
skip
in 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:
writeToFile
in 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.
-
-