/** * Convenience class to transform a node. * * @param xsl path name to the xsl file. * @param xml dom source document. * @param out output stream destination. */ public void transform(String xsl, Node xml, OutputStream out) throws Exception { TransformerImpl transformer; transformer = (TransformerImpl) newTemplates(xsl).newTransformer(); transformer.transform(xml, out); }
/** * Implements javax.xml.transform.sax.TransformerHandler.setResult() Enables the user of the * TransformerHandler to set the to set the Result for the transformation. * * @param result A Result instance, should not be null * @throws IllegalArgumentException if result is invalid for some reason */ public void setResult(Result result) throws IllegalArgumentException { _result = result; if (null == result) { ErrorMsg err = new ErrorMsg(ErrorMsg.ER_RESULT_NULL); throw new IllegalArgumentException(err.toString()); // "result should not be null"); } if (_isIdentity) { try { // Connect this object with output system directly SerializationHandler outputHandler = _transformer.getOutputHandler(result); _transformer.transferOutputProperties(outputHandler); _handler = outputHandler; _lexHandler = outputHandler; } catch (TransformerException e) { _result = null; } } else if (_done) { // Run the transformation now, if not already done try { _transformer.setDOM(_dom); _transformer.transform(null, _result); } catch (TransformerException e) { // What the hell are we supposed to do with this??? throw new IllegalArgumentException(e.getMessage()); } } }
/** * Implements org.xml.sax.ContentHandler.endDocument() Receive notification of the end of a * document. */ public void endDocument() throws SAXException { // Signal to the DOMBuilder that the document is complete _handler.endDocument(); if (!_isIdentity) { // Run the transformation now if we have a reference to a Result object if (_result != null) { try { _transformer.setDOM(_dom); _transformer.transform(null, _result); } catch (TransformerException e) { throw new SAXException(e); } } // Signal that the internal DOM is built (see 'setResult()'). _done = true; // Set this DOM as the transformer's DOM _transformer.setDOM(_dom); } if (_isIdentity && _result instanceof DOMResult) { ((DOMResult) _result).setNode(_transformer.getTransletOutputHandlerFactory().getNode()); } }
/** * Convenience class to transform a node. * * @param xsl DOM containing the parsed xsl. * @param xml DOM document node. * @param out output stream destination. */ public void transform(Document xsl, Node xml, OutputStream out) throws Exception { TransformerImpl transformer = (TransformerImpl) newTransformer(xsl); transformer.transform(xml, out); }