/** * @param blocks the Blocks to assert * @param factory the Renderer Factory to use to serialize the passed Block * @return The serialized block. * @since 4.2M1 */ private static String render(List<Block> blocks, PrintRendererFactory factory) { // Assert the result by parsing it through the EventsRenderer to generate easily // assertable events. XDOM dom = new XDOM(blocks); WikiPrinter printer = new DefaultWikiPrinter(); PrintRenderer eventRenderer = factory.createRenderer(printer); dom.traverse(eventRenderer); return printer.toString(); }
@Override public String getAnnotatedRenderedContent(String sourceReference, String sourceSyntax, String outputSyntax, Collection<Annotation> annotations) throws AnnotationServiceException { try { XDOM xdom = targetIoService.getXDOM(sourceReference, sourceSyntax); // build the annotations renderer hint for the specified output syntax String outputSyntaxId = "annotations-" + outputSyntax; AnnotationPrintRenderer annotationsRenderer = componentManager.getInstance(AnnotationPrintRenderer.class, outputSyntaxId); WikiPrinter printer = new DefaultWikiPrinter(); annotationsRenderer.setPrinter(printer); // set the annotations for this renderer annotationsRenderer.setAnnotations(annotations); xdom.traverse(annotationsRenderer); return printer.toString(); } catch (Exception exc) { throw new AnnotationServiceException(exc); } }
/** * 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(); }