protected void fixElements ( ) { for ( Element fosterElement : fosterElements ) { // find parent table Element lastTable = findLastTable ( fosterElement ) ; Node fosterElementParent = fosterElement . getParentNode ( ) ; // filter our foster element Node [ ] fosterChilds = fosterElement . getChildNodes ( ) ; for ( Node fosterChild : fosterChilds ) { if ( fosterChild . getNodeType ( ) == Node . NodeType . ELEMENT ) { if ( isOneOfTableElements ( ( Element ) fosterChild ) ) { // move all child table elements outside // the foster element fosterChild . detachFromParent ( ) ; fosterElementParent . insertBefore ( fosterChild , fosterElement ) ; } } } // finally, move foster element above the table fosterElement . detachFromParent ( ) ; lastTable . getParentNode ( ) . insertBefore ( fosterElement , lastTable ) ; } }
Performs the fix for elements .