private static void alterHtmlDocs ( Options opt , String outputFolder , String packageName , String className , String htmlFileName , Pattern insertPointPattern , RootDoc root ) throws IOException { // setup files File output = new File ( outputFolder , packageName . replace ( "." , "/" ) ) ; File htmlFile = new File ( output , htmlFileName ) ; File alteredFile = new File ( htmlFile . getAbsolutePath ( ) + ".uml" ) ; if ( ! htmlFile . exists ( ) ) { System . err . println ( "Expected file not found: " + htmlFile . getAbsolutePath ( ) ) ; return ; } // parse & rewrite BufferedWriter writer = null ; BufferedReader reader = null ; boolean matched = false ; try { writer = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( alteredFile ) , opt . outputEncoding ) ) ; reader = new BufferedReader ( new InputStreamReader ( new FileInputStream ( htmlFile ) , opt . outputEncoding ) ) ; String line ; while ( ( line = reader . readLine ( ) ) != null ) { writer . write ( line ) ; writer . newLine ( ) ; if ( ! matched && insertPointPattern . matcher ( line ) . matches ( ) ) { matched = true ; String tag ; if ( opt . autoSize ) tag = String . format ( UML_AUTO_SIZED_DIV_TAG , className ) ; else tag = String . format ( UML_DIV_TAG , className ) ; if ( opt . collapsibleDiagrams ) tag = String . format ( EXPANDABLE_UML , tag , "Show UML class diagram" , "Hide UML class diagram" ) ; writer . write ( "<!-- UML diagram added by UMLGraph version " + Version . VERSION + " (http://www.spinellis.gr/umlgraph/) -->" ) ; writer . newLine ( ) ; writer . write ( tag ) ; writer . newLine ( ) ; } } } finally { if ( writer != null ) writer . close ( ) ; if ( reader != null ) reader . close ( ) ; } // if altered, delete old file and rename new one to the old file name if ( matched ) { htmlFile . delete ( ) ; alteredFile . renameTo ( htmlFile ) ; } else { root . printNotice ( "Warning, could not find a line that matches the pattern '" + insertPointPattern . pattern ( ) + "'.\n Class diagram reference not inserted" ) ; alteredFile . delete ( ) ; } }
Takes an HTML file looks for the first instance of the specified insertion point and inserts the diagram image reference and a client side map in that point .