use of org.xwiki.rendering.renderer.printer.WikiPrinter in project xwiki-platform by xwiki.
the class RenderingScriptService method render.
/**
* Render a list of Blocks into the passed syntax.
*
* @param block the block to render
* @param outputSyntaxId the syntax in which to render the blocks
* @return the string representing the passed blocks in the passed syntax or null if an error occurred
* @since 3.2M3
*/
public String render(Block block, String outputSyntaxId) {
String result;
WikiPrinter printer = new DefaultWikiPrinter();
try {
BlockRenderer renderer = this.componentManagerProvider.get().getInstance(BlockRenderer.class, outputSyntaxId);
renderer.render(block, printer);
result = printer.toString();
} catch (Exception e) {
result = null;
}
return result;
}
use of org.xwiki.rendering.renderer.printer.WikiPrinter in project xwiki-platform by xwiki.
the class LocalizationScriptServiceTest method setUp.
@Before
public void setUp() throws Exception {
componentManager = mock(ComponentManager.class);
Provider<ComponentManager> componentManagerProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(componentManager);
renderer = mock(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString());
when(componentManager.getInstance(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString())).thenReturn(renderer);
localizationContext = mocker.getInstance(LocalizationContext.class);
localizationManager = mocker.getInstance(LocalizationManager.class);
localizationScriptService = (LocalizationScriptService) mocker.getComponentUnderTest();
translation = mock(Translation.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
WikiPrinter printer = (WikiPrinter) invocation.getArguments()[1];
printer.print("print result");
return null;
}
}).when(renderer).render(eq(new WordBlock("message")), any(WikiPrinter.class));
when(translation.render(Locale.ROOT, ArrayUtils.EMPTY_OBJECT_ARRAY)).thenReturn(new WordBlock("message"));
when(localizationManager.getTranslation("key", Locale.ROOT)).thenReturn(translation);
when(localizationContext.getCurrentLocale()).thenReturn(Locale.ROOT);
environment = mocker.getInstance(Environment.class);
}
use of org.xwiki.rendering.renderer.printer.WikiPrinter in project xwiki-platform by xwiki.
the class XWikiDocument method renderXDOM.
/**
* Render privided XDOM into content of the provided syntax identifier.
*
* @param content the XDOM content to render
* @param targetSyntax the syntax identifier of the rendered content
* @return the rendered content
* @throws XWikiException if an exception occurred during the rendering process
*/
protected static String renderXDOM(XDOM content, Syntax targetSyntax) throws XWikiException {
try {
BlockRenderer renderer = Utils.getComponent(BlockRenderer.class, targetSyntax.toIdString());
WikiPrinter printer = new DefaultWikiPrinter();
renderer.render(content, printer);
return printer.toString();
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_RENDERING, XWikiException.ERROR_XWIKI_UNKNOWN, "Failed to render document to syntax [" + targetSyntax + "]", e);
}
}
Aggregations