/// <summary>Normalizes the declaration URIs.</summary>
 /// <param name="declarations">the declarations</param>
 private void NormalizeDeclarationURIs(IList <CssDeclaration> declarations)
 {
     // This is the case when css has no location and thus urls should not be resolved against base css location
     if (this.uriResolver == null)
     {
         return;
     }
     foreach (CssDeclaration declaration in declarations)
     {
         if (declaration.GetExpression().Contains("url("))
         {
             CssDeclarationValueTokenizer       tokenizer = new CssDeclarationValueTokenizer(declaration.GetExpression());
             CssDeclarationValueTokenizer.Token token;
             StringBuilder normalizedDeclaration = new StringBuilder();
             while ((token = tokenizer.GetNextValidToken()) != null)
             {
                 String strToAppend;
                 if (token.GetType() == CssDeclarationValueTokenizer.TokenType.FUNCTION && token.GetValue().StartsWith("url("
                                                                                                                       ))
                 {
                     String url = token.GetValue().Trim();
                     url = url.JSubstring(4, url.Length - 1).Trim();
                     if (CssUtils.IsBase64Data(url))
                     {
                         strToAppend = token.GetValue().Trim();
                     }
                     else
                     {
                         if (url.StartsWith("'") && url.EndsWith("'") || url.StartsWith("\"") && url.EndsWith("\""))
                         {
                             url = url.JSubstring(1, url.Length - 1);
                         }
                         url = url.Trim();
                         String finalUrl = url;
                         try {
                             finalUrl = uriResolver.ResolveAgainstBaseUri(url).ToExternalForm();
                         }
                         catch (UriFormatException) {
                         }
                         strToAppend = MessageFormatUtil.Format("url({0})", finalUrl);
                     }
                 }
                 else
                 {
                     strToAppend = token.GetValue();
                 }
                 if (normalizedDeclaration.Length > 0)
                 {
                     normalizedDeclaration.Append(' ');
                 }
                 normalizedDeclaration.Append(strToAppend);
             }
             declaration.SetExpression(normalizedDeclaration.ToString());
         }
     }
 }