PaginationControlWrapper { private static String embedCss( String pageContent ) throws IOException { Matcher cssLinkMatcher = CSS.matcher( pageContent ); while ( cssLinkMatcher.find() && cssLinkMatcher.groupCount() > 1 ) { final String cssContent = getSolutionDirFileContent( STAGING_PATH + cssLinkMatcher.group( 2 ) ); pageContent = cssLinkMatcher.replaceFirst( "<style>\n" + cssContent + "\n</style>" ); cssLinkMatcher = CSS.matcher( pageContent ); } return pageContent; } private  PaginationControlWrapper(); static void write( final OutputStream stream, final IReportContent content );  }
@Test public void embedCss() throws Exception { File tmp = new File( "target/test/resource/solution/system/tmp" ); tmp.mkdirs(); final String solutionPath = PentahoSystem.getApplicationContext().getSolutionPath( "system/tmp/test.css" ); final File file = new File( solutionPath ); try { FileUtils.writeStringToFile(file, ".fakeClass{}"); final Map<Integer, byte[]> pages = new HashMap<>(); pages .put( 0, "<link type=\"text/css\" rel=\"stylesheet\" href=\"/pentaho/getImage?image=test.css\">".getBytes() ); pages .put( 1, "<link type=\"text/css\" rel=\"stylesheet\" href=\"/pentaho/getImage?image=nofile.css\">".getBytes() ); final String res; try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { PaginationControlWrapper.write( baos, new ReportContentImpl( 1, pages ) ); res = new String( baos.toByteArray(), "UTF-8" ); } assertTrue( res.contains( "var pages = [ 'Jmx0O3N0eWxlJmd0OwouZmFrZUNsYXNze30KJmx0Oy9zdHlsZSZndDs=', \n" + "'Jmx0O2xpbmsgdHlwZT0mcXVvdDt0ZXh0L2NzcyZxdW90OyByZWw9JnF1b3Q7c3R5bGVzaGVldCZxdW90OyBocmVmPSZxdW90Oy9wZW50YWhvL2dldEltYWdlP2ltYWdlPW5vZmlsZS5jc3MmcXVvdDsmZ3Q7' ];" ) ); assertFalse( res.contains( "link" ) ); assertTrue( res.contains( "style" ) ); } finally { file.delete(); tmp.delete(); } }