@Test public void applyCSSWhenExistingStyleDefinedUsingShorthandNotation() throws Exception { this.oldcore.getMocker().registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "currentmixed"); this.oldcore.getMocker().registerMockComponent(EntityReferenceSerializer.TYPE_STRING); this.oldcore.getMocker().registerMockComponent(DocumentAccessBridge.class); this.oldcore.getMocker().registerMockComponent(DocumentAccessBridge.class); this.oldcore.getMocker().registerMockComponent(PDFResourceResolver.class); this.oldcore.getMocker().registerMockComponent(Environment.class); this.oldcore.getMocker().registerMockComponent(VelocityManager.class); this.oldcore.getMocker().registerMockComponent(XSLFORenderer.class, "fop"); PdfExportImpl pdfExport = new PdfExportImpl(); String html = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE html PUBLIC \"- + "\"http: + "<html xmlns=\"http: + "<title>\n" + " Main.ttt - ttt\n" + "</title>\n" + "<meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\" />\n" + "<meta content=\"en\" name=\"language\" />\n" + "\n" + "</head><body class=\"exportbody\" id=\"body\" pdfcover=\"0\" pdftoc=\"0\">\n" + "\n" + "<div id=\"xwikimaincontainer\">\n" + "<div id=\"xwikimaincontainerinner\">\n" + "\n" + "<div id=\"xwikicontent\">\n" + " <p><span style=\"background: white;\">Hello Cl&eacute;ment</span></p>\n" + " </div>\n" + "</div>\n" + "</div>\n" + "\n" + "</body></html>"; String css = "span { color:red; }"; XWikiContext xcontext = this.oldcore.getXWikiContext(); XWikiDocument doc = mock(XWikiDocument.class); when(doc.getExternalURL("view", xcontext)).thenReturn("http: xcontext.setDoc(doc); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE html PUBLIC \"- + "\"http: + "<html xmlns=\"http: + " Main.ttt - ttt\n" + "</title>" + "<meta content=\"text/html; charset=UTF-8\" http-equiv=\"Content-Type\"/>" + "<meta content=\"en\" name=\"language\"/>" + "</head><body class=\"exportbody\" id=\"body\" pdfcover=\"0\" pdftoc=\"0\">" + "<div id=\"xwikimaincontainer\">\n" + "<div id=\"xwikimaincontainerinner\">\n\n" + "<div id=\"xwikicontent\">\n" + " <p><span style=\"color: #f00; background-color: #fff; background-image: none; " + "background-position: 0% 0%; background-size: auto auto; background-origin: padding-box; " + "background-clip: border-box; background-repeat: repeat repeat; " + "background-attachment: scroll; \">Hello Clément</span></p>\n" + " </div>\n" + "</div>\n" + "</div>" + "</body></html>"; assertEquals(expected, pdfExport.applyCSS(html, css, xcontext)); }
private String applyCSS(String html, XWikiContext context) { String css = (context == null || context.getWiki() == null) ? "" : context.getWiki().parseTemplate("pdf.css", context); String style = getPDFTemplateProperty("style", context); if (style != null) { css += style; } return StringUtils.isBlank(css) ? html : applyCSS(html, css, context); }
PdfExportImpl implements PdfExport { private String applyCSS(String html, XWikiContext context) { String css = (context == null || context.getWiki() == null) ? "" : context.getWiki().parseTemplate("pdf.css", context); String style = getPDFTemplateProperty("style", context); if (style != null) { css += style; } return StringUtils.isBlank(css) ? html : applyCSS(html, css, context); } }
PdfExportImpl implements PdfExport { private String applyCSS(String html, XWikiContext context) { String css = (context == null || context.getWiki() == null) ? "" : context.getWiki().parseTemplate("pdf.css", context); String style = getPDFTemplateProperty("style", context); if (style != null) { css += style; } return StringUtils.isBlank(css) ? html : applyCSS(html, css, context); }  }
PdfExportImpl implements PdfExport { private String applyCSS(String html, XWikiContext context) { String css = (context == null || context.getWiki() == null) ? "" : context.getWiki().parseTemplate("pdf.css", context); String style = getPDFTemplateProperty("style", context); if (style != null) { css += style; } return StringUtils.isBlank(css) ? html : applyCSS(html, css, context); }  @Override void exportToPDF(XWikiDocument doc, OutputStream out, XWikiContext context); @Override void export(XWikiDocument doc, OutputStream out, ExportType type, XWikiContext context); @Override void exportHtml(String html, OutputStream out, ExportType type, XWikiContext context); }
PdfExportImpl implements PdfExport { private String applyCSS(String html, XWikiContext context) { String css = (context == null || context.getWiki() == null) ? "" : context.getWiki().parseTemplate("pdf.css", context); String style = getPDFTemplateProperty("style", context); if (style != null) { css += style; } return StringUtils.isBlank(css) ? html : applyCSS(html, css, context); }  @Override void exportToPDF(XWikiDocument doc, OutputStream out, XWikiContext context); @Override void export(XWikiDocument doc, OutputStream out, ExportType type, XWikiContext context); @Override void exportHtml(String html, OutputStream out, ExportType type, XWikiContext context);  }