private Templates createValidatingStyleSheet ( StreamSource rulesSource , StreamSource preprocessorSource , String phase ) throws ObjectValidityException , TransformerException { ReadableCharArrayWriter out = new ReadableCharArrayWriter ( 4096 ) ; try { // Create a transformer for that uses the Schematron preprocessor stylesheet. // Transform the Schematron schema (rules) into a validating stylesheet. Transformer ptransformer = XmlTransformUtility . getTransformer ( preprocessorSource ) ; ptransformer . setParameter ( "phase" , phase ) ; ptransformer . transform ( rulesSource , new StreamResult ( out ) ) ; out . close ( ) ; } catch ( Exception e ) { logger . error ( "Schematron validation failed" , e ) ; throw new ObjectValidityException ( e . getMessage ( ) ) ; } return XmlTransformUtility . getTemplates ( new StreamSource ( out . toReader ( ) ) ) ; }
Create the validating stylesheet which will be used to perform the actual Schematron validation . The validating stylesheet is created dynamically using the preprocessor stylesheet and the Schematron schema for Fedora . The phase is key . The stylesheet is created for the appropriate phase as specified in the Schematron rules schema . Valid work flow phases are currently ingest and store . Different schematron rules apply to different phases of the object lifecycle . Some rules are applied when an object is first being ingested into the repository . Other rules apply before the object is put into permanent storage .