use of org.xwiki.rendering.renderer.printer.WikiPrinter in project xwiki-platform by xwiki.
the class InternalTemplateManager method render.
private void render(XDOM xdom, Writer writer) {
WikiPrinter printer = new WriterWikiPrinter(writer);
BlockRenderer blockRenderer;
try {
blockRenderer = this.componentManagerProvider.get().getInstance(BlockRenderer.class, getTargetSyntax().toIdString());
} catch (ComponentLookupException e) {
blockRenderer = this.plainRenderer;
}
blockRenderer.render(xdom, printer);
}
use of org.xwiki.rendering.renderer.printer.WikiPrinter 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.WikiPrinter 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.WikiPrinter 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.WikiPrinter 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();
}
Aggregations