Search in sources :

Example 21 with DefaultWikiPrinter

use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.

the class CacheMacro method execute.

@Override
public List<Block> execute(CacheMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
    // Idea for improvement: use context.getId() (which contains the document name) as part of the cache key to
    // make it even more unique (when the cache macro parameter id is not specified).
    String cacheKey;
    if (parameters.getId() != null) {
        // Consider that the id contains wiki syntax and parse it with the same wiki parser than the current
        // transformation is using and render the result as plain text.
        WikiPrinter printer = new DefaultWikiPrinter();
        this.plainTextBlockRenderer.render(this.contentParser.parse(parameters.getId(), context, true, false), printer);
        cacheKey = printer.toString();
    } else {
        cacheKey = content;
    }
    Cache<List<Block>> contentCache = getContentCache(parameters.getTimeToLive(), parameters.getMaxEntries());
    List<Block> result = contentCache.get(cacheKey);
    if (result == null) {
        // Run the parser for the syntax on the content
        // We run the current transformation on the cache macro content. We need to do this since we want to cache
        // the XDOM resulting from the execution of Macros because that's where lengthy processing happens.
        result = this.contentParser.parse(content, context, true, context.isInline()).getChildren();
        contentCache.set(cacheKey, result);
    }
    return result;
}
Also used : DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) Block(org.xwiki.rendering.block.Block) List(java.util.List) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)

Example 22 with DefaultWikiPrinter

use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.

the class ExpandedMacroBlock method getContent.

@Override
public String getContent() {
    // Keep the macro content synchronized with the child blocks.
    WikiPrinter printer = new DefaultWikiPrinter();
    XDOM xdom;
    // We need the begin/endDocument events so we wrap the child blocks in a XDOM block.
    if (getChildren().size() == 1 && getChildren().get(0) instanceof XDOM) {
        xdom = (XDOM) getChildren().get(0);
    } else {
        xdom = new XDOM(getChildren());
    }
    getContentRenderer().render(xdom, printer);
    return printer.toString();
}
Also used : DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)

Example 23 with DefaultWikiPrinter

use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.

the class AbstractTableBlockDataSource method cellContentAsString.

/**
 * Renders the cell content as a string.
 *
 * @param cell the {@link TableCellBlock}.
 * @return cell content rendered as a string.
 */
private String cellContentAsString(TableCellBlock cell) {
    WikiPrinter printer = new DefaultWikiPrinter();
    this.plainTextBlockRenderer.render(cell.getChildren(), printer);
    return printer.toString();
}
Also used : DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)

Example 24 with DefaultWikiPrinter

use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.

the class DistributionInternalScriptService method renderCurrentStepToXHTML.

public String renderCurrentStepToXHTML(String transformationId) {
    DistributionJob job = this.distributionManager.getCurrentDistributionJob();
    if (job != null) {
        JobStatus jobStatus = job.getStatus();
        if (jobStatus != null) {
            State jobState = jobStatus.getState();
            if (jobState == State.RUNNING || jobState == State.WAITING) {
                Block block = job.getCurrentStep().executeInteractive();
                WikiPrinter printer = new DefaultWikiPrinter();
                this.xhtmlRenderer.render(block, printer);
                return printer.toString();
            }
        }
    }
    return null;
}
Also used : JobStatus(org.xwiki.job.event.status.JobStatus) DistributionJobStatus(org.xwiki.extension.distribution.internal.job.DistributionJobStatus) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) DistributionJob(org.xwiki.extension.distribution.internal.job.DistributionJob) DistributionState(org.xwiki.extension.distribution.internal.DistributionManager.DistributionState) State(org.xwiki.job.event.status.JobStatus.State) Block(org.xwiki.rendering.block.Block) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)

Example 25 with DefaultWikiPrinter

use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.

the class EmailTemplateRenderer method renderHTML.

/**
 * Render a block to HTML syntax.
 * @param block block to render
 * @return the HTML rendered version of the block
 */
public String renderHTML(Block block) {
    WikiPrinter printer = new DefaultWikiPrinter();
    htmlBlockRenderer.render(block, printer);
    return printer.toString();
}
Also used : DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) DefaultWikiPrinter(org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)

Aggregations

DefaultWikiPrinter (org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)41 WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)28 StringReader (java.io.StringReader)18 Test (org.junit.Test)12 Converter (org.xwiki.rendering.converter.Converter)12 XDOM (org.xwiki.rendering.block.XDOM)10 BlockRenderer (org.xwiki.rendering.renderer.BlockRenderer)8 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)7 Block (org.xwiki.rendering.block.Block)6 ParseException (org.xwiki.rendering.parser.ParseException)5 Parser (org.xwiki.rendering.parser.Parser)5 TransformationException (org.xwiki.rendering.transformation.TransformationException)4 XWikiException (com.xpn.xwiki.XWikiException)3 HashMap (java.util.HashMap)3 Expectations (org.jmock.Expectations)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 TransformationContext (org.xwiki.rendering.transformation.TransformationContext)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 Reader (java.io.Reader)2