author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58022 | 12885822f0c5 |
permissions | -rw-r--r-- |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
1 |
/* |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
4 |
* |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
8 |
* |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
13 |
* accompanied this code). |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
14 |
* |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
18 |
* |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
21 |
* questions. |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
22 |
*/ |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
23 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
24 |
package transform; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
25 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
26 |
import java.io.ByteArrayInputStream; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
27 |
import java.io.ByteArrayOutputStream; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
28 |
import java.io.InputStream; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
29 |
import java.io.PrintStream; |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
30 |
import java.io.StringReader; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
31 |
import java.io.StringWriter; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
32 |
import java.util.ArrayList; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
33 |
import java.util.List; |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
34 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
35 |
import javax.xml.transform.ErrorListener; |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
36 |
import javax.xml.transform.OutputKeys; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
37 |
import javax.xml.transform.Transformer; |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
38 |
import javax.xml.transform.TransformerConfigurationException; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
39 |
import javax.xml.transform.TransformerException; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
40 |
import javax.xml.transform.TransformerFactory; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
41 |
import javax.xml.transform.sax.SAXSource; |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
42 |
import javax.xml.transform.stream.StreamResult; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
43 |
import javax.xml.transform.stream.StreamSource; |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
44 |
import org.testng.Assert; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
45 |
import org.testng.annotations.AfterClass; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
46 |
import org.testng.annotations.BeforeClass; |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
47 |
import org.testng.annotations.DataProvider; |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
48 |
import org.testng.annotations.Test; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
49 |
import org.xml.sax.InputSource; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
50 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
51 |
/* |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
52 |
* @test |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
53 |
* @bug 8157830 8228854 |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
54 |
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
55 |
* @run testng/othervm transform.ErrorListenerTest |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
56 |
* @summary Verifies that ErrorListeners are handled properly |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
57 |
*/ |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
58 |
public class ErrorListenerTest { |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
59 |
static final int SYSTEM_ERR = 1; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
60 |
static final int SYSTEM_OUT = 2; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
61 |
static final String ERR_STDERR = "Msg sent to stderr"; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
62 |
static final String ERR_STDOUT = "Msg sent to stdout"; |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
63 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
64 |
static final private String INVALID_STYLESHEET = "xxx"; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
65 |
static final private String SYSTEM_ID = "http://openjdk_java_net/xsl/dummy.xsl"; |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
66 |
|
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
67 |
final private String INCLUDE_NOT_EXIST = "<?xml version=\"1.1\" encoding=\"UTF-8\"?>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
68 |
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
69 |
" <xsl:import href=\"NOSUCHFILE.xsl\"/>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
70 |
"</xsl:stylesheet>"; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
71 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
72 |
final private String VAR_UNDEFINED = "<?xml version=\"1.1\" encoding=\"ISO-8859-1\"?>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
73 |
"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
74 |
" <xsl:template match=\"/\"> " + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
75 |
" <test1><xsl:apply-templates select=\"$ids\"/></test1>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
76 |
" <test2><xsl:apply-templates select=\"$dummy//ids/id\"/></test2>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
77 |
" </xsl:template>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
78 |
"</xsl:stylesheet>"; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
79 |
final private String XSL_DOC_FUNCTION = "<?xml version=\"1.1\" encoding=\"ISO-8859-1\"?>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
80 |
"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
81 |
" <xsl:output method=\"xml\" indent=\"yes\"/>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
82 |
" <xsl:variable name=\"ids\" select=\"//ids//id\"/>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
83 |
" <xsl:variable name=\"dummy\" select=\"document('NOSUCHFILE.xml')\"/>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
84 |
" <xsl:template match=\"/\"> " + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
85 |
" <test1><xsl:apply-templates select=\"$ids\"/></test1>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
86 |
" <test2><xsl:apply-templates select=\"$dummy//ids/id\"/></test2>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
87 |
" </xsl:template>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
88 |
" <xsl:template match=\"id\">" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
89 |
" <xsl:variable name=\"entity\" select=\"id(@value)\"/> " + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
90 |
" <must-be-one><xsl:value-of select=\"count($entity)\"/></must-be-one>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
91 |
" </xsl:template>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
92 |
"</xsl:stylesheet>"; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
93 |
final private String XML_DOC_FUNCTION = "<?xml version=\"1.1\" encoding=\"ISO-8859-1\" standalone=\"no\"?>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
94 |
"<organization2>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
95 |
" <company id=\"xca\" count=\"2\">" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
96 |
" <department id=\"xda\"/>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
97 |
" </company>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
98 |
" <company id=\"xcb\" count=\"0\"/>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
99 |
" <company id=\"xcc\" count=\"5\"/>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
100 |
" <ids>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
101 |
" <id value=\"xca\"/>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
102 |
" <id value=\"xcb\"/>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
103 |
" </ids>" + |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
104 |
"</organization2>"; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
105 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
106 |
PrintStream originalErr, originalOut; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
107 |
List<String> testMsgs = new ArrayList<>(); |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
108 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
109 |
@BeforeClass |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
110 |
public void setUpClass() throws Exception { |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
111 |
// save the PrintStream |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
112 |
originalErr = System.err; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
113 |
originalOut = System.out; |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
114 |
} |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
115 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
116 |
@AfterClass |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
117 |
protected void tearDown() throws Exception { |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
118 |
// set back to the original |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
119 |
System.setErr(originalErr); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
120 |
System.setOut(originalOut); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
121 |
// print out test messages |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
122 |
testMsgs.stream().forEach((msg) -> { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
123 |
System.out.println(msg); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
124 |
}); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
125 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
126 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
127 |
/* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
128 |
DataProvider: for ErrorListenner tests |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
129 |
Data: xsl, xml, setListener(true/false), output channel(stderr/stdout), |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
130 |
expected console output, expected listener output |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
131 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
132 |
@DataProvider(name = "testCreatingTransformer") |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
133 |
public Object[][] getTransformer() { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
134 |
return new Object[][]{ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
135 |
/* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
136 |
* Verifies that the default implementation does not print out |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
137 |
* warnings and errors to stderr. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
138 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
139 |
{INCLUDE_NOT_EXIST, false, ""}, |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
140 |
{VAR_UNDEFINED, false, ""}, |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
141 |
/* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
142 |
* Verifies that the registered listener is used. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
143 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
144 |
{INCLUDE_NOT_EXIST, true, "NOSUCHFILE.xsl"}, |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
145 |
{VAR_UNDEFINED, true, "'ids' is undefined"}, |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
146 |
/* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
147 |
* The original test for JDK8157830 |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
148 |
* Verifies that when an ErrorListener is registered, parser errors |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
149 |
* are passed onto the listener without other output. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
150 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
151 |
{INVALID_STYLESHEET, true, "Content is not allowed in prolog"}, |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
152 |
}; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
153 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
154 |
/* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
155 |
DataProvider: for ErrorListenner tests |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
156 |
Data: xsl, xml, setListener(true/false), output channel(stderr/stdout), |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
157 |
expected console output, expected listener output |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
158 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
159 |
@DataProvider(name = "testTransform") |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
160 |
public Object[][] getTransform() { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
161 |
return new Object[][]{ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
162 |
/* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
163 |
* Verifies that the default implementation does not print out |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
164 |
* warnings and errors to stderr. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
165 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
166 |
{XSL_DOC_FUNCTION, XML_DOC_FUNCTION, false, ""}, |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
167 |
/* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
168 |
* Verifies that the default implementation does not print out |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
169 |
* warnings and errors to stderr. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
170 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
171 |
{XSL_DOC_FUNCTION, XML_DOC_FUNCTION, true, "NOSUCHFILE.xml"} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
172 |
}; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
173 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
174 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
175 |
/* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
176 |
DataProvider: for ErrorListenner tests |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
177 |
Data: xsl, xml, setListener(true/false), expected listener output |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
178 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
179 |
@DataProvider(name = "testEncoding") |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
180 |
public Object[][] getData() { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
181 |
return new Object[][]{ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
182 |
{"<foo><bar></bar></foo>", false, ""}, |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
183 |
{"<foo><bar></bar></foo>", true, "'dummy' is not supported"} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
184 |
}; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
185 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
186 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
187 |
/** |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
188 |
* Verifies that ErrorListeners are properly set and propagated, or the |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
189 |
* default ErrorListener does not send messages to stderr/stdout. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
190 |
* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
191 |
* @param xsl the stylesheet |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
192 |
* @param setListener a flag indicating whether a listener should be set |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
193 |
* @param msgL the expected listener output |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
194 |
* @throws Exception if the test fails |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
195 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
196 |
@Test(dataProvider = "testCreatingTransformer") |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
197 |
public void testTransformer(String xsl, boolean setListener, String msgL) |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
198 |
throws Exception { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
199 |
ErrListener listener = setListener ? new ErrListener("test") : null; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
200 |
String msgConsole = getTransformerErr("testTransformer", xsl, listener); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
201 |
evalResult(listener, msgConsole, setListener, msgL); |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
202 |
} |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
203 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
204 |
/** |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
205 |
* Verifies that ErrorListeners are properly set and propagated, or the |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
206 |
* default ErrorListener does not send messages to stderr/stdout. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
207 |
* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
208 |
* @param xsl the stylesheet |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
209 |
* @param xml the XML |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
210 |
* @param setListener a flag indicating whether a listener should be set |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
211 |
* @param msgL the expected listener output |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
212 |
* @throws Exception if the test fails |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
213 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
214 |
//@Test(dataProvider = "testTransform") |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
215 |
public void testTransform(String xsl, String xml, boolean setListener, String msgL) |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
216 |
throws Exception { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
217 |
ErrListener listener = setListener ? new ErrListener("test") : null; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
218 |
Transformer t = getTransformer("testDocFunc", xsl, listener); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
219 |
String msgConsole = transform("testDocFunc", xml, t); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
220 |
evalResult(listener, msgConsole, setListener, msgL); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
221 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
222 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
223 |
/** |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
224 |
* Verifies that the default implementation does not print out warnings and |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
225 |
* errors to the console when an invalid encoding is set. |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
226 |
* |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
227 |
* @throws Exception if the test fails |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
228 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
229 |
//@Test(dataProvider = "testEncoding") |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
230 |
public void testEncoding(String xml, boolean setListener, String msgL) |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
231 |
throws Exception { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
232 |
ErrListener listener = setListener ? new ErrListener("test") : null; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
233 |
Transformer t = TransformerFactory.newInstance().newTransformer(); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
234 |
if (setListener) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
235 |
t.setErrorListener(listener); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
236 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
237 |
t.setOutputProperty(OutputKeys.ENCODING, "dummy"); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
238 |
String msgConsole = transform("testEncoding", "<foo><bar></bar></foo>", t); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
239 |
evalResult(listener, msgConsole, setListener, msgL); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
240 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
241 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
242 |
private void evalResult(ErrListener l, String m, boolean setListener, String msgL) |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
243 |
throws Exception{ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
244 |
Assert.assertTrue(!m.contains(ERR_STDERR), "no output to stderr"); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
245 |
Assert.assertTrue(!m.contains(ERR_STDOUT), "no output to stdout"); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
246 |
if (setListener) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
247 |
testMsgs.add("l.errMsg=" + l.errMsg); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
248 |
testMsgs.add("evalResult.msgL=" + msgL); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
249 |
Assert.assertTrue(l.errMsg.contains(msgL), |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
250 |
"The registered listener shall be used."); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
251 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
252 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
253 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
254 |
/** |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
255 |
* Obtains a Transformer. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
256 |
* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
257 |
* @param test the name of the test |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
258 |
* @param xsl the stylesheet |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
259 |
* @param setListener a flag indicating whether to set a listener |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
260 |
* @return the Transformer, null if error occurs |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
261 |
* @throws Exception |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
262 |
*/ |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
263 |
private Transformer getTransformer(String test, String xsl, ErrorListener listener) |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
264 |
throws Exception { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
265 |
Transformer f = null; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
266 |
InputSource source = new InputSource(new ByteArrayInputStream(xsl.getBytes())); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
267 |
TransformerFactory factory = TransformerFactory.newInstance(); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
268 |
if (listener != null) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
269 |
factory.setErrorListener(listener); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
270 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
271 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
272 |
try { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
273 |
f = factory.newTransformer(new SAXSource(source)); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
274 |
if (listener != null) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
275 |
f.setErrorListener(listener); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
276 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
277 |
} catch (TransformerConfigurationException e) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
278 |
testMsgs.add(test + "::catch: " + e.getMessage()); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
279 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
280 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
281 |
return f; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
282 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
283 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
284 |
/** |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
285 |
* Attempts to capture messages sent to stderr/stdout during the creation |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
286 |
* of a Transformer. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
287 |
* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
288 |
* @param test the name of the test |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
289 |
* @param xsl the stylesheet |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
290 |
* @param setListener a flag indicating whether to set a listener |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
291 |
* @return message sent to stderr/stdout, null if none |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
292 |
* @throws Exception |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
293 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
294 |
private String getTransformerErr(String test, String xsl, ErrorListener listener) |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
295 |
throws Exception { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
296 |
InputStream is = new ByteArrayInputStream(xsl.getBytes()); |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
297 |
InputSource source = new InputSource(is); |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
298 |
|
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
299 |
ByteArrayOutputStream baos1 = setOutput(SYSTEM_ERR); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
300 |
ByteArrayOutputStream baos2 = setOutput(SYSTEM_OUT); |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
301 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
302 |
TransformerFactory factory = TransformerFactory.newInstance(); |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
303 |
if (listener != null) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
304 |
factory.setErrorListener(listener); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
305 |
} |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
306 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
307 |
try { |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
308 |
factory.newTransformer(new SAXSource(source)); |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
309 |
} catch (TransformerConfigurationException e) { |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
310 |
testMsgs.add(test + "::catch: " + e.getMessage()); |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
311 |
} |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
312 |
reset(); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
313 |
String msg = !"".equals(baos1.toString()) ? ERR_STDERR : ""; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
314 |
msg = !"".equals(baos2.toString()) ? msg + ERR_STDOUT : msg; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
315 |
return msg; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
316 |
} |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
317 |
|
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
318 |
/** |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
319 |
* Transforms an XML file. Attempts to capture stderr/stdout as the Transformer |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
320 |
* may direct messages to stdout. |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
321 |
* |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
322 |
* @param test the name of the test |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
323 |
* @param xml the XML file |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
324 |
* @param t the Transformer |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
325 |
* @param type the flag indicating which output channel to capture |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
326 |
* @return message sent to stdout, null if none |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
327 |
* @throws Exception |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
328 |
*/ |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
329 |
private String transform(String test, String xml, Transformer t) |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
330 |
throws Exception { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
331 |
StreamSource source = new StreamSource(new StringReader(xml)); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
332 |
StreamResult result = new StreamResult(new StringWriter()); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
333 |
ByteArrayOutputStream baos1 = setOutput(SYSTEM_ERR); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
334 |
ByteArrayOutputStream baos2 = setOutput(SYSTEM_OUT); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
335 |
try { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
336 |
t.transform(source, result); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
337 |
} catch (Exception e) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
338 |
testMsgs.add(test + "::catch: " + e.getMessage()); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
339 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
340 |
reset(); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
341 |
String msg = !"".equals(baos1.toString()) ? ERR_STDERR : ""; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
342 |
msg = !"".equals(baos2.toString()) ? msg + ERR_STDOUT : msg; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
343 |
return msg; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
344 |
} |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
345 |
|
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
346 |
private ByteArrayOutputStream setOutput(int type) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
347 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
348 |
PrintStream ps = new PrintStream(baos); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
349 |
if (type == SYSTEM_ERR) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
350 |
System.setErr(ps); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
351 |
} else { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
352 |
System.setOut(ps); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
353 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
354 |
return baos; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
355 |
} |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
356 |
|
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
357 |
private void reset() { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
358 |
System.setErr(originalErr); |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
359 |
System.setOut(originalOut); |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
360 |
} |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
361 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
362 |
class ErrListener implements ErrorListener { |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
363 |
String testName; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
364 |
String errMsg = ""; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
365 |
ErrListener(String test) { |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
366 |
testName = test; |
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
367 |
} |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
368 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
369 |
@Override |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
370 |
public void error(TransformerException e) |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
371 |
throws TransformerException { |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
372 |
errMsg = errMsg + "#error: " + e.getMessage(); |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
373 |
} |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
374 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
375 |
@Override |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
376 |
public void fatalError(TransformerException e) |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
377 |
throws TransformerException { |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
378 |
errMsg = errMsg + "#fatalError: " + e.getMessage(); |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
379 |
} |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
380 |
|
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
381 |
@Override |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
382 |
public void warning(TransformerException e) |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
383 |
throws TransformerException { |
58022
12885822f0c5
8228854: Default ErrorListener reports warnings and errors to the console
joehw
parents:
55742
diff
changeset
|
384 |
errMsg = errMsg + "#warning: " + e.getMessage(); |
55742
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
385 |
} |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
386 |
} |
6e1161923897
8157830: Errors in XSLT stylesheet are not dispatched correctly to ErrorListener
joehw
parents:
diff
changeset
|
387 |
} |