[bugfix] fn:transform() now logs xsl:message output - #235
Conversation
Closes #234 We have registered a Saxon MessageListener on the Xslt30Transformer so xsl:message output now goes to the Elemental log instead of just printing to the console.
Not up to standards ⛔
|
408190a to
933b1be
Compare
|
|
||
| final Xslt30Transformer xslt30Transformer = xsltExecutable.load30(); | ||
|
|
||
| xslt30Transformer.setMessageListener((content, terminate, locator) ->{ |
There was a problem hiding this comment.
Can you please have this as a separate class at the bottom of the file rather than a large lambda here,
e.g.
private static class XsltMessageListener implements MessageListener {
...
}| import net.sf.saxon.s9api.*; | ||
| import net.sf.saxon.serialize.SerializationProperties; | ||
| import net.sf.saxon.trans.UncheckedXPathException; | ||
| import org.apache.commons.io.output.StringBuilderWriter; |
There was a problem hiding this comment.
Just use java.io.StringWriter here please
| serializer.setOutputWriter(writer); | ||
| serializer.serializeNode(content); | ||
|
|
||
| final String source; |
There was a problem hiding this comment.
@Nullable final String source;
Import the annotation from googlecode findbugs library please
| sourceColumn = -1; | ||
| } | ||
|
|
||
| LOGGER.info("<xsl:message terminate=\"{}\" source=\"{}\" sourceLine=\"{}\" sourceColumn=\"{}\">{}</xsl:message>", |
There was a problem hiding this comment.
if source is null please don't print out the source= bit. Same goes for if sourceLine is -1 please don't print out the sourceLine and sourceColumn
| final XQueryUtil.QueryResult queryResult = XQueryUtil.query(broker, new StringSource(query), false, null, null, null, null, null)) { | ||
| assertNotNull(queryResult.result); | ||
| } catch (final XPathException e) { | ||
| fail("Transform should have succeeded: " + e.getMessage()); |
There was a problem hiding this comment.
Just throw the exception from tests
| fail("Transform should have succeeded: " + e.getMessage()); | ||
| } | ||
|
|
||
| final Optional<String> logged = appender.getMessages().stream() |
| */ | ||
| private static class CapturingAppender extends AbstractAppender { | ||
|
|
||
| private final List<String> messages = new CopyOnWriteArrayList<>(); |
There was a problem hiding this comment.
Should not be CopyOnWriteArrayList
| " \"stylesheet-text\": '<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"3.0\">\n" + | ||
| " <xsl:template match=\"/\">\n" + | ||
| " <xsl:message>Hello from XSLT</xsl:message>\n" + | ||
| " <out/>\n" + |
| try { | ||
| final String query = | ||
| "fn:transform(map {\n" + | ||
| " \"stylesheet-text\": '<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"3.0\">\n" + |
There was a problem hiding this comment.
version should be 2.0 not 3.0
| final CapturingAppender appender = new CapturingAppender(); | ||
| appender.start(); | ||
|
|
||
| final org.apache.logging.log4j.core.Logger transformLogger = |
There was a problem hiding this comment.
Fully qualified names hare are not needed
We have registered a Saxon MessageListener on the Xslt30Transformer so xsl:message output now goes to the Elemental log instead of just printing to the console.
closes #234