use of org.xwiki.rendering.renderer.BlockRenderer in project xwiki-platform by xwiki.
the class DefaultHTMLConverterTest method toHTML.
/**
* Unit test for {@link DefaultHTMLConverter#toHTML(String, String)}.
*/
@Test
public void toHTML() throws Exception {
String source = "wiki syntax";
String syntaxId = "syntax/x.y";
// The source should be parsed.
Parser parser = this.mocker.registerMockComponent(Parser.class, syntaxId);
XDOM xdom = new XDOM(Collections.<Block>emptyList());
when(parser.parse(any(StringReader.class))).thenReturn(xdom);
Assert.assertEquals("", mocker.getComponentUnderTest().toHTML(source, syntaxId));
// Verify that the macro transformations have been executed.
Transformation macroTransformation = mocker.getInstance(Transformation.class, "macro");
RenderingContext renderingContext = mocker.getInstance(RenderingContext.class);
// It's very important to verify that a transformation context id is set as otherwise if the content being
// edited has different velocity macros executing, they'll be executed in isolation and thus what's defined in
// one won't be visible from the other ones (For example see https://jira.xwiki.org/browse/XWIKI-11695).
ArgumentCaptor<TransformationContext> txContextArgument = ArgumentCaptor.forClass(TransformationContext.class);
verify((MutableRenderingContext) renderingContext).transformInContext(same(macroTransformation), txContextArgument.capture(), same(xdom));
assertEquals("wysiwygtxid", txContextArgument.getValue().getId());
// Verify the XDOM is rendered to Annotated XHTML.
BlockRenderer xhtmlRenderer = mocker.getInstance(BlockRenderer.class, "annotatedxhtml/1.0");
verify(xhtmlRenderer).render(same(xdom), any(WikiPrinter.class));
}
use of org.xwiki.rendering.renderer.BlockRenderer in project xwiki-platform by xwiki.
the class XDOMOfficeDocument method renderTitle.
/**
* Utility method for rendering a title.
*
* @param header header block which contains the title.
* @return header block content rendered as a string.
*/
private String renderTitle(HeaderBlock header) {
try {
WikiPrinter printer = new DefaultWikiPrinter();
BlockRenderer renderer = this.componentManager.getInstance(BlockRenderer.class, "plain/1.0");
renderer.render(header, printer);
return printer.toString();
} catch (ComponentLookupException ex) {
// Ignore.
}
return null;
}
use of org.xwiki.rendering.renderer.BlockRenderer in project xwiki-platform by xwiki.
the class DefaultOfficeViewerScriptServiceTest method view.
@Test
public void view() throws Exception {
Execution execution = mocker.getInstance(Execution.class);
when(execution.getContext()).thenReturn(new ExecutionContext());
AttachmentReference attachmentReference = new AttachmentReference("file.odt", new DocumentReference("wiki", "Space", "Page"));
DocumentModelBridge document = mock(DocumentModelBridge.class);
DocumentAccessBridge documentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
when(documentAccessBridge.isDocumentViewable(attachmentReference.getDocumentReference())).thenReturn(true);
when(documentAccessBridge.getTranslatedDocumentInstance(attachmentReference.getDocumentReference())).thenReturn(document);
when(document.getSyntax()).thenReturn(Syntax.TEX_1_0);
XDOM xdom = new XDOM(Collections.<Block>emptyList());
OfficeViewer viewer = mocker.getInstance(OfficeViewer.class);
when(viewer.createView(attachmentReference, Collections.<String, String>emptyMap())).thenReturn(xdom);
BlockRenderer xhtmlRenderer = mocker.registerMockComponent(BlockRenderer.class, "xhtml/1.0");
Assert.assertEquals("", mocker.getComponentUnderTest().view(attachmentReference));
TransformationManager transformationManager = mocker.getInstance(TransformationManager.class);
verify(transformationManager).performTransformations(eq(xdom), notNull(TransformationContext.class));
verify(xhtmlRenderer).render(eq(xdom), notNull(WikiPrinter.class));
}
use of org.xwiki.rendering.renderer.BlockRenderer in project xwiki-platform by xwiki.
the class DisplayScriptService method renderXDOM.
/**
* Renders the provided XDOM.
*
* @param content the XDOM content to render
* @param targetSyntax the syntax of the rendering result
* @return the result of rendering the given XDOM
* @throws XWikiException if an exception occurred during the rendering process
*/
private String renderXDOM(XDOM content, Syntax targetSyntax) throws XWikiException {
try {
BlockRenderer renderer = this.componentManager.getInstance(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 XDOM to syntax [" + targetSyntax + "]", e);
}
}
use of org.xwiki.rendering.renderer.BlockRenderer 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;
}
Aggregations