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