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 sax;
25
26 import java.io.IOException;
27
28 import javax.xml.parsers.ParserConfigurationException;
29 import javax.xml.parsers.SAXParser;
30 import javax.xml.parsers.SAXParserFactory;
31
32 import org.testng.Assert;
33 import org.testng.AssertJUnit;
34 import org.testng.annotations.Test;
35 import org.xml.sax.SAXException;
36 import org.xml.sax.SAXNotRecognizedException;
37 import org.xml.sax.XMLReader;
38 import org.xml.sax.ext.DefaultHandler2;
39 import org.xml.sax.helpers.DefaultHandler;
40 import org.xml.sax.helpers.ParserAdapter;
41 import org.xml.sax.helpers.XMLFilterImpl;
42 import org.xml.sax.helpers.XMLReaderFactory;
43
44 /*
45 * @summary Test DefaultHandler2.
46 */
47 public class DefaultHandler2Test {
48
49 @Test
50 public void testParse01() {
51 System.out.println("===in testParse01===");
52 try {
53 DefaultHandler handler = new MyDefaultHandler2();
54 SAXParserFactory saxFac = SAXParserFactory.newInstance();
55 System.out.println(saxFac.getFeature("http://xml.org/sax/features/use-locator2"));
56
57 // set use-entity-resolver2 as FALSE to use EntityResolver firstly.
58 saxFac.setFeature("http://xml.org/sax/features/use-entity-resolver2", false);
59 saxFac.setValidating(true);
60
61 SAXParser parser = saxFac.newSAXParser();
62 parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
63 parser.setProperty("http://xml.org/sax/properties/declaration-handler", handler);
64
65 parser.parse(this.getClass().getResource("toys.xml").getFile(), handler);
66 } catch (ParserConfigurationException e) {
|
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 sax;
25
26 import java.io.IOException;
27
28 import javax.xml.parsers.ParserConfigurationException;
29 import javax.xml.parsers.SAXParser;
30 import javax.xml.parsers.SAXParserFactory;
31
32 import org.testng.Assert;
33 import org.testng.AssertJUnit;
34 import org.testng.annotations.Listeners;
35 import org.testng.annotations.Test;
36 import org.xml.sax.SAXException;
37 import org.xml.sax.SAXNotRecognizedException;
38 import org.xml.sax.XMLReader;
39 import org.xml.sax.ext.DefaultHandler2;
40 import org.xml.sax.helpers.DefaultHandler;
41 import org.xml.sax.helpers.ParserAdapter;
42 import org.xml.sax.helpers.XMLFilterImpl;
43 import org.xml.sax.helpers.XMLReaderFactory;
44
45 /*
46 * @summary Test DefaultHandler2.
47 */
48 @Listeners({jaxp.library.FilePolicy.class})
49 public class DefaultHandler2Test {
50
51 @Test
52 public void testParse01() {
53 System.out.println("===in testParse01===");
54 try {
55 DefaultHandler handler = new MyDefaultHandler2();
56 SAXParserFactory saxFac = SAXParserFactory.newInstance();
57 System.out.println(saxFac.getFeature("http://xml.org/sax/features/use-locator2"));
58
59 // set use-entity-resolver2 as FALSE to use EntityResolver firstly.
60 saxFac.setFeature("http://xml.org/sax/features/use-entity-resolver2", false);
61 saxFac.setValidating(true);
62
63 SAXParser parser = saxFac.newSAXParser();
64 parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
65 parser.setProperty("http://xml.org/sax/properties/declaration-handler", handler);
66
67 parser.parse(this.getClass().getResource("toys.xml").getFile(), handler);
68 } catch (ParserConfigurationException e) {
|