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 validation;
25
26 import java.io.IOException;
27 import java.io.StringReader;
28
29 import javax.xml.parsers.ParserConfigurationException;
30 import javax.xml.parsers.SAXParserFactory;
31 import javax.xml.transform.stream.StreamSource;
32 import javax.xml.validation.Schema;
33 import javax.xml.validation.SchemaFactory;
34 import javax.xml.validation.TypeInfoProvider;
35 import javax.xml.validation.ValidatorHandler;
36
37 import org.testng.Assert;
38 import org.testng.annotations.Test;
39 import org.xml.sax.Attributes;
40 import org.xml.sax.InputSource;
41 import org.xml.sax.SAXException;
42 import org.xml.sax.XMLReader;
43 import org.xml.sax.helpers.DefaultHandler;
44
45 /*
46 * @bug 4970402
47 * @summary Test TypeInfoProvider's attribute accessing methods throw IndexOutOfBoundsException when index parameter is invalid.
48 */
49 public class Bug4970402 {
50
51 public static final String XSD = "<?xml version='1.0'?>\n" + "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n" + " xmlns:test='jaxp13_test'\n"
52 + " targetNamespace='jaxp13_test'\n" + " elementFormDefault='qualified'>\n" + " <element name='test'>\n"
53 + " <complexType>\n" + " <sequence>\n" + " <element name='child' type='string'/>\n" + " </sequence>\n"
54 + " <attribute name='id' />\n" + " </complexType>\n" + " </element>\n" + "</schema>\n";
55
56 public static final String XML = "<?xml version='1.0'?>\n" + "<ns:test xmlns:ns='jaxp13_test' id='2003-12-02'>\n" + " <ns:child>123abc</ns:child>\n"
57 + "</ns:test>\n";
58
59 private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
60 SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
61
62 StringReader reader = new StringReader(xsd);
63 StreamSource xsdSource = new StreamSource(reader);
64
65 Schema schema = schemaFactory.newSchema(xsdSource);
66 return schema.newValidatorHandler();
67 }
68
|
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 validation;
25
26 import java.io.IOException;
27 import java.io.StringReader;
28
29 import javax.xml.parsers.ParserConfigurationException;
30 import javax.xml.parsers.SAXParserFactory;
31 import javax.xml.transform.stream.StreamSource;
32 import javax.xml.validation.Schema;
33 import javax.xml.validation.SchemaFactory;
34 import javax.xml.validation.TypeInfoProvider;
35 import javax.xml.validation.ValidatorHandler;
36
37 import org.testng.Assert;
38 import org.testng.annotations.Listeners;
39 import org.testng.annotations.Test;
40 import org.xml.sax.Attributes;
41 import org.xml.sax.InputSource;
42 import org.xml.sax.SAXException;
43 import org.xml.sax.XMLReader;
44 import org.xml.sax.helpers.DefaultHandler;
45
46 /*
47 * @bug 4970402
48 * @summary Test TypeInfoProvider's attribute accessing methods throw IndexOutOfBoundsException when index parameter is invalid.
49 */
50 @Listeners({jaxp.library.BasePolicy.class})
51 public class Bug4970402 {
52
53 public static final String XSD = "<?xml version='1.0'?>\n" + "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n" + " xmlns:test='jaxp13_test'\n"
54 + " targetNamespace='jaxp13_test'\n" + " elementFormDefault='qualified'>\n" + " <element name='test'>\n"
55 + " <complexType>\n" + " <sequence>\n" + " <element name='child' type='string'/>\n" + " </sequence>\n"
56 + " <attribute name='id' />\n" + " </complexType>\n" + " </element>\n" + "</schema>\n";
57
58 public static final String XML = "<?xml version='1.0'?>\n" + "<ns:test xmlns:ns='jaxp13_test' id='2003-12-02'>\n" + " <ns:child>123abc</ns:child>\n"
59 + "</ns:test>\n";
60
61 private ValidatorHandler createValidatorHandler(String xsd) throws SAXException {
62 SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
63
64 StringReader reader = new StringReader(xsd);
65 StreamSource xsdSource = new StreamSource(reader);
66
67 Schema schema = schemaFactory.newSchema(xsdSource);
68 return schema.newValidatorHandler();
69 }
70
|