Search in sources :

Example 1 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 2 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)

Example 3 with StringOutput

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

the class WikiMarkupRenderer method render.

/**
 * @see org.olat.core.gui.components.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 sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    WikiMarkupComponent wikiComp = (WikiMarkupComponent) source;
    AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
    boolean iframePostEnabled = flags.isIframePostEnabled();
    ParserInput input = new ParserInput();
    input.setWikiUser(null);
    input.setAllowSectionEdit(false);
    input.setDepth(10);
    input.setContext("");
    // input.setTableOfContents(null);
    input.setLocale(new Locale("en"));
    // input.setVirtualWiki(Long.toString(wikiComp.getOres().getResourceableId()));
    input.setTopicName("dummy");
    input.setUserIpAddress("0.0.0.0");
    OlatWikiDataHandler dataHandler = new OlatWikiDataHandler(wikiComp.getOres(), wikiComp.getImageBaseUri());
    input.setDataHandler(dataHandler);
    StringOutput out = new StringOutput(100);
    ubu.buildURI(out, null, null, iframePostEnabled ? AJAXFlags.MODE_TOBGIFRAME : AJAXFlags.MODE_NORMAL);
    String uri = out.toString();
    ParserDocument parsedDoc = null;
    String uniqueId = "o_wiki".concat(wikiComp.getDispatchID());
    try {
        uri = URLDecoder.decode(uri, "utf-8");
        input.setVirtualWiki(uri.substring(1, uri.length() - 1));
        if (iframePostEnabled) {
            String targetUrl = " onclick=\"o_XHREvent(jQuery(this).attr('href'),false,true); return false;\"";
            input.setURLTarget(targetUrl);
        }
        sb.append("<div style=\"min-height:" + wikiComp.getMinHeight() + "px\" id=\"");
        sb.append(uniqueId);
        sb.append("\">");
        JFlexParser parser = new JFlexParser(input);
        parsedDoc = parser.parseHTML(wikiComp.getWikiContent());
    } catch (UnsupportedEncodingException e) {
    // encoding utf-8 should be ok
    } catch (Exception e) {
        throw new OLATRuntimeException(this.getClass(), "error while rendering wiki page with content:" + wikiComp.getWikiContent(), e);
    }
    // Use global js math formatter for latex formulas
    sb.append(Formatter.formatLatexFormulas(parsedDoc.getContent()));
    sb.append("</div>");
    // set targets of media, image and external links to target "_blank"
    sb.append("<script type=\"text/javascript\">/* <![CDATA[ */ ");
    String instanceUrl = Settings.getServerContextPathURI();
    sb.append("changeAnchorTargets('").append(uniqueId).append("','").append(instanceUrl).append("');");
    sb.append("/* ]]> */</script>");
}
Also used : Locale(java.util.Locale) JFlexParser(org.jamwiki.parser.jflex.JFlexParser) AJAXFlags(org.olat.core.gui.control.winmgr.AJAXFlags) ParserInput(org.jamwiki.parser.ParserInput) UnsupportedEncodingException(java.io.UnsupportedEncodingException) StringOutput(org.olat.core.gui.render.StringOutput) ParserDocument(org.jamwiki.parser.ParserDocument) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 4 with StringOutput

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

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

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

the class ExportBinderAsPDFResource method createResultHTML.

private String createResultHTML(Component content) {
    String pagePath = Util.getPackageVelocityRoot(this.getClass()) + "/export.html";
    VelocityContainer mainVC = new VelocityContainer("html", pagePath, translator, null);
    mainVC.put("cmp", content);
    mainVC.contextPut("bodyCssClass", "o_portfolio_export");
    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) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer) URLBuilder(org.olat.core.gui.render.URLBuilder) VelocityRenderDecorator(org.olat.core.gui.render.velocity.VelocityRenderDecorator)

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