protected boolean postValidateXML ( final ContentSpec contentSpec , final KeyValueNode < String > keyValueNode , final String wrappedElement , String parentElement ) { String fixedWrappedElement = DocBookUtilities . escapeForXML ( wrappedElement ) ; // Get the docbook DTD final String docbookFileName ; final XMLValidator . ValidationMethod validationMethod ; final byte [ ] docbookSchema ; if ( contentSpec . getFormat ( ) . equalsIgnoreCase ( CommonConstants . DOCBOOK_50_TITLE ) ) { final BlobConstantWrapper docbookRng = blobConstantProvider . getBlobConstant ( serverEntities . getDocBook50RNGBlobConstantId ( ) ) ; docbookFileName = docbookRng . getName ( ) ; validationMethod = XMLValidator . ValidationMethod . RELAXNG ; docbookSchema = docbookRng . getValue ( ) ; // Further wrap the element for docbook 5.0 if ( CommonConstants . CS_TITLE_TITLE . equalsIgnoreCase ( keyValueNode . getKey ( ) ) ) { fixedWrappedElement = DocBookUtilities . addDocBook50Namespace ( "<book><info>" + fixedWrappedElement + "</info></book>" ) ; } else { fixedWrappedElement = DocBookUtilities . addDocBook50Namespace ( "<book><info><title />" + fixedWrappedElement + "</info></book>" ) ; } parentElement = "book" ; } else { final BlobConstantWrapper rocbookDtd = blobConstantProvider . getBlobConstant ( serverEntities . getRocBook45DTDBlobConstantId ( ) ) ; docbookFileName = rocbookDtd . getName ( ) ; validationMethod = XMLValidator . ValidationMethod . DTD ; docbookSchema = rocbookDtd . getValue ( ) ; } // Create the dummy XML entities file final StringBuilder xmlEntities = new StringBuilder ( DocBookUtilities . DOCBOOK_ENTITIES_STRING ) ; xmlEntities . append ( "\n" ) . append ( CSConstants . DUMMY_CS_NAME_ENT_FILE ) ; if ( ! isNullOrEmpty ( contentSpec . getEntities ( ) ) ) { xmlEntities . append ( contentSpec . getEntities ( ) ) ; } // Validate the XML content against the dtd final XMLValidator validator = new XMLValidator ( false ) ; if ( ! validator . validate ( validationMethod , fixedWrappedElement , docbookFileName , docbookSchema , xmlEntities . toString ( ) , parentElement ) ) { final String line = keyValueNode . getText ( ) ; log . error ( String . format ( ProcessorConstants . ERROR_INVALID_METADATA_MSG , keyValueNode . getKey ( ) , validator . getErrorText ( ) , line ) ) ; return false ; } return true ; }
Checks that the XML for a keyvalue node is valid DocBook XML .