public void generate ( final File fileName ) { final File outputFile = removeTemplatePrefix ( fileName ) ; templateFile = fileName ; try ( final InputStream in = new BufferedInputStream ( new FileInputStream ( fileName ) ) ; final OutputStream out = new BufferedOutputStream ( new FileOutputStream ( outputFile ) ) ) { final Transformer transformer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; final SAXParserFactory parserFactory = SAXParserFactory . newInstance ( ) ; parserFactory . setNamespaceAware ( true ) ; XMLReader reader = parserFactory . newSAXParser ( ) . getXMLReader ( ) ; this . setContentHandler ( null ) ; this . setParent ( reader ) ; reader = this ; final Source source = new SAXSource ( reader , new InputSource ( in ) ) ; source . setSystemId ( fileName . toURI ( ) . toString ( ) ) ; final Result result = new StreamResult ( out ) ; transformer . transform ( source , result ) ; } catch ( final RuntimeException e ) { throw e ; } catch ( final Exception e ) { logger . error ( "Failed to transform " + fileName + ": " + e . getMessage ( ) , e ) ; } }
Generator the output file .