Search in sources :

Example 1 with WikiDocument

use of org.apache.wiki.parser.WikiDocument in project jspwiki by apache.

the class AbstractReferralPlugin method makeHTML.

/**
 *  Makes HTML with common parameters.
 *
 *  @param context The WikiContext
 *  @param wikitext The wikitext to render
 *  @return HTML
 *  @since 1.6.4
 */
protected String makeHTML(WikiContext context, String wikitext) {
    String result = "";
    RenderingManager mgr = m_engine.getRenderingManager();
    try {
        MarkupParser parser = mgr.getParser(context, wikitext);
        parser.addLinkTransmutator(new CutMutator(m_maxwidth));
        parser.enableImageInlining(false);
        WikiDocument doc = parser.parse();
        result = mgr.getHTML(context, doc);
    } catch (IOException e) {
        log.error("Failed to convert page data to HTML", e);
    }
    return result;
}
Also used : RenderingManager(org.apache.wiki.render.RenderingManager) IOException(java.io.IOException) WikiDocument(org.apache.wiki.parser.WikiDocument) MarkupParser(org.apache.wiki.parser.MarkupParser)

Example 2 with WikiDocument

use of org.apache.wiki.parser.WikiDocument in project jspwiki by apache.

the class RenderingManager method getRenderedDocument.

/**
 *  Returns a cached document, if one is found.
 *
 * @param context the wiki context
 * @param pagedata the page data
 * @return the rendered wiki document
 * @throws IOException If rendering cannot be accomplished
 */
// FIXME: The cache management policy is not very good: deleted/changed pages should be detected better.
protected WikiDocument getRenderedDocument(WikiContext context, String pagedata) throws IOException {
    String pageid = context.getRealPage().getName() + VERSION_DELIMITER + context.getRealPage().getVersion() + VERSION_DELIMITER + context.getVariable(RenderingManager.VAR_EXECUTE_PLUGINS);
    if (useCache(context)) {
        Element element = m_documentCache.get(pageid);
        if (element != null) {
            WikiDocument doc = (WikiDocument) element.getObjectValue();
            // FIXME: Figure out a faster method
            if (pagedata.equals(doc.getPageData())) {
                if (log.isDebugEnabled()) {
                    log.debug("Using cached HTML for page " + pageid);
                }
                return doc;
            }
        } else if (log.isDebugEnabled()) {
            log.debug("Re-rendering and storing " + pageid);
        }
    }
    // 
    try {
        MarkupParser parser = getParser(context, pagedata);
        WikiDocument doc = parser.parse();
        doc.setPageData(pagedata);
        if (useCache(context)) {
            m_documentCache.put(new Element(pageid, doc));
        }
        return doc;
    } catch (IOException ex) {
        log.error("Unable to parse", ex);
    }
    return null;
}
Also used : Element(net.sf.ehcache.Element) IOException(java.io.IOException) WikiDocument(org.apache.wiki.parser.WikiDocument) MarkupParser(org.apache.wiki.parser.MarkupParser) JSPWikiMarkupParser(org.apache.wiki.parser.JSPWikiMarkupParser)

Example 3 with WikiDocument

use of org.apache.wiki.parser.WikiDocument in project jspwiki by apache.

the class CreoleRendererTest method render.

private String render(String s) throws IOException {
    WikiPage dummyPage = new WikiPage(m_testEngine, "TestPage");
    WikiContext ctx = new WikiContext(m_testEngine, dummyPage);
    StringReader in = new StringReader(s);
    JSPWikiMarkupParser p = new JSPWikiMarkupParser(ctx, in);
    WikiDocument d = p.parse();
    CreoleRenderer cr = new CreoleRenderer(ctx, d);
    return cr.getString();
}
Also used : WikiContext(org.apache.wiki.WikiContext) JSPWikiMarkupParser(org.apache.wiki.parser.JSPWikiMarkupParser) WikiPage(org.apache.wiki.WikiPage) StringReader(java.io.StringReader) WikiDocument(org.apache.wiki.parser.WikiDocument)

Example 4 with WikiDocument

use of org.apache.wiki.parser.WikiDocument in project jspwiki by apache.

the class RenderingManagerTest method testCache.

/**
 * Tests the relative speed of the DOM cache with respect to
 * page being parsed every single time.
 * @throws Exception
 */
@Test
public void testCache() throws Exception {
    m_engine.saveText("TestPage", TEST_TEXT);
    StopWatch sw = new StopWatch();
    // System.out.println("DOM cache speed test:");
    sw.start();
    for (int i = 0; i < 300; i++) {
        WikiPage page = m_engine.getPage("TestPage");
        String pagedata = m_engine.getPureText(page);
        WikiContext context = new WikiContext(m_engine, page);
        MarkupParser p = m_manager.getParser(context, pagedata);
        WikiDocument d = p.parse();
        String html = m_manager.getHTML(context, d);
        Assert.assertNotNull("noncached got null response", html);
    }
    sw.stop();
    // System.out.println("  Nocache took "+sw);
    long nocachetime = sw.getTime();
    sw.reset();
    sw.start();
    for (int i = 0; i < 300; i++) {
        WikiPage page = m_engine.getPage("TestPage");
        String pagedata = m_engine.getPureText(page);
        WikiContext context = new WikiContext(m_engine, page);
        String html = m_manager.getHTML(context, pagedata);
        Assert.assertNotNull("cached got null response", html);
    }
    sw.stop();
    // System.out.println("  Cache took "+sw);
    long speedup = nocachetime / sw.getTime();
// System.out.println("  Approx speedup: "+speedup+"x");
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) WikiDocument(org.apache.wiki.parser.WikiDocument) StopWatch(org.apache.commons.lang.time.StopWatch) MarkupParser(org.apache.wiki.parser.MarkupParser) Test(org.junit.Test)

Example 5 with WikiDocument

use of org.apache.wiki.parser.WikiDocument in project jspwiki by apache.

the class WysiwygEditingRendererTest method render.

private String render(String s) throws IOException {
    WikiPage dummyPage = new WikiPage(testEngine, "TestPage");
    WikiContext ctx = new WikiContext(testEngine, dummyPage);
    StringReader in = new StringReader(s);
    JSPWikiMarkupParser p = new JSPWikiMarkupParser(ctx, in);
    WikiDocument d = p.parse();
    WysiwygEditingRenderer wer = new WysiwygEditingRenderer(ctx, d);
    return wer.getString();
}
Also used : WikiContext(org.apache.wiki.WikiContext) JSPWikiMarkupParser(org.apache.wiki.parser.JSPWikiMarkupParser) WikiPage(org.apache.wiki.WikiPage) StringReader(java.io.StringReader) WikiDocument(org.apache.wiki.parser.WikiDocument)

Aggregations

WikiDocument (org.apache.wiki.parser.WikiDocument)9 MarkupParser (org.apache.wiki.parser.MarkupParser)6 WikiPage (org.apache.wiki.WikiPage)5 IOException (java.io.IOException)4 WikiContext (org.apache.wiki.WikiContext)4 JSPWikiMarkupParser (org.apache.wiki.parser.JSPWikiMarkupParser)4 StringReader (java.io.StringReader)3 RenderingManager (org.apache.wiki.render.RenderingManager)3 StopWatch (org.apache.commons.lang.time.StopWatch)2 Element (net.sf.ehcache.Element)1 WikiEngine (org.apache.wiki.WikiEngine)1 FilterException (org.apache.wiki.api.exceptions.FilterException)1 WikiRenderer (org.apache.wiki.render.WikiRenderer)1 XHTMLRenderer (org.apache.wiki.render.XHTMLRenderer)1 Test (org.junit.Test)1