author | aefimov |
Fri, 08 May 2015 11:07:35 +0300 | |
changeset 30521 | 42e1babcddcc |
permissions | -rw-r--r-- |
30521
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
1 |
/* |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
4 |
* |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
8 |
* |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
13 |
* accompanied this code). |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
14 |
* |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
18 |
* |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
21 |
* questions. |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
22 |
*/ |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
23 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
24 |
package javax.xml.transform; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
25 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
26 |
import java.io.StringReader; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
27 |
import java.io.StringWriter; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
28 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
29 |
import javax.xml.transform.stream.StreamResult; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
30 |
import javax.xml.transform.stream.StreamSource; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
31 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
32 |
import org.testng.annotations.DataProvider; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
33 |
import org.testng.annotations.Test; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
34 |
import static org.testng.Assert.assertEquals; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
35 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
36 |
/* |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
37 |
* @summary This class contains tests for XSLT functions. |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
38 |
*/ |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
39 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
40 |
public class XSLTFunctionsTest { |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
41 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
42 |
/** |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
43 |
* @bug 8062518 |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
44 |
* Verifies that a reference to the DTM created by XSLT document function is |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
45 |
* actually read from the DTM by an extension function. |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
46 |
* @param xml Content of xml file to process |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
47 |
* @param xsl stylesheet content that loads external document {@code externalDoc} |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
48 |
* with XSLT 'document' function and then reads it with |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
49 |
* DocumentExtFunc.test() function |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
50 |
* @param externalDoc Content of the external xml document |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
51 |
* @param expectedResult Expected transformation result |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
52 |
**/ |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
53 |
@Test(dataProvider = "document") |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
54 |
public void testDocument(final String xml, final String xsl, |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
55 |
final String externalDoc, final String expectedResult) throws Exception { |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
56 |
// Prepare sources for transormation |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
57 |
Source src = new StreamSource(new StringReader(xml)); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
58 |
Source xslsrc = new StreamSource(new StringReader(xsl)); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
59 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
60 |
// Create factory and transformer |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
61 |
TransformerFactory tf = TransformerFactory.newInstance(); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
62 |
Transformer t = tf.newTransformer( xslsrc ); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
63 |
t.setErrorListener(tf.getErrorListener()); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
64 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
65 |
// Set URI Resolver to return the newly constructed xml |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
66 |
// stream source object from xml test string |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
67 |
t.setURIResolver(new URIResolver() { |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
68 |
@Override |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
69 |
public Source resolve(String href, String base) |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
70 |
throws TransformerException { |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
71 |
if (href.contains("externalDoc")) { |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
72 |
return new StreamSource(new StringReader(externalDoc)); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
73 |
} else { |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
74 |
return new StreamSource(new StringReader(xml)); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
75 |
} |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
76 |
} |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
77 |
}); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
78 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
79 |
// Prepare output stream |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
80 |
StringWriter xmlResultString = new StringWriter(); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
81 |
StreamResult xmlResultStream = new StreamResult(xmlResultString); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
82 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
83 |
//Transform the xml |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
84 |
t.transform(src, xmlResultStream); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
85 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
86 |
// If the document can't be accessed and the bug is in place then |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
87 |
// reported exception will be thrown during transformation |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
88 |
System.out.println("Transformation result:"+xmlResultString.toString().trim()); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
89 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
90 |
// Check the result - it should contain two (node name, node values) entries - |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
91 |
// one for original document, another for a document created with |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
92 |
// call to 'document' function |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
93 |
assertEquals(xmlResultString.toString().trim(), expectedResult); |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
94 |
} |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
95 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
96 |
@DataProvider(name = "document") |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
97 |
public static Object[][] documentTestData() { |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
98 |
return new Object[][] { |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
99 |
{documentTestXml, documentTestXsl, documentTestExternalDoc, documentTesteExpectedResult}, |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
100 |
}; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
101 |
} |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
102 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
103 |
static final String documentTestXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Test>Doc</Test>"; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
104 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
105 |
static final String documentTestExternalDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Test>External Doc</Test>"; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
106 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
107 |
static final String documentTestXsl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
108 |
+ "<xsl:transform version=\"1.0\"" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
109 |
+ " xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" " |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
110 |
+ " xmlns:cfunc=\"http://xml.apache.org/xalan/java/\">" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
111 |
+ "<xsl:template match=\"/\">" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
112 |
+ "<xsl:element name=\"root\">" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
113 |
+ "<xsl:variable name=\"other_doc\" select=\"document('externalDoc')\"/>" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
114 |
+ "<!-- Source -->" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
115 |
+ "<xsl:value-of select=\"cfunc:javax.xml.transform.DocumentExtFunc.test(/Test)\"/>" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
116 |
+ "<!-- document() -->" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
117 |
+ "<xsl:value-of select=\"cfunc:javax.xml.transform.DocumentExtFunc.test($other_doc/Test)\"/>" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
118 |
+ "</xsl:element></xsl:template></xsl:transform>"; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
119 |
|
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
120 |
static final String documentTesteExpectedResult = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
121 |
+ "<root>[Test:Doc][Test:External Doc]</root>"; |
42e1babcddcc
8062518: AIOBE occurs when accessing to document function in extended function in JAXP
aefimov
parents:
diff
changeset
|
122 |
} |