src/java.xml/share/classes/com/sun/org/apache/xml/internal/utils/XMLReaderManager.java

Print this page

        

*** 1,48 **** /* ! * reserved comment block ! * DO NOT REMOVE OR ALTER! */ /* ! * 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 * * 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, * 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. */ ! /* ! * $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; import com.sun.org.apache.xalan.internal.utils.FactoryImpl; 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.parsers.FactoryConfigurationError; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; /** * Creates XMLReader objects and caches them for re-use. * This class follows the singleton pattern. */ public class XMLReaderManager { private static final String NAMESPACES_FEATURE = "http://xml.org/sax/features/namespaces"; private static final String NAMESPACE_PREFIXES_FEATURE = --- 1,50 ---- /* ! * 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. ! * 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 * * 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. */ ! package com.sun.org.apache.xml.internal.utils; 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.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; /** * 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 = "http://xml.org/sax/features/namespaces"; private static final String NAMESPACE_PREFIXES_FEATURE =
*** 56,71 **** private static SAXParserFactory m_parserFactory; /** * Cache of XMLReader objects */ ! private ThreadLocal m_readers; /** * Keeps track of whether an XMLReader object is in use. */ ! private HashMap m_inUse; private boolean m_useServicesMechanism = true; private boolean _secureProcessing; /** --- 58,73 ---- private static SAXParserFactory m_parserFactory; /** * Cache of XMLReader objects */ ! private ThreadLocal<XMLReader> m_readers; /** * Keeps track of whether an XMLReader object is in use. */ ! private HashMap<XMLReader, Boolean> m_inUse; private boolean m_useServicesMechanism = true; private boolean _secureProcessing; /**
*** 73,82 **** --- 75,88 ---- */ private String _accessExternalDTD = XalanConstants.EXTERNAL_ACCESS_DEFAULT; private XMLSecurityManager _xmlSecurityManager; + //Catalog Feature + private boolean _useCatalog; + private CatalogFeatures _catalogFeatures; + /** * Hidden constructor */ private XMLReaderManager() { }
*** 99,119 **** XMLReader reader; 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(); } if (m_inUse == null) { ! 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(); boolean threadHasReader = (reader != null); String factory = SecuritySupport.getSystemProperty(property); if (threadHasReader && m_inUse.get(reader) != Boolean.TRUE && ( factory == null || reader.getClass().getName().equals(factory))) { m_inUse.put(reader, Boolean.TRUE); --- 105,125 ---- XMLReader reader; 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<>(); } if (m_inUse == null) { ! 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 = m_readers.get(); boolean threadHasReader = (reader != null); String factory = SecuritySupport.getSystemProperty(property); if (threadHasReader && m_inUse.get(reader) != Boolean.TRUE && ( factory == null || reader.getClass().getName().equals(factory))) { m_inUse.put(reader, Boolean.TRUE);
*** 129,139 **** reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, _secureProcessing); } catch (SAXNotRecognizedException e) { XMLSecurityManager.printWarning(reader.getClass().getName(), XMLConstants.FEATURE_SECURE_PROCESSING, e); } ! } catch (Exception e) { try { // If unable to create an instance, let's try to use // the XMLReader from JAXP if (m_parserFactory == null) { m_parserFactory = FactoryImpl.getSAXFactory(m_useServicesMechanism); --- 135,145 ---- reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, _secureProcessing); } catch (SAXNotRecognizedException e) { XMLSecurityManager.printWarning(reader.getClass().getName(), XMLConstants.FEATURE_SECURE_PROCESSING, e); } ! } catch (SAXException e) { try { // If unable to create an instance, let's try to use // the XMLReader from JAXP if (m_parserFactory == null) { m_parserFactory = FactoryImpl.getSAXFactory(m_useServicesMechanism);
*** 154,165 **** } } catch (ParserConfigurationException ex) { throw new SAXException(ex); } catch (FactoryConfigurationError ex1) { throw new SAXException(ex1.toString()); ! } catch (NoSuchMethodError ex2) { ! } catch (AbstractMethodError ame) { } // Cache the XMLReader if this is the first time we've created // a reader for this thread. if (!threadHasReader) { --- 160,170 ---- } } catch (ParserConfigurationException ex) { throw new SAXException(ex); } catch (FactoryConfigurationError ex1) { throw new SAXException(ex1.toString()); ! } catch (NoSuchMethodError | AbstractMethodError ex2) { } // Cache the XMLReader if this is the first time we've created // a reader for this thread. if (!threadHasReader) {
*** 191,200 **** --- 196,222 ---- } } catch (SAXException se) { 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; } /** * Mark the cached XMLReader as available. If the reader was not
*** 227,236 **** --- 249,260 ---- * Set feature */ 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; } } /** * Get property value
*** 250,257 **** --- 274,284 ---- public void setProperty(String name, Object value) { if (name.equals(XMLConstants.ACCESS_EXTERNAL_DTD)) { _accessExternalDTD = (String)value; } else if (name.equals(XalanConstants.SECURITY_MANAGER)) { _xmlSecurityManager = (XMLSecurityManager)value; + } else if (JdkXmlFeatures.CATALOG_FEATURES.equals(name)) { + _catalogFeatures = (CatalogFeatures)value; } + } }