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;
}
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;
}
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();
}
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");
}
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();
}
Aggregations