public void validate(Source source, Result result) throws SAXException, IOException { if (result instanceof SAXResult || result == null) { final SAXSource saxSource = (SAXSource) source; final SAXResult saxResult = (SAXResult) result; if (result != null) { setContentHandler(saxResult.getHandler()); } try { XMLReader reader = saxSource.getXMLReader(); if (reader == null) { // create one now SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true); try { reader = spf.newSAXParser().getXMLReader(); // If this is a Xerces SAX parser, set the security manager if there is one if (reader instanceof com.sun.org.apache.xerces.internal.parsers.SAXParser) { SecurityManager securityManager = (SecurityManager) fComponentManager.getProperty(SECURITY_MANAGER); if (securityManager != null) { try { reader.setProperty(SECURITY_MANAGER, securityManager); } // Ignore the exception if the security manager cannot be set. catch (SAXException exc) { } } } } catch (Exception e) { // this is impossible, but better safe than sorry throw new FactoryConfigurationError(e); } } // If XML names and Namespace URIs are already internalized we // can avoid running them through the SymbolTable. try { fStringsInternalized = reader.getFeature(STRING_INTERNING); } catch (SAXException exc) { // The feature isn't recognized or getting it is not supported. // In either case, assume that strings are not internalized. fStringsInternalized = false; } ErrorHandler errorHandler = fComponentManager.getErrorHandler(); reader.setErrorHandler( errorHandler != null ? errorHandler : DraconianErrorHandler.getInstance()); reader.setEntityResolver(fResolutionForwarder); fResolutionForwarder.setEntityResolver(fComponentManager.getResourceResolver()); reader.setContentHandler(this); reader.setDTDHandler(this); InputSource is = saxSource.getInputSource(); reader.parse(is); } finally { // release the reference to user's handler ASAP setContentHandler(null); } return; } throw new IllegalArgumentException( JAXPValidationMessageFormatter.formatMessage( Locale.getDefault(), "SourceResultMismatch", new Object[] {source.getClass().getName(), result.getClass().getName()})); }
public ErrorHandler getErrorHandler() { return fComponentManager.getErrorHandler(); }