private URI handleLocalDita ( final URI href , final AttributesImpl atts ) { final URI attValue = href ; final int sharpIndex = attValue . toString ( ) . indexOf ( SHARP ) ; URI pathFromMap ; URI retAttValue ; if ( sharpIndex != - 1 ) { // href value refer to an id in a topic if ( sharpIndex == 0 ) { pathFromMap = toURI ( filePath ) ; } else { pathFromMap = toURI ( filePath ) . resolve ( attValue . toString ( ) . substring ( 0 , sharpIndex ) ) ; } XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_OHREF , toURI ( pathFromMap + attValue . toString ( ) . substring ( sharpIndex ) ) . toString ( ) ) ; final String topicID = getTopicID ( attValue . getFragment ( ) ) ; final int index = attValue . toString ( ) . indexOf ( SLASH , sharpIndex ) ; final String elementId = index != - 1 ? attValue . toString ( ) . substring ( index ) : "" ; final URI pathWithTopicID = setFragment ( dirPath . toURI ( ) . resolve ( pathFromMap ) , topicID ) ; if ( util . findId ( pathWithTopicID ) ) { // topicId found retAttValue = toURI ( SHARP + util . getIdValue ( pathWithTopicID ) + elementId ) ; } else { // topicId not found retAttValue = toURI ( SHARP + util . addId ( pathWithTopicID ) + elementId ) ; } } else { // href value refer to a topic pathFromMap = toURI ( filePath ) . resolve ( attValue . toString ( ) ) ; URI absolutePath = dirPath . toURI ( ) . resolve ( pathFromMap ) ; XMLUtils . addOrSetAttribute ( atts , ATTRIBUTE_NAME_OHREF , pathFromMap . toString ( ) ) ; if ( util . findId ( absolutePath ) ) { retAttValue = toURI ( SHARP + util . getIdValue ( absolutePath ) ) ; } else { final String fileId = util . getFirstTopicId ( absolutePath , false ) ; final URI key = setFragment ( absolutePath , fileId ) ; if ( util . findId ( key ) ) { util . addId ( absolutePath , util . getIdValue ( key ) ) ; retAttValue = toURI ( SHARP + util . getIdValue ( key ) ) ; } else { retAttValue = toURI ( SHARP + util . addId ( absolutePath ) ) ; util . addId ( key , util . getIdValue ( absolutePath ) ) ; } } } return retAttValue ; }
Rewrite local DITA href value .