This is an automated email from the ASF dual-hosted git repository. vladimirsitnikov pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push: new f1db79f [CALCITE-4131] remove the XmlFunctions exception handled by System.out f1db79f is described below commit f1db79fb876ac9ba3c405283e99bb0438e4e97be Author: NobiGo <nobigo...@gmail.com> AuthorDate: Sat Sep 25 23:05:54 2021 +0800 [CALCITE-4131] remove the XmlFunctions exception handled by System.out --- .../org/apache/calcite/runtime/XmlFunctions.java | 26 +++++++++++++++++++++- core/src/test/resources/sql/functions.iq | 7 ++++++ gradle.properties | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/runtime/XmlFunctions.java b/core/src/main/java/org/apache/calcite/runtime/XmlFunctions.java index 13d270f..8c81647 100644 --- a/core/src/main/java/org/apache/calcite/runtime/XmlFunctions.java +++ b/core/src/main/java/org/apache/calcite/runtime/XmlFunctions.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.xml.transform.ErrorListener; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; @@ -61,7 +62,11 @@ public class XmlFunctions { private static final ThreadLocal<@Nullable XPathFactory> XPATH_FACTORY = ThreadLocal.withInitial(XPathFactory::newInstance); private static final ThreadLocal<@Nullable TransformerFactory> TRANSFORMER_FACTORY = - ThreadLocal.withInitial(TransformerFactory::newInstance); + ThreadLocal.withInitial(() -> { + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setErrorListener(new InternalErrorListener()); + return transformerFactory; + }); private static final Pattern VALID_NAMESPACE_PATTERN = Pattern .compile("^(([0-9a-zA-Z:_-]+=\"[^\"]*\")( [0-9a-zA-Z:_-]+=\"[^\"]*\")*)$"); @@ -107,6 +112,7 @@ public class XmlFunctions { .newTransformer(xsltSource); final StringWriter writer = new StringWriter(); final StreamResult result = new StreamResult(writer); + transformer.setErrorListener(new InternalErrorListener()); transformer.transform(xmlSource, result); return writer.toString(); } catch (TransformerConfigurationException e) { @@ -203,8 +209,26 @@ public class XmlFunctions { private static String convertNodeToString(Node node) throws TransformerException { StringWriter writer = new StringWriter(); Transformer transformer = castNonNull(TRANSFORMER_FACTORY.get()).newTransformer(); + transformer.setErrorListener(new InternalErrorListener()); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } + + /** The internal default ErrorListener for Transformer. Just rethrows errors to + * discontinue the XML transformation. */ + private static class InternalErrorListener implements ErrorListener { + + @Override public void warning(TransformerException exception) throws TransformerException { + throw exception; + } + + @Override public void error(TransformerException exception) throws TransformerException { + throw exception; + } + + @Override public void fatalError(TransformerException exception) throws TransformerException { + throw exception; + } + } } diff --git a/core/src/test/resources/sql/functions.iq b/core/src/test/resources/sql/functions.iq index b3cefad..58770a0 100644 --- a/core/src/test/resources/sql/functions.iq +++ b/core/src/test/resources/sql/functions.iq @@ -179,5 +179,12 @@ SELECT EXISTSNODE( !ok +SELECT XMLTRANSFORM( + '<', + '<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> + </xsl:stylesheet>' + ); +Invalid input for XMLTRANSFORM xml: '<' +!error # End functions.iq diff --git a/gradle.properties b/gradle.properties index 7a3d179..23365ad 100644 --- a/gradle.properties +++ b/gradle.properties @@ -134,7 +134,7 @@ pig.version=0.16.0 pigunit.version=0.16.0 postgresql.version=9.3-1102-jdbc41 protobuf.version=3.17.1 -quidem.version=0.9 +quidem.version=0.10 scala-library.version=2.10.3 scott-data-hsqldb.version=0.1 servlet.version=4.0.1