void walkMap ( final Element elem , final KeyScope scope , final List < ResolveTask > res ) { List < KeyScope > ss = Collections . singletonList ( scope ) ; if ( elem . getAttributeNode ( ATTRIBUTE_NAME_KEYSCOPE ) != null ) { ss = new ArrayList <> ( ) ; for ( final String keyscope : elem . getAttribute ( ATTRIBUTE_NAME_KEYSCOPE ) . trim ( ) . split ( "\\s+" ) ) { final KeyScope s = scope . getChildScope ( keyscope ) ; assert s != null ; ss . add ( s ) ; } } Attr hrefNode = elem . getAttributeNode ( ATTRIBUTE_NAME_COPY_TO ) ; if ( hrefNode == null ) { hrefNode = elem . getAttributeNode ( ATTRIBUTE_NAME_HREF ) ; } if ( hrefNode == null && SUBMAP . matches ( elem ) ) { hrefNode = elem . getAttributeNode ( ATTRIBUTE_NAME_DITA_OT_ORIG_HREF ) ; } final boolean isResourceOnly = isResourceOnly ( elem ) ; for ( final KeyScope s : ss ) { if ( hrefNode != null ) { final URI href = stripFragment ( job . getInputMap ( ) . resolve ( hrefNode . getValue ( ) ) ) ; final FileInfo fi = job . getFileInfo ( href ) ; if ( fi != null && fi . hasKeyref ) { final int count = usage . getOrDefault ( fi . uri , 0 ) ; final Optional < ResolveTask > existing = res . stream ( ) . filter ( rt -> rt . scope . equals ( s ) && rt . in . uri . equals ( fi . uri ) ) . findAny ( ) ; if ( count != 0 && existing . isPresent ( ) ) { final ResolveTask resolveTask = existing . get ( ) ; if ( resolveTask . out != null ) { final URI value = tempFileNameScheme . generateTempFileName ( resolveTask . out . result ) ; hrefNode . setValue ( value . toString ( ) ) ; } } else { final ResolveTask resolveTask = processTopic ( fi , s , isResourceOnly ) ; res . add ( resolveTask ) ; final Integer used = usage . get ( fi . uri ) ; if ( used > 1 ) { final URI value = tempFileNameScheme . generateTempFileName ( resolveTask . out . result ) ; hrefNode . setValue ( value . toString ( ) ) ; } } } } for ( final Element child : getChildElements ( elem , MAP_TOPICREF ) ) { walkMap ( child , s , res ) ; } } }
Recursively walk map and process topics that have keyrefs .