@Test public void fromHTML() throws Exception { String html = "some HTML"; String syntaxId = "syntax/x.y"; HTMLCleaner cleaner = this.componentManager.getInstance(HTMLCleaner.class); when(cleaner.clean(html)).thenReturn(html); PrintRendererFactory printRendererFactory = this.componentManager.registerMockComponent(PrintRendererFactory.class, syntaxId); PrintRenderer printRenderer = mock(PrintRenderer.class); when(printRendererFactory.createRenderer(any(WikiPrinter.class))).thenReturn(printRenderer); assertEquals("", this.converter.fromHTML(html, syntaxId)); StreamParser xhtmlStreamParser = this.componentManager.getInstance(StreamParser.class, "xhtml/1.0"); verify(xhtmlStreamParser).parse(any(StringReader.class), same(printRenderer)); }
@Override public String fromHTML(String dirtyHTML, String syntaxId) { boolean renderingContextPushed = false; try { String html = this.htmlCleaner.clean(dirtyHTML); renderingContextPushed = maybeSetRenderingContextSyntax(Syntax.valueOf(syntaxId)); 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); } finally { if (renderingContextPushed) { ((MutableRenderingContext) this.renderingContext).pop(); } } }
DefaultHTMLConverter implements HTMLConverter { @Override public String fromHTML(String dirtyHTML, String syntaxId) { boolean renderingContextPushed = false; try { String html = this.htmlCleaner.clean(dirtyHTML); renderingContextPushed = maybeSetRenderingContextSyntax(Syntax.valueOf(syntaxId)); 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); } finally { if (renderingContextPushed) { ((MutableRenderingContext) this.renderingContext).pop(); } } } }
DefaultHTMLConverter implements HTMLConverter { @Override public String fromHTML(String dirtyHTML, String syntaxId) { boolean renderingContextPushed = false; try { String html = this.htmlCleaner.clean(dirtyHTML); renderingContextPushed = maybeSetRenderingContextSyntax(Syntax.valueOf(syntaxId)); 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); } finally { if (renderingContextPushed) { ((MutableRenderingContext) this.renderingContext).pop(); } } }  }
DefaultHTMLConverter implements HTMLConverter { @Override public String fromHTML(String dirtyHTML, String syntaxId) { boolean renderingContextPushed = false; try { String html = this.htmlCleaner.clean(dirtyHTML); renderingContextPushed = maybeSetRenderingContextSyntax(Syntax.valueOf(syntaxId)); 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); } finally { if (renderingContextPushed) { ((MutableRenderingContext) this.renderingContext).pop(); } } }  @Override String fromHTML(String dirtyHTML, String syntaxId); @Override String toHTML(String source, String syntaxId); @Override String toHTML(String source, Syntax syntax, EntityReference sourceReference); @Override String parseAndRender(String dirtyHTML, String syntaxId); @Override String parseAndRender(String dirtyHTML, Syntax syntax, EntityReference sourceReference); }
DefaultHTMLConverter implements HTMLConverter { @Override public String fromHTML(String dirtyHTML, String syntaxId) { boolean renderingContextPushed = false; try { String html = this.htmlCleaner.clean(dirtyHTML); renderingContextPushed = maybeSetRenderingContextSyntax(Syntax.valueOf(syntaxId)); 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); } finally { if (renderingContextPushed) { ((MutableRenderingContext) this.renderingContext).pop(); } } }  @Override String fromHTML(String dirtyHTML, String syntaxId); @Override String toHTML(String source, String syntaxId); @Override String toHTML(String source, Syntax syntax, EntityReference sourceReference); @Override String parseAndRender(String dirtyHTML, String syntaxId); @Override String parseAndRender(String dirtyHTML, Syntax syntax, EntityReference sourceReference);  }