author | joehw |
Thu, 31 Oct 2013 13:51:58 -0700 | |
changeset 21427 | e4cc509e47b2 |
parent 19383 | c27d061358c5 |
child 21613 | 19a42489efef |
permissions | -rw-r--r-- |
19383 | 1 |
/* |
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/** |
|
25 |
* @test @bug 8022548 |
|
26 |
* @summary test that a parser can use DTDConfiguration |
|
27 |
* @run main XOMParserTest |
|
28 |
*/ |
|
29 |
import com.sun.org.apache.xerces.internal.impl.Constants; |
|
30 |
import com.sun.org.apache.xerces.internal.parsers.*; |
|
31 |
import java.io.*; |
|
32 |
import javax.xml.transform.*; |
|
33 |
import javax.xml.transform.stream.StreamResult; |
|
34 |
import javax.xml.transform.stream.StreamSource; |
|
35 |
import org.xml.sax.InputSource; |
|
36 |
||
37 |
/** |
|
38 |
* <p>Test {@link javax.xml.transform.Transformer} for JDK-8022548: SPECJVM2008 |
|
39 |
* has errors introduced in 7u40-b34 |
|
40 |
* |
|
41 |
* Test XOM is supported after jaxp 1.5 </p> |
|
42 |
* |
|
43 |
* @author Joe Wang <huizhe.wang@oracle.com> |
|
44 |
* |
|
45 |
*/ |
|
46 |
public class XOMParserTest extends TestBase { |
|
47 |
||
48 |
public XOMParserTest(String name) { |
|
49 |
super(name); |
|
50 |
} |
|
51 |
||
52 |
/** |
|
53 |
* @param args the command line arguments |
|
54 |
*/ |
|
55 |
public static void main(String[] args) { |
|
56 |
XOMParserTest test = new XOMParserTest("XOM parser test"); |
|
57 |
test.setUp(); |
|
58 |
test.testTransform(); |
|
59 |
test.tearDown(); |
|
60 |
} |
|
61 |
||
62 |
public final void testTransform() { |
|
63 |
||
64 |
try { |
|
65 |
||
66 |
String inFilename = filePath + "/JDK8022548.xml"; |
|
67 |
String xslFilename = filePath + "/JDK8022548.xsl"; |
|
21427
e4cc509e47b2
8024876: [TEST_BUG] javax/xml/jaxp/parsers/8022548/XOMParserTest.java failed when testbase dir has read only permissions
joehw
parents:
19383
diff
changeset
|
68 |
String outFilename = "JDK8022548.out"; |
19383 | 69 |
|
70 |
StringWriter sw = new StringWriter(); |
|
71 |
// Create transformer factory |
|
72 |
TransformerFactory factory = TransformerFactory.newInstance(); |
|
73 |
// set the translet name |
|
74 |
// factory.setAttribute("translet-name", "myTranslet"); |
|
75 |
||
76 |
// set the destination directory |
|
77 |
// factory.setAttribute("destination-directory", "c:\\temp"); |
|
78 |
// factory.setAttribute("generate-translet", Boolean.TRUE); |
|
79 |
||
80 |
// Use the factory to create a template containing the xsl file |
|
81 |
Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslFilename))); |
|
82 |
// Use the template to create a transformer |
|
83 |
Transformer xformer = template.newTransformer(); |
|
84 |
// Prepare the input and output files |
|
85 |
Source source = new StreamSource(new FileInputStream(inFilename)); |
|
86 |
Result result = new StreamResult(new FileOutputStream(outFilename)); |
|
87 |
//Result result = new StreamResult(sw); |
|
88 |
// Apply the xsl file to the source file and write the result to the output file |
|
89 |
xformer.transform(source, result); |
|
90 |
||
91 |
/** |
|
92 |
* String out = sw.toString(); if (out.indexOf("<p>") < 0 ) { |
|
93 |
* fail(out); } |
|
94 |
*/ |
|
95 |
String canonicalizedFileName = outFilename + ".canonicalized"; |
|
96 |
canonicalize(outFilename, canonicalizedFileName); |
|
97 |
} catch (Exception e) { |
|
98 |
// unexpected failure |
|
99 |
fail(e.getMessage()); |
|
100 |
} |
|
101 |
} |
|
102 |
||
103 |
public void canonicalize(String inName, String outName) { |
|
104 |
try (//FileOutputStream outStream = new FileOutputStream(outName); |
|
105 |
FileInputStream inputStream = new FileInputStream(inName);) { |
|
106 |
JDK15XML1_0Parser parser = new JDK15XML1_0Parser(); |
|
107 |
parser.parse(new InputSource(inputStream)); |
|
108 |
success("test passed"); |
|
109 |
} catch (Exception e) { |
|
110 |
fail(e.getMessage()); |
|
111 |
} |
|
112 |
||
113 |
} |
|
114 |
||
115 |
class JDK15XML1_0Parser extends SAXParser { |
|
116 |
||
117 |
JDK15XML1_0Parser() throws org.xml.sax.SAXException { |
|
118 |
||
119 |
super(new DTDConfiguration()); |
|
120 |
// workaround for Java 1.5 beta 2 bugs |
|
121 |
com.sun.org.apache.xerces.internal.util.SecurityManager manager = |
|
122 |
new com.sun.org.apache.xerces.internal.util.SecurityManager(); |
|
123 |
setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.SECURITY_MANAGER_PROPERTY, manager); |
|
124 |
||
125 |
} |
|
126 |
} |
|
127 |
} |