@Service public class NoteTemplateService extends Object
Modifier and Type | Field and Description |
---|---|
static String |
NOTE_PROPERTY_KEY_TEMPLATE_ID
Key of the NoteProperty that holds the template ID.
|
static String |
NOTE_PROPERTY_KEY_TEMPLATE_PROPERTIES
Key of the NoteProperty that holds the template properties.
|
Constructor and Description |
---|
NoteTemplateService() |
Modifier and Type | Method and Description |
---|---|
boolean |
addDefinition(NoteTemplateDefinition definition)
Add a template definition.
|
boolean |
addTool(String toolKey,
Object tool)
Add a tool which should be accessible from within the template.
|
NoteTemplateDefinition |
getDefinition(String templateId)
Return the template definition for the given ID or null if there is none.
|
void |
init()
initialize required components
|
void |
removeDefinition(String templateId)
Remove a template definition.
|
void |
removeTool(String toolKey)
Remove a tool that was previously added via
addTool(String, Object) |
String |
renderTemplate(String templateId,
String templatePropertiesJSON,
NoteRenderContext renderContext,
boolean validateTemplateProperties)
Render a template and returns the resulting string which can than be used as note content.
|
public static final String NOTE_PROPERTY_KEY_TEMPLATE_ID
public static final String NOTE_PROPERTY_KEY_TEMPLATE_PROPERTIES
public boolean addDefinition(NoteTemplateDefinition definition)
definition
- the template definition to addpublic boolean addTool(String toolKey, Object tool)
toolKey
- the key under which the tool should be accessible. If there is already a tool for
the key the new one will be ignored.tool
- the tool to addpublic NoteTemplateDefinition getDefinition(String templateId)
templateId
- the ID for which a definition should be returned@PostConstruct public void init()
public void removeDefinition(String templateId)
templateId
- the ID of the template definition to remove. In case there is no definition for
the ID nothing will happen.public void removeTool(String toolKey)
addTool(String, Object)
toolKey
- the key of the tool to remove. In case there is no tool for the key nothing will
happen.public String renderTemplate(String templateId, String templatePropertiesJSON, NoteRenderContext renderContext, boolean validateTemplateProperties) throws NoteTemplateNotFoundException, NoteTemplateRenderException
templateId
- the ID of the template definition whose template should be renderedtemplatePropertiesJSON
- optional string in JSON which should be passed to the template engine and can
contain any additional data the template might need. The string is converted into
a nested map for easier processing within the template. The variable is called
'props'.renderContext
- the render context to use when getting the actual template from the template
definition. The rendering context will also be put into the velocity context so it
can be used in the template. The variable is called 'context'validateTemplateProperties
- whether to call the validator of the template definition to validate the template
properties. In case the definition has no validator this argument is ignored.NoteTemplateNotFoundException
- in case there is no template definition for the given IDNoteTemplateRenderException
- in case of an error while rendering the templateCopyright © 2019 Communote team. All rights reserved.