/** * Writes the generator's state to pw */ private void generate(PrintWriter pw) { // Use JAXP's transformation API to turn SAX events into pretty // XML text try { Source src = new SAXSource(this, new InputSource()); Result res = new StreamResult(pw); TransformerFactory xFactory = TransformerFactory.newInstance(); Transformer xform = xFactory.newTransformer(); xform.setOutputProperty(OutputKeys.METHOD, "xml"); xform.setOutputProperty(OutputKeys.INDENT, "yes"); if (!useSchema) { // set the doctype system and public ids from version for older DTDs. xform.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, version.getSystemId()); xform.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, version.getPublicId()); } xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); xform.transform(src, res); pw.flush(); } catch (Exception ex) { RuntimeException ex2 = new RuntimeException(LocalizedStrings.CacheXmlGenerator_AN_EXCEPTION_WAS_THROWN_WHILE_GENERATING_XML.toLocalizedString()); ex2.initCause(ex); throw ex2; } }