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.StringReader;
27
28 import javax.xml.XMLConstants;
29 import javax.xml.parsers.SAXParser;
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
35 import org.testng.Assert;
36 import org.testng.annotations.Test;
37 import org.xml.sax.InputSource;
38 import org.xml.sax.SAXException;
39
40 /*
41 * @bug 5025825
42 * @summary Test if SAXParserFactory set a Schema object, when SAXParser sets "http://java.sun.com/xml/jaxp/properties/schemaSource" property
43 * and/or "http://java.sun.com/xml/jaxp/properties/schemaLanguage" property, it shall throw SAXException.
44 */
45 public class Bug5025825 {
46
47 String schemaSource = "<?xml version='1.0'?>\n" + "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>\n" + " <xsd:element name='test101'>\n"
48 + " <xsd:complexType>\n" + " <xsd:attribute name='attr'/>\n" + " <xsd:attribute name='attr2' default='DEF'/>\n"
49 + " </xsd:complexType>\n" + " </xsd:element>\n" + "</xsd:schema>\n";
50
51 private Schema createSchema() throws SAXException {
52 SchemaFactory schFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
53 return schFactory.newSchema(new StreamSource(new StringReader(schemaSource)));
54 }
55
56 @Test
57 public void test1() throws Exception {
58 Schema sch = createSchema();
59 Assert.assertNotNull(sch);
60
61 SAXParserFactory spFactory = SAXParserFactory.newInstance();
62 spFactory.setNamespaceAware(true);
63 spFactory.setValidating(true);
64 spFactory.setSchema(sch);
|
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.StringReader;
27
28 import javax.xml.XMLConstants;
29 import javax.xml.parsers.SAXParser;
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
35 import org.testng.Assert;
36 import org.testng.annotations.Listeners;
37 import org.testng.annotations.Test;
38 import org.xml.sax.InputSource;
39 import org.xml.sax.SAXException;
40
41 /*
42 * @bug 5025825
43 * @summary Test if SAXParserFactory set a Schema object, when SAXParser sets "http://java.sun.com/xml/jaxp/properties/schemaSource" property
44 * and/or "http://java.sun.com/xml/jaxp/properties/schemaLanguage" property, it shall throw SAXException.
45 */
46 @Listeners({jaxp.library.BasePolicy.class})
47 public class Bug5025825 {
48
49 String schemaSource = "<?xml version='1.0'?>\n" + "<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>\n" + " <xsd:element name='test101'>\n"
50 + " <xsd:complexType>\n" + " <xsd:attribute name='attr'/>\n" + " <xsd:attribute name='attr2' default='DEF'/>\n"
51 + " </xsd:complexType>\n" + " </xsd:element>\n" + "</xsd:schema>\n";
52
53 private Schema createSchema() throws SAXException {
54 SchemaFactory schFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
55 return schFactory.newSchema(new StreamSource(new StringReader(schemaSource)));
56 }
57
58 @Test
59 public void test1() throws Exception {
60 Schema sch = createSchema();
61 Assert.assertNotNull(sch);
62
63 SAXParserFactory spFactory = SAXParserFactory.newInstance();
64 spFactory.setNamespaceAware(true);
65 spFactory.setValidating(true);
66 spFactory.setSchema(sch);
|