public void validate ( StreamSource objectSource ) throws ServerException { DOValidatorSchematronResult result = null ; try { // Create a transformer that uses the validating stylesheet. // Run the Schematron validation of the Fedora object and // output results in DOM format. Transformer vtransformer = validatingStyleSheet . newTransformer ( ) ; DOMResult validationResult = new DOMResult ( ) ; vtransformer . transform ( objectSource , validationResult ) ; result = new DOValidatorSchematronResult ( validationResult ) ; } catch ( Exception e ) { Validation validation = new Validation ( "unknown" ) ; String problem = "Schematron validation failed:" . concat ( e . getMessage ( ) ) ; validation . setObjectProblems ( Collections . singletonList ( problem ) ) ; logger . error ( "Schematron validation failed" , e ) ; throw new ObjectValidityException ( e . getMessage ( ) , validation ) ; } if ( ! result . isValid ( ) ) { String msg = null ; try { msg = result . getXMLResult ( ) ; } catch ( Exception e ) { logger . warn ( "Error getting XML result of schematron validation failure" , e ) ; } Validation validation = new Validation ( "unknown" ) ; if ( msg == null ) { msg = "Unknown schematron error. Error getting XML results of schematron validation" ; } validation . setObjectProblems ( Collections . singletonList ( msg ) ) ; throw new ObjectValidityException ( msg , validation ) ; } }
Run the Schematron validation on a Fedora object .