@Override public String format( String projectName, String path, String revision, String abbrRev, ConfigSection cfg, InputStream raw) throws IOException { // Docx4J tries to load some resources dynamically. This fails if the Gerrit // core classloader is used since it doesn't see the resources that are // contained in the plugin jar. To make the resource loading work we // must set a context classloader on the current thread. ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); WordprocessingMLPackage p = Docx4J.load(raw); HTMLSettings htmlSettings = Docx4J.createHTMLSettings(); htmlSettings.setWmlPackage(p); Docx4jProperties.setProperty("docx4j.Convert.Out.HTML.OutputMethodXML", true); try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { Docx4J.toHTML(htmlSettings, out, Docx4J.FLAG_EXPORT_PREFER_XSL); String html = out.toString(UTF_8.name()); return util.applyCss(html, NAME, projectName); } } catch (Docx4JException e) { throw new IOException(e); } finally { Thread.currentThread().setContextClassLoader(loader); } }
@Override public String format( String projectName, String path, String revision, String abbrRev, ConfigSection globalCfg, String raw) throws IOException { if (!globalCfg.getBoolean(KEY_ALLOW_HTML, false)) { raw = suppressHtml(raw); } ConfigSection projectCfg = formatters.getFormatterConfig(NAME, projectName); String html = Asciidoctor.Factory.create(AsciidoctorFormatter.class.getClassLoader()) .convert(raw, createOptions(projectCfg, abbrRev)); return util.applyCss(html, NAME, projectName); }