static void adjustPositionSet ( List < NodeInfo > order , Element positionSet , IntegrationResult result ) { Node nodeToMatch = positionSet . getFirstChild ( ) ; Element nodeToInsertBefore = positionSet . getOwnerDocument ( ) . createElement ( "INSERT_POINT" ) ; positionSet . insertBefore ( nodeToInsertBefore , nodeToMatch ) ; for ( Iterator < NodeInfo > iter = order . iterator ( ) ; iter . hasNext ( ) ; ) { NodeInfo ni = iter . next ( ) ; if ( ni . getPositionDirective ( ) != null ) { // found one check it against the current one in the position // set to see if it is different. If so then indicate that // something (the position set) has changed in the plf if ( ni . getPositionDirective ( ) != nodeToMatch ) result . setChangedPLF ( true ) ; ; // now bump the insertion point forward prior to // moving on to the next position node to be evaluated if ( nodeToMatch != null ) nodeToMatch = nodeToMatch . getNextSibling ( ) ; // now insert it prior to insertion point positionSet . insertBefore ( ni . getPositionDirective ( ) , nodeToInsertBefore ) ; } } // now for any left over after the insert point remove them. int removeFails = 0 ; // avoid infinite loop, if stuck while ( nodeToInsertBefore . getNextSibling ( ) != null && removeFails < 5 ) { Node toRemove = nodeToInsertBefore . getNextSibling ( ) ; try { toRemove . getParentNode ( ) . removeChild ( toRemove ) ; } catch ( DOMException de ) { LOG . error ( "DOM issue removing next child after insert point: {} -- {}" , toRemove . toString ( ) , de . getLocalizedMessage ( ) ) ; removeFails ++ ; } } // now remove the insertion point if ( nodeToInsertBefore . getParentNode ( ) != null ) { nodeToInsertBefore . getParentNode ( ) . removeChild ( nodeToInsertBefore ) ; } }
This method trims down the position set to the position directives on the node info elements still having a position directive . Any directives that violated restrictions were removed from the node info objects so the position set should be made to match the order of those still having one .