Search in sources :

Example 6 with GlobalSettings

use of org.olat.core.gui.GlobalSettings 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 GlobalSettings

use of org.olat.core.gui.GlobalSettings 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 8 with GlobalSettings

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

the class Renderer method render.

/**
 * used by the renderer, and also by the panel and tabbedpane renderer to delegate rendering
 * @param sb
 * @param source
 * @param args
 */
public void render(StringOutput sb, Component source, String[] args) {
    GlobalSettings gset = getGlobalSettings();
    boolean ajaxon = gset.getAjaxFlags().isIframePostEnabled();
    // wrap with div's so javascript can replace this component by doing a document.getElementById(cid).innerHTML and so on.
    boolean domReplaceable = source.isDomReplaceable();
    boolean useSpan = source.getSpanAsDomReplaceable();
    boolean domReplacementWrapperRequired = source.isDomReplacementWrapperRequired();
    boolean forceDebugDivs = gset.isIdDivsForced();
    if (source.isVisible()) {
        int lev = renderResult.getNestedLevel();
        if (lev > 60)
            throw new AssertException("components were nested more than 60 times, assuming endless loop bug: latest comp name: " + source.getComponentName());
        Translator componentTranslator = source.getTranslator();
        // identifier for dom replacement
        if (domReplaceable && domReplacementWrapperRequired && (ajaxon || forceDebugDivs)) {
            if (useSpan) {
                sb.append("<span id='o_c").append(source.getDispatchID());
            } else {
                sb.append("<div id='o_c").append(source.getDispatchID());
            }
            if (Settings.isDebuging()) {
            // sb.append("' title='").append(source.getComponentName());
            }
            sb.append("'>");
        }
        ComponentRenderer cr = findComponentRenderer(source);
        URLBuilder cubu = urlBuilder.createCopyFor(source);
        renderResult.incNestedLevel();
        // ---- for gui debug mode, direct the rendering to a special componentrenderer
        InterceptHandlerInstance dhi = renderResult.getInterceptHandlerInstance();
        if (dhi != null) {
            cr = dhi.createInterceptComponentRenderer(cr);
        }
        try {
            int preRenderLength = sb.length();
            cr.render(this, sb, source, cubu, componentTranslator, renderResult, args);
            if (preRenderLength == sb.length()) {
                // Add bugfix for IE min-height on empty div problem: min-height does
                // not get applied when div contains an empty comment.
                // Affects IE6, IE7
                sb.append("<!-- empty -->");
            }
            source.setDirty(false);
        } catch (Exception e) {
            // in order to produce a decent error msg, we need to postpone the
            // exception
            renderResult.setRenderExceptionInfo("exception while rendering component '" + source.getComponentName() + "' (" + source.getClass().getName() + ") " + source.getListenerInfo() + "<br />Message of exception: " + e.getMessage(), e);
        }
        renderResult.decNestedLevel();
        if (ajaxon && domReplaceable && domReplacementWrapperRequired) {
            if (useSpan) {
                sb.append("</span>");
            } else {
                sb.append("</div>");
            }
        }
    } else {
        // not visible
        if (domReplaceable && (ajaxon || forceDebugDivs)) {
            // browser dom tree
            if (useSpan) {
                sb.append("<span id=\"o_c").append(source.getDispatchID()).append("\"></span>");
            } else {
                // Add bugfix for IE min-height on empty div problem: min-height does
                // not get applied when div contains an empty comment.
                // Affects IE6, IE7
                sb.append("<div id=\"o_c").append(source.getDispatchID()).append("\"><!-- empty --></div>");
            }
        }
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) ComponentRenderer(org.olat.core.gui.components.ComponentRenderer) Translator(org.olat.core.gui.translator.Translator) GlobalSettings(org.olat.core.gui.GlobalSettings) InterceptHandlerInstance(org.olat.core.gui.render.intercept.InterceptHandlerInstance) AssertException(org.olat.core.logging.AssertException)

Aggregations

GlobalSettings (org.olat.core.gui.GlobalSettings)8 RenderResult (org.olat.core.gui.render.RenderResult)6 Renderer (org.olat.core.gui.render.Renderer)6 StringOutput (org.olat.core.gui.render.StringOutput)6 InterceptHandlerInstance (org.olat.core.gui.render.intercept.InterceptHandlerInstance)6 AssertException (org.olat.core.logging.AssertException)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)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 AsyncMediaResponsible (org.olat.core.gui.media.AsyncMediaResponsible)4 URLBuilder (org.olat.core.gui.render.URLBuilder)4 InterceptHandler (org.olat.core.gui.render.intercept.InterceptHandler)4 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)4 ComponentTraverser (org.olat.core.util.component.ComponentTraverser)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Context (org.apache.velocity.context.Context)2 JSONArray (org.json.JSONArray)2