use of org.xwiki.rendering.renderer.PrintRenderer in project xwiki-platform by xwiki.
the class AbstractAnnotationMaintainer method renderPlainText.
/**
* Helper method to render the plain text version of the passed content.
*
* @param content the content to render in plain text
* @param syntaxId the source syntax of the content to render
* @throws Exception if anything goes wrong while rendering the content
* @return the normalized plain text rendered content
*/
private String renderPlainText(String content, String syntaxId) throws Exception {
PrintRenderer renderer = componentManager.getInstance(PrintRenderer.class, "normalizer-plain/1.0");
// parse
Parser parser = componentManager.getInstance(Parser.class, syntaxId);
XDOM xdom = parser.parse(new StringReader(content));
// run transformations -> although it's going to be at least strange to handle rendered content since there
// is no context
Syntax sourceSyntax = Syntax.valueOf(syntaxId);
TransformationManager transformationManager = componentManager.getInstance(TransformationManager.class);
transformationManager.performTransformations(xdom, sourceSyntax);
// render
WikiPrinter printer = new DefaultWikiPrinter();
renderer.setPrinter(printer);
xdom.traverse(renderer);
return printer.toString();
}
use of org.xwiki.rendering.renderer.PrintRenderer in project xwiki-platform by xwiki.
the class DefaultHTMLConverterTest method fromHTML.
/**
* Unit test for {@link DefaultHTMLConverter#fromHTML(String, String)}.
*/
@Test
public void fromHTML() throws Exception {
String html = "some HTML";
String syntaxId = "syntax/x.y";
// Verify the HTML is cleaned.
HTMLCleaner cleaner = mocker.getInstance(HTMLCleaner.class);
when(cleaner.clean(html)).thenReturn(html);
PrintRendererFactory printRendererFactory = this.mocker.registerMockComponent(PrintRendererFactory.class, syntaxId);
PrintRenderer printRenderer = mock(PrintRenderer.class);
when(printRendererFactory.createRenderer(any(WikiPrinter.class))).thenReturn(printRenderer);
Assert.assertEquals("", mocker.getComponentUnderTest().fromHTML(html, syntaxId));
// Verify the HTML is converted to the specified syntax.
StreamParser xhtmlStreamParser = mocker.getInstance(StreamParser.class, "xhtml/1.0");
verify(xhtmlStreamParser).parse(any(StringReader.class), same(printRenderer));
}
Aggregations