protected void doLinkSecondPass ( final BuildData buildData , final Map < SpecTopic , Set < String > > usedIdAttributes ) throws BuildProcessingException { final List < SpecTopic > topics = buildData . getBuildDatabase ( ) . getAllSpecTopics ( ) ; for ( final SpecTopic specTopic : topics ) { final Document doc = specTopic . getXMLDocument ( ) ; // Get the XRef links in the topic document final Set < String > linkIds = new HashSet < String > ( ) ; DocBookBuildUtilities . getTopicLinkIds ( doc , linkIds ) ; final Map < String , SpecTopic > invalidLinks = new HashMap < String , SpecTopic > ( ) ; for ( final String linkId : linkIds ) { // Ignore error links if ( linkId . startsWith ( CommonConstants . ERROR_XREF_ID_PREFIX ) ) continue ; // Find the linked topic SpecTopic linkedTopic = null ; for ( final Map . Entry < SpecTopic , Set < String > > usedIdEntry : usedIdAttributes . entrySet ( ) ) { if ( usedIdEntry . getValue ( ) . contains ( linkId ) ) { linkedTopic = usedIdEntry . getKey ( ) ; break ; } } // If the linked topic has been set as an error, than update the links to point to the topic id if ( linkedTopic != null && buildData . getErrorDatabase ( ) . hasErrorData ( linkedTopic . getTopic ( ) ) ) { final TopicErrorData errorData = buildData . getErrorDatabase ( ) . getErrorData ( linkedTopic . getTopic ( ) ) ; if ( errorData . hasFatalErrors ( ) ) { invalidLinks . put ( linkId , linkedTopic ) ; } } } // Go through and fix any invalid links if ( ! invalidLinks . isEmpty ( ) ) { final List < Node > linkNodes = XMLUtilities . getChildNodes ( doc , "xref" , "link" ) ; for ( final Node linkNode : linkNodes ) { final String linkId = ( ( Element ) linkNode ) . getAttribute ( "linkend" ) ; if ( invalidLinks . containsKey ( linkId ) ) { final SpecTopic linkedTopic = invalidLinks . get ( linkId ) ; ( ( Element ) linkNode ) . setAttribute ( "linkend" , linkedTopic . getUniqueLinkId ( buildData . isUseFixedUrls ( ) ) ) ; } } } } }
Fixes any topics links that have been broken due to the linked topics XML being invalid .