private ImmutableList < Element > getNodeListForTagElement ( Document dom , CrawlElement crawlElement , EventableConditionChecker eventableConditionChecker ) { Builder < Element > result = ImmutableList . builder ( ) ; if ( crawlElement . getTagName ( ) == null ) { return result . build ( ) ; } EventableCondition eventableCondition = eventableConditionChecker . getEventableCondition ( crawlElement . getId ( ) ) ; // TODO Stefan; this part of the code should be re-factored, Hack-ed it this way to prevent // performance problems. ImmutableList < String > expressions = getFullXpathForGivenXpath ( dom , eventableCondition ) ; NodeList nodeList = dom . getElementsByTagName ( crawlElement . getTagName ( ) ) ; for ( int k = 0 ; k < nodeList . getLength ( ) ; k ++ ) { Element element = ( Element ) nodeList . item ( k ) ; boolean matchesXpath = elementMatchesXpath ( eventableConditionChecker , eventableCondition , expressions , element ) ; LOG . debug ( "Element {} matches Xpath={}" , DomUtils . getElementString ( element ) , matchesXpath ) ; /* * TODO Stefan This is a possible Thread-Interleaving problem, as / isChecked can return * false and when needed to add it can return true. / check if element is a candidate */ String id = element . getNodeName ( ) + ": " + DomUtils . getAllElementAttributes ( element ) ; if ( matchesXpath && ! checkedElements . isChecked ( id ) && ! isExcluded ( dom , element , eventableConditionChecker ) ) { addElement ( element , result , crawlElement ) ; } else { LOG . debug ( "Element {} was not added" , element ) ; } } return result . build ( ) ; }
Returns a list of Elements form the DOM tree matching the tag element .