use of org.xwiki.rendering.block.CompositeBlock in project xwiki-platform by xwiki.
the class HelloWorldUIExtension method execute.
@Override
public Block execute() {
List<Block> blocks = new ArrayList<Block>();
blocks.add(new WordBlock("HelloWorld"));
return new CompositeBlock(blocks);
}
use of org.xwiki.rendering.block.CompositeBlock in project xwiki-platform by xwiki.
the class WikiUIExtensionRenderer method execute.
/**
* @return the rendered content of the extension
*/
public CompositeBlock execute() {
// We need to clone the xdom to avoid transforming the original and make it useless after the first
// transformation
XDOM transformedXDOM = xdom.clone();
// Perform macro transformations.
try {
// Get the document holding the UIX and put it in the UIX context
XWikiDocument xdoc = getXWikiContext().getWiki().getDocument(documentReference, getXWikiContext());
Map<String, Object> uixContext = new HashMap<>();
uixContext.put(WikiUIExtension.CONTEXT_UIX_DOC_KEY, xdoc.newDocument(getXWikiContext()));
// Put the UIX context in the XWiki context
getXWikiContext().put(WikiUIExtension.CONTEXT_UIX_KEY, uixContext);
// Transform the macros
TransformationContext transformationContext = new TransformationContext(xdom, xdoc.getSyntax());
transformationContext.setId(roleHint);
((MutableRenderingContext) renderingContext).transformInContext(macroTransformation, transformationContext, transformedXDOM);
} catch (TransformationException e) {
LOGGER.warn("Error while executing wiki component macro transformation for extension [{}]", roleHint);
} catch (XWikiException ex) {
LOGGER.warn("Failed to retrieve document [{}]", documentReference);
}
return new CompositeBlock(transformedXDOM.getChildren());
}
use of org.xwiki.rendering.block.CompositeBlock in project xwiki-platform by xwiki.
the class MessageToolTranslationMessageParserTest method messageWithEscapedParameter.
@Test
public void messageWithEscapedParameter() throws ComponentLookupException {
TranslationMessage translationMessage = getMockedComponent().parse("'{0}");
Assert.assertEquals("'{0}", translationMessage.getRawSource());
Assert.assertEquals(new CompositeBlock(Arrays.<Block>asList(new SpecialSymbolBlock('{'), new WordBlock("0"), new SpecialSymbolBlock('}'))), translationMessage.render(null, null, "word"));
}
use of org.xwiki.rendering.block.CompositeBlock in project xwiki-platform by xwiki.
the class MessageToolTranslationMessageParserTest method messageEmpty.
@Test
public void messageEmpty() throws ComponentLookupException {
TranslationMessage translationMessage = getMockedComponent().parse("");
Assert.assertEquals("", translationMessage.getRawSource());
Assert.assertEquals(new CompositeBlock(), translationMessage.render(null, null));
}
use of org.xwiki.rendering.block.CompositeBlock in project xwiki-platform by xwiki.
the class ParameterTranslationMessageElement method render.
@Override
public Block render(Locale locale, Collection<TranslationBundle> bundles, Object... parameters) {
Object parameter = parameters[index];
Block block;
if (parameter instanceof Block) {
block = (Block) parameter;
} else if (parameter != null) {
try {
XDOM xdom = this.plainParser.parse(new StringReader(parameter.toString()));
List<Block> blocks = xdom.getChildren();
PARSERUTILS.removeTopLevelParagraph(blocks);
if (blocks.isEmpty()) {
block = null;
} else if (blocks.size() == 1) {
block = blocks.get(0);
} else {
block = new CompositeBlock(blocks);
}
} catch (ParseException e) {
// make the #render fail instead ?
block = null;
}
} else {
block = null;
}
return block;
}
Aggregations