private void processElement ( Element element ) { context . setCurrentSegment ( element ) ; currentProp = null ; currentAttribute = null ; // Process attributes boolean shouldPopContext = processElementAttributes ( element ) ; // Process text segments StreamSupport . stream ( ( ( Iterable < Segment > ) element :: getNodeIterator ) . spliterator ( ) , false ) . filter ( segment -> ! ( segment instanceof Tag ) && ! ( segment instanceof CharacterReference ) ) . filter ( segment -> { for ( Element child : element . getChildElements ( ) ) { if ( child . encloses ( segment ) ) { return false ; } } return true ; } ) . forEach ( this :: processTextNode ) ; // Recurse downwards element . getChildElements ( ) . forEach ( this :: processElement ) ; // After downward recursion, pop the context layer if necessary if ( shouldPopContext ) { context . popContextLayer ( ) ; } }
Recursive method that will process the whole template DOM tree .