@ Override public String filter ( URL sourceUrl , Metadata sourceMetadata , String urlString ) { Iterator < Rule > i = rules . iterator ( ) ; while ( i . hasNext ( ) ) { Rule r = i . next ( ) ; Matcher matcher = r . pattern . matcher ( urlString ) ; urlString = matcher . replaceAll ( r . substitution ) ; } if ( urlString . equals ( "" ) ) { urlString = null ; } return urlString ; }
This function does the replacements by iterating through all the regex patterns . It accepts a string url as input and returns the altered string . If the normalized url is an empty string the function will return null .