public static boolean isValidSchematron ( @ Nullable final Source aSource ) { if ( aSource == null ) return false ; try { // Get a validator from the RNC schema. final Validator aValidator = RelaxNGCompactSchemaCache . getInstance ( ) . getValidator ( SCHEMATRON_RNC ) ; // Ensure a collecting error handler is set final ErrorHandler aOldEH = aValidator . getErrorHandler ( ) ; CollectingSAXErrorHandler aCEH ; if ( aOldEH instanceof CollectingSAXErrorHandler ) aCEH = ( CollectingSAXErrorHandler ) aOldEH ; else { aCEH = new CollectingSAXErrorHandler ( ) ; aValidator . setErrorHandler ( aCEH . andThen ( aOldEH ) ) ; } // Perform validation aValidator . validate ( aSource , null ) ; // Check results return aCEH . getErrorList ( ) . getMostSevereErrorLevel ( ) . isLT ( EErrorLevel . ERROR ) ; } catch ( final SAXException ex ) { // Document is not valid in respect to XML } catch ( final IOException ex ) { LOGGER . warn ( "Failed to read source " + aSource , ex ) ; } return false ; }
Check if the passed source is a valid schematron instance .