use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultHTMLConverter method parseAndRender.
@Override
public String parseAndRender(String dirtyHTML, String syntaxId) {
try {
// Clean
String html = this.htmlCleaner.clean(dirtyHTML);
// Parse
XDOM xdom = this.xhtmlParser.parse(new StringReader(html));
// The XHTML parser sets the "syntax" meta data property of the created XDOM to "xhtml/1.0". The syntax meta
// data is used as the default syntax for macro content. We have to change this to the specified syntax
// because HTML is used only to be able to edit the source syntax in the WYSIWYG editor.
Syntax syntax = Syntax.valueOf(syntaxId);
xdom.getMetaData().addMetaData(MetaData.SYNTAX, syntax);
// Execute the macro transformation
executeMacroTransformation(xdom, Syntax.valueOf(syntaxId));
// Render
WikiPrinter printer = new DefaultWikiPrinter();
this.xhtmlRenderer.render(xdom, printer);
return printer.toString();
} catch (Exception e) {
this.logger.error(e.getLocalizedMessage(), e);
throw new RuntimeException("Exception while refreshing HTML", e);
}
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultHTMLConverter method fromHTML.
@Override
public String fromHTML(String dirtyHTML, String syntaxId) {
try {
// Clean
String html = this.htmlCleaner.clean(dirtyHTML);
// Parse & Render
// Note that transformations are not executed when converting XHTML to source syntax.
WikiPrinter printer = new DefaultWikiPrinter();
PrintRendererFactory printRendererFactory = this.contextComponentManager.getInstance(PrintRendererFactory.class, syntaxId);
this.xhtmlStreamParser.parse(new StringReader(html), printRendererFactory.createRenderer(printer));
return printer.toString();
} catch (Exception e) {
this.logger.error(e.getLocalizedMessage(), e);
throw new RuntimeException("Exception while parsing HTML", e);
}
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class DefaultHTMLConverter method toHTML.
@Override
public String toHTML(String source, String syntaxId) {
try {
// Parse
Parser parser = this.contextComponentManager.getInstance(Parser.class, syntaxId);
XDOM xdom = parser.parse(new StringReader(source));
// Execute the macro transformation
executeMacroTransformation(xdom, Syntax.valueOf(syntaxId));
// Render
WikiPrinter printer = new DefaultWikiPrinter();
this.xhtmlRenderer.render(xdom, printer);
return printer.toString();
} catch (Exception e) {
this.logger.error(e.getLocalizedMessage(), e);
throw new RuntimeException("Exception while rendering HTML", e);
}
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter in project xwiki-platform by xwiki.
the class OfficeMacroImporter method render.
/**
* Renders the given XDOM to the annotated XHTML syntax.
*
* @param xdom the XDOM to be rendered
* @return the result of rendering the given XDOM to annotated XHTML syntax
* @throws Exception if the rendering process fails
*/
public String render(XDOM xdom) throws Exception {
TransformationContext txContext = new TransformationContext();
txContext.setXDOM(xdom);
((MutableRenderingContext) renderingContext).transformInContext(macroTransformation, txContext, xdom);
WikiPrinter printer = new DefaultWikiPrinter();
xhtmlRenderer.render(xdom, printer);
return printer.toString();
}
use of org.xwiki.rendering.renderer.printer.DefaultWikiPrinter 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());
}
Aggregations