--- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/XalanConstants.java 2016-07-24 18:45:21.503851882 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/XalanConstants.java 2016-07-24 18:45:21.427848105 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -223,12 +223,6 @@ public static final String XML_SECURITY_PROPERTY_MANAGER = ORACLE_JAXP_PROPERTY_PREFIX + "xmlSecurityPropertyManager"; - /** - * Feature enableExtensionFunctions - */ - public static final String ORACLE_ENABLE_EXTENSION_FUNCTION = - ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions"; - public static final String SP_ORACLE_ENABLE_EXTENSION_FUNCTION = "javax.xml.enableExtensionFunctions"; /** * Values for a feature --- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java 2016-07-24 18:45:21.827867985 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java 2016-07-24 18:45:21.751864208 -0700 @@ -35,7 +35,6 @@ import com.sun.org.apache.bcel.internal.generic.LocalVariableGen; import com.sun.org.apache.bcel.internal.generic.NEW; import com.sun.org.apache.bcel.internal.generic.PUSH; -import com.sun.org.apache.xalan.internal.utils.FeatureManager; import com.sun.org.apache.xalan.internal.utils.ObjectFactory; import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType; import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator; @@ -57,6 +56,7 @@ import java.util.Map; import java.util.Objects; import java.util.Vector; +import jdk.xml.internal.JdkXmlFeatures; /** * @author Jacek Ambroziak @@ -743,7 +743,7 @@ final InstructionList il = methodGen.getInstructionList(); final boolean isSecureProcessing = classGen.getParser().getXSLTC().isSecureProcessing(); final boolean isExtensionFunctionEnabled = classGen.getParser().getXSLTC() - .getFeature(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION); + .getFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION); int index; // Translate calls to methods in the BasisLibrary @@ -927,7 +927,7 @@ if (_clazz == null) { final boolean isSecureProcessing = getXSLTC().isSecureProcessing(); final boolean isExtensionFunctionEnabled = getXSLTC() - .getFeature(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION); + .getFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION); //Check if FSP and SM - only then process with loading if (namespace != null && isSecureProcessing --- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java 2016-07-24 18:45:22.163884684 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java 2016-07-24 18:45:22.083880708 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -37,6 +37,7 @@ import java.io.File; import java.io.IOException; import java.io.StringReader; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -44,17 +45,20 @@ import java.util.Properties; import java.util.Stack; import java.util.StringTokenizer; -import java.util.Vector; import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; +import jdk.xml.internal.JdkXmlFeatures; +import jdk.xml.internal.JdkXmlUtils; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.AttributesImpl; @@ -75,8 +79,8 @@ private XSLTC _xsltc; // Reference to the compiler object. private XPathParser _xpathParser; // Reference to the XPath parser. - private Vector _errors; // Contains all compilation errors - private Vector _warnings; // Contains all compilation errors + private ArrayList _errors; // Contains all compilation errors + private ArrayList _warnings; // Contains all compilation errors private Map _instructionClasses; // Maps instructions to classes private Map _instructionAttrs; // reqd and opt attrs @@ -113,8 +117,8 @@ _instructionAttrs = new HashMap<>(); _variableScope = new HashMap<>(); _template = null; - _errors = new Vector(); - _warnings = new Vector(); + _errors = new ArrayList<>(); + _warnings = new ArrayList<>(); _symbolTable = new SymbolTable(); _xpathParser = new XPathParser(this); _currentStylesheet = null; @@ -475,9 +479,10 @@ try { factory.setFeature(Constants.NAMESPACE_FEATURE,true); } - catch (Exception e) { + catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) { factory.setNamespaceAware(true); } + final SAXParser parser = factory.newSAXParser(); try { parser.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, @@ -488,6 +493,28 @@ reportError(WARNING, err); } + boolean supportCatalog = true; + boolean useCatalog = _xsltc.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG); + try { + factory.setFeature(JdkXmlUtils.USE_CATALOG,useCatalog); + } + catch (ParserConfigurationException | SAXNotRecognizedException | SAXNotSupportedException e) { + supportCatalog = false; + } + + if (supportCatalog && useCatalog) { + try { + CatalogFeatures cf = (CatalogFeatures)_xsltc.getProperty(JdkXmlFeatures.CATALOG_FEATURES); + if (cf != null) { + for (CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + parser.setProperty(f.getPropertyName(), cf.get(f)); + } + } + } catch (SAXNotRecognizedException e) { + //shall not happen for internal settings + } + } + final XMLReader reader = parser.getXMLReader(); String lastProperty = ""; try { @@ -1191,7 +1218,7 @@ if (size > 0) { System.err.println(new ErrorMsg(ErrorMsg.COMPILER_ERROR_KEY)); for (int i = 0; i < size; i++) { - System.err.println(" " + _errors.elementAt(i)); + System.err.println(" " + _errors.get(i)); } } } @@ -1204,7 +1231,7 @@ if (size > 0) { System.err.println(new ErrorMsg(ErrorMsg.COMPILER_WARNING_KEY)); for (int i = 0; i < size; i++) { - System.err.println(" " + _warnings.elementAt(i)); + System.err.println(" " + _warnings.get(i)); } } } @@ -1217,36 +1244,36 @@ case Constants.INTERNAL: // Unexpected internal errors, such as null-ptr exceptions, etc. // Immediately terminates compilation, no translet produced - _errors.addElement(error); + _errors.add(error); break; case Constants.UNSUPPORTED: // XSLT elements that are not implemented and unsupported ext. // Immediately terminates compilation, no translet produced - _errors.addElement(error); + _errors.add(error); break; case Constants.FATAL: // Fatal error in the stylesheet input (parsing or content) // Immediately terminates compilation, no translet produced - _errors.addElement(error); + _errors.add(error); break; case Constants.ERROR: // Other error in the stylesheet input (parsing or content) // Does not terminate compilation, no translet produced - _errors.addElement(error); + _errors.add(error); break; case Constants.WARNING: // Other error in the stylesheet input (content errors only) // Does not terminate compilation, a translet is produced - _warnings.addElement(error); + _warnings.add(error); break; } } - public Vector getErrors() { + public ArrayList getErrors() { return _errors; } - public Vector getWarnings() { + public ArrayList getWarnings() { return _warnings; } --- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java 2016-07-24 18:45:22.503901581 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java 2016-07-24 18:45:22.423897606 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -25,8 +25,6 @@ import com.sun.org.apache.bcel.internal.classfile.JavaClass; import com.sun.org.apache.xalan.internal.XalanConstants; -import com.sun.org.apache.xalan.internal.utils.FeatureManager; -import com.sun.org.apache.xalan.internal.utils.FeatureManager.Feature; import com.sun.org.apache.xalan.internal.utils.SecuritySupport; import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager; import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; @@ -39,20 +37,22 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; +import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; -import java.util.Properties; import java.util.Objects; +import java.util.Properties; import java.util.Vector; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import jdk.xml.internal.JdkXmlFeatures; +import jdk.xml.internal.JdkXmlUtils; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; @@ -101,7 +101,7 @@ // All literal text in the stylesheet - private Vector m_characterData; + private ArrayList m_characterData; // These define the various methods for outputting the translet public static final int FILE_OUTPUT = 0; @@ -152,7 +152,7 @@ private XMLSecurityManager _xmlSecurityManager; - private final FeatureManager _featureManager; + private final JdkXmlFeatures _xmlFeatures; /** * Extension function class loader variables @@ -167,11 +167,16 @@ private final Map _externalExtensionFunctions; /** + * Catalog features + */ + CatalogFeatures _catalogFeatures; + + /** * XSLTC compiler constructor */ - public XSLTC(boolean useServicesMechanism, FeatureManager featureManager) { + public XSLTC(boolean useServicesMechanism, JdkXmlFeatures featureManager) { _parser = new Parser(this, useServicesMechanism); - _featureManager = featureManager; + _xmlFeatures = featureManager; _extensionClassLoader = null; _externalExtensionFunctions = new HashMap<>(); } @@ -208,12 +213,14 @@ * @param name name of the feature * @return true if the feature is enabled, false otherwise */ - public boolean getFeature(Feature name) { - return _featureManager.isFeatureEnabled(name); + public boolean getFeature(JdkXmlFeatures.XmlFeature name) { + return _xmlFeatures.getFeature(name); } /** * Return allowed protocols for accessing external stylesheet. + * @param name the name of the property + * @return the value of the property */ public Object getProperty(String name) { if (name.equals(XMLConstants.ACCESS_EXTERNAL_STYLESHEET)) { @@ -225,12 +232,16 @@ return _xmlSecurityManager; } else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) { return _extensionClassLoader; + } else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) { + return _catalogFeatures; } return null; } /** * Set allowed protocols for accessing external stylesheet. + * @param name the name of the property + * @param value the value of the property */ public void setProperty(String name, Object value) { if (name.equals(XMLConstants.ACCESS_EXTERNAL_STYLESHEET)) { @@ -245,6 +256,8 @@ /* Clear the external extension functions HashMap if extension class loader was changed */ _externalExtensionFunctions.clear(); + } else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) { + _catalogFeatures = (CatalogFeatures)value; } } @@ -604,7 +617,7 @@ * Get a Vector containing all compile error messages * @return A Vector containing all compile error messages */ - public Vector getErrors() { + public ArrayList getErrors() { return _parser.getErrors(); } @@ -612,7 +625,7 @@ * Get a Vector containing all compile warning messages * @return A Vector containing all compile error messages */ - public Vector getWarnings() { + public ArrayList getWarnings() { return _parser.getWarnings(); } @@ -991,7 +1004,7 @@ * char[]. */ public String getCharacterData(int index) { - return ((StringBuffer) m_characterData.elementAt(index)).toString(); + return (m_characterData.get(index)).toString(); } /** @@ -1010,14 +1023,13 @@ * @return int offset at which character data will be stored */ public int addCharacterData(String newData) { - StringBuffer currData; + StringBuilder currData; if (m_characterData == null) { - m_characterData = new Vector(); - currData = new StringBuffer(); - m_characterData.addElement(currData); + m_characterData = new ArrayList<>(); + currData = new StringBuilder(); + m_characterData.add(currData); } else { - currData = (StringBuffer) m_characterData - .elementAt(m_characterData.size()-1); + currData = m_characterData.get(m_characterData.size()-1); } // Character data could take up to three-times as much space when @@ -1025,8 +1037,8 @@ // constant is 65535/3. If we exceed that, // (We really should use some "bin packing".) if (newData.length() + currData.length() > 21845) { - currData = new StringBuffer(); - m_characterData.addElement(currData); + currData = new StringBuilder(); + m_characterData.add(currData); } int newDataOffset = currData.length(); --- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesHandlerImpl.java 2016-07-24 18:45:22.839918280 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesHandlerImpl.java 2016-07-24 18:45:22.759914304 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -17,18 +17,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * $Id: TemplatesHandlerImpl.java,v 1.2.4.1 2005/09/06 12:09:03 pvedula Exp $ - */ package com.sun.org.apache.xalan.internal.xsltc.trax; -import javax.xml.XMLConstants; -import javax.xml.transform.Source; -import javax.xml.transform.Templates; -import javax.xml.transform.TransformerException; -import javax.xml.transform.URIResolver; -import javax.xml.transform.sax.TemplatesHandler; import com.sun.org.apache.xalan.internal.XalanConstants; import com.sun.org.apache.xalan.internal.xsltc.compiler.CompilerException; import com.sun.org.apache.xalan.internal.xsltc.compiler.Parser; @@ -37,14 +28,20 @@ import com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode; import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC; import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; - +import java.util.ArrayList; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.transform.Source; +import javax.xml.transform.Templates; +import javax.xml.transform.TransformerException; +import javax.xml.transform.URIResolver; +import javax.xml.transform.sax.TemplatesHandler; +import jdk.xml.internal.JdkXmlFeatures; +import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; -import org.xml.sax.Attributes; - -import java.util.Vector; /** * Implementation of a JAXP1.1 TemplatesHandler @@ -85,6 +82,12 @@ */ private TemplatesImpl _templates = null; + // Catalog features + CatalogFeatures _catalogFeatures; + + // Catalog is enabled by default + boolean _useCatalog = true; + /** * Default constructor */ @@ -95,7 +98,7 @@ _tfactory = tfactory; // Instantiate XSLTC and get reference to parser object - XSLTC xsltc = new XSLTC(tfactory.useServicesMechnism(), tfactory.getFeatureManager()); + XSLTC xsltc = new XSLTC(tfactory.useServicesMechnism(), tfactory.getJdkXmlFeatures()); if (tfactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)) xsltc.setSecureProcessing(true); @@ -112,6 +115,10 @@ else xsltc.setTemplateInlining(false); + _useCatalog = tfactory.getFeature(XMLConstants.USE_CATALOG); + _catalogFeatures = (CatalogFeatures)tfactory.getAttribute(JdkXmlFeatures.CATALOG_FEATURES); + xsltc.setProperty(JdkXmlFeatures.CATALOG_FEATURES, _catalogFeatures); + _parser = xsltc.getParser(); } @@ -229,7 +236,8 @@ stylesheet.setTemplateInlining(false); // Set a document loader (for xsl:include/import) if defined - if (_uriResolver != null) { + if (_uriResolver != null || (_useCatalog && + _catalogFeatures.get(CatalogFeatures.Feature.FILES) != null)) { stylesheet.setSourceLoader(this); } @@ -268,13 +276,13 @@ } } else { - StringBuffer errorMessage = new StringBuffer(); - Vector errors = _parser.getErrors(); + StringBuilder errorMessage = new StringBuilder(); + ArrayList errors = _parser.getErrors(); final int count = errors.size(); for (int i = 0; i < count; i++) { if (errorMessage.length() > 0) errorMessage.append('\n'); - errorMessage.append(errors.elementAt(i).toString()); + errorMessage.append(errors.get(i).toString()); } throw new SAXException(ErrorMsg.JAXP_COMPILE_ERR, new TransformerException(errorMessage.toString())); } --- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java 2016-07-24 18:45:23.231937763 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java 2016-07-24 18:45:23.155933985 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -17,17 +17,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * $Id: TransformerFactoryImpl.java,v 1.8 2007/04/09 21:30:41 joehw Exp $ - */ package com.sun.org.apache.xalan.internal.xsltc.trax; import com.sun.org.apache.xalan.internal.XalanConstants; import com.sun.org.apache.xalan.internal.utils.FactoryImpl; -import com.sun.org.apache.xalan.internal.utils.FeatureManager; import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase; -import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase.State; import com.sun.org.apache.xalan.internal.utils.ObjectFactory; import com.sun.org.apache.xalan.internal.utils.SecuritySupport; import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager; @@ -48,6 +43,7 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import java.util.Enumeration; import java.util.Map; import java.util.Properties; @@ -55,6 +51,10 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogFeatures.Feature; +import javax.xml.catalog.CatalogManager; +import javax.xml.catalog.CatalogUriResolver; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.ErrorListener; @@ -75,6 +75,8 @@ import javax.xml.transform.stax.*; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import jdk.xml.internal.JdkXmlFeatures; +import jdk.xml.internal.JdkXmlUtils; import org.xml.sax.InputSource; import org.xml.sax.XMLFilter; import org.xml.sax.XMLReader; @@ -86,6 +88,7 @@ * @author Morten Jorgensen * @author Santiago Pericas-Geertsen */ +@SuppressWarnings("deprecation") //org.xml.sax.helpers.XMLReaderFactory public class TransformerFactoryImpl extends SAXTransformerFactory implements SourceLoader, ErrorListener { @@ -229,7 +232,7 @@ private XMLSecurityPropertyManager _xmlSecurityPropertyMgr; private XMLSecurityManager _xmlSecurityManager; - private final FeatureManager _featureManager; + private final JdkXmlFeatures _xmlFeatures; private ClassLoader _extensionClassLoader = null; @@ -238,6 +241,15 @@ // type checking private Map _xsltcExtensionFunctions; + CatalogUriResolver _catalogUriResolver; + CatalogFeatures _catalogFeatures; + CatalogFeatures.Builder cfBuilder = CatalogFeatures.builder(); + // Catalog features + String _catalogFiles = null; + String _catalogDefer = null; + String _catalogPrefer = null; + String _catalogResolve = null; + /** * javax.xml.transform.sax.TransformerFactory implementation. */ @@ -251,15 +263,13 @@ private TransformerFactoryImpl(boolean useServicesMechanism) { this._useServicesMechanism = useServicesMechanism; - _featureManager = new FeatureManager(); if (System.getSecurityManager() != null) { _isSecureMode = true; _isNotSecureProcessing = false; - _featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION, - FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE); } + _xmlFeatures = new JdkXmlFeatures(!_isNotSecureProcessing); _xmlSecurityPropertyMgr = new XMLSecurityPropertyManager(); _accessExternalDTD = _xmlSecurityPropertyMgr.getValue( Property.ACCESS_EXTERNAL_DTD); @@ -332,10 +342,10 @@ return _transletName; } else if (name.equals(GENERATE_TRANSLET)) { - return new Boolean(_generateTranslet); + return _generateTranslet; } else if (name.equals(AUTO_TRANSLET)) { - return new Boolean(_autoTranslet); + return _autoTranslet; } else if (name.equals(ENABLE_INLINING)) { if (_enableInlining) @@ -346,6 +356,16 @@ return _xmlSecurityManager; } else if (name.equals(XalanConstants.JDK_EXTENSION_CLASSLOADER)) { return _extensionClassLoader; + } else if (JdkXmlUtils.CATALOG_FILES.equals(name)) { + return _catalogFiles; + } else if (JdkXmlUtils.CATALOG_DEFER.equals(name)) { + return _catalogDefer; + } else if (JdkXmlUtils.CATALOG_PREFER.equals(name)) { + return _catalogPrefer; + } else if (JdkXmlUtils.CATALOG_RESOLVE.equals(name)) { + return _catalogResolve; + } else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) { + return buildCatalogFeatures(); } /** Check to see if the property is managed by the security manager **/ @@ -398,7 +418,7 @@ } else if (name.equals(GENERATE_TRANSLET)) { if (value instanceof Boolean) { - _generateTranslet = ((Boolean) value).booleanValue(); + _generateTranslet = ((Boolean) value); return; } else if (value instanceof String) { @@ -408,7 +428,7 @@ } else if (name.equals(AUTO_TRANSLET)) { if (value instanceof Boolean) { - _autoTranslet = ((Boolean) value).booleanValue(); + _autoTranslet = ((Boolean) value); return; } else if (value instanceof String) { @@ -418,7 +438,7 @@ } else if (name.equals(USE_CLASSPATH)) { if (value instanceof Boolean) { - _useClasspath = ((Boolean) value).booleanValue(); + _useClasspath = ((Boolean) value); return; } else if (value instanceof String) { @@ -428,7 +448,7 @@ } else if (name.equals(DEBUG)) { if (value instanceof Boolean) { - _debug = ((Boolean) value).booleanValue(); + _debug = ((Boolean) value); return; } else if (value instanceof String) { @@ -438,7 +458,7 @@ } else if (name.equals(ENABLE_INLINING)) { if (value instanceof Boolean) { - _enableInlining = ((Boolean) value).booleanValue(); + _enableInlining = ((Boolean) value); return; } else if (value instanceof String) { @@ -457,7 +477,7 @@ } } else if (value instanceof Integer) { - _indentNumber = ((Integer) value).intValue(); + _indentNumber = ((Integer) value); return; } } @@ -470,6 +490,22 @@ = new ErrorMsg(ErrorMsg.JAXP_INVALID_ATTR_VALUE_ERR, "Extension Functions ClassLoader"); throw new IllegalArgumentException(err.toString()); } + } else if (JdkXmlUtils.CATALOG_FILES.equals(name)) { + _catalogFiles = (String) value; + cfBuilder = CatalogFeatures.builder().with(Feature.FILES, _catalogFiles); + return; + } else if (JdkXmlUtils.CATALOG_DEFER.equals(name)) { + _catalogDefer = (String) value; + cfBuilder = CatalogFeatures.builder().with(Feature.DEFER, _catalogDefer); + return; + } else if (JdkXmlUtils.CATALOG_PREFER.equals(name)) { + _catalogPrefer = (String) value; + cfBuilder = CatalogFeatures.builder().with(Feature.PREFER, _catalogPrefer); + return; + } else if (JdkXmlUtils.CATALOG_RESOLVE.equals(name)) { + _catalogResolve = (String) value; + cfBuilder = CatalogFeatures.builder().with(Feature.RESOLVE, _catalogResolve); + return; } if (_xmlSecurityManager != null && @@ -534,18 +570,18 @@ // set external access restriction when FSP is explicitly set if (value) { _xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_DTD, - State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP); + FeaturePropertyBase.State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP); _xmlSecurityPropertyMgr.setValue(Property.ACCESS_EXTERNAL_STYLESHEET, - State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP); + FeaturePropertyBase.State.FSP, XalanConstants.EXTERNAL_ACCESS_DEFAULT_FSP); _accessExternalDTD = _xmlSecurityPropertyMgr.getValue( Property.ACCESS_EXTERNAL_DTD); _accessExternalStylesheet = _xmlSecurityPropertyMgr.getValue( Property.ACCESS_EXTERNAL_STYLESHEET); } - if (value && _featureManager != null) { - _featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION, - FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE); + if (value && _xmlFeatures != null) { + _xmlFeatures.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION, + JdkXmlFeatures.State.FSP, false); } } else if (name.equals(XalanConstants.ORACLE_FEATURE_SERVICE_MECHANISM)) { @@ -554,8 +590,8 @@ _useServicesMechanism = value; } else { - if (_featureManager != null && - _featureManager.setValue(name, State.APIPROPERTY, value)) { + if (_xmlFeatures != null && + _xmlFeatures.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) { return; } @@ -603,16 +639,15 @@ return true; } } - // secure processing? + if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { - return !_isNotSecureProcessing; + return !_isNotSecureProcessing; } - /** Check to see if the property is managed by the security manager **/ - String propertyValue = (_featureManager != null) ? - _featureManager.getValueAsString(name) : null; - if (propertyValue != null) { - return Boolean.parseBoolean(propertyValue); + /** Check to see if the property is managed by the JdkXmlFeatues **/ + int index = _xmlFeatures.getIndex(name); + if (index > -1) { + return _xmlFeatures.getFeature(index); } // Feature not supported @@ -628,8 +663,8 @@ /** * @return the feature manager */ - public FeatureManager getFeatureManager() { - return _featureManager; + public JdkXmlFeatures getJdkXmlFeatures() { + return _xmlFeatures; } /** @@ -736,21 +771,9 @@ } catch (StopParseException e ) { // startElement encountered so do not parse further - } catch (javax.xml.parsers.ParserConfigurationException e) { - + } catch (javax.xml.parsers.ParserConfigurationException | org.xml.sax.SAXException | IOException e) { throw new TransformerConfigurationException( "getAssociatedStylesheets failed", e); - - } catch (org.xml.sax.SAXException se) { - - throw new TransformerConfigurationException( - "getAssociatedStylesheets failed", se); - - - } catch (IOException ioe ) { - throw new TransformerConfigurationException( - "getAssociatedStylesheets failed", ioe); - } return _stylesheetPIHandler.getAssociatedStylesheet(); @@ -768,6 +791,9 @@ public Transformer newTransformer() throws TransformerConfigurationException { + // create CatalogFeatures that is accessible by the Transformer + // through the factory instance + buildCatalogFeatures(); TransformerImpl result = new TransformerImpl(new Properties(), _indentNumber, this); if (_uriResolver != null) { @@ -805,7 +831,7 @@ /** * Pass warning messages from the compiler to the error listener */ - private void passWarningsToListener(Vector messages) + private void passWarningsToListener(ArrayList messages) throws TransformerException { if (_errorListener == null || messages == null) { @@ -814,7 +840,7 @@ // Pass messages to listener, one by one final int count = messages.size(); for (int pos = 0; pos < count; pos++) { - ErrorMsg msg = (ErrorMsg)messages.elementAt(pos); + ErrorMsg msg = messages.get(pos); // Workaround for the TCK failure ErrorListener.errorTests.error001. if (msg.isWarningError()) _errorListener.error( @@ -828,7 +854,7 @@ /** * Pass error messages from the compiler to the error listener */ - private void passErrorsToListener(Vector messages) { + private void passErrorsToListener(ArrayList messages) { try { if (_errorListener == null || messages == null) { return; @@ -836,7 +862,7 @@ // Pass messages to listener, one by one final int count = messages.size(); for (int pos = 0; pos < count; pos++) { - String message = messages.elementAt(pos).toString(); + String message = messages.get(pos).toString(); _errorListener.error(new TransformerException(message)); } } @@ -917,7 +943,7 @@ } // Create and initialize a stylesheet compiler - final XSLTC xsltc = new XSLTC(_useServicesMechanism, _featureManager); + final XSLTC xsltc = new XSLTC(_useServicesMechanism, _xmlFeatures); if (_debug) xsltc.setDebug(true); if (_enableInlining) xsltc.setTemplateInlining(true); @@ -929,11 +955,16 @@ xsltc.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD); xsltc.setProperty(XalanConstants.SECURITY_MANAGER, _xmlSecurityManager); xsltc.setProperty(XalanConstants.JDK_EXTENSION_CLASSLOADER, _extensionClassLoader); + + // set Catalog features + buildCatalogFeatures(); + xsltc.setProperty(JdkXmlFeatures.CATALOG_FEATURES, _catalogFeatures); + xsltc.init(); if (!_isNotSecureProcessing) _xsltcExtensionFunctions = xsltc.getExternalExtensionFunctions(); // Set a document loader (for xsl:include/import) if defined - if (_uriResolver != null) { + if (_uriResolver != null || (_xmlFeatures.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG) && _catalogFiles != null)) { xsltc.setSourceLoader(this); } @@ -1010,43 +1041,47 @@ } // Check that the transformation went well before returning - if (bytecodes == null) { - Vector errs = xsltc.getErrors(); - ErrorMsg err; - if (errs != null) { - err = (ErrorMsg)errs.elementAt(errs.size()-1); - } else { - err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR); - } - Throwable cause = err.getCause(); - TransformerConfigurationException exc; - if (cause != null) { - exc = new TransformerConfigurationException(cause.getMessage(), cause); - } else { - exc = new TransformerConfigurationException(err.toString()); - } + if (bytecodes == null) { + ArrayList errs = xsltc.getErrors(); + ErrorMsg err; + if (errs != null) { + err = errs.get(errs.size()-1); + } else { + err = new ErrorMsg(ErrorMsg.JAXP_COMPILE_ERR); + } + Throwable cause = err.getCause(); + TransformerConfigurationException exc; + if (cause != null) { + exc = new TransformerConfigurationException(cause.getMessage(), cause); + } else { + exc = new TransformerConfigurationException(err.toString()); + } - // Pass compiler errors to the error listener - if (_errorListener != null) { - passErrorsToListener(xsltc.getErrors()); + // Pass compiler errors to the error listener + if (_errorListener != null) { + passErrorsToListener(xsltc.getErrors()); - // As required by TCK 1.2, send a fatalError to the - // error listener because compilation of the stylesheet - // failed and no further processing will be possible. - try { - _errorListener.fatalError(exc); - } catch (TransformerException te) { - // well, we tried. + // As required by TCK 1.2, send a fatalError to the + // error listener because compilation of the stylesheet + // failed and no further processing will be possible. + try { + _errorListener.fatalError(exc); + } catch (TransformerException te) { + // well, we tried. + } } + else { + xsltc.printErrors(); + } + throw exc; } - else { - xsltc.printErrors(); - } - throw exc; - } - return new TemplatesImpl(bytecodes, transletName, - xsltc.getOutputProperties(), _indentNumber, this); + TemplatesImpl templates = new TemplatesImpl(bytecodes, transletName, + xsltc.getOutputProperties(), _indentNumber, this); + if (_uriResolver != null) { + templates.setURIResolver(_uriResolver); + } + return templates; } /** @@ -1061,6 +1096,9 @@ public TemplatesHandler newTemplatesHandler() throws TransformerConfigurationException { + // create CatalogFeatures that is accessible by the Handler + // through the factory instance + buildCatalogFeatures(); final TemplatesHandlerImpl handler = new TemplatesHandlerImpl(_indentNumber, this); if (_uriResolver != null) { @@ -1272,11 +1310,19 @@ @Override public InputSource loadSource(String href, String context, XSLTC xsltc) { try { + Source source = null; if (_uriResolver != null) { - final Source source = _uriResolver.resolve(href, context); - if (source != null) { - return Util.getInputSource(xsltc, source); + source = _uriResolver.resolve(href, context); + } + if (source == null && _catalogFiles != null && + _xmlFeatures.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG)) { + if (_catalogUriResolver == null) { + _catalogUriResolver = CatalogManager.catalogUriResolver(_catalogFeatures); } + source = _catalogUriResolver.resolve(href, context); + } + if (source != null) { + return Util.getInputSource(xsltc, source); } } catch (TransformerException e) { @@ -1289,6 +1335,26 @@ } /** + * Build the CatalogFeatures object when a newTemplates or newTransformer is + * created. This will read any System Properties for the CatalogFeatures that + * may have been set. + */ + private CatalogFeatures buildCatalogFeatures() { + // build will cause the CatalogFeatures to read SPs for those not set through the API + if (_catalogFeatures == null) { + _catalogFeatures = cfBuilder.build(); + } + + // update fields + _catalogFiles = _catalogFeatures.get(Feature.FILES); + _catalogDefer = _catalogFeatures.get(Feature.DEFER); + _catalogPrefer = _catalogFeatures.get(Feature.PREFER); + _catalogResolve = _catalogFeatures.get(Feature.RESOLVE); + + return _catalogFeatures; + } + + /** * Reset the per-session attributes to their default values */ private void resetTransientAttributes() { --- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java 2016-07-24 18:45:23.651958636 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java 2016-07-24 18:45:23.575954859 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -60,6 +60,9 @@ import java.util.Properties; import java.util.StringTokenizer; import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogManager; +import javax.xml.catalog.CatalogUriResolver; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -80,6 +83,8 @@ import javax.xml.transform.stax.StAXSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import jdk.xml.internal.JdkXmlFeatures; +import jdk.xml.internal.JdkXmlUtils; import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -217,6 +222,14 @@ */ private Map _parameters = null; + // Catalog features + CatalogFeatures _catalogFeatures; + CatalogUriResolver _catalogUriResolver; + + // Catalog is enabled by default + boolean _useCatalog = true; + + /** * This class wraps an ErrorListener into a MessageHandler in order to * capture messages reported via xsl:message. @@ -270,6 +283,16 @@ _readerManager.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD); _readerManager.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, _isSecureProcessing); _readerManager.setProperty(XalanConstants.SECURITY_MANAGER, _securityManager); + + _useCatalog = _tfactory.getFeature(XMLConstants.USE_CATALOG); + if (_useCatalog) { + _catalogFeatures = (CatalogFeatures)_tfactory.getAttribute(JdkXmlFeatures.CATALOG_FEATURES); + String catalogFiles = _catalogFeatures.get(CatalogFeatures.Feature.DEFER); + if (catalogFiles != null) { + _readerManager.setFeature(XMLConstants.USE_CATALOG, _useCatalog); + _readerManager.setProperty(JdkXmlFeatures.CATALOG_FEATURES, _catalogFeatures); + } + } //_isIncremental = tfactory._incremental; } @@ -339,7 +362,8 @@ throw new TransformerException(err.toString()); } - if (_uriResolver != null && !_isIdentity) { + if (!_isIdentity && (_uriResolver != null || (_tfactory.getFeature(XMLConstants.USE_CATALOG) + && _tfactory.getAttribute(JdkXmlUtils.CATALOG_FILES) != null))) { _translet.setDOMCache(this); } @@ -723,15 +747,33 @@ ((SAXSource)source).getXMLReader()==null )|| (source instanceof DOMSource && ((DOMSource)source).getNode()==null)){ - DocumentBuilderFactory builderF = FactoryImpl.getDOMFactory(_useServicesMechanism); - DocumentBuilder builder = builderF.newDocumentBuilder(); - String systemID = source.getSystemId(); - source = new DOMSource(builder.newDocument()); - - // Copy system ID from original, empty Source to new - if (systemID != null) { - source.setSystemId(systemID); + + boolean supportCatalog = true; + + DocumentBuilderFactory builderF = FactoryImpl.getDOMFactory(_useServicesMechanism); + try { + builderF.setFeature(XMLConstants.USE_CATALOG, _useCatalog); + } catch (ParserConfigurationException e) { + supportCatalog = false; + } + + if (supportCatalog && _useCatalog) { + CatalogFeatures cf = (CatalogFeatures)_tfactory.getAttribute(JdkXmlFeatures.CATALOG_FEATURES); + if (cf != null) { + for (CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + builderF.setAttribute(f.getPropertyName(), cf.get(f)); } + } + } + + DocumentBuilder builder = builderF.newDocumentBuilder(); + String systemID = source.getSystemId(); + source = new DOMSource(builder.newDocument()); + + // Copy system ID from original, empty Source to new + if (systemID != null) { + source.setSystemId(systemID); + } } if (_isIdentity) { transformIdentity(source, handler); @@ -1287,7 +1329,19 @@ * com.sun.org.apache.xalan.internal.xsltc.dom.LoadDocument * */ - Source resolvedSource = _uriResolver.resolve(href, baseURI); + Source resolvedSource = null; + if (_uriResolver != null) { + resolvedSource = _uriResolver.resolve(href, baseURI); + } + + if (resolvedSource == null && _useCatalog && + _catalogFeatures.get(CatalogFeatures.Feature.FILES) != null) { + if (_catalogUriResolver == null) { + _catalogUriResolver = CatalogManager.catalogUriResolver(_catalogFeatures); + } + resolvedSource = _catalogUriResolver.resolve(href, baseURI); + } + if (resolvedSource == null) { StreamSource streamSource = new StreamSource( SystemIDResolver.getAbsoluteURI(href, baseURI)); --- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/Util.java 2016-07-24 18:45:23.991975534 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/Util.java 2016-07-24 18:45:23.911971558 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -17,37 +17,32 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * $Id: Util.java,v 1.2.4.1 2005/09/14 09:37:34 pvedula Exp $ - */ package com.sun.org.apache.xalan.internal.xsltc.trax; import com.sun.org.apache.xalan.internal.XalanConstants; +import com.sun.org.apache.xalan.internal.utils.FactoryImpl; +import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager; +import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC; +import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; import java.io.InputStream; import java.io.Reader; - import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogFeatures.Feature; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; - import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLStreamReader; - import javax.xml.transform.Source; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stax.StAXSource; import javax.xml.transform.stream.StreamSource; - -import com.sun.org.apache.xalan.internal.utils.FactoryImpl; -import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager; -import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC; -import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg; - +import jdk.xml.internal.JdkXmlFeatures; +import jdk.xml.internal.JdkXmlUtils; import org.w3c.dom.Document; - import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; @@ -57,6 +52,8 @@ /** * @author Santiago Pericas-Geertsen + * + * Added Catalog Support for URI resolution */ public final class Util { @@ -72,9 +69,6 @@ return com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util.toJavaName(name); } - - - /** * Creates a SAX2 InputSource object from a TrAX Source object */ @@ -169,6 +163,29 @@ } catch (SAXException se) { XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se); } + + boolean supportCatalog = true; + boolean useCatalog = xsltc.getFeature(JdkXmlFeatures.XmlFeature.USE_CATALOG); + try { + reader.setFeature(JdkXmlUtils.USE_CATALOG, useCatalog); + } + catch (SAXNotRecognizedException | SAXNotSupportedException e) { + supportCatalog = false; + } + + if (supportCatalog & useCatalog) { + try { + CatalogFeatures cf = (CatalogFeatures)xsltc.getProperty(JdkXmlFeatures.CATALOG_FEATURES); + if (cf != null) { + for (Feature f : CatalogFeatures.Feature.values()) { + reader.setProperty(f.getPropertyName(), cf.get(f)); + } + } + } catch (SAXNotRecognizedException e) { + //shall not happen for internal settings + } + } + xsltc.setXMLReader(reader); }catch (SAXNotRecognizedException snre ) { throw new TransformerConfigurationException --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java 2016-07-24 18:45:24.291990444 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java 2016-07-24 18:45:24.215986667 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -51,6 +51,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Locale; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import jdk.xml.internal.JdkXmlUtils; +import jdk.xml.internal.SecuritySupport; import org.w3c.dom.DOMConfiguration; import org.w3c.dom.DOMErrorHandler; import org.w3c.dom.DOMException; @@ -191,7 +195,7 @@ protected SymbolTable fSymbolTable; /** Components. */ - protected ArrayList fComponents; + protected ArrayList fComponents; protected ValidationManager fValidationManager; @@ -253,7 +257,8 @@ NORMALIZE_DATA, SEND_PSVI, NAMESPACE_GROWTH, - TOLERATE_DUPLICATES + TOLERATE_DUPLICATES, + XMLConstants.USE_CATALOG }; addRecognizedFeatures(recognizedFeatures); @@ -266,6 +271,7 @@ setFeature(XERCES_NAMESPACES, true); setFeature(SEND_PSVI, true); setFeature(NAMESPACE_GROWTH, false); + setFeature(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); // add default recognized properties final String[] recognizedProperties = { @@ -282,7 +288,11 @@ DTD_VALIDATOR_FACTORY_PROPERTY, SCHEMA_DV_FACTORY, SECURITY_MANAGER, - XML_SECURITY_PROPERTY_MANAGER + XML_SECURITY_PROPERTY_MANAGER, + JdkXmlUtils.CATALOG_DEFER, + JdkXmlUtils.CATALOG_FILES, + JdkXmlUtils.CATALOG_PREFER, + JdkXmlUtils.CATALOG_RESOLVE }; addRecognizedProperties(recognizedProperties); @@ -300,7 +310,7 @@ } fSymbolTable = symbolTable; - fComponents = new ArrayList(); + fComponents = new ArrayList<>(); setProperty(SYMBOL_TABLE, fSymbolTable); fErrorReporter = new XMLErrorReporter(); @@ -354,7 +364,10 @@ // REVISIT: What is the right thing to do? -Ac } - + // Initialize Catalog features + for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + setProperty(f.getPropertyName(), null); + } } // (SymbolTable) @@ -1027,7 +1040,7 @@ int count = fComponents.size(); for (int i = 0; i < count; i++) { - XMLComponent c = (XMLComponent) fComponents.get(i); + XMLComponent c = fComponents.get(i); c.reset(this); } --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/PropertyManager.java 2016-07-24 18:45:24.608006149 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/PropertyManager.java 2016-07-24 18:45:24.532002372 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,9 +29,13 @@ import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; import com.sun.xml.internal.stream.StaxEntityResolverWrapper; import java.util.HashMap; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLResolver; +import jdk.xml.internal.JdkXmlUtils; +import jdk.xml.internal.SecuritySupport; /** * This class manages different properties related to Stax specification and its implementation. @@ -58,7 +62,7 @@ private static final String XML_SECURITY_PROPERTY_MANAGER = Constants.XML_SECURITY_PROPERTY_MANAGER; - HashMap supportedProps = new HashMap(); + HashMap supportedProps = new HashMap<>(); private XMLSecurityManager fSecurityManager; private XMLSecurityPropertyManager fSecurityPropertyMgr; @@ -85,13 +89,13 @@ */ public PropertyManager(PropertyManager propertyManager){ - HashMap properties = propertyManager.getProperties(); + HashMap properties = propertyManager.getProperties(); supportedProps.putAll(properties); fSecurityManager = (XMLSecurityManager)getProperty(SECURITY_MANAGER); fSecurityPropertyMgr = (XMLSecurityPropertyManager)getProperty(XML_SECURITY_PROPERTY_MANAGER); } - private HashMap getProperties(){ + private HashMap getProperties(){ return supportedProps ; } @@ -117,30 +121,36 @@ //zephyr (implementation) specific properties which can be set by the application. //interning is always done - supportedProps.put(Constants.SAX_FEATURE_PREFIX + Constants.STRING_INTERNING_FEATURE , new Boolean(true)); + supportedProps.put(Constants.SAX_FEATURE_PREFIX + Constants.STRING_INTERNING_FEATURE , true); //recognizing java encoding names by default - supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE, new Boolean(true)) ; + supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.ALLOW_JAVA_ENCODINGS_FEATURE, true) ; //in stax mode, namespace declarations are not added as attributes supportedProps.put(Constants.ADD_NAMESPACE_DECL_AS_ATTRIBUTE , Boolean.FALSE) ; - supportedProps.put(Constants.READER_IN_DEFINED_STATE, new Boolean(true)); - supportedProps.put(Constants.REUSE_INSTANCE, new Boolean(true)); - supportedProps.put(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT , new Boolean(false)); + supportedProps.put(Constants.READER_IN_DEFINED_STATE, true); + supportedProps.put(Constants.REUSE_INSTANCE, true); + supportedProps.put(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.STAX_REPORT_CDATA_EVENT , false); supportedProps.put(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD, Boolean.FALSE); - supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE, new Boolean(false)); - supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE, new Boolean(false)); - supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE, new Boolean(false)); + supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE, false); + supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_DUPLICATE_ENTITYDEF_FEATURE, false); + supportedProps.put(Constants.XERCES_FEATURE_PREFIX + Constants.WARN_ON_UNDECLARED_ELEMDEF_FEATURE, false); fSecurityManager = new XMLSecurityManager(true); supportedProps.put(SECURITY_MANAGER, fSecurityManager); fSecurityPropertyMgr = new XMLSecurityPropertyManager(); supportedProps.put(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); + + // Initialize Catalog features + supportedProps.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); + for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + supportedProps.put(f.getPropertyName(), null); + } } private void initWriterProps(){ supportedProps.put(XMLOutputFactory.IS_REPAIRING_NAMESPACES , Boolean.FALSE); //default value of escaping characters is 'true' supportedProps.put(Constants.ESCAPE_CHARACTERS , Boolean.TRUE); - supportedProps.put(Constants.REUSE_INSTANCE, new Boolean(true)); + supportedProps.put(Constants.REUSE_INSTANCE, true); } /** @@ -160,20 +170,20 @@ public void setProperty(String property, Object value){ String equivalentProperty = null ; - if(property == XMLInputFactory.IS_NAMESPACE_AWARE || property.equals(XMLInputFactory.IS_NAMESPACE_AWARE)){ + if(property.equals(XMLInputFactory.IS_NAMESPACE_AWARE)){ equivalentProperty = Constants.XERCES_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE ; } - else if(property == XMLInputFactory.IS_VALIDATING || property.equals(XMLInputFactory.IS_VALIDATING)){ + else if(property.equals(XMLInputFactory.IS_VALIDATING)){ if( (value instanceof Boolean) && ((Boolean)value).booleanValue()){ throw new java.lang.IllegalArgumentException("true value of isValidating not supported") ; } } - else if(property == STRING_INTERNING || property.equals(STRING_INTERNING)){ + else if(property.equals(STRING_INTERNING)){ if( (value instanceof Boolean) && !((Boolean)value).booleanValue()){ throw new java.lang.IllegalArgumentException("false value of " + STRING_INTERNING + "feature is not supported") ; } } - else if(property == XMLInputFactory.RESOLVER || property.equals(XMLInputFactory.RESOLVER)){ + else if(property.equals(XMLInputFactory.RESOLVER)){ //add internal stax property supportedProps.put( Constants.XERCES_PROPERTY_PREFIX + Constants.STAX_ENTITY_RESOLVER_PROPERTY , new StaxEntityResolverWrapper((XMLResolver)value)) ; } --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java 2016-07-24 18:45:24.932022251 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java 2016-07-24 18:45:24.852018276 -0700 @@ -48,9 +48,11 @@ import com.sun.xml.internal.stream.dtd.DTDGrammarUtil; import java.io.EOFException; import java.io.IOException; +import javax.xml.XMLConstants; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.events.XMLEvent; +import jdk.xml.internal.JdkXmlUtils; /** * @@ -175,7 +177,8 @@ VALIDATION, NOTIFY_BUILTIN_REFS, NOTIFY_CHAR_REFS, - Constants.STAX_REPORT_CDATA_EVENT + Constants.STAX_REPORT_CDATA_EVENT, + XMLConstants.USE_CATALOG }; /** Feature defaults. */ @@ -184,15 +187,20 @@ null, Boolean.FALSE, Boolean.FALSE, - Boolean.TRUE + Boolean.TRUE, + JdkXmlUtils.USE_CATALOG_DEFAULT }; /** Recognized properties. */ private static final String[] RECOGNIZED_PROPERTIES = { - SYMBOL_TABLE, + SYMBOL_TABLE, ERROR_REPORTER, ENTITY_MANAGER, - XML_SECURITY_PROPERTY_MANAGER + XML_SECURITY_PROPERTY_MANAGER, + JdkXmlUtils.CATALOG_DEFER, + JdkXmlUtils.CATALOG_FILES, + JdkXmlUtils.CATALOG_PREFER, + JdkXmlUtils.CATALOG_RESOLVE }; /** Property defaults. */ @@ -200,9 +208,14 @@ null, null, null, + null, + null, + null, + null, null }; + private static final char [] cdata = {'[','C','D','A','T','A','['}; static final char [] xmlDecl = {'<','?','x','m','l'}; // private static final char [] endTag = {'<','/'}; --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java 2016-07-24 18:45:25.388044914 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java 2016-07-24 18:45:25.312041137 -0700 @@ -53,7 +53,17 @@ import java.util.Map; import java.util.Stack; import java.util.StringTokenizer; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogException; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogFeatures.Feature; +import javax.xml.catalog.CatalogManager; +import javax.xml.catalog.CatalogResolver; +import javax.xml.catalog.CatalogUriResolver; import javax.xml.stream.XMLInputFactory; +import javax.xml.transform.Source; +import jdk.xml.internal.JdkXmlUtils; +import org.xml.sax.InputSource; /** @@ -184,7 +194,8 @@ EXTERNAL_PARAMETER_ENTITIES, ALLOW_JAVA_ENCODINGS, WARN_ON_DUPLICATE_ENTITYDEF, - STANDARD_URI_CONFORMANT + STANDARD_URI_CONFORMANT, + XMLConstants.USE_CATALOG }; /** Feature defaults. */ @@ -194,7 +205,8 @@ Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, - Boolean.FALSE + Boolean.FALSE, + JdkXmlUtils.USE_CATALOG_DEFAULT }; /** Recognized properties. */ @@ -205,7 +217,11 @@ VALIDATION_MANAGER, BUFFER_SIZE, SECURITY_MANAGER, - XML_SECURITY_PROPERTY_MANAGER + XML_SECURITY_PROPERTY_MANAGER, + JdkXmlUtils.CATALOG_DEFER, + JdkXmlUtils.CATALOG_FILES, + JdkXmlUtils.CATALOG_PREFER, + JdkXmlUtils.CATALOG_RESOLVE }; /** Property defaults. */ @@ -214,7 +230,11 @@ null, null, null, - new Integer(DEFAULT_BUFFER_SIZE), + DEFAULT_BUFFER_SIZE, + null, + null, + null, + null, null, null }; @@ -396,6 +416,17 @@ /** Pool of character buffers. */ private CharacterBufferPool fBufferPool = new CharacterBufferPool(fBufferSize, DEFAULT_INTERNAL_BUFFER_SIZE); + /** indicate whether Catalog should be used for resolving external resources */ + private boolean fUseCatalog = true; + CatalogFeatures fCatalogFeatures; + CatalogResolver fCatalogResolver; + CatalogUriResolver fCatalogUriResolver; + + private String fCatalogFile; + private String fDefer; + private String fPrefer; + private String fResolve; + // // Constructors // @@ -1007,6 +1038,22 @@ staxInputSource = new StaxXMLInputSource(xmlInputSource, fISCreatedByResolver); } + if (staxInputSource == null) { + if (fCatalogFeatures == null) { + fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve); + } + fCatalogFile = fCatalogFeatures.get(Feature.FILES); + if (fUseCatalog && fCatalogFile != null) { + if (fCatalogResolver == null) { + fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures); + } + InputSource is = fCatalogResolver.resolveEntity(publicId, literalSystemId); + if (is != null && !is.isEmpty()) { + staxInputSource = new StaxXMLInputSource(new XMLInputSource(is, true), true); + } + } + } + // do default resolution //this works for both stax & Xerces, if staxInputSource is null, //it means parser need to revert to default resolution @@ -1085,6 +1132,41 @@ xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier); } + if (xmlInputSource == null) { + if (fCatalogFeatures == null) { + fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve); + } + fCatalogFile = fCatalogFeatures.get(Feature.FILES); + if (fUseCatalog && fCatalogFile != null) { + /* + since the method can be called from various processors, both + CatalogResolver and CatalogUriResolver are used to attempt to find + a match + */ + InputSource is = null; + try { + if (fCatalogResolver == null) { + fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures); + } + String pid = (publicId != null? publicId : resourceIdentifier.getNamespace()); + if (pid != null || literalSystemId != null) { + is = fCatalogResolver.resolveEntity(pid, literalSystemId); + } + } catch (CatalogException e) {} + if (is != null && !is.isEmpty()) { + xmlInputSource = new XMLInputSource(is, true); + } else if (literalSystemId != null) { + if (fCatalogUriResolver == null) { + fCatalogUriResolver = CatalogManager.catalogUriResolver(fCatalogFeatures); + } + Source source = fCatalogUriResolver.resolve(literalSystemId, baseSystemId); + if (source != null && !source.isEmpty()) { + xmlInputSource = new XMLInputSource(publicId, source.getSystemId(), baseSystemId, true); + } + } + } + } + // do default resolution // REVISIT: what's the correct behavior if the user provided an entity // resolver (fEntityResolver != null), but resolveEntity doesn't return @@ -1442,12 +1524,19 @@ fStaxEntityResolver = null; } - fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue(); - fReplaceEntityReferences = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)).booleanValue(); - fSupportExternalEntities = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES)).booleanValue(); + fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)); + fReplaceEntityReferences = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES)); + fSupportExternalEntities = ((Boolean)propertyManager.getProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES)); // Zephyr feature ignore-external-dtd is the opposite of Xerces' load-external-dtd - fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue(); + fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)); + + //Use Catalog + fUseCatalog = (Boolean)propertyManager.getProperty(XMLConstants.USE_CATALOG); + fCatalogFile = (String)propertyManager.getProperty(JdkXmlUtils.CATALOG_FILES); + fDefer = (String)propertyManager.getProperty(JdkXmlUtils.CATALOG_DEFER); + fPrefer = (String)propertyManager.getProperty(JdkXmlUtils.CATALOG_PREFER); + fResolve = (String)propertyManager.getProperty(JdkXmlUtils.CATALOG_RESOLVE); // JAXP 1.5 feature XMLSecurityPropertyManager spm = (XMLSecurityPropertyManager) propertyManager.getProperty(XML_SECURITY_PROPERTY_MANAGER); @@ -1535,6 +1624,13 @@ } fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD); + //Use Catalog + fUseCatalog = componentManager.getFeature(XMLConstants.USE_CATALOG, true); + fCatalogFile = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_FILES); + fDefer = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_DEFER); + fPrefer = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_PREFER); + fResolve = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_RESOLVE); + //reset general state reset(); @@ -1631,6 +1727,8 @@ fLoadExternalDTD = state; return; } + } else if (featureId.equals(XMLConstants.USE_CATALOG)) { + fUseCatalog = state; } } // setFeature(String,boolean) @@ -1691,6 +1789,18 @@ { XMLSecurityPropertyManager spm = (XMLSecurityPropertyManager)value; fAccessExternalDTD = spm.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD); + return; + } + + //Catalog properties + if (propertyId.equals(JdkXmlUtils.CATALOG_FILES)) { + fCatalogFile = (String)value; + } else if (propertyId.equals(JdkXmlUtils.CATALOG_DEFER)) { + fDefer = (String)value; + } else if (propertyId.equals(JdkXmlUtils.CATALOG_PREFER)) { + fPrefer = (String)value; + } else if (propertyId.equals(JdkXmlUtils.CATALOG_RESOLVE)) { + fResolve = (String)value; } } @@ -2066,7 +2176,6 @@ // system id has to be a valid URI if (strict) { - try { // if it's already an absolute one, return it new URI(systemId); --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java 2016-07-24 18:45:25.820066385 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java 2016-07-24 18:45:25.740062409 -0700 @@ -76,6 +76,7 @@ import java.util.StringTokenizer; import java.util.WeakHashMap; import javax.xml.XMLConstants; +import jdk.xml.internal.JdkXmlUtils; import org.w3c.dom.DOMConfiguration; import org.w3c.dom.DOMError; import org.w3c.dom.DOMErrorHandler; @@ -173,7 +174,8 @@ HONOUR_ALL_SCHEMALOCATIONS, NAMESPACE_GROWTH, TOLERATE_DUPLICATES, - USE_SERVICE_MECHANISM + USE_SERVICE_MECHANISM, + XMLConstants.USE_CATALOG }; // property identifiers @@ -187,7 +189,7 @@ Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; /** Property identifier: error handler. */ - protected static final String ERROR_HANDLER = + public static final String ERROR_HANDLER = Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_HANDLER_PROPERTY; /** Property identifier: entity resolver. */ @@ -244,7 +246,11 @@ SECURITY_MANAGER, LOCALE, SCHEMA_DV_FACTORY, - XML_SECURITY_PROPERTY_MANAGER + XML_SECURITY_PROPERTY_MANAGER, + JdkXmlUtils.CATALOG_DEFER, + JdkXmlUtils.CATALOG_FILES, + JdkXmlUtils.CATALOG_PREFER, + JdkXmlUtils.CATALOG_RESOLVE }; // Data @@ -813,7 +819,7 @@ // InputSource also, apart from [] of type Object. Object[] objArr = (Object[]) fJAXPSource; // make local array for storing target namespaces of schemasources specified in object arrays. - ArrayList jaxpSchemaSourceNamespaces = new ArrayList(); + ArrayList jaxpSchemaSourceNamespaces = new ArrayList<>(); for (int i = 0; i < objArr.length; i++) { if (objArr[i] instanceof InputStream || objArr[i] instanceof InputSource) { @@ -1280,7 +1286,7 @@ */ public DOMStringList getParameterNames() { if (fRecognizedParameters == null){ - ArrayList v = new ArrayList(); + ArrayList v = new ArrayList<>(); v.add(Constants.DOM_VALIDATE); v.add(Constants.DOM_ERROR_HANDLER); v.add(Constants.DOM_RESOURCE_RESOLVER); @@ -1381,7 +1387,7 @@ } - XMLInputSource dom2xmlInputSource(LSInput is) { + XMLInputSource dom2xmlInputSource(LSInput is) { // need to wrap the LSInput with an XMLInputSource XMLInputSource xis = null; --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java 2016-07-24 18:45:26.140082288 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java 2016-07-24 18:45:26.064078511 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -86,6 +86,8 @@ import java.util.Stack; import java.util.Vector; import javax.xml.XMLConstants; +import jdk.xml.internal.JdkXmlUtils; +import jdk.xml.internal.SecuritySupport; /** * The XML Schema validator. The validator implements a document @@ -264,6 +266,8 @@ protected static final String USE_SERVICE_MECHANISM = Constants.ORACLE_FEATURE_SERVICE_MECHANISM; + protected static final String USE_CATALOG = XMLConstants.USE_CATALOG; + // recognized features and properties /** Recognized features. */ @@ -286,7 +290,8 @@ UNPARSED_ENTITY_CHECKING, NAMESPACE_GROWTH, TOLERATE_DUPLICATES, - USE_SERVICE_MECHANISM + USE_SERVICE_MECHANISM, + USE_CATALOG }; /** Feature defaults. */ @@ -317,7 +322,8 @@ null, null, null, - Boolean.TRUE + Boolean.TRUE, + JdkXmlUtils.USE_CATALOG_DEFAULT }; /** Recognized properties. */ @@ -334,12 +340,17 @@ ROOT_TYPE_DEF, ROOT_ELEMENT_DECL, SCHEMA_DV_FACTORY, - XML_SECURITY_PROPERTY_MANAGER + XML_SECURITY_PROPERTY_MANAGER, + JdkXmlUtils.CATALOG_DEFER, + JdkXmlUtils.CATALOG_FILES, + JdkXmlUtils.CATALOG_PREFER, + JdkXmlUtils.CATALOG_RESOLVE }; /** Property defaults. */ private static final Object[] PROPERTY_DEFAULTS = - { null, null, null, null, null, null, null, null, null, null, null, null}; + { null, null, null, null, null, null, null, null, null, null, null, null, + null, null, null, null}; // this is the number of valuestores of each kind // we expect an element to have. It's almost --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/opti/SchemaParsingConfig.java 2016-07-24 18:45:26.560103162 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/opti/SchemaParsingConfig.java 2016-07-24 18:45:26.480099186 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -39,7 +39,6 @@ import com.sun.org.apache.xerces.internal.parsers.BasicParserConfiguration; import com.sun.org.apache.xerces.internal.util.FeatureState; import com.sun.org.apache.xerces.internal.util.PropertyState; -import com.sun.org.apache.xerces.internal.util.Status; import com.sun.org.apache.xerces.internal.util.SymbolTable; import com.sun.org.apache.xerces.internal.xni.XMLLocator; import com.sun.org.apache.xerces.internal.xni.XNIException; @@ -51,6 +50,9 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner; import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration; +import javax.xml.XMLConstants; +import jdk.xml.internal.JdkXmlUtils; +import jdk.xml.internal.SecuritySupport; /** * @xerces.internal @@ -301,7 +303,8 @@ PARSER_SETTINGS, WARN_ON_DUPLICATE_ATTDEF, WARN_ON_UNDECLARED_ELEMDEF, ALLOW_JAVA_ENCODINGS, CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, NOTIFY_BUILTIN_REFS, - NOTIFY_CHAR_REFS, GENERATE_SYNTHETIC_ANNOTATIONS + NOTIFY_CHAR_REFS, GENERATE_SYNTHETIC_ANNOTATIONS, + XMLConstants.USE_CATALOG }; addRecognizedFeatures(recognizedFeatures); fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); @@ -315,6 +318,7 @@ fFeatures.put(NOTIFY_BUILTIN_REFS, Boolean.FALSE); fFeatures.put(NOTIFY_CHAR_REFS, Boolean.FALSE); fFeatures.put(GENERATE_SYNTHETIC_ANNOTATIONS, Boolean.FALSE); + fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); // add default recognized properties final String[] recognizedProperties = { @@ -328,7 +332,11 @@ DATATYPE_VALIDATOR_FACTORY, VALIDATION_MANAGER, GENERATE_SYNTHETIC_ANNOTATIONS, - LOCALE + LOCALE, + JdkXmlUtils.CATALOG_DEFER, + JdkXmlUtils.CATALOG_FILES, + JdkXmlUtils.CATALOG_PREFER, + JdkXmlUtils.CATALOG_RESOLVE }; addRecognizedProperties(recognizedProperties); --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java 2016-07-24 18:45:26.892119662 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/traversers/XSDHandler.java 2016-07-24 18:45:26.812115686 -0700 @@ -102,9 +102,11 @@ import java.util.Stack; import java.util.Vector; import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import jdk.xml.internal.JdkXmlUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -391,7 +393,7 @@ private Locale fLocale; // the XMLEntityManager - private XMLEntityResolver fEntityManager; + private XMLEntityManager fEntityManager; // the XSAttributeChecker private XSAttributeChecker fAttributeChecker; @@ -411,6 +413,13 @@ // the security property manager private XMLSecurityPropertyManager fSecurityPropertyMgr = null; + /** indicate whether Catalog should be used for resolving external resources */ + private boolean fUseCatalog = true; + private String fCatalogFile; + private String fDefer; + private String fPrefer; + private String fResolve; + //************ Traversers ********** XSDAttributeGroupTraverser fAttributeGroupTraverser; XSDAttributeTraverser fAttributeTraverser; @@ -710,6 +719,13 @@ fAnnotationValidator.setProperty(ERROR_HANDLER, (fErrorHandler != null) ? fErrorHandler : new DefaultErrorHandler()); /** Set locale. **/ fAnnotationValidator.setProperty(LOCALE, fLocale); + + // Passing on the Catalog settings + fAnnotationValidator.setFeature(XMLConstants.USE_CATALOG, fUseCatalog); + fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_FILES, fCatalogFile); + fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_DEFER, fDefer); + fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_PREFER, fPrefer); + fAnnotationValidator.setProperty(JdkXmlUtils.CATALOG_RESOLVE, fResolve); } /** @@ -3514,7 +3530,7 @@ fSecurityManager = (XMLSecurityManager) componentManager.getProperty(SECURITY_MANAGER, null); //set entity manager - fEntityManager = (XMLEntityResolver) componentManager.getProperty(ENTITY_MANAGER); + fEntityManager = (XMLEntityManager) componentManager.getProperty(ENTITY_MANAGER); //set entity resolver XMLEntityResolver er = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER); @@ -3593,6 +3609,20 @@ fAccessExternalDTD = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_DTD); fAccessExternalSchema = fSecurityPropertyMgr.getValue(XMLSecurityPropertyManager.Property.ACCESS_EXTERNAL_SCHEMA); + // Passing the Catalog settings to the parser + fUseCatalog = componentManager.getFeature(XMLConstants.USE_CATALOG); + fSchemaParser.setFeature(XMLConstants.USE_CATALOG, fUseCatalog); + fEntityManager.setFeature(XMLConstants.USE_CATALOG, fUseCatalog); + + fCatalogFile = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_FILES); + fDefer = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_DEFER); + fPrefer = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_PREFER); + fResolve = (String)componentManager.getProperty(JdkXmlUtils.CATALOG_RESOLVE); + + for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + fSchemaParser.setProperty(f.getPropertyName(), componentManager.getProperty(f.getPropertyName())); + fEntityManager.setProperty(f.getPropertyName(), componentManager.getProperty(f.getPropertyName())); + } } // reset(XMLComponentManager) --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/StreamValidatorHelper.java 2016-07-24 18:45:27.352142524 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/StreamValidatorHelper.java 2016-07-24 18:45:27.276138747 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -32,6 +32,7 @@ import java.io.IOException; import java.lang.ref.SoftReference; import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.TransformerConfigurationException; @@ -41,6 +42,8 @@ import javax.xml.transform.sax.TransformerHandler; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import jdk.xml.internal.JdkXmlFeatures; +import jdk.xml.internal.JdkXmlUtils; import org.xml.sax.SAXException; /** @@ -190,6 +193,10 @@ fComponentManager.getProperty(Constants.XML_SECURITY_PROPERTY_MANAGER)); config.setProperty(Constants.SECURITY_MANAGER, fComponentManager.getProperty(Constants.SECURITY_MANAGER)); + + // Passing on the CatalogFeatures settings + JdkXmlUtils.catalogFeaturesConfig2Config(fComponentManager, config); + fConfiguration = new SoftReference(config); return config; } --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorHandlerImpl.java 2016-07-24 18:45:27.636156639 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorHandlerImpl.java 2016-07-24 18:45:27.556152663 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -71,6 +71,8 @@ import com.sun.org.apache.xerces.internal.xs.ItemPSVI; import com.sun.org.apache.xerces.internal.xs.PSVIProvider; import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; +import javax.xml.catalog.CatalogFeatures; +import jdk.xml.internal.JdkXmlUtils; import org.w3c.dom.TypeInfo; import org.w3c.dom.ls.LSInput; import org.w3c.dom.ls.LSResourceResolver; @@ -701,6 +703,9 @@ XMLConstants.ACCESS_EXTERNAL_DTD, exc); } } + + // Passing on the CatalogFeatures settings from a configuration object to the reader + JdkXmlUtils.catalogFeaturesConfig2Reader(fComponentManager, reader); } catch( Exception e ) { // this is impossible, but better safe than sorry throw new FactoryConfigurationError(e); @@ -1046,7 +1051,7 @@ */ InputSource inputSource = new InputSource(); inputSource.setPublicId(pubId); - inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(systemId, baseSystemId) : systemId); + inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(sysId, baseSystemId) : sysId); if (charStream != null) { inputSource.setCharacterStream(charStream); --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorImpl.java 2016-07-24 18:45:27.928171151 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorImpl.java 2016-07-24 18:45:27.852167374 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -22,17 +22,19 @@ import java.io.IOException; -import javax.xml.XMLConstants; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXSource; -import javax.xml.transform.stax.StAXResult; import javax.xml.transform.stax.StAXSource; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Validator; import com.sun.org.apache.xerces.internal.impl.Constants; +import static com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.ENTITY_RESOLVER; +import static com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader.ERROR_HANDLER; +import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper; +import com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper; import com.sun.org.apache.xerces.internal.util.SAXMessageFormatter; import com.sun.org.apache.xerces.internal.util.Status; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; @@ -83,12 +85,20 @@ private boolean fResourceResolverChanged = false; /** Support current-element-node property */ - private static final String CURRENT_ELEMENT_NODE = Constants.XERCES_PROPERTY_PREFIX + Constants.CURRENT_ELEMENT_NODE_PROPERTY; + private static final String CURRENT_ELEMENT_NODE = + Constants.XERCES_PROPERTY_PREFIX + Constants.CURRENT_ELEMENT_NODE_PROPERTY; public ValidatorImpl(XSGrammarPoolContainer grammarContainer) { fComponentManager = new XMLSchemaValidatorComponentManager(grammarContainer); - setErrorHandler(null); - setResourceResolver(null); + ErrorHandlerWrapper ehWrapper = + (ErrorHandlerWrapper)grammarContainer.getProperty(ERROR_HANDLER); + ErrorHandler eh = (ehWrapper == null) ? null : ehWrapper.getErrorHandler(); + setErrorHandler(eh); + + DOMEntityResolverWrapper erWrapper = + (DOMEntityResolverWrapper)grammarContainer.getProperty(ENTITY_RESOLVER); + LSResourceResolver er = (erWrapper == null) ? null : erWrapper.getEntityResolver(); + setResourceResolver(er); } public void validate(Source source, Result result) --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java 2016-07-24 18:45:28.232186260 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java 2016-07-24 18:45:28.156182482 -0700 @@ -1,4 +1,7 @@ /* + * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. + */ +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -17,20 +20,6 @@ package com.sun.org.apache.xerces.internal.jaxp.validation; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; - -import javax.xml.XMLConstants; -import javax.xml.stream.XMLEventReader; -import javax.xml.transform.Source; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.sax.SAXSource; -import javax.xml.transform.stax.StAXSource; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; - import com.sun.org.apache.xerces.internal.impl.Constants; import com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaLoader; import com.sun.org.apache.xerces.internal.util.DOMEntityResolverWrapper; @@ -49,6 +38,20 @@ import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures.Feature; +import javax.xml.stream.XMLEventReader; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stax.StAXSource; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import jdk.xml.internal.JdkXmlUtils; import org.w3c.dom.Node; import org.w3c.dom.ls.LSResourceResolver; import org.xml.sax.ErrorHandler; @@ -156,6 +159,12 @@ fSecurityPropertyMgr = new XMLSecurityPropertyManager(); fXMLSchemaLoader.setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); + + // use catalog + fXMLSchemaLoader.setFeature(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); + for (Feature f : Feature.values()) { + fXMLSchemaLoader.setProperty(f.getPropertyName(), null); + } } /** --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaValidatorComponentManager.java 2016-07-24 18:45:28.540201567 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaValidatorComponentManager.java 2016-07-24 18:45:28.464197790 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Locale; -import java.util.Iterator; import java.util.Map; import javax.xml.XMLConstants; @@ -48,6 +47,7 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; +import javax.xml.catalog.CatalogFeatures; import org.w3c.dom.ls.LSResourceResolver; import org.xml.sax.ErrorHandler; @@ -176,7 +176,7 @@ private boolean fUseGrammarPoolOnly; /** Lookup map for components required for validation. **/ - private final HashMap fComponents = new HashMap(); + private final HashMap fComponents = new HashMap<>(); // // Components @@ -202,10 +202,10 @@ // /** Stores initial feature values for validator reset. */ - private final HashMap fInitFeatures = new HashMap(); + private final HashMap fInitFeatures = new HashMap<>(); /** Stores initial property values for validator reset. */ - private final HashMap fInitProperties = new HashMap(); + private final HashMap fInitProperties = new HashMap<>(); /** Stores the initial security manager. */ private XMLSecurityManager fInitSecurityManager; @@ -262,13 +262,15 @@ DISALLOW_DOCTYPE_DECL_FEATURE, NORMALIZE_DATA, SCHEMA_ELEMENT_DEFAULT, - SCHEMA_AUGMENT_PSVI + SCHEMA_AUGMENT_PSVI, + XMLConstants.USE_CATALOG }; addRecognizedFeatures(recognizedFeatures); fFeatures.put(DISALLOW_DOCTYPE_DECL_FEATURE, Boolean.FALSE); fFeatures.put(NORMALIZE_DATA, Boolean.FALSE); fFeatures.put(SCHEMA_ELEMENT_DEFAULT, Boolean.FALSE); fFeatures.put(SCHEMA_AUGMENT_PSVI, Boolean.TRUE); + fFeatures.put(XMLConstants.USE_CATALOG, grammarContainer.getFeature(XMLConstants.USE_CATALOG)); addRecognizedParamsAndSetDefaults(fEntityManager, grammarContainer); addRecognizedParamsAndSetDefaults(fErrorReporter, grammarContainer); @@ -304,6 +306,11 @@ fSecurityPropertyMgr = (XMLSecurityPropertyManager) grammarContainer.getProperty(Constants.XML_SECURITY_PROPERTY_MANAGER); setProperty(XML_SECURITY_PROPERTY_MANAGER, fSecurityPropertyMgr); + + //initialize Catalog properties + for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + setProperty(f.getPropertyName(), grammarContainer.getProperty(f.getPropertyName())); + } } /** @@ -541,20 +548,16 @@ // Reset feature and property values to their initial values if (!fInitFeatures.isEmpty()) { - Iterator iter = fInitFeatures.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); - String name = (String) entry.getKey(); - boolean value = ((Boolean) entry.getValue()).booleanValue(); + for (Map.Entry entry : fInitFeatures.entrySet()) { + String name = entry.getKey(); + boolean value = entry.getValue(); super.setFeature(name, value); } fInitFeatures.clear(); } if (!fInitProperties.isEmpty()) { - Iterator iter = fInitProperties.entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); - String name = (String) entry.getKey(); + for (Map.Entry entry : fInitProperties.entrySet()) { + String name = entry.getKey(); Object value = entry.getValue(); super.setProperty(name, value); } --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/DTDConfiguration.java 2016-07-24 18:45:28.828215881 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/DTDConfiguration.java 2016-07-24 18:45:28.752212103 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -36,7 +36,6 @@ import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; import com.sun.org.apache.xerces.internal.util.FeatureState; import com.sun.org.apache.xerces.internal.util.PropertyState; -import com.sun.org.apache.xerces.internal.util.Status; import com.sun.org.apache.xerces.internal.util.SymbolTable; import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; import com.sun.org.apache.xerces.internal.xni.XMLLocator; @@ -49,6 +48,9 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner; import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import jdk.xml.internal.JdkXmlUtils; /** * This is the DTD-only parser configuration. It extends the basic @@ -308,6 +310,7 @@ //NOTIFY_BUILTIN_REFS, // from XMLDocumentFragmentScannerImpl //NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl //WARN_ON_DUPLICATE_ENTITYDEF, // from XMLEntityManager + XMLConstants.USE_CATALOG }; addRecognizedFeatures(recognizedFeatures); @@ -320,6 +323,7 @@ //setFeature(NOTIFY_BUILTIN_REFS, false); // from XMLDocumentFragmentScannerImpl //setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager + fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); // add default recognized properties final String[] recognizedProperties = { @@ -337,7 +341,11 @@ JAXP_SCHEMA_LANGUAGE, LOCALE, SECURITY_MANAGER, - XML_SECURITY_PROPERTY_MANAGER + XML_SECURITY_PROPERTY_MANAGER, + JdkXmlUtils.CATALOG_DEFER, + JdkXmlUtils.CATALOG_FILES, + JdkXmlUtils.CATALOG_PREFER, + JdkXmlUtils.CATALOG_RESOLVE }; addRecognizedProperties(recognizedProperties); @@ -416,6 +424,11 @@ } setProperty(XML_SECURITY_PROPERTY_MANAGER, new XMLSecurityPropertyManager()); + + // Initialize Catalog features + for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + setProperty(f.getPropertyName(), null); + } } // (SymbolTable,XMLGrammarPool) // --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/NonValidatingConfiguration.java 2016-07-24 18:45:29.120230393 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/NonValidatingConfiguration.java 2016-07-24 18:45:29.044226616 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2001-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -47,6 +47,9 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentScanner; import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import jdk.xml.internal.JdkXmlUtils; /** * This is the non validating parser configuration. It extends the basic @@ -281,8 +284,8 @@ // add default recognized features final String[] recognizedFeatures = { - PARSER_SETTINGS, - NAMESPACES, + PARSER_SETTINGS, + NAMESPACES, //WARN_ON_DUPLICATE_ATTDEF, // from XMLDTDScannerImpl //WARN_ON_UNDECLARED_ELEMDEF, // from XMLDTDScannerImpl //ALLOW_JAVA_ENCODINGS, // from XMLEntityManager @@ -291,6 +294,7 @@ //NOTIFY_BUILTIN_REFS, // from XMLDocumentFragmentScannerImpl //NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl //WARN_ON_DUPLICATE_ENTITYDEF // from XMLEntityManager + XMLConstants.USE_CATALOG }; addRecognizedFeatures(recognizedFeatures); @@ -299,12 +303,13 @@ //setFeature(WARN_ON_UNDECLARED_ELEMDEF, false); // from XMLDTDScannerImpl //setFeature(ALLOW_JAVA_ENCODINGS, false); // from XMLEntityManager fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE); - fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); - fFeatures.put(NAMESPACES, Boolean.TRUE); + fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); + fFeatures.put(NAMESPACES, Boolean.TRUE); //setFeature(LOAD_EXTERNAL_DTD, true); // from XMLDTDScannerImpl //setFeature(NOTIFY_BUILTIN_REFS, false); // from XMLDocumentFragmentScannerImpl //setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager + fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); // add default recognized properties final String[] recognizedProperties = { @@ -319,7 +324,11 @@ VALIDATION_MANAGER, LOCALE, SECURITY_MANAGER, - XML_SECURITY_PROPERTY_MANAGER + XML_SECURITY_PROPERTY_MANAGER, + JdkXmlUtils.CATALOG_DEFER, + JdkXmlUtils.CATALOG_FILES, + JdkXmlUtils.CATALOG_PREFER, + JdkXmlUtils.CATALOG_RESOLVE }; addRecognizedProperties(recognizedProperties); @@ -377,6 +386,11 @@ } setProperty(XML_SECURITY_PROPERTY_MANAGER, new XMLSecurityPropertyManager()); + + // Initialize Catalog features + for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + setProperty(f.getPropertyName(), null); + } } // (SymbolTable,XMLGrammarPool) // --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java 2016-07-24 18:45:29.496249080 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/parsers/XML11Configuration.java 2016-07-24 18:45:29.420245303 -0700 @@ -20,12 +20,6 @@ package com.sun.org.apache.xerces.internal.parsers; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Locale; -import javax.xml.XMLConstants; - import com.sun.org.apache.xerces.internal.impl.Constants; import com.sun.org.apache.xerces.internal.impl.XML11DTDScannerImpl; import com.sun.org.apache.xerces.internal.impl.XML11DocumentScannerImpl; @@ -52,7 +46,6 @@ import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; import com.sun.org.apache.xerces.internal.util.PropertyState; import com.sun.org.apache.xerces.internal.util.SymbolTable; -import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; @@ -69,6 +62,13 @@ import com.sun.org.apache.xerces.internal.xni.parser.XMLErrorHandler; import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Locale; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import jdk.xml.internal.JdkXmlUtils; +import jdk.xml.internal.SecuritySupport; /** * This class is the configuration used to parse XML 1.0 and XML 1.1 documents. @@ -478,10 +478,6 @@ // Common components for XML 1.1. and XML 1.0 fCommonComponents = new ArrayList<>(); - // create table for features and properties - fFeatures = new HashMap<>(); - fProperties = new HashMap<>(); - // add default recognized features final String[] recognizedFeatures = { @@ -503,7 +499,8 @@ EXTERNAL_GENERAL_ENTITIES, EXTERNAL_PARAMETER_ENTITIES, PARSER_SETTINGS, - XMLConstants.FEATURE_SECURE_PROCESSING + XMLConstants.FEATURE_SECURE_PROCESSING, + XMLConstants.USE_CATALOG }; addRecognizedFeatures(recognizedFeatures); // set state for default features @@ -528,6 +525,7 @@ fFeatures.put(USE_GRAMMAR_POOL_ONLY, Boolean.FALSE); fFeatures.put(PARSER_SETTINGS, Boolean.TRUE); fFeatures.put(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE); + fFeatures.put(XMLConstants.USE_CATALOG, JdkXmlUtils.USE_CATALOG_DEFAULT); // add default recognized properties final String[] recognizedProperties = @@ -559,7 +557,11 @@ LOCALE, SCHEMA_DV_FACTORY, SECURITY_MANAGER, - XML_SECURITY_PROPERTY_MANAGER + XML_SECURITY_PROPERTY_MANAGER, + JdkXmlUtils.CATALOG_DEFER, + JdkXmlUtils.CATALOG_FILES, + JdkXmlUtils.CATALOG_PREFER, + JdkXmlUtils.CATALOG_RESOLVE }; addRecognizedProperties(recognizedProperties); @@ -622,6 +624,11 @@ // REVISIT: What is the right thing to do? -Ac } + // Initialize Catalog features + for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + fProperties.put(f.getPropertyName(), null); + } + fConfigUpdated = false; } // (SymbolTable,XMLGrammarPool) --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/ParserConfigurationSettings.java 2016-07-24 18:45:29.836265978 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/util/ParserConfigurationSettings.java 2016-07-24 18:45:29.760262201 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2001, 2002,2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -20,16 +20,15 @@ package com.sun.org.apache.xerces.internal.util; +import com.sun.org.apache.xerces.internal.impl.Constants; +import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; +import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import com.sun.org.apache.xerces.internal.impl.Constants; -import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; -import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; - /** * This class implements the basic operations for managing parser * configuration features and properties. This utility class can @@ -87,12 +86,12 @@ public ParserConfigurationSettings(XMLComponentManager parent) { // create storage for recognized features and properties - fRecognizedFeatures = new HashSet(); - fRecognizedProperties = new HashSet(); + fRecognizedFeatures = new HashSet<>(); + fRecognizedProperties = new HashSet<>(); // create table for features and properties - fFeatures = new HashMap(); - fProperties = new HashMap(); + fFeatures = new HashMap<>(); + fProperties = new HashMap<>(); // save parent fParentSettings = parent; @@ -195,6 +194,7 @@ * it is really * a critical error. */ + @Override public final boolean getFeature(String featureId) throws XMLConfigurationException { @@ -205,6 +205,7 @@ return state.state; } // getFeature(String):boolean + @Override public final boolean getFeature(String featureId, boolean defaultValue) { FeatureState state = getFeatureState(featureId); if (state.isExceptional()) { @@ -213,8 +214,9 @@ return state.state; } + @Override public FeatureState getFeatureState(String featureId) { - Boolean state = (Boolean) fFeatures.get(featureId); + Boolean state = fFeatures.get(featureId); if (state == null) { FeatureState checkState = checkFeature(featureId); @@ -238,6 +240,7 @@ * it is really * a critical error. */ + @Override public final Object getProperty(String propertyId) throws XMLConfigurationException { @@ -249,6 +252,7 @@ return state.state; } // getProperty(String):Object + @Override public final Object getProperty(String propertyId, Object defaultValue) { PropertyState state = getPropertyState(propertyId); if (state.isExceptional()) { @@ -258,6 +262,7 @@ return state.state; } + @Override public PropertyState getPropertyState(String propertyId) { Object propertyValue = fProperties.get(propertyId); @@ -307,6 +312,7 @@ * * @param propertyId The unique identifier (URI) of the property * being set. + * @return the PropertyState * @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the * requested feature is not known. */ --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/SecuritySupport.java 2016-07-24 18:45:30.160282080 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/utils/SecuritySupport.java 2016-07-24 18:45:30.084278303 -0700 @@ -1,21 +1,26 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * Copyright 2002,2004 The Apache Software Foundation. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). * - * http://www.apache.org/licenses/LICENSE-2.0 + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ package com.sun.org.apache.xerces.internal.utils; @@ -48,72 +53,57 @@ /** * Return an instance of this class. + * @return an instance of this class */ public static SecuritySupport getInstance() { return securitySupport; } static ClassLoader getContextClassLoader() { - return (ClassLoader) - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - ClassLoader cl = null; - try { - cl = Thread.currentThread().getContextClassLoader(); - } catch (SecurityException ex) { } - return cl; - } + return AccessController.doPrivileged((PrivilegedAction) () -> { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } catch (SecurityException ex) { } + return cl; }); } static ClassLoader getSystemClassLoader() { - return (ClassLoader) - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - ClassLoader cl = null; - try { - cl = ClassLoader.getSystemClassLoader(); - } catch (SecurityException ex) {} - return cl; - } + return AccessController.doPrivileged((PrivilegedAction) () -> { + ClassLoader cl = null; + try { + cl = ClassLoader.getSystemClassLoader(); + } catch (SecurityException ex) {} + return cl; }); } static ClassLoader getParentClassLoader(final ClassLoader cl) { - return (ClassLoader) - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - ClassLoader parent = null; - try { - parent = cl.getParent(); - } catch (SecurityException ex) {} - - // eliminate loops in case of the boot - // ClassLoader returning itself as a parent - return (parent == cl) ? null : parent; - } + return AccessController.doPrivileged((PrivilegedAction) () -> { + ClassLoader parent = null; + try { + parent = cl.getParent(); + } catch (SecurityException ex) {} + + // eliminate loops in case of the boot + // ClassLoader returning itself as a parent + return (parent == cl) ? null : parent; }); } public static String getSystemProperty(final String propName) { - return (String) - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(propName); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> + System.getProperty(propName)); } static FileInputStream getFileInputStream(final File file) throws FileNotFoundException { try { - return (FileInputStream) - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws FileNotFoundException { - return new FileInputStream(file); - } - }); + return AccessController.doPrivileged( + (PrivilegedExceptionAction)() -> + new FileInputStream(file)); } catch (PrivilegedActionException e) { throw (FileNotFoundException)e.getException(); } @@ -135,38 +125,28 @@ * @return a resource bundle for the given base name and locale */ public static ResourceBundle getResourceBundle(final String bundle, final Locale locale) { - return AccessController.doPrivileged(new PrivilegedAction() { - public ResourceBundle run() { + return AccessController.doPrivileged((PrivilegedAction) () -> { + try { + return PropertyResourceBundle.getBundle(bundle, locale); + } catch (MissingResourceException e) { try { - return PropertyResourceBundle.getBundle(bundle, locale); - } catch (MissingResourceException e) { - try { - return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US")); - } catch (MissingResourceException e2) { - throw new MissingResourceException( - "Could not load any resource bundle by " + bundle, bundle, ""); - } + return PropertyResourceBundle.getBundle(bundle, new Locale("en", "US")); + } catch (MissingResourceException e2) { + throw new MissingResourceException( + "Could not load any resource bundle by " + bundle, bundle, ""); } } }); } static boolean getFileExists(final File f) { - return ((Boolean) - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return f.exists() ? Boolean.TRUE : Boolean.FALSE; - } - })).booleanValue(); + return (AccessController.doPrivileged((PrivilegedAction) () -> + f.exists())); } static long getLastModified(final File f) { - return ((Long) - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return new Long(f.lastModified()); - } - })).longValue(); + return (AccessController.doPrivileged((PrivilegedAction) () -> + f.lastModified())); } /** @@ -193,6 +173,7 @@ * @param allowedProtocols a list of allowed protocols separated by comma * @param accessAny keyword to indicate allowing any protocol * @return the name of the protocol if rejected, null otherwise + * @throws java.io.IOException */ public static String checkAccess(String systemId, String allowedProtocols, String accessAny) throws IOException { if (systemId == null || (allowedProtocols != null && @@ -201,7 +182,7 @@ } String protocol; - if (systemId.indexOf(":")==-1) { + if (!systemId.contains(":")) { protocol = "file"; } else { URL url = new URL(systemId); @@ -249,15 +230,15 @@ * Read JAXP system property in this order: system property, * $java.home/conf/jaxp.properties if the system property is not specified * - * @param propertyId the Id of the property + * @param sysPropertyId the Id of the property * @return the value of the property */ public static String getJAXPSystemProperty(String sysPropertyId) { - String accessExternal = getSystemProperty(sysPropertyId); - if (accessExternal == null) { - accessExternal = readJAXPProperty(sysPropertyId); + String value = getSystemProperty(sysPropertyId); + if (value == null) { + value = readJAXPProperty(sysPropertyId); } - return accessExternal; + return value; } /** @@ -288,7 +269,7 @@ value = cacheProps.getProperty(propertyId); } - catch (Exception ex) {} + catch (IOException ex) {} finally { if (is != null) { try { --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java 2016-07-24 18:45:30.488298382 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java 2016-07-24 18:45:30.408294406 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 2003-2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -17,6 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.sun.org.apache.xerces.internal.xinclude; import java.io.CharConversionException; @@ -70,6 +71,14 @@ import com.sun.org.apache.xerces.internal.utils.ObjectFactory; import com.sun.org.apache.xerces.internal.utils.XMLSecurityPropertyManager; import java.util.Objects; +import javax.xml.catalog.CatalogException; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogManager; +import javax.xml.catalog.CatalogResolver; +import javax.xml.catalog.CatalogUriResolver; +import javax.xml.transform.Source; +import jdk.xml.internal.JdkXmlUtils; +import org.xml.sax.InputSource; /** *

@@ -247,7 +256,7 @@ { ERROR_REPORTER, ENTITY_RESOLVER, SECURITY_MANAGER, BUFFER_SIZE }; /** Property defaults. */ - private static final Object[] PROPERTY_DEFAULTS = { null, null, null, new Integer(XMLEntityManager.DEFAULT_BUFFER_SIZE) }; + private static final Object[] PROPERTY_DEFAULTS = { null, null, null, XMLEntityManager.DEFAULT_BUFFER_SIZE}; // instance variables @@ -335,8 +344,8 @@ private int[] fState = new int[INITIAL_SIZE]; // buffering the necessary DTD events - private ArrayList fNotations; - private ArrayList fUnparsedEntities; + private final ArrayList fNotations; + private final ArrayList fUnparsedEntities; // flags which control whether base URI or language fixup is performed. private boolean fFixupBaseURIs = true; @@ -358,6 +367,17 @@ // track whether the child config needs its features refreshed private boolean fNeedCopyFeatures = true; + /** indicate whether Catalog should be used for resolving external resources */ + private boolean fUseCatalog = true; + CatalogFeatures fCatalogFeatures; + CatalogResolver fCatalogResolver; + CatalogUriResolver fCatalogUriResolver; + + private String fCatalogFile; + private String fDefer; + private String fPrefer; + private String fResolve; + // Constructors public XIncludeHandler() { @@ -366,8 +386,8 @@ fSawFallback[fDepth] = false; fSawInclude[fDepth] = false; fState[fDepth] = STATE_NORMAL_PROCESSING; - fNotations = new ArrayList(); - fUnparsedEntities = new ArrayList(); + fNotations = new ArrayList<>(); + fUnparsedEntities = new ArrayList<>(); fBaseURIScope = new IntStack(); fBaseURI = new Stack(); @@ -534,24 +554,31 @@ fSecurityPropertyMgr = (XMLSecurityPropertyManager) componentManager.getProperty(Constants.XML_SECURITY_PROPERTY_MANAGER); + //Use Catalog + fUseCatalog = componentManager.getFeature(XMLConstants.USE_CATALOG); + fCatalogFile = (String)componentManager.getProperty(CatalogFeatures.Feature.FILES.getPropertyName()); + fDefer = (String)componentManager.getProperty(CatalogFeatures.Feature.DEFER.getPropertyName()); + fPrefer = (String)componentManager.getProperty(CatalogFeatures.Feature.PREFER.getPropertyName()); + fResolve = (String)componentManager.getProperty(CatalogFeatures.Feature.RESOLVE.getPropertyName()); + // Get buffer size. try { Integer value = (Integer)componentManager.getProperty( BUFFER_SIZE); - if (value != null && value.intValue() > 0) { - fBufferSize = value.intValue(); + if (value != null && value > 0) { + fBufferSize = value; if (fChildConfig != null) { fChildConfig.setProperty(BUFFER_SIZE, value); } } else { - fBufferSize = ((Integer)getPropertyDefault(BUFFER_SIZE)).intValue(); + fBufferSize = ((Integer)getPropertyDefault(BUFFER_SIZE)); } } catch (XMLConfigurationException e) { - fBufferSize = ((Integer)getPropertyDefault(BUFFER_SIZE)).intValue(); + fBufferSize = ((Integer)getPropertyDefault(BUFFER_SIZE)); } // Reset XML 1.0 text reader. @@ -1599,6 +1626,39 @@ includedSource = fEntityResolver.resolveEntity(resourceIdentifier); + if (includedSource == null) { + if (fCatalogFeatures == null) { + fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve); + } + fCatalogFile = fCatalogFeatures.get(CatalogFeatures.Feature.FILES); + if (fUseCatalog && fCatalogFile != null) { + /* + Although URI entry is preferred for resolving XInclude, system entry + is allowed as well. + */ + Source source = null; + try { + if (fCatalogUriResolver == null) { + fCatalogUriResolver = CatalogManager.catalogUriResolver(fCatalogFeatures); + } + source = fCatalogUriResolver.resolve(href, fCurrentBaseURI.getExpandedSystemId()); + } catch (CatalogException e) {} + + if (source != null && !source.isEmpty()) { + includedSource = new XMLInputSource(null, source.getSystemId(), + fCurrentBaseURI.getExpandedSystemId(), true); + } else { + if (fCatalogResolver == null) { + fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures); + } + InputSource is = fCatalogResolver.resolveEntity(href, href); + if (is != null && !is.isEmpty()) { + includedSource = new XMLInputSource(is, true); + } + } + } + } + if (includedSource != null && !(includedSource instanceof HTTPInputSource) && (accept != null || acceptLanguage != null) && --- old/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xni/parser/XMLInputSource.java 2016-07-24 18:45:30.896318659 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xni/parser/XMLInputSource.java 2016-07-24 18:45:30.816314683 -0700 @@ -21,9 +21,9 @@ package com.sun.org.apache.xerces.internal.xni.parser; import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; - import java.io.InputStream; import java.io.Reader; +import org.xml.sax.InputSource; /** * This class represents an input source for an XML document. The @@ -108,6 +108,23 @@ } // (XMLResourceIdentifier) /** + * Constructs an input source from a SAX InputSource + * object. + * + * @param inputSource a SAX InputSource + * @param isCreatedByResolver a flag to indicate whether the source is + * created by a resolver + */ + public XMLInputSource(InputSource inputSource, boolean isCreatedByResolver) { + fPublicId = inputSource.getPublicId(); + fSystemId = inputSource.getSystemId(); + fByteStream = inputSource.getByteStream(); + fCharStream = inputSource.getCharacterStream(); + fEncoding = inputSource.getEncoding(); + fIsCreatedByResolver = isCreatedByResolver; + } + + /** * Constructs an input source from a byte stream. * * @param publicId The public identifier, if known. --- old/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/XMLReaderManager.java 2016-07-24 18:45:31.200333768 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/XMLReaderManager.java 2016-07-24 18:45:31.120329792 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -17,9 +17,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * $Id: XMLReaderManager.java,v 1.2.4.1 2005/09/15 08:16:02 suresh_emailid Exp $ - */ + package com.sun.org.apache.xml.internal.utils; import com.sun.org.apache.xalan.internal.XalanConstants; @@ -27,13 +25,16 @@ import com.sun.org.apache.xalan.internal.utils.SecuritySupport; import com.sun.org.apache.xalan.internal.utils.XMLSecurityManager; import java.util.HashMap; - import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; import javax.xml.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; +import jdk.xml.internal.JdkXmlFeatures; +import jdk.xml.internal.JdkXmlUtils; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; @@ -41,6 +42,7 @@ * Creates XMLReader objects and caches them for re-use. * This class follows the singleton pattern. */ +@SuppressWarnings("deprecation") //org.xml.sax.helpers.XMLReaderFactory public class XMLReaderManager { private static final String NAMESPACES_FEATURE = @@ -58,12 +60,12 @@ /** * Cache of XMLReader objects */ - private ThreadLocal m_readers; + private ThreadLocal m_readers; /** * Keeps track of whether an XMLReader object is in use. */ - private HashMap m_inUse; + private HashMap m_inUse; private boolean m_useServicesMechanism = true; @@ -75,6 +77,10 @@ private XMLSecurityManager _xmlSecurityManager; + //Catalog Feature + private boolean _useCatalog; + private CatalogFeatures _catalogFeatures; + /** * Hidden constructor */ @@ -101,17 +107,17 @@ if (m_readers == null) { // When the m_readers.get() method is called for the first time // on a thread, a new XMLReader will automatically be created. - m_readers = new ThreadLocal(); + m_readers = new ThreadLocal<>(); } if (m_inUse == null) { - m_inUse = new HashMap(); + m_inUse = new HashMap<>(); } // If the cached reader for this thread is in use, construct a new // one; otherwise, return the cached reader unless it isn't an // instance of the class set in the 'org.xml.sax.driver' property - reader = (XMLReader) m_readers.get(); + reader = m_readers.get(); boolean threadHasReader = (reader != null); String factory = SecuritySupport.getSystemProperty(property); if (threadHasReader && m_inUse.get(reader) != Boolean.TRUE && @@ -131,7 +137,7 @@ XMLSecurityManager.printWarning(reader.getClass().getName(), XMLConstants.FEATURE_SECURE_PROCESSING, e); } - } catch (Exception e) { + } catch (SAXException e) { try { // If unable to create an instance, let's try to use // the XMLReader from JAXP @@ -156,8 +162,7 @@ throw new SAXException(ex); } catch (FactoryConfigurationError ex1) { throw new SAXException(ex1.toString()); - } catch (NoSuchMethodError ex2) { - } catch (AbstractMethodError ame) { + } catch (NoSuchMethodError | AbstractMethodError ex2) { } // Cache the XMLReader if this is the first time we've created @@ -193,6 +198,23 @@ XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se); } + boolean supportCatalog = true; + try { + reader.setFeature(JdkXmlUtils.USE_CATALOG, _useCatalog); + } + catch (SAXNotRecognizedException | SAXNotSupportedException e) { + supportCatalog = false; + } + + if (supportCatalog && _useCatalog && _catalogFeatures != null) { + try { + for (CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + reader.setProperty(f.getPropertyName(), _catalogFeatures.get(f)); + } + } catch (SAXNotRecognizedException e) { + //shall not happen for internal settings + } + } return reader; } @@ -229,6 +251,8 @@ public void setFeature(String name, boolean value) { if (name.equals(XMLConstants.FEATURE_SECURE_PROCESSING)) { _secureProcessing = value; + } else if (XMLConstants.USE_CATALOG.equals(name)) { + _useCatalog = value; } } @@ -252,6 +276,9 @@ _accessExternalDTD = (String)value; } else if (name.equals(XalanConstants.SECURITY_MANAGER)) { _xmlSecurityManager = (XMLSecurityManager)value; + } else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) { + _catalogFeatures = (CatalogFeatures)value; } + } } --- old/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/JAXPExtensionsProvider.java 2016-07-24 18:45:31.592353250 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/JAXPExtensionsProvider.java 2016-07-24 18:45:31.512349274 -0700 @@ -1,15 +1,15 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -18,27 +18,21 @@ * limitations under the License. */ -// $Id: JAXPExtensionsProvider.java,v 1.1.2.1 2005/08/01 01:30:17 jeffsuttor Exp $ - package com.sun.org.apache.xpath.internal.jaxp; -import javax.xml.transform.TransformerException; -import javax.xml.xpath.XPathFunctionResolver; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; - +import com.sun.org.apache.xalan.internal.res.XSLMessages; import com.sun.org.apache.xpath.internal.ExtensionsProvider; -import com.sun.org.apache.xpath.internal.XPathContext; -import com.sun.org.apache.xpath.internal.objects.XObject; +import com.sun.org.apache.xpath.internal.functions.FuncExtFunction; import com.sun.org.apache.xpath.internal.objects.XNodeSet; +import com.sun.org.apache.xpath.internal.objects.XObject; import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; -import com.sun.org.apache.xalan.internal.res.XSLMessages; -import com.sun.org.apache.xalan.internal.utils.FeatureManager; - -import com.sun.org.apache.xpath.internal.functions.FuncExtFunction; -import java.util.Vector; import java.util.ArrayList; +import java.util.Vector; import javax.xml.namespace.QName; +import javax.xml.xpath.XPathFunction; +import javax.xml.xpath.XPathFunctionException; +import javax.xml.xpath.XPathFunctionResolver; +import jdk.xml.internal.JdkXmlFeatures; /** * @@ -55,10 +49,10 @@ } public JAXPExtensionsProvider(XPathFunctionResolver resolver, - boolean featureSecureProcessing, FeatureManager featureManager ) { + boolean featureSecureProcessing, JdkXmlFeatures featureManager ) { this.resolver = resolver; if (featureSecureProcessing && - !featureManager.isFeatureEnabled(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION)) { + !featureManager.getFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION)) { this.extensionInvocationDisabled = true; } } --- old/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathExpressionImpl.java 2016-07-24 18:45:31.912369154 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathExpressionImpl.java 2016-07-24 18:45:31.836365377 -0700 @@ -20,7 +20,6 @@ package com.sun.org.apache.xpath.internal.jaxp; -import com.sun.org.apache.xalan.internal.utils.FeatureManager; import com.sun.org.apache.xpath.internal.objects.XObject; import javax.xml.namespace.QName; import javax.xml.transform.TransformerException; @@ -30,6 +29,7 @@ import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFunctionResolver; import javax.xml.xpath.XPathVariableResolver; +import jdk.xml.internal.JdkXmlFeatures; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.InputSource; @@ -48,7 +48,7 @@ */ protected XPathExpressionImpl() { this(null, null, null, null, - false, true, new FeatureManager()); + false, true, new JdkXmlFeatures(false)); }; protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, @@ -56,13 +56,13 @@ XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver) { this(xpath, prefixResolver, functionResolver, variableResolver, - false, true, new FeatureManager()); + false, true, new JdkXmlFeatures(false)); }; protected XPathExpressionImpl(com.sun.org.apache.xpath.internal.XPath xpath, JAXPPrefixResolver prefixResolver,XPathFunctionResolver functionResolver, XPathVariableResolver variableResolver, boolean featureSecureProcessing, - boolean useServiceMechanism, FeatureManager featureManager) { + boolean useServiceMechanism, JdkXmlFeatures featureManager) { this.xpath = xpath; this.prefixResolver = prefixResolver; this.functionResolver = functionResolver; --- old/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.java 2016-07-24 18:45:32.236385257 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.java 2016-07-24 18:45:32.156381281 -0700 @@ -22,16 +22,14 @@ package com.sun.org.apache.xpath.internal.jaxp; import com.sun.org.apache.xalan.internal.XalanConstants; -import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; import com.sun.org.apache.xalan.internal.res.XSLMessages; -import com.sun.org.apache.xalan.internal.utils.FeatureManager; -import com.sun.org.apache.xalan.internal.utils.FeaturePropertyBase; - +import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; import javax.xml.XMLConstants; import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactoryConfigurationException; import javax.xml.xpath.XPathFunctionResolver; import javax.xml.xpath.XPathVariableResolver; +import jdk.xml.internal.JdkXmlFeatures; /** * The XPathFactory builds XPaths. @@ -69,7 +67,7 @@ private boolean _useServicesMechanism = true; - private final FeatureManager _featureManager; + private final JdkXmlFeatures _featureManager; public XPathFactoryImpl() { this(true); @@ -80,13 +78,11 @@ } public XPathFactoryImpl(boolean useServicesMechanism) { - _featureManager = new FeatureManager(); if (System.getSecurityManager() != null) { _isSecureMode = true; _isNotSecureProcessing = false; - _featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION, - FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE); } + _featureManager = new JdkXmlFeatures(!_isNotSecureProcessing); this._useServicesMechanism = useServicesMechanism; } /** @@ -189,8 +185,8 @@ _isNotSecureProcessing = !value; if (value && _featureManager != null) { - _featureManager.setValue(FeatureManager.Feature.ORACLE_ENABLE_EXTENSION_FUNCTION, - FeaturePropertyBase.State.FSP, XalanConstants.FEATURE_FALSE); + _featureManager.setFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION, + JdkXmlFeatures.State.FSP, false); } // all done processing feature @@ -204,7 +200,7 @@ } if (_featureManager != null && - _featureManager.setValue(name, FeaturePropertyBase.State.APIPROPERTY, value)) { + _featureManager.setFeature(name, JdkXmlFeatures.State.APIPROPERTY, value)) { return; } @@ -257,11 +253,10 @@ return _useServicesMechanism; } - /** Check to see if the property is managed by the security manager **/ - String propertyValue = (_featureManager != null) ? - _featureManager.getValueAsString(name) : null; - if (propertyValue != null) { - return _featureManager.isFeatureEnabled(name); + /** Check to see if the property is managed by the feature manager **/ + int index = _featureManager.getIndex(name); + if (index > -1) { + return _featureManager.getFeature(index); } // unknown feature --- old/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java 2016-07-24 18:45:32.564401558 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java 2016-07-24 18:45:32.484397582 -0700 @@ -20,20 +20,20 @@ package com.sun.org.apache.xpath.internal.jaxp; -import javax.xml.namespace.QName; +import com.sun.org.apache.xpath.internal.*; +import com.sun.org.apache.xpath.internal.objects.XObject; import javax.xml.namespace.NamespaceContext; -import javax.xml.xpath.XPathExpressionException; +import javax.xml.namespace.QName; +import javax.xml.transform.TransformerException; import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathEvaluationResult; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFunctionResolver; import javax.xml.xpath.XPathVariableResolver; -import javax.xml.xpath.XPathExpression; -import com.sun.org.apache.xpath.internal.*; -import com.sun.org.apache.xpath.internal.objects.XObject; -import com.sun.org.apache.xalan.internal.utils.FeatureManager; +import jdk.xml.internal.JdkXmlFeatures; import org.w3c.dom.Document; import org.xml.sax.InputSource; -import javax.xml.transform.TransformerException; -import javax.xml.xpath.XPathEvaluationResult; /** * The XPathImpl class provides implementation for the methods defined in @@ -54,12 +54,12 @@ private NamespaceContext namespaceContext=null; XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr) { - this(vr, fr, false, true, new FeatureManager()); + this(vr, fr, false, true, new JdkXmlFeatures(false)); } XPathImpl(XPathVariableResolver vr, XPathFunctionResolver fr, boolean featureSecureProcessing, boolean useServiceMechanism, - FeatureManager featureManager) { + JdkXmlFeatures featureManager) { this.origVariableResolver = this.variableResolver = vr; this.origFunctionResolver = this.functionResolver = fr; this.featureSecureProcessing = featureSecureProcessing; --- old/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImplUtil.java 2016-07-24 18:45:32.888417661 -0700 +++ new/src/java.xml/share/classes/com/sun/org/apache/xpath/internal/jaxp/XPathImplUtil.java 2016-07-24 18:45:32.808413685 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,7 +27,6 @@ import com.sun.org.apache.xalan.internal.res.XSLMessages; import com.sun.org.apache.xalan.internal.utils.FactoryImpl; -import com.sun.org.apache.xalan.internal.utils.FeatureManager; import com.sun.org.apache.xml.internal.dtm.DTM; import com.sun.org.apache.xpath.internal.objects.XObject; import com.sun.org.apache.xpath.internal.res.XPATHErrorResources; @@ -42,6 +41,7 @@ import javax.xml.xpath.XPathFunctionResolver; import javax.xml.xpath.XPathNodes; import javax.xml.xpath.XPathVariableResolver; +import jdk.xml.internal.JdkXmlFeatures; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.traversal.NodeIterator; @@ -61,7 +61,7 @@ // Secure Processing Feature is set on XPathFactory then the invocation of // extensions function need to throw XPathFunctionException boolean featureSecureProcessing = false; - FeatureManager featureManager; + JdkXmlFeatures featureManager; /** * Evaluate an XPath context using the internal XPath engine --- old/src/java.xml/share/classes/javax/xml/XMLConstants.java 2016-07-24 18:45:33.208433565 -0700 +++ new/src/java.xml/share/classes/javax/xml/XMLConstants.java 2016-07-24 18:45:33.132429788 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -381,4 +381,42 @@ */ public static final String ACCESS_EXTERNAL_STYLESHEET = "http://javax.xml.XMLConstants/property/accessExternalStylesheet"; + + /** + * Feature: useCatalog + * + *

+ * Instructs XML processors to use XML Catalogs to resolve entity references. + * Catalogs may be set through JAXP factories, system properties, or + * jaxp.properties by using the {@code javax.xml.catalog.files} property + * defined in {@link javax.xml.catalog.CatalogFeatures}. + * The following code enables Catalog on SAX parser: + *

{@code
+         *      SAXParserFactory spf = SAXParserFactory.newInstance();
+         *      spf.setFeature(XMLConstants.USE_CATALOG, true);
+         *      SAXParser parser = spf.newSAXParser();
+         *      parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), "catalog.xml");
+         * }
+ * + *

+ * Value: a boolean. If the value is true, and a catalog is set, + * the XML parser will resolve external references using + * {@link javax.xml.catalog.CatalogResolver}. If the value is false, + * XML Catalog is ignored even if one is set. The default value is true. + * + *

+ * System Property: The value of this property can be set or overridden by + * system property {@code javax.xml.useCatalog} + * + *

+ * jaxp.properties: This configuration file is in standard + * {@link java.util.Properties} format and typically located in the {@code conf} + * directory of the Java installation. If the file exists and the system + * property is specified, its value will be used to override the default + * value of the property. + * + * @since 9 + */ + public static final String USE_CATALOG = "http://javax.xml.XMLConstants/feature/useCatalog"; + } --- old/src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java 2016-07-24 18:45:33.600453047 -0700 +++ new/src/java.xml/share/classes/javax/xml/catalog/CatalogFeatures.java 2016-07-24 18:45:33.452445692 -0700 @@ -195,29 +195,184 @@ .build(); * } * + *

+ *

JAXP XML Processor Support

+ * The Catalog Features are supported throughout the JAXP processors, including + * SAX and DOM ({@link javax.xml.parsers}), and StAX parsers ({@link javax.xml.stream}), + * Schema Validation ({@link javax.xml.validation}), and XML Transformation + * ({@link javax.xml.transform}). The features described above can be set through JAXP + * factories or processors that define a setProperty or setAttribute interface. + * For example, the following code snippet sets a path to a catalog file on a SAX + * parser through the {@code javax.xml.catalog.files} property: + *

+ *

{@code
+ *      SAXParserFactory spf = SAXParserFactory.newInstance();
+ *      spf.setFeature(XMLConstants.USE_CATALOG, true); [1]
+ *      SAXParser parser = spf.newSAXParser();
+ *      parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), "catalog.xml");
+ * }
+ *

+ * [1] Note that this statement is not required since the default value of + * {@link javax.xml.XMLConstants#USE_CATALOG USE_CATALOG} is true. + * + *

+ * The JAXP Processors' support for Catalog depends on both the + * {@link javax.xml.XMLConstants#USE_CATALOG USE_CATALOG} feature and the + * existence of valid Catalog file(s). A JAXP processor will use the Catalog + * only when the feature is true and valid Catalog file(s) are specified through + * the {@code javax.xml.catalog.files} property. It will make no attempt to use + * the Catalog if either {@link javax.xml.XMLConstants#USE_CATALOG USE_CATALOG} + * is set to false, or there is no Catalog file specified. + * + *

+ * The JAXP processors will observe the default settings of the + * {@link javax.xml.catalog.CatalogFeatures}. The processors, for example, will + * report an Exception by default when no matching entry is found since the + * default value of the {@code javax.xml.catalog.resolve} property is strict. + * + *

+ * The JAXP processors give preference to user-specified custom resolvers. If such + * a resolver is registered, it will be used over the CatalogResolver. If it returns + * null however, the processors will continue resolving with the CatalogResolver. + * If it returns an empty source, no attempt will be made by the CatalogResolver. + * + *

+ * The Catalog support is available for any process in the JAXP library that + * supports a resolver. The following table lists all such processes. + * + *

+ *

Processes with Catalog Support

+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
ProcessCatalog Entry TypeExample
DTDs and external entitiespublic, system + *
{@literal
+   The following DTD reference:
+   
+
+   Can be resolved using the following Catalog entry:
+   
+   or
+   
+ * }
+ *
XIncludeuri + *
{@literal
+   The following XInclude element:
+   
+
+   can be resolved using an uri entry:
+   
+   or
+   
+ * }
+ *
XSD importuri + *
{@literal
+   The following import element:
+    
+
+   can be resolved using an uri entry:
+   
+   or
+   
+   or
+   
+ * }
+ *
XSD includeuri + *
{@literal
+   The following include element:
+   
+
+   can be resolved using an uri entry:
+   
+   or
+   
+ * }
+ *
XSL import and includeuri + *
{@literal
+   The following include element:
+   
+
+   can be resolved using an uri entry:
+   
+   or
+   
+ * }
+ *
XSL document functionuri + *
{@literal
+   The document in the following element:
+   
+
+   can be resolved using an uri entry:
+   
+   or
+   
+ * }
+ *
+ * * @since 9 */ public class CatalogFeatures { /** - * The constant name of the javax.xml.catalog.files property. See the property table for more details. + * The constant name of the javax.xml.catalog.files property as described + * in the property table above. */ static final String CATALOG_FILES = "javax.xml.catalog.files"; /** - * The javax.xml.catalog.prefer property. See the property table for more details. + * The javax.xml.catalog.prefer property as described + * in the property table above. */ static final String CATALOG_PREFER = "javax.xml.catalog.prefer"; /** - * Determines whether or not delegated catalogs and nextCatalog will be read - * when the current catalog is loaded. + * The javax.xml.catalog.defer property as described + * in the property table above. */ static final String CATALOG_DEFER = "javax.xml.catalog.defer"; /** - * Determines the action if there is no matching entry found after - * all of the specified catalogs are exhausted. + * The javax.xml.catalog.resolve property as described + * in the property table above. */ static final String CATALOG_RESOLVE = "javax.xml.catalog.resolve"; @@ -305,7 +460,7 @@ * Returns the default value of the property. * @return the default value of the property */ - String defaultValue() { + public String defaultValue() { return defaultValue; } --- old/src/java.xml/share/classes/jdk/xml/internal/SecuritySupport.java 2016-07-24 18:45:33.928469349 -0700 +++ new/src/java.xml/share/classes/jdk/xml/internal/SecuritySupport.java 2016-07-24 18:45:33.848465373 -0700 @@ -83,6 +83,22 @@ } /** + * Reads boolean type system property. + * + * @param propName the name of the property + * @param defValue the default value + * @return the value of the property, or the default value of no system + * property is found + */ + public static boolean getJAXPSystemProperty(String propName, boolean defValue) { + String value = getJAXPSystemProperty(propName); + if (value == null) { + return defValue; + } + return Boolean.parseBoolean(value); + } + + /** * Reads JAXP system property in this order: system property, * $java.home/conf/jaxp.properties if the system property is not specified * --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java 2016-07-24 18:45:34.156480680 -0700 @@ -0,0 +1,348 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.xml.internal; + +import javax.xml.XMLConstants; +import static jdk.xml.internal.JdkXmlUtils.SP_USE_CATALOG; + +/** + * This class manages JDK's XML Features. Previously added features and properties + * may be gradually moved to this class. + */ +public class JdkXmlFeatures { + public static final String ORACLE_JAXP_PROPERTY_PREFIX = + "http://www.oracle.com/xml/jaxp/properties/"; + /** + * Feature enableExtensionFunctions + */ + public static final String ORACLE_ENABLE_EXTENSION_FUNCTION = + ORACLE_JAXP_PROPERTY_PREFIX + "enableExtensionFunctions"; + public static final String SP_ENABLE_EXTENSION_FUNCTION = + "javax.xml.enableExtensionFunctions"; + public static final String CATALOG_FEATURES = "javax.xml.catalog.catalogFeatures"; + + public final static String PROPERTY_USE_CATALOG = XMLConstants.USE_CATALOG; + + public static enum XmlFeature { + /** + * Feature enableExtensionFunctions + * FSP: extension function is enforced by FSP. When FSP is on, entension + * function is disabled. + */ + ENABLE_EXTENSION_FUNCTION(ORACLE_ENABLE_EXTENSION_FUNCTION, + SP_ENABLE_EXTENSION_FUNCTION, true, false, true, true), + /** + * The {@link javax.xml.XMLConstants.USE_CATALOG} feature. + * FSP: USE_CATALOG is not enforced by FSP. + */ + USE_CATALOG(PROPERTY_USE_CATALOG, SP_USE_CATALOG, true, false, true, false); + + private final String name; + private final String nameSP; + private final boolean valueDefault; + private final boolean valueEnforced; + private final boolean hasSystem; + private final boolean enforced; + + /** + * Constructs an XmlFeature instance. + * @param name the name of the feature + * @param nameSP the name of the System Property + * @param value the value of the feature + * @param hasSystem a flag to indicate whether the feature is supported + * @param enforced a flag indicating whether the feature is + * FSP (Feature_Secure_Processing) enforced + * with a System property + */ + XmlFeature(String name, String nameSP, boolean value, boolean valueEnforced, boolean hasSystem, boolean enforced) { + this.name = name; + this.nameSP = nameSP; + this.valueDefault = value; + this.valueEnforced = valueEnforced; + this.hasSystem = hasSystem; + this.enforced = enforced; + } + + /** + * Checks whether the specified property is equal to the current property. + * @param propertyName the name of a property + * @return true if the specified property is the current property, false + * otherwise + */ + boolean equalsPropertyName(String propertyName) { + return name.equals(propertyName); + } + + /** + * Returns the name of the property. + * + * @return the name of the property + */ + public String apiProperty() { + return name; + } + + /** + * Returns the name of the corresponding System Property. + * + * @return the name of the System Property + */ + String systemProperty() { + return nameSP; + } + + /** + * Returns the default value of the property. + * @return the default value of the property + */ + public boolean defaultValue() { + return valueDefault; + } + + /** + * Returns the FSP-enforced value. + * @return the FSP-enforced value + */ + public boolean enforcedValue() { + return valueEnforced; + } + + /** + * Checks whether System property is supported for the feature. + * @return true it is supported, false otherwise + */ + boolean hasSystemProperty() { + return hasSystem; + } + + /** + * Checks whether the property is enforced by FSP + * @return true it is, false otherwise + */ + boolean enforced() { + return enforced; + } + + } + + /** + * States of the settings of a property, in the order: default value, value + * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system + * properties, and jaxp api properties + */ + public static enum State { + //this order reflects the overriding order + + DEFAULT("default"), FSP("FEATURE_SECURE_PROCESSING"), + JAXPDOTPROPERTIES("jaxp.properties"), SYSTEMPROPERTY("system property"), + APIPROPERTY("property"); + + final String literal; + State(String literal) { + this.literal = literal; + } + + String literal() { + return literal; + } + } + + /** + * Values of the features + */ + private boolean[] featureValues; + + /** + * States of the settings for each property + */ + private State[] states; + + /** + * Flag indicating if secure processing is set + */ + boolean secureProcessing; + + /** + * Instantiate JdkXmlFeatures and initialize the fields + * @param secureProcessing + */ + public JdkXmlFeatures(boolean secureProcessing) { + featureValues = new boolean[XmlFeature.values().length]; + states = new State[XmlFeature.values().length]; + this.secureProcessing = secureProcessing; + for (XmlFeature f : XmlFeature.values()) { + if (secureProcessing && f.enforced()) { + featureValues[f.ordinal()] = f.enforcedValue(); + states[f.ordinal()] = State.FSP; + } else { + featureValues[f.ordinal()] = f.defaultValue(); + states[f.ordinal()] = State.DEFAULT; + } + } + //read system properties or jaxp.properties + readSystemProperties(); + } + + /** + * Updates the JdkXmlFeatures instance by reading the system properties again. + * This will become necessary in case the system properties are set after + * the instance has been created. + */ + public void update() { + readSystemProperties(); + } + + /** + * Set feature by property name and state + * @param propertyName property name + * @param state the state of the property + * @param value the value of the property + * @return true if the property is managed by the JdkXmlFeatures instance; + * false otherwise. + */ + public boolean setFeature(String propertyName, State state, Object value) { + int index = getIndex(propertyName); + if (index > -1) { + setFeature(index, state, value); + return true; + } + return false; + } + + /** + * Set the value for a specific feature. + * + * @param feature the feature + * @param state the state of the property + * @param value the value of the property + */ + public void setFeature(XmlFeature feature, State state, boolean value) { + setFeature(feature.ordinal(), state, value); + } + + /** + * Return the value of the specified property + * + * @param feature the property + * @return the value of the property + */ + public boolean getFeature(XmlFeature feature) { + return featureValues[feature.ordinal()]; + } + + /** + * Return the value of a feature by its index (the Feature's ordinal) + * @param index the index of a feature + * @return value of a feature + */ + public boolean getFeature(int index) { + return featureValues[index]; + } + + /** + * Set the value of a property by its index + * + * @param index the index of the property + * @param state the state of the property + * @param value the value of the property + */ + public void setFeature(int index, State state, Object value) { + boolean temp; + if (Boolean.class.isAssignableFrom(value.getClass())) { + temp = (Boolean)value; + } else { + temp = Boolean.parseBoolean((String) value); + } + setFeature(index, state, temp); + } + + /** + * Set the value of a property by its index + * + * @param index the index of the property + * @param state the state of the property + * @param value the value of the property + */ + public void setFeature(int index, State state, boolean value) { + //only update if it shall override + if (state.compareTo(states[index]) >= 0) { + featureValues[index] = value; + states[index] = state; + } + } + + /** + * Get the index by property name + * + * @param propertyName property name + * @return the index of the property if found; return -1 if not + */ + public int getIndex(String propertyName) { + for (XmlFeature feature : XmlFeature.values()) { + if (feature.equalsPropertyName(propertyName)) { + //internally, ordinal is used as index + return feature.ordinal(); + } + } + return -1; + } + + /** + * Read from system properties, or those in jaxp.properties + */ + private void readSystemProperties() { + for (XmlFeature feature : XmlFeature.values()) { + getSystemProperty(feature, feature.systemProperty()); + } + } + + /** + * Read from system properties, or those in jaxp.properties + * + * @param property the type of the property + * @param sysPropertyName the name of system property + */ + private boolean getSystemProperty(XmlFeature feature, String sysPropertyName) { + try { + String value = SecuritySupport.getSystemProperty(sysPropertyName); + if (value != null && !value.equals("")) { + setFeature(feature, State.SYSTEMPROPERTY, Boolean.parseBoolean(value)); + return true; + } + + value = SecuritySupport.readJAXPProperty(sysPropertyName); + if (value != null && !value.equals("")) { + setFeature(feature, State.JAXPDOTPROPERTIES, Boolean.parseBoolean(value)); + return true; + } + } catch (NumberFormatException e) { + //invalid setting + throw new NumberFormatException("Invalid setting for system property: " + feature.systemProperty()); + } + return false; + } + +} --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/src/java.xml/share/classes/jdk/xml/internal/JdkXmlUtils.java 2016-07-24 18:45:34.404493006 -0700 @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.xml.internal; + +import com.sun.org.apache.xerces.internal.util.ParserConfigurationSettings; +import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; +import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogFeatures.Feature; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; + +/** + * Constants for use across JAXP processors. + */ +public class JdkXmlUtils { + /** + * Catalog features + */ + public final static String USE_CATALOG = XMLConstants.USE_CATALOG; + public final static String SP_USE_CATALOG = "javax.xml.useCatalog"; + public final static String CATALOG_FILES = CatalogFeatures.Feature.FILES.getPropertyName(); + public final static String CATALOG_DEFER = CatalogFeatures.Feature.DEFER.getPropertyName(); + public final static String CATALOG_PREFER = CatalogFeatures.Feature.PREFER.getPropertyName(); + public final static String CATALOG_RESOLVE = CatalogFeatures.Feature.RESOLVE.getPropertyName(); + + /** + * Values for a feature + */ + public static final String FEATURE_TRUE = "true"; + public static final String FEATURE_FALSE = "false"; + + /** + * Default value of USE_CATALOG. This will read the System property + */ + public static final boolean USE_CATALOG_DEFAULT = + SecuritySupport.getJAXPSystemProperty(SP_USE_CATALOG, true); + + /** + * Returns the value of a Catalog feature by the property name. + * @param features a CatalogFeatures instance + * @param name the name of a Catalog feature + * @return the value of a Catalog feature, null if the name does not match + * any feature supported by the Catalog. + */ + public static String getCatalogFeature(CatalogFeatures features, String name) { + for (Feature feature : Feature.values()) { + if (feature.getPropertyName().equals(name)) { + return features.get(feature); + } + } + return null; + } + + /** + * Creates an instance of a CatalogFeatures. + * + * @param defer the defer property defined in CatalogFeatures + * @param file the file path to a catalog + * @param prefer the prefer property defined in CatalogFeatures + * @param resolve the resolve property defined in CatalogFeatures + * @return a {@link javax.xml.transform.Source} object + */ + public static CatalogFeatures getCatalogFeatures(String defer, String file, + String prefer, String resolve) { + + CatalogFeatures.Builder builder = CatalogFeatures.builder(); + if (file != null) { + builder = builder.with(CatalogFeatures.Feature.FILES, file); + } + if (prefer != null) { + builder = builder.with(CatalogFeatures.Feature.PREFER, prefer); + } + if (defer != null) { + builder = builder.with(CatalogFeatures.Feature.DEFER, defer); + } + if (resolve != null) { + builder = builder.with(CatalogFeatures.Feature.RESOLVE, resolve); + } + + return builder.build(); + } + + + /** + * Passing on the CatalogFeatures settings from one Xerces configuration object + * to another. + * + * @param config1 a Xerces configuration object + * @param config2 a Xerces configuration object + */ + public static void catalogFeaturesConfig2Config(XMLComponentManager config1, + ParserConfigurationSettings config2) { + boolean supportCatalog = true; + boolean useCatalog = config1.getFeature(XMLConstants.USE_CATALOG); + try { + config2.setFeature(JdkXmlUtils.USE_CATALOG, useCatalog); + } + catch (XMLConfigurationException e) { + supportCatalog = false; + } + + if (supportCatalog && useCatalog) { + try { + for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + config2.setProperty(f.getPropertyName(), config1.getProperty(f.getPropertyName())); + } + } catch (XMLConfigurationException e) { + //shall not happen for internal settings + } + } + } + + /** + * Passing on the CatalogFeatures settings from a Xerces configuration object + * to an XMLReader. + * + * @param config a Xerces configuration object + * @param reader an XMLReader + */ + public static void catalogFeaturesConfig2Reader(XMLComponentManager config, XMLReader reader) { + boolean supportCatalog = true; + boolean useCatalog = config.getFeature(XMLConstants.USE_CATALOG); + try { + reader.setFeature(JdkXmlUtils.USE_CATALOG, useCatalog); + } + catch (SAXNotRecognizedException | SAXNotSupportedException e) { + supportCatalog = false; + } + + if (supportCatalog && useCatalog) { + try { + for( CatalogFeatures.Feature f : CatalogFeatures.Feature.values()) { + reader.setProperty(f.getPropertyName(), config.getProperty(f.getPropertyName())); + } + } catch (SAXNotRecognizedException | SAXNotSupportedException e) { + //shall not happen for internal settings + } + } + } +} --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.java 2016-07-24 18:45:34.648505133 -0700 @@ -0,0 +1,325 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package catalog; + +import java.io.File; +import java.io.StringReader; +import javax.xml.transform.Source; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stax.StAXSource; +import javax.xml.transform.stream.StreamSource; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.ls.LSResourceResolver; +import org.xml.sax.InputSource; + +/** + * @bug 8158084 8162435 8162438 8162442 + * @summary verifies the use of Catalog in SAX/DOM/StAX/Validation/Transform. + * The two main scenarios for all processors are: + * A custom resolver is used whether or not there's a Catalog; + * A Catalog is used when there's no custom resolver, and the USE_CATALOG + * is true (which is the case by default). + */ + +/** + * Support Catalog: + * With this patch, the Catalog features are supported by all of the JAXP processors. + * The support is enabled by default. Using Catalog is as simple as setting a + * path to a catalog, through the API, or System property, or jaxp.properties. + * + * Test notes: + * For all DataProviders, the 1st and 2nd columns determine whether to set USE_CATALOG + * through the API and to use Catalog. When a custom resolver is specified, these + * settings should not affect the operation, thus the tests are repeated for both + * false and true. + * + * @author huizhe.wang@oracle.com + */ +public class CatalogSupport extends CatalogSupportBase { + /* + * Initializing fields + */ + @BeforeClass + public void setUpClass() throws Exception { + setUp(); + } + + /* + Verifies the Catalog support on SAXParser. + */ + @Test(dataProvider = "data_SAXA") + public void testSAXA(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testSAX(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XMLReader. + */ + @Test(dataProvider = "data_SAXA") + public void testXMLReaderA(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testXMLReader(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XInclude. + */ + @Test(dataProvider = "data_XIA") + public void testXIncludeA(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on DOM parser. + */ + @Test(dataProvider = "data_DOMA") + public void testDOMA(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on resolving DTD, xsd import and include in + Schema files. + */ + @Test(dataProvider = "data_SchemaA") + public void testValidationA(boolean setUseCatalog, boolean useCatalog, + String catalog, String xsd, LSResourceResolver resolver) + throws Exception { + + testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ; + } + + /* + @bug 8158084 8162435 8162438 these tests also verifies the fix for 8162435 and 8162438 + Verifies the Catalog support on the Schema Validator. + */ + @Test(dataProvider = "data_ValidatorA") + public void testValidatorA(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog, + Source source, LSResourceResolver resolver1, LSResourceResolver resolver2, + String catalog1, String catalog2) + throws Exception { + testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source, + resolver1, resolver2, catalog1, catalog2); + } + + /* + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLA") + public void testXSLImportA(boolean setUseCatalog, boolean useCatalog, String catalog, + SAXSource xsl, StreamSource xml, URIResolver resolver, String expected) + throws Exception { + + testXSLImport(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + @bug 8158084 8162442 + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLA") + public void testXSLImportWTemplatesA(boolean setUseCatalog, boolean useCatalog, + String catalog, SAXSource xsl, StreamSource xml, URIResolver resolver, String expected) + throws Exception { + testXSLImportWTemplates(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + DataProvider: for testing the SAX parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_SAXA") + Object[][] getDataSAX() { + String[] systemIds = {"system.xsd"}; + InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))}; + MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem); + return new Object[][]{ + {false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}, + {false, true, xml_catalog, xml_system, entityHandler, expectedWResolver}, + {true, true, xml_catalog, xml_system, entityHandler, expectedWResolver} + }; + } + + /* + DataProvider: for testing XInclude + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_XIA") + Object[][] getDataXI() { + String[] systemIds = {"XI_simple.xml"}; + InputSource[] returnValues = {new InputSource(xml_xIncludeSimple)}; + MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInXISimple); + return new Object[][]{ + {false, true, xml_catalog, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog}, + {false, true, xml_catalog, xml_xInclude, entityHandler, contentInXIutf8}, + {true, true, xml_catalog, xml_xInclude, entityHandler, contentInXIutf8} + }; + } + + /* + DataProvider: for testing DOM parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_DOMA") + Object[][] getDataDOM() { + String[] systemIds = {"system.xsd"}; + InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))}; + MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem); + return new Object[][]{ + {false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}, + {false, true, xml_catalog, xml_system, getMyEntityHandler(elementInSystem, systemIds, + new InputSource(new StringReader(dtd_systemResolved))), expectedWResolver}, + {true, true, xml_catalog, xml_system, getMyEntityHandler(elementInSystem, systemIds, + new InputSource(new StringReader(dtd_systemResolved))), expectedWResolver} + }; + } + + MyEntityHandler getMyEntityHandler(String elementName, String[] systemIds, InputSource... returnValues) { + return new MyEntityHandler(systemIds, returnValues, elementName); + } + + /* + DataProvider: for testing Schema validation + Data: set use_catalog, use_catalog, catalog file, xsd file, a LSResourceResolver + */ + @DataProvider(name = "data_SchemaA") + Object[][] getDataSchema() { + String[] systemIds = {"pathto/XMLSchema.dtd", "datatypes.dtd"}; + XmlInput[] returnValues = {new XmlInput(null, dtd_xmlSchema, null), new XmlInput(null, dtd_datatypes, null)}; + LSResourceResolver resolver = new SourceResolver(null, systemIds, returnValues); + + String[] systemIds1 = {"xml.xsd"}; + XmlInput[] returnValues1 = {new XmlInput(null, xsd_xml, null)}; + LSResourceResolver resolverImport = new SourceResolver(null, systemIds1, returnValues1); + + String[] systemIds2 = {"XSDInclude_person.xsd", "XSDInclude_product.xsd"}; + XmlInput[] returnValues2 = {new XmlInput(null, xsd_include_person, null), + new XmlInput(null, xsd_include_product, null)}; + LSResourceResolver resolverInclude = new SourceResolver(null, systemIds2, returnValues2); + + return new Object[][]{ + // for resolving DTD in xsd + {false, true, xml_catalog, xsd_xmlSchema, null}, + {false, true, xml_bogus_catalog, xsd_xmlSchema, resolver}, + {true, true, xml_bogus_catalog, xsd_xmlSchema, resolver}, + // for resolving xsd import + {false, true, xml_catalog, xsd_xmlSchema_import, null}, + {false, true, xml_bogus_catalog, xsd_xmlSchema_import, resolverImport}, + {true, true, xml_bogus_catalog, xsd_xmlSchema_import, resolverImport}, + // for resolving xsd include + {false, true, xml_catalog, xsd_include_company, null}, + {false, true, xml_bogus_catalog, xsd_include_company, resolverInclude}, + {true, true, xml_bogus_catalog, xsd_include_company, resolverInclude} + }; + } + + /* + DataProvider: for testing Schema Validator + Data: source, resolver1, resolver2, catalog1, a catalog2 + */ + @DataProvider(name = "data_ValidatorA") + Object[][] getDataValidator() { + DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, false, true, xml_catalog); + + SAXSource ss = new SAXSource(new InputSource(xml_val_test)); + ss.setSystemId(xml_val_test_id); + + StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id); + StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id); + + StreamSource source = new StreamSource(new File(xml_val_test)); + + String[] systemIds = {"system.dtd", "val_test.xsd"}; + XmlInput[] returnValues = {new XmlInput(null, dtd_system, null), new XmlInput(null, xsd_val_test, null)}; + LSResourceResolver resolver = new SourceResolver(null, systemIds, returnValues); + + StAXSource stax2 = getStaxSource(xml_val_test, xml_val_test_id); + StAXSource stax3 = getStaxSource(xml_val_test, xml_val_test_id); + + return new Object[][]{ + // use catalog + {false, false, true, ds, null, null, xml_catalog, null}, + {false, false, true, ds, null, null, null, xml_catalog}, + {false, false, true, ss, null, null, xml_catalog, null}, + {false, false, true, ss, null, null, null, xml_catalog}, + {false, false, true, stax, null, null, xml_catalog, null}, + {false, false, true, stax1, null, null, null, xml_catalog}, + {false, false, true, source, null, null, xml_catalog, null}, + {false, false, true, source, null, null, null, xml_catalog}, + // use resolver + {false, false, true, ds, resolver, null, xml_bogus_catalog, null}, + {false, false, true, ds, null, resolver, null, xml_bogus_catalog}, + {false, false, true, ss, resolver, null, xml_bogus_catalog, null}, + {false, false, true, ss, null, resolver, null, xml_bogus_catalog}, + {false, false, true, stax2, resolver, null, xml_bogus_catalog, null}, + {false, false, true, stax3, null, resolver, null, xml_bogus_catalog}, + {false, false, true, source, resolver, null, xml_bogus_catalog, null}, + {false, false, true, source, null, resolver, null, xml_bogus_catalog} + }; + } + + /* + DataProvider: for testing XSL import and include + Data: set use_catalog, use_catalog, catalog file, xsl file, xml file, a URIResolver, expected result + */ + @DataProvider(name = "data_XSLA") + Object[][] getDataXSL() { + // XSLInclude.xsl has one import XSLImport_html.xsl and two includes, + // XSLInclude_header.xsl and XSLInclude_footer.xsl; + String[] hrefs = {"XSLImport_html.xsl", "XSLInclude_header.xsl", "XSLInclude_footer.xsl"}; + Source[] returnValues = {new StreamSource(xsl_import_html), + new StreamSource(xsl_include_header), + new StreamSource(xsl_include_footer)}; + URIResolver resolver = new XslResolver(hrefs, returnValues); + SAXSource xslSourceDTD = new SAXSource(new InputSource(new StringReader(xsl_includeDTD))); + StreamSource xmlSourceDTD = new StreamSource(new StringReader(xml_xslDTD)); + + String[] hrefs1 = {"pathto/DocFunc2.xml"}; + Source[] returnValues1 = {new StreamSource(xml_doc2)}; + URIResolver docResolver = new XslResolver(hrefs1, returnValues1); + SAXSource xslDocSource = new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString())); + StreamSource xmlDocSource = new StreamSource(new File(xml_doc)); + return new Object[][]{ + // for resolving DTD, import and include in xsl + {false, true, xml_catalog, xslSourceDTD, xmlSourceDTD, null, ""}, + {false, true, xml_bogus_catalog, new SAXSource(new InputSource(new StringReader(xsl_include))), + new StreamSource(new StringReader(xml_xsl)), resolver, ""}, + {true, true, xml_bogus_catalog, new SAXSource(new InputSource(new StringReader(xsl_include))), + new StreamSource(new StringReader(xml_xsl)), resolver, ""}, + // for resolving reference by the document function + {false, true, xml_catalog, xslDocSource, xmlDocSource, null, "Resolved by a catalog"}, + {false, true, xml_bogus_catalog, xslDocSource, xmlDocSource, docResolver, "Resolved by a resolver"}, + {true, true, xml_bogus_catalog, xslDocSource, xmlDocSource, docResolver, "Resolved by a resolver"} + }; + } +} --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.xml 2016-07-24 18:45:34.896517458 -0700 @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/CatalogSupport1.java 2016-07-24 18:45:35.144529784 -0700 @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package catalog; + +import java.io.File; +import java.io.StringReader; +import javax.xml.catalog.CatalogFeatures.Feature; +import javax.xml.transform.Source; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stax.StAXSource; +import javax.xml.transform.stream.StreamSource; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.ls.LSResourceResolver; +import org.xml.sax.InputSource; + +/* + * @bug 8158084 8162435 8162438 8162442 + * @summary extends CatalogSupport, verifies that the catalog file can be set + * using the System property. + */ + +/** + * The name of a System property in javax.xml.catalog is the same as that of the + * property, and can be read through CatalogFeatures.Feature. + * + * @author huizhe.wang@oracle.com + */ +public class CatalogSupport1 extends CatalogSupportBase { + /* + * Initializing fields + */ + @BeforeClass + public void setUpClass() throws Exception { + setUp(); + System.setProperty(Feature.FILES.getPropertyName(), xml_catalog); + } + + @AfterClass + public void tearDownClass() throws Exception { + System.clearProperty(Feature.FILES.getPropertyName()); + } + + /* + Verifies the Catalog support on SAXParser. + */ + @Test(dataProvider = "data_SAXC") + public void testSAXC(boolean setUseCatalog, boolean useCatalog, String catalog, String xml, MyHandler handler, String expected) throws Exception { + testSAX(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XMLReader. + */ + @Test(dataProvider = "data_SAXC") + public void testXMLReaderC(boolean setUseCatalog, boolean useCatalog, String catalog, String xml, MyHandler handler, String expected) throws Exception { + testXMLReader(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XInclude. + */ + @Test(dataProvider = "data_XIC") + public void testXIncludeC(boolean setUseCatalog, boolean useCatalog, String catalog, String xml, MyHandler handler, String expected) throws Exception { + testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on DOM parser. + */ + @Test(dataProvider = "data_DOMC") + public void testDOMC(boolean setUseCatalog, boolean useCatalog, String catalog, String xml, MyHandler handler, String expected) throws Exception { + testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on resolving DTD, xsd import and include in + Schema files. + */ + @Test(dataProvider = "data_SchemaC") + public void testValidationC(boolean setUseCatalog, boolean useCatalog, String catalog, String xsd, LSResourceResolver resolver) + throws Exception { + + testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ; + } + + /* + @bug 8158084 8162435 8162438 these tests also verifies the fix for 8162435 and 8162438 + Verifies the Catalog support on the Schema Validator. + */ + @Test(dataProvider = "data_ValidatorC") + public void testValidatorA(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog, + Source source, LSResourceResolver resolver1, LSResourceResolver resolver2, + String catalog1, String catalog2) + throws Exception { + testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source, + resolver1, resolver2, catalog1, catalog2); + } + + /* + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLC") + public void testXSLImportC(boolean setUseCatalog, boolean useCatalog, String catalog, SAXSource xsl, StreamSource xml, + URIResolver resolver, String expected) throws Exception { + + testXSLImport(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + @bug 8158084 8162442 + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLC") + public void testXSLImportWTemplatesC(boolean setUseCatalog, boolean useCatalog, String catalog, SAXSource xsl, StreamSource xml, + URIResolver resolver, String expected) throws Exception { + testXSLImportWTemplates(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + DataProvider: for testing the SAX parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_SAXC") + Object[][] getDataSAXC() { + return new Object[][]{ + {false, true, null, xml_system, new MyHandler(elementInSystem), expectedWCatalog} + + }; + } + + /* + DataProvider: for testing XInclude + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_XIC") + Object[][] getDataXIC() { + return new Object[][]{ + {false, true, null, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog}, + }; + } + + /* + DataProvider: for testing DOM parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_DOMC") + Object[][] getDataDOMC() { + return new Object[][]{ + {false, true, null, xml_system, new MyHandler(elementInSystem), expectedWCatalog} + }; + } + + /* + DataProvider: for testing Schema validation + Data: set use_catalog, use_catalog, catalog file, xsd file, a LSResourceResolver + */ + @DataProvider(name = "data_SchemaC") + Object[][] getDataSchemaC() { + + return new Object[][]{ + // for resolving DTD in xsd + {false, true, null, xsd_xmlSchema, null}, + // for resolving xsd import + {false, true, null, xsd_xmlSchema_import, null}, + // for resolving xsd include + {false, true, null, xsd_include_company, null} + }; + } + + + /* + DataProvider: for testing Schema Validator + Data: source, resolver1, resolver2, catalog1, a catalog2 + */ + @DataProvider(name = "data_ValidatorC") + Object[][] getDataValidator() { + DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, false, true, null); + + SAXSource ss = new SAXSource(new InputSource(xml_val_test)); + ss.setSystemId(xml_val_test_id); + + StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id); + StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id); + + StreamSource source = new StreamSource(new File(xml_val_test)); + + String[] systemIds = {"system.dtd", "val_test.xsd"}; + XmlInput[] returnValues = {new XmlInput(null, dtd_system, null), new XmlInput(null, xsd_val_test, null)}; + LSResourceResolver resolver = new SourceResolver(null, systemIds, returnValues); + + StAXSource stax2 = getStaxSource(xml_val_test, xml_val_test_id); + StAXSource stax3 = getStaxSource(xml_val_test, xml_val_test_id); + + return new Object[][]{ + // use catalog + {false, false, true, ds, null, null, null, null}, + {false, false, true, ds, null, null, null, null}, + {false, false, true, ss, null, null, null, null}, + {false, false, true, ss, null, null, null, null}, + {false, false, true, stax, null, null, null, null}, + {false, false, true, stax1, null, null, null, null}, + {false, false, true, source, null, null, null, null}, + {false, false, true, source, null, null, null, null}, + // use resolver + {false, false, true, ds, resolver, null, xml_bogus_catalog, null}, + {false, false, true, ds, null, resolver, null, xml_bogus_catalog}, + {false, false, true, ss, resolver, null, xml_bogus_catalog, null}, + {false, false, true, ss, null, resolver, null, xml_bogus_catalog}, + {false, false, true, stax2, resolver, null, xml_bogus_catalog, null}, + {false, false, true, stax3, null, resolver, null, xml_bogus_catalog}, + {false, false, true, source, resolver, null, xml_bogus_catalog, null}, + {false, false, true, source, null, resolver, null, xml_bogus_catalog} + }; + } + + /* + DataProvider: for testing XSL import and include + Data: set use_catalog, use_catalog, catalog file, xsl file, xml file, a URIResolver, expected + */ + @DataProvider(name = "data_XSLC") + Object[][] getDataXSLC() { + SAXSource xslSourceDTD = new SAXSource(new InputSource(new StringReader(xsl_includeDTD))); + StreamSource xmlSourceDTD = new StreamSource(new StringReader(xml_xslDTD)); + + SAXSource xslDocSource = new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString())); + StreamSource xmlDocSource = new StreamSource(new File(xml_doc)); + return new Object[][]{ + // for resolving DTD, import and include in xsl + {false, true, null, xslSourceDTD, xmlSourceDTD, null, ""}, + // for resolving reference by the document function + {false, true, null, xslDocSource, xmlDocSource, null, "Resolved by a catalog"}, + }; + } + +} --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/CatalogSupport2.java 2016-07-24 18:45:35.392542109 -0700 @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package catalog; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.StringReader; +import java.net.SocketTimeoutException; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stax.StAXSource; +import javax.xml.transform.stream.StreamSource; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.ls.LSResourceResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +/* + * @bug 8158084 8162435 8162438 8162442 + * @summary extends CatalogSupport tests, verifies that the use of the Catalog may + * be disabled through the System property. + */ + +/** + * For all of the JAXP processors that support the Catalog, the use of the Catalog + * is turned on by default. It can then be turned off through the API and the + * System property. + * + * @author huizhe.wang@oracle.com + */ +public class CatalogSupport2 extends CatalogSupportBase { + static final String TTIMEOUTREAD = "sun.net.client.defaultReadTimeout"; + static final String TIMEOUTCONNECT = "sun.net.client.defaultConnectTimeout"; + static String timeoutRead = System.getProperty(TTIMEOUTREAD); + static String timeoutConnect = System.getProperty(TIMEOUTCONNECT); + + /* + * Initializing fields + */ + @BeforeClass + public void setUpClass() throws Exception { + setUp(); + System.setProperty(SP_USE_CATALOG, "false"); + timeoutRead = System.getProperty(TTIMEOUTREAD); + timeoutConnect = System.getProperty(TIMEOUTCONNECT); + System.setProperty(TTIMEOUTREAD, "1000"); + System.setProperty(TIMEOUTCONNECT, "1000"); + } + + @AfterClass + public void tearDownClass() throws Exception { + System.clearProperty(SP_USE_CATALOG); + System.setProperty(TIMEOUTCONNECT, "-1"); + System.setProperty(TTIMEOUTREAD, "-1"); + } + + /* + Verifies the Catalog support on SAXParser. + */ + @Test(dataProvider = "data_SAXC", expectedExceptions = FileNotFoundException.class) + public void testSAXC(boolean setUseCatalog, boolean useCatalog, String catalog, String + xml, MyHandler handler, String expected) throws Exception { + testSAX(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XMLReader. + */ + @Test(dataProvider = "data_SAXC", expectedExceptions = FileNotFoundException.class) + public void testXMLReaderC(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testXMLReader(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XInclude. + */ + @Test(dataProvider = "data_XIC", expectedExceptions = SAXParseException.class) + public void testXIncludeC(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on DOM parser. + */ + @Test(dataProvider = "data_DOMC", expectedExceptions = {FileNotFoundException.class, SocketTimeoutException.class}) + public void testDOMC(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on resolving DTD, xsd import and include in + Schema files. + */ + @Test(dataProvider = "data_SchemaC", expectedExceptions = SAXParseException.class) + public void testValidationC(boolean setUseCatalog, boolean useCatalog, String catalog, + String xsd, LSResourceResolver resolver) + throws Exception { + testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ; + } + + @Test(dataProvider = "data_ValidatorC", expectedExceptions = {SAXException.class, FileNotFoundException.class}) + public void testValidatorC(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog, + Source source, LSResourceResolver resolver1, LSResourceResolver resolver2, + String catalog1, String catalog2) + throws Exception { + testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source, + resolver1, resolver2, catalog1, catalog2); + } + + /* + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLC", expectedExceptions = TransformerException.class) + public void testXSLImportC(boolean setUseCatalog, boolean useCatalog, String catalog, + SAXSource xsl, StreamSource xml, URIResolver resolver, String expected) throws Exception { + + testXSLImport(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + @bug 8158084 8162442 + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLC", expectedExceptions = TransformerException.class) + public void testXSLImportWTemplatesC(boolean setUseCatalog, boolean useCatalog, String catalog, + SAXSource xsl, StreamSource xml, URIResolver resolver, String expected) throws Exception { + testXSLImportWTemplates(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + DataProvider: for testing the SAX parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_SAXC") + Object[][] getDataSAXC() { + return new Object[][]{ + {false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog} + + }; + } + + /* + DataProvider: for testing XInclude + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_XIC") + Object[][] getDataXIC() { + return new Object[][]{ + {false, true, xml_catalog, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog}, + }; + } + + /* + DataProvider: for testing DOM parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_DOMC") + Object[][] getDataDOMC() { + return new Object[][]{ + {false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog} + }; + } + + /* + DataProvider: for testing Schema validation + Data: set use_catalog, use_catalog, catalog file, xsd file, a LSResourceResolver + */ + @DataProvider(name = "data_SchemaC") + Object[][] getDataSchemaC() { + + return new Object[][]{ + // for resolving DTD in xsd + {false, true, xml_catalog, xsd_xmlSchema, null}, + // for resolving xsd import + {false, true, xml_catalog, xsd_xmlSchema_import, null}, + // for resolving xsd include + {false, true, xml_catalog, xsd_include_company, null} + }; + } + + + /* + DataProvider: for testing Schema Validator + Data: source, resolver1, resolver2, catalog1, a catalog2 + */ + @DataProvider(name = "data_ValidatorC") + Object[][] getDataValidator() { + DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, true, true, xml_catalog); + + SAXSource ss = new SAXSource(new InputSource(xml_val_test)); + ss.setSystemId(xml_val_test_id); + + StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id); + StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id); + + StreamSource source = new StreamSource(new File(xml_val_test)); + + return new Object[][]{ + // use catalog + {false, false, true, ds, null, null, xml_catalog, null}, + {false, false, true, ds, null, null, null, xml_catalog}, + {false, false, true, ss, null, null, xml_catalog, null}, + {false, false, true, ss, null, null, null, xml_catalog}, + {false, false, true, stax, null, null, xml_catalog, null}, + {false, false, true, stax1, null, null, null, xml_catalog}, + {false, false, true, source, null, null, xml_catalog, null}, + {false, false, true, source, null, null, null, xml_catalog}, + }; + } + + /* + DataProvider: for testing XSL import and include + Data: set use_catalog, use_catalog, catalog file, xsl file, xml file, a URIResolver, expected + */ + @DataProvider(name = "data_XSLC") + Object[][] getDataXSLC() { + SAXSource xslSourceDTD = new SAXSource(new InputSource(new StringReader(xsl_includeDTD))); + StreamSource xmlSourceDTD = new StreamSource(new StringReader(xml_xslDTD)); + + SAXSource xslDocSource = new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString())); + StreamSource xmlDocSource = new StreamSource(new File(xml_doc)); + return new Object[][]{ + // for resolving DTD, import and include in xsl + {false, true, xml_catalog, xslSourceDTD, xmlSourceDTD, null, ""}, + // for resolving reference by the document function + {false, true, xml_catalog, xslDocSource, xmlDocSource, null, "Resolved by a catalog"}, + }; + } +} --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/CatalogSupport3.java 2016-07-24 18:45:35.704557616 -0700 @@ -0,0 +1,273 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package catalog; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.StringReader; +import java.net.SocketTimeoutException; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stax.StAXSource; +import javax.xml.transform.stream.StreamSource; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.ls.LSResourceResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +/* + * @bug 8158084 8162435 8162438 8162442 + * @summary extends CatalogSupport tests, verifies that the use of the Catalog may + * be disabled through the API property. + */ + +/** + * For all of the JAXP processors that support the Catalog, the use of the Catalog + * is turned on by default. It can then be turned off through the API and the + * System property. + * + * @author huizhe.wang@oracle.com + */ +public class CatalogSupport3 extends CatalogSupportBase { + static final String TTIMEOUTREAD = "sun.net.client.defaultReadTimeout"; + static final String TIMEOUTCONNECT = "sun.net.client.defaultConnectTimeout"; + static String timeoutRead = System.getProperty(TTIMEOUTREAD); + static String timeoutConnect = System.getProperty(TIMEOUTCONNECT); + /* + * Initializing fields + */ + @BeforeClass + public void setUpClass() throws Exception { + setUp(); + timeoutRead = System.getProperty(TTIMEOUTREAD); + timeoutConnect = System.getProperty(TIMEOUTCONNECT); + System.setProperty(TTIMEOUTREAD, "1000"); + System.setProperty(TIMEOUTCONNECT, "1000"); + } + + @AfterClass + public void tearDownClass() throws Exception { + System.setProperty(TIMEOUTCONNECT, "-1"); + System.setProperty(TTIMEOUTREAD, "-1"); + } + + /* + Verifies the Catalog support on SAXParser. + */ + @Test(dataProvider = "data_SAXC", expectedExceptions = FileNotFoundException.class) + public void testSAXC(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testSAX(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XMLReader. + */ + @Test(dataProvider = "data_SAXC", expectedExceptions = FileNotFoundException.class) + public void testXMLReaderC(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testXMLReader(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XInclude. + */ + @Test(dataProvider = "data_XIC", expectedExceptions = SAXParseException.class) + public void testXIncludeC(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on DOM parser. + */ + @Test(dataProvider = "data_DOMC", expectedExceptions = {FileNotFoundException.class, SocketTimeoutException.class}) + public void testDOMC(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on resolving DTD, xsd import and include in + Schema files. + */ + @Test(dataProvider = "data_SchemaC", expectedExceptions = SAXParseException.class) + public void testValidationC(boolean setUseCatalog, boolean useCatalog, String catalog, + String xsd, LSResourceResolver resolver) + throws Exception { + testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ; + } + + /* + @bug 8158084 8162435 8162438 these tests also verifies the fix for 8162435 and 8162438 + Verifies the Catalog support on the Schema Validator. + */ + @Test(dataProvider = "data_ValidatorC", expectedExceptions = {SAXException.class, FileNotFoundException.class}) + public void testValidatorC(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog, + Source source, LSResourceResolver resolver1, LSResourceResolver resolver2, + String catalog1, String catalog2) + throws Exception { + testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source, + resolver1, resolver2, catalog1, catalog2); + } + + /* + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLC", expectedExceptions = TransformerException.class) + public void testXSLImportC(boolean setUseCatalog, boolean useCatalog, String catalog, SAXSource xsl, StreamSource xml, + URIResolver resolver, String expected) throws Exception { + + testXSLImport(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + @bug 8158084 8162442 + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLC", expectedExceptions = TransformerException.class) + public void testXSLImportWTemplatesC(boolean setUseCatalog, boolean useCatalog, String catalog, + SAXSource xsl, StreamSource xml, + URIResolver resolver, String expected) throws Exception { + testXSLImportWTemplates(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + DataProvider: for testing the SAX parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_SAXC") + Object[][] getDataSAXC() { + return new Object[][]{ + {true, false, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog} + + }; + } + + /* + DataProvider: for testing XInclude + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_XIC") + Object[][] getDataXIC() { + return new Object[][]{ + {true, false, xml_catalog, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog}, + }; + } + + /* + DataProvider: for testing DOM parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_DOMC") + Object[][] getDataDOMC() { + return new Object[][]{ + {true, false, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog} + }; + } + + /* + DataProvider: for testing Schema validation + Data: set use_catalog, use_catalog, catalog file, xsd file, a LSResourceResolver + */ + @DataProvider(name = "data_SchemaC") + Object[][] getDataSchemaC() { + + return new Object[][]{ + // for resolving DTD in xsd + {true, false, xml_catalog, xsd_xmlSchema, null}, + // for resolving xsd import + {true, false, xml_catalog, xsd_xmlSchema_import, null}, + // for resolving xsd include + {true, false, xml_catalog, xsd_include_company, null} + }; + } + + + /* + DataProvider: for testing Schema Validator + Data: source, resolver1, resolver2, catalog1, a catalog2 + */ + @DataProvider(name = "data_ValidatorC") + Object[][] getDataValidator() { + DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, false, true, xml_catalog); + + SAXSource ss = new SAXSource(new InputSource(xml_val_test)); + ss.setSystemId(xml_val_test_id); + + StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id); + StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id); + + StreamSource source = new StreamSource(new File(xml_val_test)); + + return new Object[][]{ + // use catalog disabled through factory + {true, false, false, ds, null, null, xml_catalog, null}, + {true, false, false, ds, null, null, null, xml_catalog}, + {true, false, false, ss, null, null, xml_catalog, null}, + {true, false, false, ss, null, null, null, xml_catalog}, + {true, false, false, stax, null, null, xml_catalog, null}, + {true, false, false, stax1, null, null, null, xml_catalog}, + {true, false, false, source, null, null, xml_catalog, null}, + {true, false, false, source, null, null, null, xml_catalog}, + // use catalog disabled through validatory + {false, true, false, ds, null, null, xml_catalog, null}, + {false, true, false, ds, null, null, null, xml_catalog}, + {false, true, false, ss, null, null, xml_catalog, null}, + {false, true, false, ss, null, null, null, xml_catalog}, + {false, true, false, stax, null, null, xml_catalog, null}, + {false, true, false, stax1, null, null, null, xml_catalog}, + {false, true, false, source, null, null, xml_catalog, null}, + {false, true, false, source, null, null, null, xml_catalog}, + }; + } + + /* + DataProvider: for testing XSL import and include + Data: set use_catalog, use_catalog, catalog file, xsl file, xml file, a URIResolver, expected + */ + @DataProvider(name = "data_XSLC") + Object[][] getDataXSLC() { + SAXSource xslSourceDTD = new SAXSource(new InputSource(new StringReader(xsl_includeDTD))); + StreamSource xmlSourceDTD = new StreamSource(new StringReader(xml_xslDTD)); + + SAXSource xslDocSource = new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString())); + StreamSource xmlDocSource = new StreamSource(new File(xml_doc)); + return new Object[][]{ + // for resolving DTD, import and include in xsl + {true, false, xml_catalog, xslSourceDTD, xmlSourceDTD, null, ""}, + // for resolving reference by the document function + {true, false, xml_catalog, xslDocSource, xmlDocSource, null, "Resolved by a catalog"}, + }; + } +} --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/CatalogSupport4.java 2016-07-24 18:45:35.948569742 -0700 @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package catalog; + +import java.io.File; +import java.io.StringReader; +import javax.xml.transform.Source; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stax.StAXSource; +import javax.xml.transform.stream.StreamSource; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.w3c.dom.ls.LSResourceResolver; +import org.xml.sax.InputSource; + +/** + * @bug 8158084 8162435 8162438 8162442 + * @summary verifies the overriding over of the USE_CATALOG feature. Extending + * CatalogSupport tests, the USE_CATALOG is turned off system-wide, however, + * a JAXP processor may decide to use Catalog by enabling it through the factory + * or a processor created by the factory. + */ + +/** + * + * Test notes: + * Same set of data as in CatalogSupport without the ones with resolvers. + * The set-use-catalog is set to true. + * + * @author huizhe.wang@oracle.com + */ +public class CatalogSupport4 extends CatalogSupportBase { + /* + * Initializing fields + */ + @BeforeClass + public void setUpClass() throws Exception { + setUp(); + //turn off USE_CATALOG system-wide + System.setProperty(SP_USE_CATALOG, "false"); + } + + @AfterClass + public void tearDownClass() throws Exception { + System.clearProperty(SP_USE_CATALOG); + } + + /* + Verifies the Catalog support on SAXParser. + */ + @Test(dataProvider = "data_SAXA") + public void testSAXA(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testSAX(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XMLReader. + */ + @Test(dataProvider = "data_SAXA") + public void testXMLReaderA(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testXMLReader(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on XInclude. + */ + @Test(dataProvider = "data_XIA") + public void testXIncludeA(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testXInclude(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on DOM parser. + */ + @Test(dataProvider = "data_DOMA") + public void testDOMA(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + testDOM(setUseCatalog, useCatalog, catalog, xml, handler, expected); + } + + /* + Verifies the Catalog support on resolving DTD, xsd import and include in + Schema files. + */ + @Test(dataProvider = "data_SchemaA") + public void testValidationA(boolean setUseCatalog, boolean useCatalog, + String catalog, String xsd, LSResourceResolver resolver) + throws Exception { + + testValidation(setUseCatalog, useCatalog, catalog, xsd, resolver) ; + } + + /* + @bug 8158084 8162435 8162438 these tests also verifies the fix for 8162435 and 8162438 + Verifies the Catalog support on the Schema Validator. + */ + @Test(dataProvider = "data_ValidatorA") + public void testValidatorA(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog, + Source source, LSResourceResolver resolver1, LSResourceResolver resolver2, + String catalog1, String catalog2) + throws Exception { + testValidator(setUseCatalog1, setUseCatalog2, useCatalog, source, + resolver1, resolver2, catalog1, catalog2); + } + + /* + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLA") + public void testXSLImportA(boolean setUseCatalog, boolean useCatalog, String catalog, + SAXSource xsl, StreamSource xml, URIResolver resolver, String expected) + throws Exception { + + testXSLImport(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + @bug 8158084 8162442 + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + @Test(dataProvider = "data_XSLA") + public void testXSLImportWTemplatesA(boolean setUseCatalog, boolean useCatalog, + String catalog, SAXSource xsl, StreamSource xml, URIResolver resolver, String expected) + throws Exception { + testXSLImportWTemplates(setUseCatalog, useCatalog, catalog, xsl, xml, resolver, expected); + } + + /* + DataProvider: for testing the SAX parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_SAXA") + Object[][] getDataSAX() { + return new Object[][]{ + {true, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}, + }; + } + + /* + DataProvider: for testing XInclude + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_XIA") + Object[][] getDataXI() { + return new Object[][]{ + {true, true, xml_catalog, xml_xInclude, new MyHandler(elementInXISimple), contentInUIutf8Catalog}, + }; + } + + /* + DataProvider: for testing DOM parser + Data: set use_catalog, use_catalog, catalog file, xml file, handler, expected result string + */ + @DataProvider(name = "data_DOMA") + Object[][] getDataDOM() { + return new Object[][]{ + {true, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog}, + }; + } + + MyEntityHandler getMyEntityHandler(String elementName, String[] systemIds, InputSource... returnValues) { + return new MyEntityHandler(systemIds, returnValues, elementName); + } + + /* + DataProvider: for testing Schema validation + Data: set use_catalog, use_catalog, catalog file, xsd file, a LSResourceResolver + */ + @DataProvider(name = "data_SchemaA") + Object[][] getDataSchema() { + return new Object[][]{ + // for resolving DTD in xsd + {true, true, xml_catalog, xsd_xmlSchema, null}, + // for resolving xsd import + {true, true, xml_catalog, xsd_xmlSchema_import, null}, + // for resolving xsd include + {true, true, xml_catalog, xsd_include_company, null}, + }; + } + + /* + DataProvider: for testing Schema Validator + Data: source, resolver1, resolver2, catalog1, a catalog2 + */ + @DataProvider(name = "data_ValidatorA") + Object[][] getDataValidator() { + DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, true, true, xml_catalog); + + SAXSource ss = new SAXSource(new InputSource(xml_val_test)); + ss.setSystemId(xml_val_test_id); + + StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id); + StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id); + + StreamSource source = new StreamSource(new File(xml_val_test)); + + return new Object[][]{ + // use catalog + {true, false, true, ds, null, null, xml_catalog, null}, + {false, true, true, ds, null, null, null, xml_catalog}, + {true, false, true, ss, null, null, xml_catalog, null}, + {false, true, true, ss, null, null, null, xml_catalog}, + {true, false, true, stax, null, null, xml_catalog, null}, + {false, true, true, stax1, null, null, null, xml_catalog}, + {true, false, true, source, null, null, xml_catalog, null}, + {false, true, true, source, null, null, null, xml_catalog}, + }; + } + + /* + DataProvider: for testing XSL import and include + Data: set use_catalog, use_catalog, catalog file, xsl file, xml file, a URIResolver, expected result + */ + @DataProvider(name = "data_XSLA") + Object[][] getDataXSL() { + // XSLInclude.xsl has one import XSLImport_html.xsl and two includes, + // XSLInclude_header.xsl and XSLInclude_footer.xsl; + SAXSource xslSourceDTD = new SAXSource(new InputSource(new StringReader(xsl_includeDTD))); + StreamSource xmlSourceDTD = new StreamSource(new StringReader(xml_xslDTD)); + + SAXSource xslDocSource = new SAXSource(new InputSource(new File(xsl_doc).toURI().toASCIIString())); + StreamSource xmlDocSource = new StreamSource(new File(xml_doc)); + return new Object[][]{ + // for resolving DTD, import and include in xsl + {true, true, xml_catalog, xslSourceDTD, xmlSourceDTD, null, ""}, + // for resolving reference by the document function + {true, true, xml_catalog, xslDocSource, xmlDocSource, null, "Resolved by a catalog"}, + }; + } +} --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/CatalogSupportBase.java 2016-07-24 18:45:36.196582068 -0700 @@ -0,0 +1,934 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package catalog; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; +import javax.xml.XMLConstants; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLResolver; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.sax.SAXSource; +import javax.xml.transform.stax.StAXSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; +import org.testng.Assert; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.ls.LSInput; +import org.w3c.dom.ls.LSResourceResolver; +import org.xml.sax.Attributes; +import org.xml.sax.ErrorHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.ext.DefaultHandler2; + +/** + * Base class: + * Initialized xml/xsd/xsl used for the test; + * Handler classes + * + * @author huizhe.wang@oracle.com + */ +public class CatalogSupportBase { + // the System Property for the USE_CATALOG feature + final static String SP_USE_CATALOG = "javax.xml.useCatalog"; + + boolean debug = false; + + String filepath; + String slash = ""; + + protected void setUp() { + String file1 = getClass().getResource("CatalogSupport.xml").getFile(); + if (System.getProperty("os.name").contains("Windows")) { + filepath = file1.substring(1, file1.lastIndexOf("/") + 1); + slash = "/"; + } else { + filepath = file1.substring(0, file1.lastIndexOf("/") + 1); + } + + initFiles(); + } + + String xml_catalog, xml_bogus_catalog; + + // For tests using system.xml + String xml_system, dtd_system, dtd_systemResolved; + final String elementInSystem = "catalogtest"; + final String expectedWCatalog = "Test system entry"; + final String expectedWResolver = "Test resolved by an EntityHandler, rather than a Catalog entry"; + + // For tests using XInclude.xml + String xml_xInclude, xml_xIncludeSimple; + final String elementInXISimple = "blue"; + final String contentInXIutf8 = "trjsagdkasgdhasdgashgdhsadgashdg"; + final String contentInUIutf8Catalog = "usingCatalog"; + + // For the xsd import and include + String xsd_xmlSchema, dtd_xmlSchema, dtd_datatypes; + String xsd_xmlSchema_import, xsd_xml; + String xml_val_test, xml_val_test_id, xsd_val_test; + String xsd_include_company, xsd_include_person, xsd_include_product; + String xsl_include, xsl_includeDTD, xsl_import_html, xsl_include_header, xsl_include_footer; + + // For the xsl import and include + String xml_xsl, xml_xslDTD; + + // For document function + String xml_doc, xsl_doc, xml_doc2; + + void initFiles() { + xml_system = filepath + "system.xml"; + dtd_system = filepath + "system.dtd"; + dtd_systemResolved = ""; + + xml_catalog = filepath + "CatalogSupport.xml"; + xml_bogus_catalog = filepath + "CatalogSupport_bogus.xml"; + + xml_xInclude = "\n" + + "\n"; + xml_xIncludeSimple = filepath + "XI_simple.xml"; + + xsd_xmlSchema = "" + + "" + + "" + + " " + + " " + + " Part 1 version: Id: structures.xsd,v 1.2 2004/01/15 11:34:25 ht Exp " + + " Part 2 version: Id: datatypes.xsd,v 1.3 2004/01/23 18:11:13 ht Exp " + + " " + + " " + + ""; + dtd_xmlSchema = filepath + "XMLSchema.dtd"; + dtd_datatypes = filepath + "datatypes.dtd"; + + xsd_xmlSchema_import = "" + + "" + + " " + + " " + + " Part 1 version: Id: structures.xsd,v 1.2 2004/01/15 11:34:25 ht Exp " + + " Part 2 version: Id: datatypes.xsd,v 1.3 2004/01/23 18:11:13 ht Exp " + + " " + + " " + + "" + + " " + + " " + + " " + + " Get access to the xml: attribute groups for xml:lang" + + " as declared on 'schema' and 'documentation' below" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + + xsd_xml = filepath + "xml.xsd"; + + xsd_include_company = "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; + xsd_include_person = filepath + "XSDInclude_person.xsd"; + xsd_include_product = filepath + "XSDInclude_product.xsd"; + + xsl_include = "" + + "" + + " " + + " " + + " " + + "" + + " " + + "

" + + "
" + + " " + + " " + + "" + + "
"; + xsl_includeDTD = "" + + "" + + "" + + " " + + " " + + " " + + "" + + " " + + "

" + + "
" + + " " + + " " + + "" + + "
"; + + xsl_import_html = filepath + "XSLImport_html.xsl"; + xsl_include_header = filepath + "XSLInclude_header.xsl"; + xsl_include_footer = filepath + "XSLInclude_footer.xsl"; + + xml_val_test = filepath + "/val_test.xml"; + xml_val_test_id = "file://" + slash + xml_val_test; + xsd_val_test = filepath + "/val_test.xsd"; + + xml_xsl = "\n" + + "\n" + + "
This is the header
\n" + + " Some content\n" + + "
footer
\n" + + "
"; + + xml_xslDTD = "\n" + + "" + + "\n" + + "
This is the header
\n" + + " Some content\n" + + "
footer
\n" + + "
"; + + xml_doc = filepath + "/DocFunc.xml"; + xsl_doc = filepath + "/DocFunc.xsl"; + xml_doc2 = filepath + "/DocFunc2.xml"; + } + + + /* + Verifies the Catalog support on SAXParser. + */ + public void testSAX(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + SAXParser parser = getSAXParser(setUseCatalog, useCatalog, catalog); + + parser.parse(xml, handler); + assertEquals(expected, handler.getResult().trim(), ""); + } + + /* + Verifies the Catalog support on XMLReader. + */ + public void testXMLReader(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + XMLReader reader = getXMLReader(setUseCatalog, useCatalog, catalog); + + reader.setContentHandler(handler); + reader.parse(xml); + assertEquals(expected, handler.getResult().trim(), ""); + } + + /* + Verifies the Catalog support on XInclude. + */ + public void testXInclude(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + SAXParser parser = getSAXParser(setUseCatalog, useCatalog, catalog); + + parser.parse(new InputSource(new StringReader(xml)), handler); + debugPrint("handler.result:" + handler.getResult()); + assertEquals(expected, handler.getResult(), "Catalog support for XInclude"); + } + + /* + Verifies the Catalog support on DOM parser. + */ + public void testDOM(boolean setUseCatalog, boolean useCatalog, String catalog, + String xml, MyHandler handler, String expected) throws Exception { + DocumentBuilder docBuilder = getDomBuilder(setUseCatalog, useCatalog, catalog); + docBuilder.setEntityResolver(handler); + Document doc = docBuilder.parse(xml); + + Node node = doc.getElementsByTagName(elementInSystem).item(0); + String result = node.getFirstChild().getTextContent(); + + assertEquals(expected, result.trim(), "Catalog support for DOM"); + } + + /* + Verifies the Catalog support on resolving DTD, xsd import and include in + Schema files. + */ + public void testValidation(boolean setUseCatalog, boolean useCatalog, String catalog, + String xsd, LSResourceResolver resolver) + throws Exception { + + SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + + // use resolver or catalog if resolver = null + if (resolver != null) { + factory.setResourceResolver(resolver); + } + if (setUseCatalog) { + factory.setFeature(XMLConstants.USE_CATALOG, useCatalog); + } + factory.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog); + + Schema schema = factory.newSchema(new StreamSource(new StringReader(xsd))); + success("XMLSchema.dtd and datatypes.dtd are resolved."); + } + + /** + * Verifies Catalog Support for the Validator. + * @param setUseCatalog1 a flag to indicate whether USE_CATALOG shall be set + * on the factory. + * @param setUseCatalog2 a flag to indicate whether USE_CATALOG shall be set + * on the Validator. + * @param source the XML source + * @param resolver1 a resolver to be set on the factory if specified + * @param resolver2 a resolver to be set on the Validator if specified + * @param catalog1 a catalog to be set on the factory if specified + * @param catalog2 a catalog to be set on the Validator if specified + */ + public void testValidator(boolean setUseCatalog1, boolean setUseCatalog2, boolean useCatalog, + Source source, LSResourceResolver resolver1, LSResourceResolver resolver2, + String catalog1, String catalog2) + throws Exception { + + SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + if (setUseCatalog1) { + schemaFactory.setFeature(XMLConstants.USE_CATALOG, useCatalog); + } + if (catalog1 != null) { + schemaFactory.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog1); + } + if (resolver1 != null) { + schemaFactory.setResourceResolver(resolver1); + } + + Schema schema = schemaFactory.newSchema(); + Validator validator = schema.newValidator(); + if (setUseCatalog2) { + validator.setFeature(XMLConstants.USE_CATALOG, useCatalog); + } + if (catalog2 != null) { + validator.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog2); + } + if (resolver2 != null) { + validator.setResourceResolver(resolver2); + } + validator.validate(source); + } + + /* + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + public void testXSLImport(boolean setUseCatalog, boolean useCatalog, String catalog, + SAXSource xsl, StreamSource xml, + URIResolver resolver, String expected) throws Exception { + + TransformerFactory factory = getTransformerFactory(setUseCatalog, useCatalog, catalog, resolver); + Transformer transformer = factory.newTransformer(xsl); + + StringWriter out = new StringWriter(); + transformer.transform(xml, new StreamResult(out)); + debugPrint("out:\n" + out.toString()); + Assert.assertTrue(out.toString().contains(expected), "testXSLImport"); + } + + /* + Verifies the Catalog support on resolving DTD, xsl import and include in + XSL files. + */ + public void testXSLImportWTemplates(boolean setUseCatalog, boolean useCatalog, + String catalog, SAXSource xsl, StreamSource xml, + URIResolver resolver, String expected) throws Exception { + + TransformerFactory factory = getTransformerFactory(setUseCatalog, useCatalog, catalog, resolver); + Transformer transformer = factory.newTemplates(xsl).newTransformer(); + StringWriter out = new StringWriter(); + transformer.transform(xml, new StreamResult(out)); + Assert.assertTrue(out.toString().contains(expected), "testXSLImportWTemplates"); + } + + /** + * Returns an instance of SAXParser with a catalog if one is provided. + * + * @param setUseCatalog a flag indicates whether USE_CATALOG shall be set + * through the factory + * @param useCatalog the value of USE_CATALOG + * @param catalog a catalog + * @return an instance of SAXParser + * @throws ParserConfigurationException + * @throws SAXException + */ + SAXParser getSAXParser(boolean setUseCatalog, boolean useCatalog, String catalog) + throws ParserConfigurationException, SAXException { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setXIncludeAware(true); + if (setUseCatalog) { + spf.setFeature(XMLConstants.USE_CATALOG, useCatalog); + } + + SAXParser parser = spf.newSAXParser(); + parser.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog); + return parser; + } + + /** + * Returns an instance of XMLReader with a catalog if one is provided. + * + * @param setUseCatalog a flag indicates whether USE_CATALOG shall be set + * through the factory + * @param useCatalog the value of USE_CATALOG + * @param catalog a catalog + * @return an instance of XMLReader + * @throws ParserConfigurationException + * @throws SAXException + */ + XMLReader getXMLReader(boolean setUseCatalog, boolean useCatalog, String catalog) + throws ParserConfigurationException, SAXException { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + XMLReader reader = spf.newSAXParser().getXMLReader(); + if (setUseCatalog) { + reader.setFeature(XMLConstants.USE_CATALOG, useCatalog); + } + reader.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog); + return reader; + } + + /** + * Returns an instance of DocumentBuilder that may have set a Catalog. + * + * @param setUseCatalog a flag indicates whether USE_CATALOG shall be set + * through the factory + * @param useCatalog the value of USE_CATALOG + * @param catalog a catalog + * @return an instance of DocumentBuilder + * @throws ParserConfigurationException + */ + DocumentBuilder getDomBuilder(boolean setUseCatalog, boolean useCatalog, String catalog) + throws ParserConfigurationException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + if (setUseCatalog) { + dbf.setFeature(XMLConstants.USE_CATALOG, useCatalog); + } + dbf.setAttribute(CatalogFeatures.Feature.FILES.getPropertyName(), catalog); + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + return docBuilder; + } + + /** + * Creates a DOMSource. + * + * @param uri the URI to the XML source file + * @param systemId the systemId of the source + * @param setUseCatalog a flag indicates whether USE_CATALOG shall be set + * through the factory + * @param useCatalog the value of USE_CATALOG + * @param catalog a catalog + * @return a DOMSource + * @throws Exception + */ + DOMSource getDOMSource(String uri, String systemId, boolean setUseCatalog, + boolean useCatalog, String catalog) { + DOMSource ds = null; + try { + DocumentBuilder builder = getDomBuilder(setUseCatalog, useCatalog, catalog); + Document doc = builder.parse(new File(uri)); + ds = new DOMSource(doc, systemId); + } catch (Exception e) {} + + return ds; + } + + /** + * Creates a StAXSource. + * + * @param xmlFile the XML source file + * @param xmlFileId the systemId of the source + * @return a StAXSource + * @throws XMLStreamException + * @throws FileNotFoundException + */ + StAXSource getStaxSource(String xmlFile, String xmlFileId) { + StAXSource ss = null; + try { + ss = new StAXSource( + XMLInputFactory.newFactory().createXMLEventReader( + xmlFileId, new FileInputStream(xmlFile))); + } catch (Exception e) {} + + return ss; + } + + /** + * Creates an XMLStreamReader. + * @param catalog the path to a catalog + * @param xml the xml to be parsed + * @param resolver a resolver to be set on the reader + * @return an instance of the XMLStreamReader + * @throws FileNotFoundException + * @throws XMLStreamException + */ + XMLStreamReader getStreamReader(boolean setUseCatalog, boolean useCatalog, + String catalog, String xml, XMLResolver resolver) + throws FileNotFoundException, XMLStreamException { + XMLInputFactory factory = XMLInputFactory.newInstance(); + factory.setProperty(CatalogFeatures.Feature.FILES.getPropertyName(), catalog); + factory.setProperty(XMLInputFactory.IS_COALESCING, true); + factory.setProperty(XMLInputFactory.RESOLVER, resolver); + if (setUseCatalog) { + factory.setProperty(XMLConstants.USE_CATALOG, useCatalog); + } + + InputStream entityxml = new FileInputStream(xml); + XMLStreamReader streamReader = factory.createXMLStreamReader(xml, entityxml); + return streamReader; + } + + /** + * Returns the text of the first element found by the reader. + * @param streamReader the XMLStreamReader + * @return the text of the first element + * @throws XMLStreamException + */ + String getText(XMLStreamReader streamReader) throws XMLStreamException { + while(streamReader.hasNext()){ + int eventType = streamReader.next() ; + if(eventType == XMLStreamConstants.START_ELEMENT){ + eventType = streamReader.next() ; + if(eventType == XMLStreamConstants.CHARACTERS){ + return streamReader.getText() ; + } + } + } + return null; + } + + /** + * Returns an instance of TransformerFactory with either a custom URIResolver + * or Catalog. + * + * @param setUseCatalog a flag indicates whether USE_CATALOG shall be set + * through the factory + * @param useCatalog the value of USE_CATALOG + * @param catalog a catalog + * @param resolver a custom resolver + * @return an instance of TransformerFactory + * @throws Exception + */ + TransformerFactory getTransformerFactory(boolean setUseCatalog, boolean useCatalog, + String catalog, URIResolver resolver) + throws Exception { + + TransformerFactory factory = TransformerFactory.newInstance(); + if (setUseCatalog) { + factory.setFeature(XMLConstants.USE_CATALOG, useCatalog); + } + if (catalog != null) { + factory.setAttribute(CatalogFeatures.Feature.FILES.getPropertyName(), catalog); + } + + // use resolver or catalog if resolver = null + if (resolver != null) { + factory.setURIResolver(resolver); + } + + return factory; + } + + void assertNotNull(Object obj, String msg) { + if (obj == null) { + debugPrint("Test failed: " + msg); + } else { + debugPrint("Test passed: " + obj + " is not null"); + } + } + + void assertEquals(String expected, String actual, String msg) { + if (!expected.equals(actual)) { + debugPrint("Test failed: " + msg); + } else { + debugPrint("Test passed: "); + } + debugPrint("Expected: " + expected); + debugPrint("Actual: " + actual); + } + + void fail(String msg) { + System.out.println("Test failed:"); + System.out.println(msg); + } + + void success(String msg) { + System.out.println("Test succeded:"); + System.out.println(msg); + } + + void debugPrint(String msg) { + if (debug) { + System.out.println(msg); + } + } + + /** + * Extends MyStaxResolver to override resolveEntity + */ + class MyStaxEntityResolver implements XMLResolver { + + public MyStaxEntityResolver() { + + } + + public Object resolveEntity(String publicId, String systemId, String baseURI, + String namespace) + throws javax.xml.stream.XMLStreamException { + try { + return new ByteArrayInputStream( + "".getBytes("UTF-8")); + } catch (UnsupportedEncodingException ex) { + return null; + } + } + + } + + /** + * A custom XMLResolver + */ + class MyStaxResolver implements XMLResolver { + + public MyStaxResolver() { + } + + public Object resolveEntity(String publicId, String systemId, String baseURI, + String namespace) throws javax.xml.stream.XMLStreamException { + return null; + } + + } + + /** + * Extends MyHandler and overrides resolveEntity + */ + class MyEntityHandler extends MyHandler { + String[] systemIds; + InputSource[] returnValues; + public MyEntityHandler(String[] systemIds, InputSource[] returnValues, String elementName) { + super(elementName); + this.systemIds = systemIds; + this.returnValues = returnValues; + } + + @Override + public InputSource resolveEntity(String name, String publicId, + String baseURI, String systemId) { + for (int i = 0; i < systemIds.length; i++) { + if (systemId.endsWith(systemIds[i])) { + return returnValues[i]; + } + } + + return null; + } + } + + /** + * SAX handler + */ + public class MyHandler extends DefaultHandler2 implements ErrorHandler { + + String elementName, currentElementName, result; + StringBuilder textContent = new StringBuilder(); + + /** + * + * @param elementName the name of the element from which the content + * is to be captured + */ + MyHandler(String elementName) { + textContent.setLength(0); + this.elementName = elementName; + } + + String getResult() { + return result.trim(); + } + + public void startDocument() throws SAXException { + } + + public void endDocument() throws SAXException { + } + + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + currentElementName = localName; + textContent.delete(0, textContent.length()); + try { + debugPrint("Element: " + uri + ":" + localName + " " + qName); + } catch (Exception e) { + throw new SAXException(e); + } + + } + + public void endElement(String uri, String localName, String qName) throws SAXException { + debugPrint("Text: " + textContent.toString() + ""); + debugPrint("End Element: " + uri + ":" + localName + " " + qName); + if (currentElementName.equals(elementName)) { + result = textContent.toString(); + } + } + + public void characters(char ch[], int start, int length) throws SAXException { + if (currentElementName.equals(elementName)) { + textContent.append(ch, start, length); + } + } + + public void internalEntityDecl(String name, String value) throws SAXException { + super.internalEntityDecl(name, value); + debugPrint("internalEntityDecl() is invoked for entity : " + name); + } + + public void externalEntityDecl(String name, String publicId, String systemId) + throws SAXException { + super.externalEntityDecl(name, publicId, systemId); + debugPrint("externalEntityDecl() is invoked for entity : " + name); + } + + public void startEntity(String name) throws SAXException { + super.startEntity(name); +// debugPrint("startEntity() is invoked for entity : " + name) ; + } + + public void endEntity(String name) throws SAXException { + super.endEntity(name); +// debugPrint("endEntity() is invoked for entity : " + name) ; + } + + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException { + debugPrint("resolveEntity(publicId, systemId) is invoked"); + return super.resolveEntity(publicId, systemId); + } + + /** + * public InputSource resolveEntity(String name, String publicId, String + * baseURI, String systemId) throws SAXException, IOException { + * System.out.println("resolveEntity(name, publicId, baseURI, systemId) + * is invoked"); return super.resolveEntity(name, publicId, baseURI, + * systemId); } + */ + public InputSource getExternalSubset(String name, String baseURI) + throws SAXException, IOException { + debugPrint("getExternalSubset() is invoked"); + return super.getExternalSubset(name, baseURI); + } + } + + /** + * The purpose of this class, vs an anonymous class, is to show clearly what + * we're testing by passing the parameters to the constructor. + */ + class SourceResolver implements LSResourceResolver { + + String publicId; + String[] systemIds; + XmlInput[] returnValues; + + public SourceResolver(String publicId, String[] systemIds, XmlInput[] returnValues) { + this.publicId = publicId; + this.systemIds = systemIds; + this.returnValues = returnValues; + } + + @Override + public LSInput resolveResource(String type, String namespaceURI, String publicId, + String systemId, String baseURI) { + for (int i = 0; i < systemIds.length; i++) { + if (systemId.endsWith(systemIds[i])) { + return returnValues[i]; + } + } + + return null; + } + } + + class XmlInput implements LSInput { + + private InputStream inputStream; + private String systemId; + private String baseUri; + + public XmlInput(InputStream inputStream, String systemId, String baseUri) { + this.inputStream = inputStream; + this.systemId = systemId; + this.baseUri = baseUri; + } + + @Override + public Reader getCharacterStream() { + return null; + } + + @Override + public void setCharacterStream(Reader characterStream) { + } + + @Override + public InputStream getByteStream() { + return inputStream; + } + + @Override + public void setByteStream(InputStream byteStream) { + this.inputStream = byteStream; + } + + @Override + public String getStringData() { + return null; + } + + @Override + public void setStringData(String stringData) { + } + + @Override + public String getSystemId() { + return systemId; + } + + @Override + public void setSystemId(String systemId) { + this.systemId = systemId; + } + + @Override + public String getPublicId() { + return null; + } + + @Override + public void setPublicId(String publicId) { + } + + @Override + public String getBaseURI() { + return baseUri; + } + + @Override + public void setBaseURI(String baseURI) { + this.baseUri = baseURI; + } + + @Override + public String getEncoding() { + return null; + } + + @Override + public void setEncoding(String encoding) { + } + + @Override + public boolean getCertifiedText() { + return false; + } + + @Override + public void setCertifiedText(boolean certifiedText) { + } + } + + class XslResolver implements URIResolver { + + String[] hrefs; + Source[] returnValues; + + public XslResolver(String[] href, Source[] returnValues) { + this.hrefs = href; + this.returnValues = returnValues; + } + + @Override + public Source resolve(String href, String base) throws TransformerException { + for (int i = 0; i < hrefs.length; i++) { + if (href.endsWith(hrefs[i])) { + return returnValues[i]; + } + } + return null; + } + } +} --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/CatalogSupport_bogus.xml 2016-07-24 18:45:36.444594393 -0700 @@ -0,0 +1,4 @@ + + + + \ No newline at end of file --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/DocFunc.xml 2016-07-24 18:45:36.688606520 -0700 @@ -0,0 +1,4 @@ + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/DocFunc.xsl 2016-07-24 18:45:36.936618846 -0700 @@ -0,0 +1,12 @@ + + + + + + + + + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/DocFunc2.xml 2016-07-24 18:45:37.180630973 -0700 @@ -0,0 +1,5 @@ + + + + Resolved by a resolver + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/DocFuncCatalog.xml 2016-07-24 18:45:37.428643298 -0700 @@ -0,0 +1,5 @@ + + + + Resolved by a catalog + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XI_red.dtd 2016-07-24 18:45:37.672655425 -0700 @@ -0,0 +1,4 @@ + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XI_simple.xml 2016-07-24 18:45:38.056674510 -0700 @@ -0,0 +1,18 @@ + + + + + + + + text + + + + + + + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XI_simple4Catalog.xml 2016-07-24 18:45:38.304686835 -0700 @@ -0,0 +1,18 @@ + + + + + + + + text + + + + + + + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XI_test2.xml 2016-07-24 18:45:38.548698962 -0700 @@ -0,0 +1,10 @@ + + + + + + + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XI_utf8.xml 2016-07-24 18:45:38.796711288 -0700 @@ -0,0 +1 @@ +trjsagdkasgdhasdgashgdhsadgashdg --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XI_utf8Catalog.xml 2016-07-24 18:45:39.040723414 -0700 @@ -0,0 +1 @@ +usingCatalog --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XMLSchema.dtd 2016-07-24 18:45:39.288735740 -0700 @@ -0,0 +1,402 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +%xs-datatypes; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XMLSchema.xsd 2016-07-24 18:45:39.536748066 -0700 @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ]> + + + + Part 1 version: Id: structures.xsd,v 1.2 2004/01/15 11:34:25 ht Exp + Part 2 version: Id: datatypes.xsd,v 1.3 2004/01/23 18:11:13 ht Exp + + + + + + The schema corresponding to this document is normative, + with respect to the syntactic constraints it expresses in the + XML Schema language. The documentation (within <documentation> elements) + below, is not normative, but rather highlights important aspects of + the W3C Recommendation of which this is a part + + + + + The simpleType element and all of its members are defined + towards the end of this schema document + + + + \ No newline at end of file --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XSDInclude_company.xsd 2016-07-24 18:45:39.784760391 -0700 @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XSDInclude_person.xsd 2016-07-24 18:45:40.120777090 -0700 @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XSDInclude_product.xsd 2016-07-24 18:45:40.364789217 -0700 @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XSLDTD.dtd 2016-07-24 18:45:40.608801344 -0700 @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XSLDTD.xml 2016-07-24 18:45:40.856813669 -0700 @@ -0,0 +1,7 @@ + + + +
This is the header
+ Some content +
footer
+
--- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XSLImport_html.xsl 2016-07-24 18:45:41.100825796 -0700 @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XSLInclude_footer.xsl 2016-07-24 18:45:41.356838520 -0700 @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/XSLInclude_header.xsl 2016-07-24 18:45:41.600850646 -0700 @@ -0,0 +1,8 @@ + + + + +

+
+ +
\ No newline at end of file --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/datatypes.dtd 2016-07-24 18:45:41.848862972 -0700 @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/include.dtd 2016-07-24 18:45:42.160878478 -0700 @@ -0,0 +1,3 @@ + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/val_test.xml 2016-07-24 18:45:42.408890804 -0700 @@ -0,0 +1,9 @@ + + + + has a &system; entry + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/val_test.xsd 2016-07-24 18:45:42.652902931 -0700 @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + --- /dev/null 2016-07-22 23:16:18.638958907 -0700 +++ new/test/javax/xml/jaxp/unittest/catalog/xml.xsd 2016-07-24 18:45:42.896915058 -0700 @@ -0,0 +1,287 @@ + + + + + + +
+

About the XML namespace

+ +
+

+ This schema document describes the XML namespace, in a form + suitable for import by other schema documents. +

+

+ See + http://www.w3.org/XML/1998/namespace.html and + + http://www.w3.org/TR/REC-xml for information + about this namespace. +

+

+ Note that local names in this namespace are intended to be + defined only by the World Wide Web Consortium or its subgroups. + The names currently defined in this namespace are listed below. + They should not be used with conflicting semantics by any Working + Group, specification, or document instance. +

+

+ See further below in this document for more information about how to refer to this schema document from your own + XSD schema documents and about the + namespace-versioning policy governing this schema document. +

+
+
+
+
+ + + + +
+ +

lang (as an attribute name)

+

+ denotes an attribute whose value + is a language code for the natural language of the content of + any element; its value is inherited. This name is reserved + by virtue of its definition in the XML specification.

+ +
+
+

Notes

+

+ Attempting to install the relevant ISO 2- and 3-letter + codes as the enumerated possible values is probably never + going to be a realistic possibility. +

+

+ See BCP 47 at + http://www.rfc-editor.org/rfc/bcp/bcp47.txt + and the IANA language subtag registry at + + http://www.iana.org/assignments/language-subtag-registry + for further information. +

+

+ The union allows for the 'un-declaration' of xml:lang with + the empty string. +

+
+
+
+ + + + + + + + + +
+ + + + +
+ +

space (as an attribute name)

+

+ denotes an attribute whose + value is a keyword indicating what whitespace processing + discipline is intended for the content of the element; its + value is inherited. This name is reserved by virtue of its + definition in the XML specification.

+ +
+
+
+ + + + + + +
+ + + +
+ +

base (as an attribute name)

+

+ denotes an attribute whose value + provides a URI to be used as the base for interpreting any + relative URIs in the scope of the element on which it + appears; its value is inherited. This name is reserved + by virtue of its definition in the XML Base specification.

+ +

+ See http://www.w3.org/TR/xmlbase/ + for information about this attribute. +

+
+
+
+
+ + + + +
+ +

id (as an attribute name)

+

+ denotes an attribute whose value + should be interpreted as if declared to be of type ID. + This name is reserved by virtue of its definition in the + xml:id specification.

+ +

+ See http://www.w3.org/TR/xml-id/ + for information about this attribute. +

+
+
+
+
+ + + + + + + + + + +
+ +

Father (in any context at all)

+ +
+

+ denotes Jon Bosak, the chair of + the original XML Working Group. This name is reserved by + the following decision of the W3C XML Plenary and + XML Coordination groups: +

+
+

+ In appreciation for his vision, leadership and + dedication the W3C XML Plenary on this 10th day of + February, 2000, reserves for Jon Bosak in perpetuity + the XML name "xml:Father". +

+
+
+
+
+
+ + + +
+

About this schema document

+ +
+

+ This schema defines attributes and an attribute group suitable + for use by schemas wishing to allow xml:base, + xml:lang, xml:space or + xml:id attributes on elements they define. +

+

+ To enable this, such a schema must import this schema for + the XML namespace, e.g. as follows: +

+
+          <schema . . .>
+           . . .
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+     
+

+ or +

+
+           <import namespace="http://www.w3.org/XML/1998/namespace"
+                      schemaLocation="http://www.w3.org/2009/01/xml.xsd"/>
+     
+

+ Subsequently, qualified reference to any of the attributes or the + group defined below will have the desired effect, e.g. +

+
+          <type . . .>
+           . . .
+           <attributeGroup ref="xml:specialAttrs"/>
+     
+

+ will define a type which will schema-validate an instance element + with any of those attributes. +

+
+
+
+
+ + + +
+

Versioning policy for this schema document

+
+

+ In keeping with the XML Schema WG's standard versioning + policy, this schema document will persist at + + http://www.w3.org/2009/01/xml.xsd. +

+

+ At the date of issue it can also be found at + + http://www.w3.org/2001/xml.xsd. +

+

+ The schema document at that URI may however change in the future, + in order to remain compatible with the latest version of XML + Schema itself, or with the XML namespace itself. In other words, + if the XML Schema or XML namespaces change, the version of this + document at + http://www.w3.org/2001/xml.xsd + + will change accordingly; the version at + + http://www.w3.org/2009/01/xml.xsd + + will not change. +

+

+ Previous dated (and unchanging) versions of this schema + document are at: +

+ +
+
+
+
+ +
+ --- old/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/utils/FeatureManager.java 2016-07-24 18:45:43.220931160 -0700 +++ /dev/null 2016-07-22 23:16:18.638958907 -0700 @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.org.apache.xalan.internal.utils; - - -import com.sun.org.apache.xalan.internal.XalanConstants; - -/** - * This class manages security related properties - * - */ -public final class FeatureManager extends FeaturePropertyBase { - - /** - * States of the settings of a property, in the order: default value, value - * set by FEATURE_SECURE_PROCESSING, jaxp.properties file, jaxp system - * properties, and jaxp api properties - */ - public static enum State { - //this order reflects the overriding order - DEFAULT, FSP, JAXPDOTPROPERTIES, SYSTEMPROPERTY, APIPROPERTY - } - - /** - * Xalan Features - */ - public static enum Feature { - ORACLE_ENABLE_EXTENSION_FUNCTION(XalanConstants.ORACLE_ENABLE_EXTENSION_FUNCTION, - "true"); - - final String name; - final String defaultValue; - - Feature(String name, String value) { - this.name = name; - this.defaultValue = value; - } - - public boolean equalsName(String propertyName) { - return (propertyName == null) ? false : name.equals(propertyName); - } - - String defaultValue() { - return defaultValue; - } - } - - /** - * Default constructor. Establishes default values - */ - public FeatureManager() { - values = new String[Feature.values().length]; - for (Feature feature : Feature.values()) { - values[feature.ordinal()] = feature.defaultValue(); - } - //read system properties or jaxp.properties - readSystemProperties(); - } - - - /** - * Check if the feature is enabled - * @param feature name of the feature - * @return true if enabled, false otherwise - */ - public boolean isFeatureEnabled(Feature feature) { - return Boolean.parseBoolean(values[feature.ordinal()]); - } - - /** - * Check if the feature is enabled - * @param propertyName name of the feature - * @return true if enabled, false otherwise - */ - public boolean isFeatureEnabled(String propertyName) { - return Boolean.parseBoolean(values[getIndex(propertyName)]); - } - - /** - * Get the index by property name - * @param propertyName property name - * @return the index of the property if found; return -1 if not - */ - public int getIndex(String propertyName){ - for (Feature feature : Feature.values()) { - if (feature.equalsName(propertyName)) { - return feature.ordinal(); - } - } - return -1; - } - - /** - * Read from system properties, or those in jaxp.properties - */ - private void readSystemProperties() { - getSystemProperty(Feature.ORACLE_ENABLE_EXTENSION_FUNCTION, - XalanConstants.SP_ORACLE_ENABLE_EXTENSION_FUNCTION); - } - -}