Project

Profile

Help

using MessageWarner causes an exception

Added by Anonymous over 14 years ago

Legacy ID: #8501577 Legacy Poster: https://www.google.com/accounts ()

I am trying to capture output from xsl:message and log it using my application's logging system. I have: transformer.setErrorListener(new ErrorListener()); ((Controller)transformer).setMessageEmitter(new net.sf.saxon.event.MessageWarner ()); ErrorListener is my own class which performs the logging. This setup works in that generated messages are captured and logged. However, when no message is produced by the xslt, I get the following exception: Caused by: java.lang.IllegalStateException: Emitter must have either a Writer or a StreamResult to write to at net.sf.saxon.event.Emitter.makeWriter(Emitter.java:133) at net.sf.saxon.event.XMLEmitter.openDocument(XMLEmitter.java:120) at net.sf.saxon.event.XMLEmitter.close(XMLEmitter.java:257) at net.sf.saxon.Controller.transformDocument(Controller.java:1849) at net.sf.saxon.Controller.transform(Controller.java:1621) This is using Saxon 9.1 (not sure which minor rev - date seems to be 2008-07-07). Is this a known bug? Am I doing something wrong? Thanks for any advice. -Mike S.


Replies (2)

RE: using MessageWarner causes an exception - Added by Anonymous over 14 years ago

Legacy ID: #8501929 Legacy Poster: https://www.google.com/accounts ()

I was able to workaround by: Properties props = new Properties(); props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setErrorListener(new ErrorListener()); MessageWarner saxonWarner = new MessageWarner (); try { saxonWarner.setOutputProperties(props); saxonWarner.setOutputStream(System.err); } catch (XPathException e2) { e2.printStackTrace(); } ((Controller)transformer).setMessageEmitter(saxonWarner);

RE: using MessageWarner causes an exception - Added by Anonymous over 14 years ago

Legacy ID: #8502013 Legacy Poster: Michael Kay (mhkay)

Thanks for reporting it. I've committed a patch that should fix it on both the 9.1 and 9.2 branches. It's a simpler fix than yours: it just gives MessageWarner a no-op close() method that prevents the close() call being handled by the superclass, which expects to have an output stream to close.

    (1-2/2)

    Please register to reply