Search in sources :

Example 1 with ParserDocument

use of org.jamwiki.parser.ParserDocument in project OpenOLAT by OpenOLAT.

the class WikiPageDocument method getContent.

private static String getContent(WikiPage wikiPage) {
    try {
        ParserInput input = new ParserInput();
        input.setWikiUser(null);
        input.setAllowSectionEdit(false);
        input.setDepth(2);
        input.setContext("");
        input.setLocale(Locale.ENGLISH);
        input.setTopicName("dummy");
        input.setUserIpAddress("0.0.0.0");
        input.setDataHandler(DUMMY_DATA_HANDLER);
        input.setVirtualWiki("/olat");
        AbstractParser parser = new JFlexParser(input);
        ParserDocument parsedDoc = parser.parseHTML(wikiPage.getContent());
        String parsedContent = parsedDoc.getContent();
        String filteredContent = FilterFactory.getHtmlTagAndDescapingFilter().filter(parsedContent);
        return filteredContent;
    } catch (Exception e) {
        log.error("", e);
        return wikiPage.getContent();
    }
}
Also used : JFlexParser(org.jamwiki.parser.jflex.JFlexParser) AbstractParser(org.jamwiki.parser.AbstractParser) ParserInput(org.jamwiki.parser.ParserInput) ParserDocument(org.jamwiki.parser.ParserDocument)

Example 2 with ParserDocument

use of org.jamwiki.parser.ParserDocument in project OpenOLAT by OpenOLAT.

the class WikiToCPExport method wikiPageToHtml.

protected String wikiPageToHtml(WikiPage page) {
    StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    sb.append("<head>\n");
    sb.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n");
    sb.append("<style type=\"text/css\">img {float:right;padding:10px;}</style>\n");
    // sb.append("<script type=\"text/javascript\" src=\"cp_offline_menu_mat/jsMath/easy/load.js\"></script>\n");
    sb.append("<script type=\"text/javascript\" src=\"cp_offline_menu_mat/wiki.js\"></script>\n");
    sb.append("<script type=\"text/javascript\" src=\"mapping.js\"></script>\n");
    sb.append("<link rel=\"StyleSheet\" href=\"cp_offline_menu_mat/wiki.css\" type=\"text/css\" media=\"screen, print\">\n");
    sb.append("</head>\n");
    sb.append("<body>\n");
    sb.append("<h3>").append(getTranslatedWikiPageName(page)).append("</h3>");
    sb.append("<hr><div id=\"olat-wiki\">");
    try {
        ParserDocument doc = parser.parseHTML(page.getContent());
        sb.append(doc.getContent());
    } catch (Exception e) {
        throw new OLATRuntimeException("error while parsing from wiki to CP. ores:" + ores.getResourceableId(), e);
    }
    sb.append("</div></body></html>");
    return sb.toString();
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) ParserDocument(org.jamwiki.parser.ParserDocument) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 3 with ParserDocument

use of org.jamwiki.parser.ParserDocument 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 ParserDocument

use of org.jamwiki.parser.ParserDocument in project openolat by klemens.

the class WikiPageDocument method getContent.

private static String getContent(WikiPage wikiPage) {
    try {
        ParserInput input = new ParserInput();
        input.setWikiUser(null);
        input.setAllowSectionEdit(false);
        input.setDepth(2);
        input.setContext("");
        input.setLocale(Locale.ENGLISH);
        input.setTopicName("dummy");
        input.setUserIpAddress("0.0.0.0");
        input.setDataHandler(DUMMY_DATA_HANDLER);
        input.setVirtualWiki("/olat");
        AbstractParser parser = new JFlexParser(input);
        ParserDocument parsedDoc = parser.parseHTML(wikiPage.getContent());
        String parsedContent = parsedDoc.getContent();
        String filteredContent = FilterFactory.getHtmlTagAndDescapingFilter().filter(parsedContent);
        return filteredContent;
    } catch (Exception e) {
        log.error("", e);
        return wikiPage.getContent();
    }
}
Also used : JFlexParser(org.jamwiki.parser.jflex.JFlexParser) AbstractParser(org.jamwiki.parser.AbstractParser) ParserInput(org.jamwiki.parser.ParserInput) ParserDocument(org.jamwiki.parser.ParserDocument)

Example 5 with ParserDocument

use of org.jamwiki.parser.ParserDocument in project openolat by klemens.

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)

Aggregations

ParserDocument (org.jamwiki.parser.ParserDocument)10 ParserInput (org.jamwiki.parser.ParserInput)8 JFlexParser (org.jamwiki.parser.jflex.JFlexParser)8 AbstractParser (org.jamwiki.parser.AbstractParser)6 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Locale (java.util.Locale)2 AJAXFlags (org.olat.core.gui.control.winmgr.AJAXFlags)2 StringOutput (org.olat.core.gui.render.StringOutput)2