use of org.apache.wiki.parser.MarkupParser in project jspwiki by apache.
the class CounterPluginTest method translate.
private String translate(String src) throws IOException, NoRequiredPropertyException, ServletException {
WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, "TestPage"));
MarkupParser p = new JSPWikiMarkupParser(context, new StringReader(src));
WikiDocument dom = p.parse();
WikiRenderer r = new XHTMLRenderer(context, dom);
return r.getString();
}
use of org.apache.wiki.parser.MarkupParser in project jspwiki by apache.
the class AuthorTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException {
WikiEngine engine = m_wikiContext.getEngine();
WikiPage page = m_wikiContext.getPage();
String author = page.getAuthor();
if (author != null && author.length() > 0) {
author = TextUtil.replaceEntities(author);
if (engine.pageExists(author)) {
// FIXME: It's very boring to have to do this.
// Slow, too.
RenderingManager mgr = engine.getRenderingManager();
MarkupParser p = mgr.getParser(m_wikiContext, "[" + author + "|" + author + "]");
WikiDocument d = p.parse();
author = mgr.getHTML(m_wikiContext, d);
}
pageContext.getOut().print(author);
} else {
pageContext.getOut().print(Preferences.getBundle(m_wikiContext, InternationalizationManager.CORE_BUNDLE).getString("common.unknownauthor"));
}
return SKIP_BODY;
}
use of org.apache.wiki.parser.MarkupParser in project jspwiki by apache.
the class WikiEngine method textToHTML.
/**
* Helper method for doing the HTML translation.
*
* @param context The WikiContext in which to do the conversion
* @param pagedata The data to render
* @param localLinkHook Is called whenever a wiki link is found
* @param extLinkHook Is called whenever an external link is found
* @param parseAccessRules Parse the access rules if we encounter them
* @param justParse Just parses the pagedata, does not actually render. In this case,
* this methods an empty string.
* @return HTML-rendered page text.
*/
private String textToHTML(WikiContext context, String pagedata, StringTransmutator localLinkHook, StringTransmutator extLinkHook, StringTransmutator attLinkHook, boolean parseAccessRules, boolean justParse) {
String result = "";
if (pagedata == null) {
log.error("NULL pagedata to textToHTML()");
return null;
}
boolean runFilters = "true".equals(m_variableManager.getValue(context, PROP_RUNFILTERS, "true"));
try {
StopWatch sw = new StopWatch();
sw.start();
if (runFilters && m_filterManager != null)
pagedata = m_filterManager.doPreTranslateFiltering(context, pagedata);
MarkupParser mp = m_renderingManager.getParser(context, pagedata);
mp.addLocalLinkHook(localLinkHook);
mp.addExternalLinkHook(extLinkHook);
mp.addAttachmentLinkHook(attLinkHook);
if (!parseAccessRules)
mp.disableAccessRules();
WikiDocument doc = mp.parse();
//
if (!justParse) {
result = m_renderingManager.getHTML(context, doc);
if (runFilters && m_filterManager != null)
result = m_filterManager.doPostTranslateFiltering(context, result);
}
sw.stop();
if (log.isDebugEnabled())
log.debug("Page " + context.getRealPage().getName() + " rendered, took " + sw);
} catch (IOException e) {
log.error("Failed to scan page data: ", e);
} catch (FilterException e) {
log.error("page filter threw exception: ", e);
// FIXME: Don't yet know what to do
}
return result;
}
Aggregations