public void earlHtmlReport ( String outputDir ) { ClassLoader cl = Thread . currentThread ( ) . getContextClassLoader ( ) ; String resourceDir = cl . getResource ( "com/occamlab/te/earl/lib" ) . getPath ( ) ; String earlXsl = cl . getResource ( "com/occamlab/te/earl_html_report.xsl" ) . toString ( ) ; File htmlOutput = new File ( outputDir , "result" ) ; htmlOutput . mkdir ( ) ; File earlResult = findEarlResultFile ( outputDir ) ; LOGR . log ( FINE , "Try to transform earl result file '" + earlResult + "' to directory " + htmlOutput ) ; try { if ( earlResult != null && earlResult . exists ( ) ) { Transformer transformer = TransformerFactory . newInstance ( ) . newTransformer ( new StreamSource ( earlXsl ) ) ; transformer . setParameter ( "outputDir" , htmlOutput ) ; File indexHtml = new File ( htmlOutput , "index.html" ) ; indexHtml . createNewFile ( ) ; // Fortify Mod: Make sure the FileOutputStream is closed when we are done with it. // transformer.transform( new StreamSource( earlResult ), // new StreamResult( new FileOutputStream( indexHtml ) ) ); FileOutputStream fo = new FileOutputStream ( indexHtml ) ; transformer . transform ( new StreamSource ( earlResult ) , new StreamResult ( fo ) ) ; fo . close ( ) ; FileUtils . copyDirectory ( new File ( resourceDir ) , htmlOutput ) ; } } catch ( Exception e ) { LOGR . log ( SEVERE , "Transformation of EARL to HTML failed." , e ) ; } }
Transform EARL result into HTML report using XSLT .