public ValidatorHandlerImpl(XMLSchemaValidatorComponentManager componentManager) { fComponentManager = componentManager; fErrorReporter = (XMLErrorReporter) fComponentManager.getProperty(ERROR_REPORTER); fNamespaceContext = (NamespaceContext) fComponentManager.getProperty(NAMESPACE_CONTEXT); fSchemaValidator = (XMLSchemaValidator) fComponentManager.getProperty(SCHEMA_VALIDATOR); fSymbolTable = (SymbolTable) fComponentManager.getProperty(SYMBOL_TABLE); fValidationManager = (ValidationManager) fComponentManager.getProperty(VALIDATION_MANAGER); }
public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { if (name == null) { throw new NullPointerException(); } try { return fComponentManager.getProperty(name); } catch (XMLConfigurationException e) { final String identifier = e.getIdentifier(); final String key = e.getType() == XMLConfigurationException.NOT_RECOGNIZED ? "property-not-recognized" : "property-not-supported"; throw new SAXNotRecognizedException( SAXMessageFormatter.formatMessage(Locale.getDefault(), key, new Object[] {identifier})); } }
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()})); }