public void write(HttpServletResponse response) { StreamResult streamResult; SAXTransformerFactory tf; TransformerHandler hd; Transformer serializer; try { try { streamResult = new StreamResult(response.getWriter()); tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); hd = tf.newTransformerHandler(); serializer = hd.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8"); serializer.setOutputProperty( OutputKeys.DOCTYPE_SYSTEM, "http://labs.omniti.com/resmon/trunk/resources/resmon.dtd"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); hd.setResult(streamResult); hd.startDocument(); AttributesImpl atts = new AttributesImpl(); hd.startElement("", "", "ResmonResults", atts); for (ResmonResult r : s) { r.write(hd); } hd.endElement("", "", "ResmonResults"); hd.endDocument(); } catch (TransformerConfigurationException tce) { response.getWriter().println(tce.getMessage()); } catch (SAXException se) { response.getWriter().println(se.getMessage()); } } catch (IOException ioe) { } }
/** * Compile a {@link Templates} from a given stream. The template is not added to the pool * automatically. */ public Templates compileTemplate(InputStream stream) throws SAXException { final StreamSource source = new StreamSource(stream); try { return tFactory.newTemplates(source); } catch (Exception e) { throw new SAXException("Could not compile stylesheet.", e); } }
/** * Compile a {@link Templates} from a given system identifier. The template is not added to the * pool, a manual call to {@link #addTemplate(String, Templates)} is required. */ public Templates compileTemplate(String systemId) throws SAXException { final StreamSource source = new StreamSource(systemId); try { return tFactory.newTemplates(source); } catch (Exception e) { throw new SAXException("Could not compile stylesheet: " + systemId, e); } }
/** @return returns the identity transformer handler. */ public TransformerHandler getIdentityTransformerHandler() throws TransformerConfigurationException { return tFactory.newTransformerHandler(); }