Search in sources :

Example 6 with VelocityRenderDecorator

use of org.olat.core.gui.render.velocity.VelocityRenderDecorator in project OpenOLAT by OpenOLAT.

the class CourseCreationConfiguration method getSinglePageText.

/**
 * @param translator
 * @return single page content
 */
public String getSinglePageText(Translator translator) {
    VelocityContainer vc = new VelocityContainer("singlePageTemplate", CourseCreationHelper.class, "singlePageTemplate", translator, null);
    vc.contextPut("coursetitle", courseTitle);
    // prepare rendering of velocity page for the content of the single page node
    GlobalSettings globalSettings = new GlobalSettings() {

        public int getFontSize() {
            return 100;
        }

        public AJAXFlags getAjaxFlags() {
            return new EmptyAJAXFlags();
        }

        public boolean isIdDivsForced() {
            return false;
        }
    };
    Context context = vc.getContext();
    Renderer fr = Renderer.getInstance(vc, translator, null, new RenderResult(), globalSettings);
    StringOutput wOut = new StringOutput(10000);
    VelocityRenderDecorator vrdec = new VelocityRenderDecorator(fr, vc, wOut);
    context.put("r", vrdec);
    VelocityHelper.getInstance().mergeContent(vc.getPage(), context, wOut, null);
    // free the decorator
    context.remove("r");
    IOUtils.closeQuietly(vrdec);
    return WysiwygFactory.createXHtmlFileContent(wOut.toString(), courseTitle);
}
Also used : Context(org.apache.velocity.context.Context) Renderer(org.olat.core.gui.render.Renderer) RenderResult(org.olat.core.gui.render.RenderResult) GlobalSettings(org.olat.core.gui.GlobalSettings) StringOutput(org.olat.core.gui.render.StringOutput) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator)

Example 7 with VelocityRenderDecorator

use of org.olat.core.gui.render.velocity.VelocityRenderDecorator in project OpenOLAT by OpenOLAT.

the class QTI21ResultsExportMediaResource method createResultHTML.

private String createResultHTML(Component results) {
    String pagePath = Util.getPackageVelocityRoot(this.getClass()) + "/qti21results.html";
    URLBuilder ubu = new URLBuilder("auth", "1", "0");
    // generate VelocityContainer and put Component
    VelocityContainer mainVC = new VelocityContainer("html", pagePath, translator, null);
    mainVC.contextPut("rootTitle", translator.translate("table.grading"));
    mainVC.put("results", results);
    // render VelocityContainer to StringOutPut
    Renderer renderer = Renderer.getInstance(mainVC, translator, ubu, new RenderResult(), new EmptyGlobalSettings());
    try (StringOutput sb = new StringOutput(32000);
        VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, mainVC, sb)) {
        mainVC.contextPut("r", vrdec);
        renderer.render(sb, mainVC, null);
        vrdec.close();
        return sb.toString();
    } catch (Exception e) {
        log.error("", e);
        return "";
    }
}
Also used : Renderer(org.olat.core.gui.render.Renderer) RenderResult(org.olat.core.gui.render.RenderResult) StringOutput(org.olat.core.gui.render.StringOutput) IOException(java.io.IOException) URLBuilder(org.olat.core.gui.render.URLBuilder) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator)

Example 8 with VelocityRenderDecorator

use of org.olat.core.gui.render.velocity.VelocityRenderDecorator in project openolat by klemens.

the class ExportBinderAsCPResource method renderVelocityContainer.

private String renderVelocityContainer(VelocityContainer mainVC) {
    StringOutput sb = new StringOutput(32000);
    URLBuilder ubu = new URLBuilder("auth", "1", "0");
    Renderer renderer = Renderer.getInstance(mainVC, translator, ubu, new RenderResult(), new EmptyGlobalSettings());
    VelocityRenderDecorator vrdec = new VelocityRenderDecorator(renderer, mainVC, sb);
    mainVC.contextPut("r", vrdec);
    renderer.render(sb, mainVC, null);
    return sb.toString();
}
Also used : Renderer(org.olat.core.gui.render.Renderer) RenderResult(org.olat.core.gui.render.RenderResult) StringOutput(org.olat.core.gui.render.StringOutput) URLBuilder(org.olat.core.gui.render.URLBuilder) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator)

Example 9 with VelocityRenderDecorator

use of org.olat.core.gui.render.velocity.VelocityRenderDecorator in project openolat by klemens.

the class CourseCreationConfiguration method getSinglePageText.

/**
 * @param translator
 * @return single page content
 */
public String getSinglePageText(Translator translator) {
    VelocityContainer vc = new VelocityContainer("singlePageTemplate", CourseCreationHelper.class, "singlePageTemplate", translator, null);
    vc.contextPut("coursetitle", courseTitle);
    // prepare rendering of velocity page for the content of the single page node
    GlobalSettings globalSettings = new GlobalSettings() {

        public int getFontSize() {
            return 100;
        }

        public AJAXFlags getAjaxFlags() {
            return new EmptyAJAXFlags();
        }

        public boolean isIdDivsForced() {
            return false;
        }
    };
    Context context = vc.getContext();
    Renderer fr = Renderer.getInstance(vc, translator, null, new RenderResult(), globalSettings);
    StringOutput wOut = new StringOutput(10000);
    VelocityRenderDecorator vrdec = new VelocityRenderDecorator(fr, vc, wOut);
    context.put("r", vrdec);
    VelocityHelper.getInstance().mergeContent(vc.getPage(), context, wOut, null);
    // free the decorator
    context.remove("r");
    IOUtils.closeQuietly(vrdec);
    return WysiwygFactory.createXHtmlFileContent(wOut.toString(), courseTitle);
}
Also used : Context(org.apache.velocity.context.Context) Renderer(org.olat.core.gui.render.Renderer) RenderResult(org.olat.core.gui.render.RenderResult) GlobalSettings(org.olat.core.gui.GlobalSettings) StringOutput(org.olat.core.gui.render.StringOutput) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator)

Example 10 with VelocityRenderDecorator

use of org.olat.core.gui.render.velocity.VelocityRenderDecorator in project openolat by klemens.

the class VelocityContainerRenderer method render.

/**
 * @see org.olat.core.gui.render.ui.ComponentRenderer#render(org.olat.core.gui.render.Renderer,
 *      org.olat.core.gui.render.StringOutput, org.olat.core.gui.components.Component,
 *      org.olat.core.gui.render.URLBuilder, org.olat.core.gui.translator.Translator,
 *      org.olat.core.gui.render.RenderResult, java.lang.String[])
 */
@Override
public void render(Renderer renderer, StringOutput target, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    VelocityContainer vc = (VelocityContainer) source;
    String pagePath = vc.getPage();
    Context ctx = vc.getContext();
    // the component id of the urlbuilder  will be overwritten by the recursive render call for
    // subcomponents (see Renderer)
    Renderer fr = Renderer.getInstance(vc, translator, ubu, renderResult, renderer.getGlobalSettings());
    VelocityRenderDecorator vrdec = new VelocityRenderDecorator(fr, vc, target);
    ctx.put("r", vrdec);
    VelocityHelper vh = VelocityHelper.getInstance();
    vh.mergeContent(pagePath, ctx, target, null);
    // free the decorator
    ctx.remove("r");
    IOUtils.closeQuietly(vrdec);
    // set all not rendered component as not dirty
    for (Component cmp : vc.getComponents()) {
        if (cmp.isDirty()) {
            cmp.setDirty(false);
        }
    }
}
Also used : Context(org.apache.velocity.context.Context) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Renderer(org.olat.core.gui.render.Renderer) VelocityHelper(org.olat.core.gui.render.velocity.VelocityHelper) Component(org.olat.core.gui.components.Component) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator)

Aggregations

Renderer (org.olat.core.gui.render.Renderer)10 VelocityRenderDecorator (org.olat.core.gui.render.velocity.VelocityRenderDecorator)10 RenderResult (org.olat.core.gui.render.RenderResult)8 StringOutput (org.olat.core.gui.render.StringOutput)8 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)6 URLBuilder (org.olat.core.gui.render.URLBuilder)6 Context (org.apache.velocity.context.Context)4 IOException (java.io.IOException)2 GlobalSettings (org.olat.core.gui.GlobalSettings)2 Component (org.olat.core.gui.components.Component)2 ComponentRenderer (org.olat.core.gui.components.ComponentRenderer)2 VelocityHelper (org.olat.core.gui.render.velocity.VelocityHelper)2