public boolean verify ( Collection knownTokens , Collection requiredTokens ) { boolean valid = true ; // For each known token, make sure there is a leading and trailing brace if ( knownTokens != null ) { for ( java . util . Iterator ii = knownTokens . iterator ( ) ; ii . hasNext ( ) ; ) { String token = ( String ) ii . next ( ) ; if ( token != null && token . length ( ) > 2 ) { // Strip braces from the known token token = token . substring ( 1 , token . length ( ) - 1 ) ; int index = _template . indexOf ( token ) ; if ( index != - 1 ) { if ( _template . charAt ( index - 1 ) != BEGIN_TOKEN_QUALIFIER || _template . charAt ( index + token . length ( ) ) != END_TOKEN_QUALIFIER ) { _log . error ( "Template token, " + token + ", is not correctly enclosed with braces in template: " + _template ) ; valid = false ; } } } } } // Parse the template into tokens and literals parseTemplate ( ) ; // Check if the required tokens are present if ( requiredTokens != null ) { for ( java . util . Iterator ii = requiredTokens . iterator ( ) ; ii . hasNext ( ) ; ) { String token = ( String ) ii . next ( ) ; TemplateItem requiredItem = new TemplateItem ( token , true ) ; if ( ! _parsedTemplate . contains ( requiredItem ) ) { _log . error ( "Required token, " + token + ", not found in template: " + _template ) ; valid = false ; } } } return valid ; }
Verification will ensure the URL template conforms to a valid format for known tokens and contains the required tokens . It will also parse the tokens and literal data into a list to improve the replacement performance when constructing the final URL string .