S9API: How To Log To A GUI Window?
Added by Anonymous over 16 years ago
Legacy ID: #4871720 Legacy Poster: W. Eliot Kimber (drmacro)
I'm using the S9 API to run a transform from a GUI application. I want to capture the message output from the transform and put it in a GUI window but I'm not seeing an obvious way to do this in a direct way. I didn't see any samples of custom error listeners in the S9API example code. Looking that API there doesn't appear to be a way to pass an ErrorListener instance to the transform. That is, I'm trying to do something like this: GuiSaxonLogger logger = new GuiSaxonLogger(logFile); Processor proc = new Processor(false); XsltCompiler compiler = proc.newXsltCompiler(); // This works but has no useful effect since my stylesheet will compile fine. compiler.setErrorListener(logger); XsltExecutable exp = compiler.compile(new StreamSource(xsltFile)); XdmNode source = proc.newDocumentBuilder().build(new StreamSource(inputMapFile)); Serializer out = new Serializer(); // Set up output options.. XsltTransformer trans = exp.load(); // Set up options and whatnot for the transform... // *** Would expect to set logger on transform here *** trans.transform(); While I can set my logger on the compiler, that doesn't seem to carry over to the transform itself (I didn't really expect it to). I know I can set the message emitter class as a configuration property on the Processor but I don't how to have a class that the Processor instantiates contribute to the GUI that's constructing the Processor. Did I miss something in the API or this simply not possible? Thanks, Eliot
Replies (3)
Please register to reply
RE: S9API: How To Log To A GUI Window? - Added by Anonymous over 16 years ago
Legacy ID: #4872464 Legacy Poster: Michael Kay (mhkay)
It's not clear to me whether you're wanting to capture error messages or xsl:message messages? The patch for 1910722, which is present in 9.0.0.4, adds a method XsltTransformer.getUnderlyingController(), which can be used to get access to all the methods available on the net.sf.saxon.Controller object (the implementation of the JAXP Transformer). This includes the ability to set MessageEmitter, ErrorListener, etc. I deliberately didn't include all these hooks in the first release of s9api, because I wanted to take the time to think how best to design them. I'm a little undecided about whether to provide access to the existing hooks (which don't follow a very coherent design) or to design a completely new and hopefully more consistent mechanism. Meanwhile, the idea is that advanced users who need this kind of thing can escape from s9api into the lower-level Saxon interfaces. Michael Kay, Saxonica
RE: S9API: How To Log To A GUI Window? - Added by Anonymous over 16 years ago
Legacy ID: #4873217 Legacy Poster: W. Eliot Kimber (drmacro)
I definitely need to capture xsl:message output but also any other messages generated by Saxon (e.g., compile failures, stack overflows, etc.). I'll check out 9.0.0.4 and see if that works. My other option would be to run the transform via Ant, which I also have integrated with this particular GUI (I'm running DITA Open Toolkit processes as well as my own XSLT preprocessing). But I would like to know how to do this with Saxon generally since I'm sure I'll need it at some point. Thanks, Eliot
RE: S9API: How To Log To A GUI Window? - Added by Anonymous over 16 years ago
Legacy ID: #4873294 Legacy Poster: W. Eliot Kimber (drmacro)
OK, I was able to use the underlying controller to set my GUI Emitter implementation, which just delegates to MessageEmitter except for the methods that get the actual message text (which I then write to a JTextField in my GUI. Easy enough once you know what to do. This same class also implements ErrorListener and gets those messages too. Not sure at this point what the best design for the S9API would be but at least there's a use case now.... Cheers, Eliot
Please register to reply