1 /*
2 * Copyright (c) 2014, 2015, 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 package parsers;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.InputStream;
29
30 import javax.xml.XMLConstants;
31 import javax.xml.parsers.DocumentBuilder;
32 import javax.xml.parsers.DocumentBuilderFactory;
33 import javax.xml.parsers.ParserConfigurationException;
34 import javax.xml.parsers.SAXParser;
35 import javax.xml.parsers.SAXParserFactory;
36 import javax.xml.transform.stream.StreamSource;
37 import javax.xml.validation.Schema;
38 import javax.xml.validation.SchemaFactory;
39
40 import org.testng.Assert;
41 import org.testng.annotations.Test;
42 import org.w3c.dom.Document;
43 import org.w3c.dom.Node;
44 import org.w3c.dom.Text;
45 import org.xml.sax.SAXException;
46 import org.xml.sax.helpers.DefaultHandler;
47
48 /*
49 * @bug 6564400
50 * @summary Test ignorable whitespace handling with schema validation.
51 */
52 public class Bug6564400 {
53 private boolean sawIgnorable = false;
54 Schema schema = null;
55
56 public Bug6564400(String name) {
57 String xsdFile = "Bug6564400.xsd";
58 File schemaFile = new File(xsdFile);
59
60 // Now attempt to load up the schema
61 try {
62 SchemaFactory schFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
63 schema = schFactory.newSchema(new StreamSource(getClass().getResourceAsStream(xsdFile)));
64 } catch (Exception e) {
65 // Nevermind, bad things will happen later
66 }
67 }
68
69 @Test
70 public void testDOM() throws ParserConfigurationException, SAXException, IOException {
71 InputStream xmlFile = getClass().getResourceAsStream("Bug6564400.xml");
151 System.out.print(" ");
152 }
153 System.out.println(node);
154 }
155
156 if (node.getNodeType() == Node.TEXT_NODE) {
157 String text = ((Text) node).getData();
158 ok = ok && text.trim().length() > 0;
159 }
160
161 if (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE) {
162 Node child = node.getFirstChild();
163 while (child != null) {
164 ok = ok && dump(child, silent, depth + 1);
165 child = child.getNextSibling();
166 }
167 }
168 return ok;
169 }
170
171 public class MyHandler extends DefaultHandler {
172 public void ignorableWhitespace(char[] ch, int start, int length) {
173 sawIgnorable = true;
174 }
175 }
176 }
|
1 /*
2 * Copyright (c) 2014, 2016, 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 package parsers;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.InputStream;
29
30 import javax.xml.XMLConstants;
31 import javax.xml.parsers.DocumentBuilder;
32 import javax.xml.parsers.DocumentBuilderFactory;
33 import javax.xml.parsers.ParserConfigurationException;
34 import javax.xml.parsers.SAXParser;
35 import javax.xml.parsers.SAXParserFactory;
36 import javax.xml.transform.stream.StreamSource;
37 import javax.xml.validation.Schema;
38 import javax.xml.validation.SchemaFactory;
39
40 import org.testng.Assert;
41 import org.testng.annotations.Listeners;
42 import org.testng.annotations.Test;
43 import org.w3c.dom.Document;
44 import org.w3c.dom.Node;
45 import org.w3c.dom.Text;
46 import org.xml.sax.SAXException;
47 import org.xml.sax.helpers.DefaultHandler;
48
49 /*
50 * @bug 6564400
51 * @summary Test ignorable whitespace handling with schema validation.
52 */
53 @Listeners({jaxp.library.FilePolicy.class})
54 public class Bug6564400 {
55 private boolean sawIgnorable = false;
56 Schema schema = null;
57
58 public Bug6564400(String name) {
59 String xsdFile = "Bug6564400.xsd";
60 File schemaFile = new File(xsdFile);
61
62 // Now attempt to load up the schema
63 try {
64 SchemaFactory schFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
65 schema = schFactory.newSchema(new StreamSource(getClass().getResourceAsStream(xsdFile)));
66 } catch (Exception e) {
67 // Nevermind, bad things will happen later
68 }
69 }
70
71 @Test
72 public void testDOM() throws ParserConfigurationException, SAXException, IOException {
73 InputStream xmlFile = getClass().getResourceAsStream("Bug6564400.xml");
153 System.out.print(" ");
154 }
155 System.out.println(node);
156 }
157
158 if (node.getNodeType() == Node.TEXT_NODE) {
159 String text = ((Text) node).getData();
160 ok = ok && text.trim().length() > 0;
161 }
162
163 if (node.getNodeType() == Node.ELEMENT_NODE || node.getNodeType() == Node.DOCUMENT_NODE) {
164 Node child = node.getFirstChild();
165 while (child != null) {
166 ok = ok && dump(child, silent, depth + 1);
167 child = child.getNextSibling();
168 }
169 }
170 return ok;
171 }
172
173 @Listeners({jaxp.library.BasePolicy.class})
174 public class MyHandler extends DefaultHandler {
175 public void ignorableWhitespace(char[] ch, int start, int length) {
176 sawIgnorable = true;
177 }
178 }
179 }
|