use of org.xwiki.rendering.renderer.printer.WikiPrinter in project xwiki-platform by xwiki.
the class AnnotationXHTMLRendererTest method getAnnotatedHTML.
/**
* Test rendering the annotations in the document description file results in the annotated html.
*
* @throws Exception in case something goes wrong looking up components and rendering
*/
@Test
public void getAnnotatedHTML() throws Exception {
Parser parser = getComponentManager().getInstance(Parser.class, docFactory.getDocument(docName).getSyntax());
XDOM xdom = parser.parse(new StringReader(docFactory.getDocument(docName).getSource()));
// run transformations
TransformationManager transformationManager = getComponentManager().getInstance(TransformationManager.class);
TransformationContext context = new TransformationContext(xdom, Syntax.valueOf(docFactory.getDocument(docName).getSyntax()));
context.setTargetSyntax(Syntax.ANNOTATED_XHTML_1_0);
transformationManager.performTransformations(xdom, context);
AnnotationPrintRenderer renderer = getComponentManager().getInstance(AnnotationPrintRenderer.class, ANNOTATIONS_RENDERER_HINT);
WikiPrinter printer = new DefaultWikiPrinter();
renderer.setPrinter(printer);
// set the annotations for this renderer
renderer.setAnnotations(docFactory.getDocument(docName).getAnnotations());
xdom.traverse(renderer);
assertEquals("[" + docName + "] test failed", docFactory.getDocument(docName).getAnnotatedContent(), printer.toString());
}
use of org.xwiki.rendering.renderer.printer.WikiPrinter in project xwiki-platform by xwiki.
the class AnnotationXHTMLRendererTest method getAnnotatedHTMLWithoutAnnotations.
/**
* Test rendering with the annotations renderer but without annotations doesn't alter the content.
*
* @throws Exception in case something goes wrong looking up components and rendering
*/
@Test
public void getAnnotatedHTMLWithoutAnnotations() throws Exception {
Parser parser = getComponentManager().getInstance(Parser.class, docFactory.getDocument(docName).getSyntax());
XDOM xdom = parser.parse(new StringReader(docFactory.getDocument(docName).getSource()));
// run transformations
TransformationManager transformationManager = getComponentManager().getInstance(TransformationManager.class);
TransformationContext context = new TransformationContext(xdom, Syntax.valueOf(docFactory.getDocument(docName).getSyntax()));
context.setTargetSyntax(Syntax.ANNOTATED_XHTML_1_0);
transformationManager.performTransformations(xdom, context);
AnnotationPrintRenderer renderer = getComponentManager().getInstance(AnnotationPrintRenderer.class, ANNOTATIONS_RENDERER_HINT);
WikiPrinter printer = new DefaultWikiPrinter();
renderer.setPrinter(printer);
xdom.traverse(renderer);
assertEquals("[" + docName + "] test failed", docFactory.getDocument(docName).getRenderedContent(), printer.toString());
}
use of org.xwiki.rendering.renderer.printer.WikiPrinter in project xwiki-platform by xwiki.
the class DefaultAnnotationService method getAnnotatedRenderedContent.
@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);
}
}
use of org.xwiki.rendering.renderer.printer.WikiPrinter 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.printer.WikiPrinter 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);
}
}
Aggregations