< prev index next >

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

Print this page




 111         // If the cached reader for this thread is in use, construct a new
 112         // one; otherwise, return the cached reader unless it isn't an
 113         // instance of the class set in the 'org.xml.sax.driver' property
 114         reader = (XMLReader) m_readers.get();
 115         boolean threadHasReader = (reader != null);
 116         String factory = SecuritySupport.getSystemProperty(property);
 117         if (threadHasReader && m_inUse.get(reader) != Boolean.TRUE &&
 118                 ( factory == null || reader.getClass().getName().equals(factory))) {
 119             m_inUse.put(reader, Boolean.TRUE);
 120         } else {
 121             try {
 122                 try {
 123                     // According to JAXP 1.2 specification, if a SAXSource
 124                     // is created using a SAX InputSource the Transformer or
 125                     // TransformerFactory creates a reader via the
 126                     // XMLReaderFactory if setXMLReader is not used
 127                     reader = XMLReaderFactory.createXMLReader();
 128                     try {
 129                         reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, _secureProcessing);
 130                     } catch (SAXNotRecognizedException e) {
 131                         System.err.println("Warning:  " + reader.getClass().getName() + ": "
 132                                 + e.getMessage());
 133                     }
 134                 } catch (Exception e) {
 135                    try {
 136                         // If unable to create an instance, let's try to use
 137                         // the XMLReader from JAXP
 138                         if (m_parserFactory == null) {
 139                             m_parserFactory = FactoryImpl.getSAXFactory(m_useServicesMechanism);
 140                             m_parserFactory.setNamespaceAware(true);
 141                         }
 142 
 143                         reader = m_parserFactory.newSAXParser().getXMLReader();
 144                    } catch (ParserConfigurationException pce) {
 145                        throw pce;   // pass along pce
 146                    }
 147                 }
 148                 try {
 149                     reader.setFeature(NAMESPACES_FEATURE, true);
 150                     reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
 151                 } catch (SAXException se) {
 152                     // Try to carry on if we've got a parser that


 155             } catch (ParserConfigurationException ex) {
 156                 throw new SAXException(ex);
 157             } catch (FactoryConfigurationError ex1) {
 158                 throw new SAXException(ex1.toString());
 159             } catch (NoSuchMethodError ex2) {
 160             } catch (AbstractMethodError ame) {
 161             }
 162 
 163             // Cache the XMLReader if this is the first time we've created
 164             // a reader for this thread.
 165             if (!threadHasReader) {
 166                 m_readers.set(reader);
 167                 m_inUse.put(reader, Boolean.TRUE);
 168             }
 169         }
 170 
 171         try {
 172             //reader is cached, but this property might have been reset
 173             reader.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD);
 174         } catch (SAXException se) {
 175             System.err.println("Warning:  " + reader.getClass().getName() + ": "
 176                         + se.getMessage());
 177         }
 178 

 179         try {
 180             if (_xmlSecurityManager != null) {
 181                 for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
 182                     reader.setProperty(limit.apiProperty(),

 183                             _xmlSecurityManager.getLimitValueAsString(limit));
 184                 }
 185                 if (_xmlSecurityManager.printEntityCountInfo()) {

 186                     reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
 187                 }
 188             }
 189         } catch (SAXException se) {
 190             System.err.println("Warning:  " + reader.getClass().getName() + ": "
 191                         + se.getMessage());
 192         }
 193 
 194         return reader;
 195     }
 196 
 197     /**
 198      * Mark the cached XMLReader as available.  If the reader was not
 199      * actually in the cache, do nothing.
 200      *
 201      * @param reader The XMLReader that's being released.
 202      */
 203     public synchronized void releaseXMLReader(XMLReader reader) {
 204         // If the reader that's being released is the cached reader
 205         // for this thread, remove it from the m_isUse list.
 206         if (m_readers.get() == reader && reader != null) {
 207             m_inUse.remove(reader);
 208         }
 209     }
 210     /**
 211      * Return the state of the services mechanism feature.




 111         // If the cached reader for this thread is in use, construct a new
 112         // one; otherwise, return the cached reader unless it isn't an
 113         // instance of the class set in the 'org.xml.sax.driver' property
 114         reader = (XMLReader) m_readers.get();
 115         boolean threadHasReader = (reader != null);
 116         String factory = SecuritySupport.getSystemProperty(property);
 117         if (threadHasReader && m_inUse.get(reader) != Boolean.TRUE &&
 118                 ( factory == null || reader.getClass().getName().equals(factory))) {
 119             m_inUse.put(reader, Boolean.TRUE);
 120         } else {
 121             try {
 122                 try {
 123                     // According to JAXP 1.2 specification, if a SAXSource
 124                     // is created using a SAX InputSource the Transformer or
 125                     // TransformerFactory creates a reader via the
 126                     // XMLReaderFactory if setXMLReader is not used
 127                     reader = XMLReaderFactory.createXMLReader();
 128                     try {
 129                         reader.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, _secureProcessing);
 130                     } catch (SAXNotRecognizedException e) {
 131                         XMLSecurityManager.printWarning(reader.getClass().getName(),
 132                                 XMLConstants.FEATURE_SECURE_PROCESSING, e);
 133                     }
 134                 } catch (Exception e) {
 135                    try {
 136                         // If unable to create an instance, let's try to use
 137                         // the XMLReader from JAXP
 138                         if (m_parserFactory == null) {
 139                             m_parserFactory = FactoryImpl.getSAXFactory(m_useServicesMechanism);
 140                             m_parserFactory.setNamespaceAware(true);
 141                         }
 142 
 143                         reader = m_parserFactory.newSAXParser().getXMLReader();
 144                    } catch (ParserConfigurationException pce) {
 145                        throw pce;   // pass along pce
 146                    }
 147                 }
 148                 try {
 149                     reader.setFeature(NAMESPACES_FEATURE, true);
 150                     reader.setFeature(NAMESPACE_PREFIXES_FEATURE, false);
 151                 } catch (SAXException se) {
 152                     // Try to carry on if we've got a parser that


 155             } catch (ParserConfigurationException ex) {
 156                 throw new SAXException(ex);
 157             } catch (FactoryConfigurationError ex1) {
 158                 throw new SAXException(ex1.toString());
 159             } catch (NoSuchMethodError ex2) {
 160             } catch (AbstractMethodError ame) {
 161             }
 162 
 163             // Cache the XMLReader if this is the first time we've created
 164             // a reader for this thread.
 165             if (!threadHasReader) {
 166                 m_readers.set(reader);
 167                 m_inUse.put(reader, Boolean.TRUE);
 168             }
 169         }
 170 
 171         try {
 172             //reader is cached, but this property might have been reset
 173             reader.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, _accessExternalDTD);
 174         } catch (SAXException se) {
 175             XMLSecurityManager.printWarning(reader.getClass().getName(),
 176                     XMLConstants.ACCESS_EXTERNAL_DTD, se);
 177         }
 178 
 179         String lastProperty = "";
 180         try {
 181             if (_xmlSecurityManager != null) {
 182                 for (XMLSecurityManager.Limit limit : XMLSecurityManager.Limit.values()) {
 183                     lastProperty = limit.apiProperty();
 184                     reader.setProperty(lastProperty,
 185                             _xmlSecurityManager.getLimitValueAsString(limit));
 186                 }
 187                 if (_xmlSecurityManager.printEntityCountInfo()) {
 188                     lastProperty = XalanConstants.JDK_ENTITY_COUNT_INFO;
 189                     reader.setProperty(XalanConstants.JDK_ENTITY_COUNT_INFO, XalanConstants.JDK_YES);
 190                 }
 191             }
 192         } catch (SAXException se) {
 193             XMLSecurityManager.printWarning(reader.getClass().getName(), lastProperty, se);

 194         }
 195 
 196         return reader;
 197     }
 198 
 199     /**
 200      * Mark the cached XMLReader as available.  If the reader was not
 201      * actually in the cache, do nothing.
 202      *
 203      * @param reader The XMLReader that's being released.
 204      */
 205     public synchronized void releaseXMLReader(XMLReader reader) {
 206         // If the reader that's being released is the cached reader
 207         // for this thread, remove it from the m_isUse list.
 208         if (m_readers.get() == reader && reader != null) {
 209             m_inUse.remove(reader);
 210         }
 211     }
 212     /**
 213      * Return the state of the services mechanism feature.


< prev index next >