public CharSequence evaluate ( CharSequence url , Resolver resolver ) { Pattern pattern = this . pattern . get ( ) ; if ( pattern == null ) { // Parse the pattern int flags = 0 ; if ( isNocase ( ) ) { flags |= Pattern . CASE_INSENSITIVE ; } pattern = Pattern . compile ( patternString , flags ) ; this . pattern . set ( pattern ) ; } Matcher matcher = pattern . matcher ( url ) ; if ( ! matcher . matches ( ) ) { // Evaluation done return null ; } // Evaluate conditions boolean done = false ; boolean rewrite = true ; Matcher lastMatcher = null ; int pos = 0 ; while ( ! done ) { if ( pos < conditions . length ) { rewrite = conditions [ pos ] . evaluate ( matcher , lastMatcher , resolver ) ; if ( rewrite ) { Matcher lastMatcher2 = conditions [ pos ] . getMatcher ( ) ; if ( lastMatcher2 != null ) { lastMatcher = lastMatcher2 ; } while ( pos < conditions . length && conditions [ pos ] . isOrnext ( ) ) { pos ++ ; } } else if ( ! conditions [ pos ] . isOrnext ( ) ) { done = true ; } pos ++ ; } else { done = true ; } } // Use the substitution to rewrite the url if ( rewrite ) { if ( isEnv ( ) ) { for ( int i = 0 ; i < envSubstitution . size ( ) ; i ++ ) { envResult . get ( i ) . set ( envSubstitution . get ( i ) . evaluate ( matcher , lastMatcher , resolver ) ) ; } } if ( isCookie ( ) ) { cookieResult . set ( cookieSubstitution . evaluate ( matcher , lastMatcher , resolver ) ) ; } if ( substitution != null ) { return substitution . evaluate ( matcher , lastMatcher , resolver ) ; } else { return url ; } } else { return null ; } }
Evaluate the rule based on the context