Search in sources :

Example 16 with WikiPrinter

use of org.xwiki.rendering.renderer.printer.WikiPrinter 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 17 with WikiPrinter

use of org.xwiki.rendering.renderer.printer.WikiPrinter 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 18 with WikiPrinter

use of org.xwiki.rendering.renderer.printer.WikiPrinter 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 19 with WikiPrinter

use of org.xwiki.rendering.renderer.printer.WikiPrinter 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 20 with WikiPrinter

use of org.xwiki.rendering.renderer.printer.WikiPrinter 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

WikiPrinter (org.xwiki.rendering.renderer.printer.WikiPrinter)33 DefaultWikiPrinter (org.xwiki.rendering.renderer.printer.DefaultWikiPrinter)28 XDOM (org.xwiki.rendering.block.XDOM)12 BlockRenderer (org.xwiki.rendering.renderer.BlockRenderer)11 StringReader (java.io.StringReader)8 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)6 Parser (org.xwiki.rendering.parser.Parser)6 Test (org.junit.Test)5 Block (org.xwiki.rendering.block.Block)5 ParseException (org.xwiki.rendering.parser.ParseException)5 TransformationException (org.xwiki.rendering.transformation.TransformationException)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 TransformationContext (org.xwiki.rendering.transformation.TransformationContext)3 XWikiException (com.xpn.xwiki.XWikiException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 WordBlock (org.xwiki.rendering.block.WordBlock)2 Converter (org.xwiki.rendering.converter.Converter)2 TransformationManager (org.xwiki.rendering.transformation.TransformationManager)2