Search in sources :

Example 26 with Renderer

use of org.olat.core.gui.render.Renderer 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 27 with Renderer

use of org.olat.core.gui.render.Renderer 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 28 with Renderer

use of org.olat.core.gui.render.Renderer 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)

Example 29 with Renderer

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

the class InlineTranslationInterceptHandlerController method createInterceptComponentRenderer.

public ComponentRenderer createInterceptComponentRenderer(final ComponentRenderer originalRenderer) {
    return new ComponentRenderer() {

        @Override
        public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
            // ------------- show translator keys
            // we must let the original renderer do its work so that the
            // collecting translator is callbacked.
            // we save the result in a new var since it is too early to
            // append it
            // to the 'stream' right now.
            StringOutput sbOrig = new StringOutput();
            try {
                originalRenderer.render(renderer, sbOrig, source, ubu, translator, renderResult, args);
            } catch (Exception e) {
                String emsg = "exception while rendering component '" + source.getComponentName() + "' (" + source.getClass().getName() + ") " + source.getListenerInfo() + "<br />Message of exception: " + e.getMessage();
                sbOrig.append("<span style=\"color:red\">Exception</span><br /><pre>" + emsg + "</pre>");
            }
            String rendered = sbOrig.toString();
            String renderedWithHTMLMarkup = InlineTranslationInterceptHandlerController.replaceLocalizationMarkupWithHTML(rendered, inlineTranslationURLBuilder, getTranslator());
            sb.append(renderedWithHTMLMarkup);
        }

        /**
         * @see org.olat.core.gui.components.ComponentRenderer#renderHeaderIncludes(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.RenderingState)
         */
        @Override
        public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
            originalRenderer.renderHeaderIncludes(renderer, sb, source, ubu, translator, rstate);
        }

        /**
         * @see org.olat.core.gui.components.ComponentRenderer#renderBodyOnLoadJSFunctionCall(org.olat.core.gui.render.Renderer,
         *      org.olat.core.gui.render.StringOutput,
         *      org.olat.core.gui.components.Component,
         *      org.olat.core.gui.render.RenderingState)
         */
        @Override
        public void renderBodyOnLoadJSFunctionCall(Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
            originalRenderer.renderBodyOnLoadJSFunctionCall(renderer, sb, source, rstate);
        }
    };
}
Also used : ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Translator(org.olat.core.gui.translator.Translator) Renderer(org.olat.core.gui.render.Renderer) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) RenderResult(org.olat.core.gui.render.RenderResult) RenderingState(org.olat.core.gui.render.RenderingState) StringOutput(org.olat.core.gui.render.StringOutput) DelegatingComponent(org.olat.core.gui.components.delegating.DelegatingComponent) Component(org.olat.core.gui.components.Component) URLBuilder(org.olat.core.gui.render.URLBuilder)

Example 30 with Renderer

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

the class TextElementImpl method initInlineEditing.

private void initInlineEditing(String predefinedValue) {
    // init the inline editing element component.
    transientValue = predefinedValue;
    AbstractInlineElementComponent aiec = new AbstractInlineElementComponent(this, new ComponentRenderer() {

        public void renderHeaderIncludes(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderingState rstate) {
        // nothing to do here
        }

        public void renderBodyOnLoadJSFunctionCall(Renderer renderer, StringOutput sb, Component source, RenderingState rstate) {
        // nothing to do here
        }

        public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
            AbstractInlineElementComponent aiec = (AbstractInlineElementComponent) source;
            InlineTextElement itei = (InlineTextElement) aiec.getInlineElement();
            StringBuilder htmlVal = new StringBuilder();
            /**
             * in case of an error show the test which caused the error which must be stored by the textelement in the transientValue.
             * the last valid value is always set over setValue(..) by the textelement, and thus can be retrieved as such here.
             */
            String tmpVal;
            String emptyVal = (itei.isInlineEditingOn() ? "" : itei.getEmptyDisplayText());
            if (itei.hasError()) {
                tmpVal = StringHelper.containsNonWhitespace(transientValue) ? transientValue : emptyVal;
            } else {
                tmpVal = StringHelper.containsNonWhitespace(getValue()) ? getValue() : emptyVal;
            }
            // append the html safe value
            htmlVal.append(StringEscapeUtils.escapeHtml(tmpVal));
            if (!itei.isEnabled()) {
                // RO view and not clickable
                String id = aiec.getFormDispatchId();
                sb.append("<div class='form-control-static' id=\"").append(id).append("\" ").append(" >").append(htmlVal).append("</div>");
            } else {
                // .......presssing ESC -> restore previous value and submit this one.
                if (itei.isInlineEditingOn()) {
                    String id = aiec.getFormDispatchId();
                    // read write view
                    sb.append("<input type=\"").append("input").append("\" class=\"form-control\" id=\"");
                    sb.append(id);
                    sb.append("\" name=\"");
                    sb.append(id);
                    sb.append("\" size=\"");
                    sb.append("30");
                    // if(itei.maxlength > -1){
                    // sb.append("\" maxlength=\"");
                    // sb.append(itei.maxlength);
                    // }
                    sb.append("\" value=\"");
                    sb.append(htmlVal);
                    sb.append("\" ");
                    sb.append(" />");
                    // Javascript
                    sb.append(FormJSHelper.getJSStart());
                    // clicking outside or pressing enter -> OK, pressing ESC -> Cancel
                    FormJSHelper.getInlineEditOkCancelJS(sb, id, StringEscapeUtils.escapeHtml(getValue()), itei.getRootForm());
                    sb.append(FormJSHelper.getJSEnd());
                } else {
                    // RO<->RW view which can be clicked
                    Translator trans = Util.createPackageTranslator(TextElementImpl.class, translator.getLocale(), translator);
                    String id = aiec.getFormDispatchId();
                    sb.append("<div id='").append(id).append("' class='form-control-static' title=\"").append(StringEscapeUtils.escapeHtml(trans.translate("inline.edit.help"))).append("\" ").append(FormJSHelper.getRawJSFor(itei.getRootForm(), id, itei.getAction())).append("> ").append(htmlVal).append(" <i class='o_icon o_icon_inline_editable'> </i></div>");
                }
            }
        // endif
        }
    });
    setInlineEditingComponent(aiec);
}
Also used : RenderingState(org.olat.core.gui.render.RenderingState) RenderResult(org.olat.core.gui.render.RenderResult) StringOutput(org.olat.core.gui.render.StringOutput) URLBuilder(org.olat.core.gui.render.URLBuilder) InlineTextElement(org.olat.core.gui.components.form.flexible.elements.InlineTextElement) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Translator(org.olat.core.gui.translator.Translator) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Renderer(org.olat.core.gui.render.Renderer) Component(org.olat.core.gui.components.Component)

Aggregations

Renderer (org.olat.core.gui.render.Renderer)30 StringOutput (org.olat.core.gui.render.StringOutput)26 RenderResult (org.olat.core.gui.render.RenderResult)24 URLBuilder (org.olat.core.gui.render.URLBuilder)20 IOException (java.io.IOException)12 VelocityRenderDecorator (org.olat.core.gui.render.velocity.VelocityRenderDecorator)10 Component (org.olat.core.gui.components.Component)8 ComponentRenderer (org.olat.core.gui.components.ComponentRenderer)8 Translator (org.olat.core.gui.translator.Translator)8 ArrayList (java.util.ArrayList)6 Context (org.apache.velocity.context.Context)6 GlobalSettings (org.olat.core.gui.GlobalSettings)6 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)6 RenderingState (org.olat.core.gui.render.RenderingState)6 VelocityHelper (org.olat.core.gui.render.velocity.VelocityHelper)6 DefaultComponentRenderer (org.olat.core.gui.components.DefaultComponentRenderer)4 DelegatingComponent (org.olat.core.gui.components.delegating.DelegatingComponent)4 InvalidRequestParameterException (org.olat.core.gui.components.form.flexible.impl.InvalidRequestParameterException)4 Command (org.olat.core.gui.control.winmgr.Command)4 JSCommand (org.olat.core.gui.control.winmgr.JSCommand)4