package com.raritan.com.raritan.xwiki; import java.io.StringReader; import org.xwiki.component.embed.EmbeddableComponentManager; import org.xwiki.rendering.converter.Converter; import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; import org.xwiki.rendering.renderer.printer.WikiPrinter; import org.xwiki.rendering.syntax.Syntax; public class LocalConverter { private EmbeddableComponentManager componentManager; private Converter converter; public LocalConverter() { initConverter(); } private void initConverter() { componentManager = new EmbeddableComponentManager(); componentManager.initialize(this.getClass().getClassLoader()); // Use the Converter component to convert between one syntax to another. try{ converter = componentManager.getInstance(Converter.class); }catch(Exception e) { } } public String HTML2XWiki(String html) { WikiPrinter printer = new DefaultWikiPrinter(); try { converter.convert(new StringReader(html), Syntax.HTML_4_01, Syntax.XWIKI_2_1, printer); }catch(Exception ex) { System.out.println(ex.getMessage()); } String x = printer.toString(); return printer.toString(); } }