Search in sources :

Example 6 with WikiDocument

use of org.apache.wiki.parser.WikiDocument 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();
}
Also used : WikiContext(org.apache.wiki.WikiContext) JSPWikiMarkupParser(org.apache.wiki.parser.JSPWikiMarkupParser) WikiPage(org.apache.wiki.WikiPage) StringReader(java.io.StringReader) WikiRenderer(org.apache.wiki.render.WikiRenderer) XHTMLRenderer(org.apache.wiki.render.XHTMLRenderer) WikiDocument(org.apache.wiki.parser.WikiDocument) MarkupParser(org.apache.wiki.parser.MarkupParser) JSPWikiMarkupParser(org.apache.wiki.parser.JSPWikiMarkupParser)

Example 7 with WikiDocument

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

the class WikiFormAdminBean method doGet.

public String doGet(WikiContext context) {
    String result = "";
    String wikiMarkup = getForm(context);
    RenderingManager mgr = context.getEngine().getRenderingManager();
    WikiDocument doc;
    try {
        doc = mgr.getParser(context, wikiMarkup).parse();
        result = mgr.getHTML(context, doc);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}
Also used : RenderingManager(org.apache.wiki.render.RenderingManager) IOException(java.io.IOException) WikiDocument(org.apache.wiki.parser.WikiDocument)

Example 8 with WikiDocument

use of org.apache.wiki.parser.WikiDocument 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;
}
Also used : RenderingManager(org.apache.wiki.render.RenderingManager) WikiPage(org.apache.wiki.WikiPage) WikiDocument(org.apache.wiki.parser.WikiDocument) WikiEngine(org.apache.wiki.WikiEngine) MarkupParser(org.apache.wiki.parser.MarkupParser)

Example 9 with WikiDocument

use of org.apache.wiki.parser.WikiDocument 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;
}
Also used : FilterException(org.apache.wiki.api.exceptions.FilterException) IOException(java.io.IOException) WikiDocument(org.apache.wiki.parser.WikiDocument) StopWatch(org.apache.commons.lang.time.StopWatch) MarkupParser(org.apache.wiki.parser.MarkupParser)

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