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/** 26 * @test 27 * @bug 8049514 28 * @summary verifies that feature set on the factory is propagated properly 29 * to the validator 30 * @run main/othervm FeaturePropagationTest 31 */ 32 33 34import java.io.ByteArrayInputStream; 35import java.io.InputStreamReader; 36import javax.xml.XMLConstants; 37import javax.xml.transform.stream.StreamSource; 38import javax.xml.validation.*; 39 40/** 41 * JDK-8049514 42 * 43 * FEATURE_SECURE_PROCESSING can not be turned off on a validator through 44 * SchemaFactory 45 */ 46public class FeaturePropagationTest { 47 48 static String xsd = "<?xml version='1.0'?>\n" + "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n" 49 + " xmlns:test='jaxp13_test'\n" 50 + " targetNamespace='jaxp13_test'\n" 51 + " elementFormDefault='qualified'>\n" 52 + " <element name='test' type='string'/>\n" 53 + "</schema>\n"; 54 55 public static void main(String[] args) throws Exception { 56 InputStreamReader reader = new InputStreamReader(new ByteArrayInputStream(xsd.getBytes())); 57 StreamSource xsdSource = new StreamSource(reader); 58 59 SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); 60 schemaFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false); 61 Schema schema = null; 62 schema = schemaFactory.newSchema(xsdSource); 63 64 Validator validator = schema.newValidator(); 65 66 if (validator.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)) { 67 throw new RuntimeException("Feature set on the factory is not inherited!"); 68 } 69 70 } 71} 72