Class RosaeContext

    • 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 template
        compileInfo - 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 compile
        includesPath - 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