protected boolean preValidateCommonContent ( final CommonContent commonContent , final BookType bookType ) { boolean valid = true ; // Check if the app should be shutdown if ( isShuttingDown . get ( ) ) { shutdown . set ( true ) ; return false ; } // Check that the title exists if ( isNullOrEmpty ( commonContent . getTitle ( ) ) ) { log . error ( String . format ( ProcessorConstants . ERROR_COMMON_CONTENT_NO_TITLE_MSG , commonContent . getLineNumber ( ) , commonContent . getText ( ) ) ) ; valid = false ; } if ( ( bookType == BookType . BOOK || bookType == BookType . BOOK_DRAFT ) ) { final Level parent = commonContent . getParent ( ) ; // Check that the common content is inside a chapter/section/process/appendix/part/preface final LevelType parentLevelType = parent . getLevelType ( ) ; if ( parent == null || parentLevelType == LevelType . BASE ) { log . error ( format ( ProcessorConstants . ERROR_COMMON_CONTENT_OUTSIDE_CHAPTER_MSG , commonContent . getLineNumber ( ) , commonContent . getText ( ) ) ) ; valid = false ; } // Check that there are no levels in the parent part (ie the common content is in the intro) if ( parent != null && parentLevelType == LevelType . PART ) { final List < Node > parentChildren = parent . getChildNodes ( ) ; final int index = parentChildren . indexOf ( commonContent ) ; for ( int i = 0 ; i < index ; i ++ ) { final Node node = parentChildren . get ( i ) ; if ( node instanceof Level && ( ( Level ) node ) . getLevelType ( ) != LevelType . INITIAL_CONTENT ) { log . error ( String . format ( ProcessorConstants . ERROR_COMMON_CONTENT_NOT_IN_PART_INTRO_MSG , commonContent . getLineNumber ( ) , commonContent . getText ( ) ) ) ; valid = false ; break ; } } } } // Check that the common content doesn't ahve a fixed url and if it does then print a warning if ( ! isNullOrEmpty ( commonContent . getFixedUrl ( ) ) ) { log . warn ( format ( ProcessorConstants . WARN_FIXED_URL_WILL_BE_IGNORED_MSG , commonContent . getLineNumber ( ) , commonContent . getText ( ) ) ) ; commonContent . setFixedUrl ( null ) ; } // Check for known common content and warn the user if it's not known if ( ! ProcessorConstants . KNOWN_COMMON_CONTENT . contains ( commonContent . getFixedTitle ( ) ) ) { log . warn ( format ( ProcessorConstants . WARN_UNRECOGNISED_COMMON_CONTENT_MSG , commonContent . getLineNumber ( ) , commonContent . getText ( ) ) ) ; } return valid ; }
Validates a Common Content node for formatting issues .