Package org.rosaenlg.lib
Class RosaeContext
- java.lang.Object
-
- org.rosaenlg.lib.RosaeContext
-
public class RosaeContext extends Object
Wrapper around RosaeNLG.- Author:
- Ludan Stoecklé [email protected]
- See Also:
- RosaeNLG documentation
-
-
Constructor Summary
Constructors Constructor Description RosaeContext(String jsonPackageAsString)
Constructor, based on a String containing all the information on a template.RosaeContext(String entryTemplate, File includesPath, CompileInfo compileInfo)
Constructor, based on traditional Pug templates.RosaeContext(String template, CompileInfo compileInfo)
Constructor, for very simple templates.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
Destroys the object by closing its context.String
getCompiledClient()
Create a compiled file for client side rendering.String
getJsonPackageAsString()
Getter on the original JSON package containing the template.String
getTemplateId()
Getter on template ID.RenderResult
render(String jsonOptionsAsString)
Render the template with input data.
-
-
-
Constructor Detail
-
RosaeContext
public RosaeContext(String template, CompileInfo compileInfo) throws RosaeContextConstructorException
Constructor, for very simple templates.Will create a new GraalVM context for this template, compile the template, and be ready to render multiple times.
- Parameters:
template
- the content of the templatecompileInfo
- how to compile the template- Throws:
RosaeContextConstructorException
- if context construction fails
-
RosaeContext
public RosaeContext(String entryTemplate, File includesPath, CompileInfo compileInfo) throws RosaeContextConstructorException
Constructor, based on traditional Pug templates.Will create a new GraalVM context for this template, compile the template, and be ready to render multiple times.
- Parameters:
entryTemplate
- the name of the template to compileincludesPath
- the path where the templates to be included are located (including the entry template)compileInfo
- how to compile the template- Throws:
RosaeContextConstructorException
- if compiling fails, or if reading disk fails
-
RosaeContext
public RosaeContext(String jsonPackageAsString) throws RosaeContextConstructorException
Constructor, based on a String containing all the information on a template.Will create a new GraalVM context for this template, compile the template, test if autotest is activated, and be ready to render multiple times. See https://rosaenlg.org/rosaenlg/1.18.1/integration/rosaenlg_packager.html to create such a package.
- Parameters:
jsonPackageAsString
- contains a template and its parameters, JSON format- Throws:
RosaeContextConstructorException
- when the JSON package is not well formated, or if the autotest was activated and failed.
-
-
Method Detail
-
render
public RenderResult render(String jsonOptionsAsString) throws RenderingException
Render the template with input data.- Parameters:
jsonOptionsAsString
- JSON string containing all the input data to render the template.- Returns:
- RenderResult the rendered result
- Throws:
RenderingException
- if an error occurs during rendering
-
getCompiledClient
public String getCompiledClient() throws CompiledClientException
Create a compiled file for client side rendering.This is useful to compile a templates, bundle everything for later rendering, typically client side in a browser.
- Returns:
- String the compiled template (which is JavaScript code)
- Throws:
CompiledClientException
- if a problem occurs
-
getTemplateId
public String getTemplateId()
Getter on template ID.- Returns:
- String the template ID
-
getJsonPackageAsString
public String getJsonPackageAsString()
Getter on the original JSON package containing the template.- Returns:
- String the JSON package containing the template.
-
destroy
public void destroy() throws DestroyException
Destroys the object by closing its context.It is recommended to use 'destroy' so that the GraalVM is explicitely closed.
- Throws:
DestroyException
- if closing the context failed
-
-