Search in sources :

Example 26 with StringOutput

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

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 27 with StringOutput

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

the class GroupChoiceForm method downloadResults.

private void downloadResults(UserRequest ureq) {
    int cdcnt = manageTableData.getColumnCount();
    int rcnt = manageTableData.getRowCount();
    StringBuilder sb = new StringBuilder();
    boolean isAdministrativeUser = securityModule.isUserAllowedAdminProps(ureq.getUserSession().getRoles());
    List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(USER_PROPS_ID, isAdministrativeUser);
    // additional informations
    sb.append(translate("cl.course.title")).append('\t').append(course.getCourseTitle());
    sb.append('\n');
    String listTitle = checklist.getTitle() == null ? "" : checklist.getTitle();
    sb.append(translate("cl.title")).append('\t').append(listTitle);
    sb.append('\n').append('\n');
    // header
    for (int c = 0; c < (cdcnt - 1); c++) {
        // skip last column (action)
        ColumnDescriptor cd = manageChecklistTable.getColumnDescriptor(c);
        String headerKey = cd.getHeaderKey();
        String headerVal = cd.translateHeaderKey() ? translate(headerKey) : headerKey;
        sb.append('\t').append(headerVal);
    }
    sb.append('\n');
    // checkpoint description
    if (isAdministrativeUser) {
        sb.append('\t');
    }
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null)
            continue;
        sb.append('\t');
    }
    for (Checkpoint checkpoint : checklist.getCheckpoints()) {
        sb.append('\t').append(checkpoint.getDescription());
    }
    sb.append('\n');
    // data
    for (int r = 0; r < rcnt; r++) {
        for (int c = 0; c < (cdcnt - 1); c++) {
            // skip last column (action)
            ColumnDescriptor cd = manageChecklistTable.getColumnDescriptor(c);
            StringOutput so = new StringOutput();
            cd.renderValue(so, r, null);
            String cellValue = so.toString();
            cellValue = StringHelper.stripLineBreaks(cellValue);
            sb.append('\t').append(cellValue);
        }
        sb.append('\n');
    }
    String res = sb.toString();
    String charset = UserManager.getInstance().getUserCharset(ureq.getIdentity());
    ExcelMediaResource emr = new ExcelMediaResource(res, charset);
    ureq.getDispatchResult().setResultingMediaResource(emr);
}
Also used : DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor) StaticColumnDescriptor(org.olat.core.gui.components.table.StaticColumnDescriptor) ColumnDescriptor(org.olat.core.gui.components.table.ColumnDescriptor) StringOutput(org.olat.core.gui.render.StringOutput) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) ExcelMediaResource(org.olat.core.gui.media.ExcelMediaResource)

Example 28 with StringOutput

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

the class AuthHelper method doLogin.

/**
 * Used by DMZDispatcher to do regular logins and by ShibbolethDispatcher
 * which is somewhat special because logins are handled asynchronuous ->
 * therefore a dedicated dispatcher is needed which also has to have access to
 * the doLogin() method.
 *
 * @param identity
 * @param authProvider
 * @param ureq
 * @return True if success, false otherwise.
 */
public static int doLogin(Identity identity, String authProvider, UserRequest ureq) {
    int initializeStatus = initializeLogin(identity, authProvider, ureq, false);
    if (initializeStatus != LOGIN_OK) {
        // login not successfull
        return initializeStatus;
    }
    // do logging
    ThreadLocalUserActivityLogger.log(OlatLoggingAction.OLAT_LOGIN, AuthHelper.class, LoggingResourceable.wrap(identity));
    // brasato:: fix it
    // successfull login, reregister window
    ChiefController occ;
    if (ureq.getUserSession().getRoles().isGuestOnly()) {
        occ = createGuestHome(ureq);
    } else {
        occ = createAuthHome(ureq);
    }
    Window currentWindow = occ.getWindow();
    currentWindow.setUriPrefix(WebappHelper.getServletContextPath() + DispatcherModule.PATH_AUTHENTICATED);
    Windows.getWindows(ureq).registerWindow(currentWindow);
    RedirectMediaResource redirect;
    String redirectTo = (String) ureq.getUserSession().getEntry("redirect-bc");
    if (StringHelper.containsNonWhitespace(redirectTo)) {
        String url = WebappHelper.getServletContextPath() + DispatcherModule.PATH_AUTHENTICATED + redirectTo;
        redirect = new RedirectMediaResource(url);
    } else {
        // redirect to AuthenticatedDispatcher
        // IMPORTANT: windowID has changed due to re-registering current window -> do not use ureq.getWindowID() to build new URLBuilder.
        URLBuilder ubu = new URLBuilder(WebappHelper.getServletContextPath() + DispatcherModule.PATH_AUTHENTICATED, currentWindow.getInstanceId(), "1");
        StringOutput sout = new StringOutput(30);
        ubu.buildURI(sout, null, null);
        redirect = new RedirectMediaResource(sout.toString());
    }
    ureq.getDispatchResult().setResultingMediaResource(redirect);
    return LOGIN_OK;
}
Also used : Window(org.olat.core.gui.components.Window) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) StringOutput(org.olat.core.gui.render.StringOutput) ChiefController(org.olat.core.gui.control.ChiefController) URLBuilder(org.olat.core.gui.render.URLBuilder)

Example 29 with StringOutput

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

the class AssessmentHtmlBuilderTest method filter.

@Test
public void filter() throws IOException {
    String content = "<html><p>Test \u00EA<strong><span><img src='img.jpg'></span></strong></p><p>Test 2</p></html>";
    AssessmentItem item = new AssessmentItem();
    ItemBody helper = new ItemBody(item);
    new AssessmentHtmlBuilder().appendHtml(helper, content);
    List<Block> paragraphs = helper.getBlocks();
    Assert.assertNotNull(paragraphs);
    Assert.assertEquals(2, paragraphs.size());
    // The serializer can throw some exceptions if it doens't like the model
    // we want to serialize.
    StringOutput sb = new StringOutput();
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    qtiSerializer.serializeJqtiObject(helper, new StreamResult(sb));
    String serializedQti = sb.toString();
    Assert.assertTrue(serializedQti.contains("img.jpg"));
    sb.close();
}
Also used : ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StreamResult(javax.xml.transform.stream.StreamResult) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) StringOutput(org.olat.core.gui.render.StringOutput) Test(org.junit.Test)

Example 30 with StringOutput

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

the class AssessmentHtmlBuilderTest method serializeVideo.

@Test
public void serializeVideo() throws IOException {
    String content = "<p><span id=\"olatFlashMovieViewer213060\" class=\"olatFlashMovieViewer\" style=\"display:block;border:solid 1px #000; width:320px; height:240px;\">\n" + "<script src=\"/raw/fx-111111x11/movie/player.js\" type=\"text/javascript\"></script>\n" + "<script type=\"text/javascript\" defer=\"defer\">// <![CDATA[\n" + "BPlayer.insertPlayer(\"demo-video.mp4\",\"olatFlashMovieViewer213060\",320,240,0,0,\"video\",undefined,false,false,true,undefined);\n" + "// ]]></script>\n" + "</span></p>";
    AssessmentItem item = new AssessmentItem();
    ItemBody helper = new ItemBody(item);
    new AssessmentHtmlBuilder().appendHtml(helper, content);
    List<Block> paragraphs = helper.getBlocks();
    Assert.assertNotNull(paragraphs);
    Assert.assertEquals(1, paragraphs.size());
    StringOutput sb = new StringOutput();
    QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
    qtiSerializer.serializeJqtiObject(helper, new StreamResult(sb));
    String serializedQti = sb.toString();
    Assert.assertNotNull(serializedQti);
    Assert.assertTrue(serializedQti.contains("object"));
    Assert.assertFalse(serializedQti.contains("span"));
    Assert.assertFalse(serializedQti.contains("script"));
    sb.close();
}
Also used : ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StreamResult(javax.xml.transform.stream.StreamResult) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) StringOutput(org.olat.core.gui.render.StringOutput) Test(org.junit.Test)

Aggregations

StringOutput (org.olat.core.gui.render.StringOutput)188 IOException (java.io.IOException)48 URLBuilder (org.olat.core.gui.render.URLBuilder)30 Renderer (org.olat.core.gui.render.Renderer)26 Block (uk.ac.ed.ph.jqtiplus.node.content.basic.Block)24 RenderResult (org.olat.core.gui.render.RenderResult)22 Component (org.olat.core.gui.components.Component)10 Translator (org.olat.core.gui.translator.Translator)10 Locale (java.util.Locale)8 Window (org.olat.core.gui.components.Window)8 Form (org.olat.core.gui.components.form.flexible.impl.Form)8 VelocityRenderDecorator (org.olat.core.gui.render.velocity.VelocityRenderDecorator)8 ArrayList (java.util.ArrayList)6 StreamResult (javax.xml.transform.stream.StreamResult)6 Test (org.junit.Test)6 GlobalSettings (org.olat.core.gui.GlobalSettings)6 ComponentRenderer (org.olat.core.gui.components.ComponentRenderer)6 DefaultColumnDescriptor (org.olat.core.gui.components.table.DefaultColumnDescriptor)6 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)6 Matcher (java.util.regex.Matcher)5