Filter example

 

A good example of the power filters provide can be seen by examining the defined filters for the "Language" property in your maindefs.bdf. Let’s break this example down to cover the details of how these Language filters are defined in maindefs.bdf and see what makes them tick.

 

The purpose of the filters defined for the Language property is to set the most likely language spoken by the person using the web browser. An example of why you may want to do that is if you’d like to automatically show a different version of your site to French speaking individuals.

 

Our maindefs.bdf is set to use a default language of "English". This can easily be changed if desired. Just highlight the "Default Browser", and double-click on the Language property listed in the right properties pane. Change the value to the language you wish to use for a default, and click the "Apply changes to child browsers" box at the bottom of the Change Properties dialog box. All browsers and folders will then be updated with your new default.

 

By default, any matching browser will have its Language property set to "English". This can be seen by viewing any browser or folder and looking at the value for the Language property. So now we need a way to override that setting if we detect the language to be something other than English. Fortunately some user agents, such as those reported by Netscape browsers, report the foreign language of a browser using a two-character country code inside of brackets. For example, a French version of Netscape 4 would have a user agent like "Mozilla/4.03 [fr] (Win98; I)".

 

What we need now is a filter that will look for "[fr]" in the user agent, and if found, set the Language property for that visiting browser to "French". Note that this applies only for this particular visiting browser, because the filter does not change your default settings for the Netscape 4 browser – it overrides this setting on a browser by browser basis, based on its particular user agent (remember that a Netscape 4 browser can be reported with hundreds of different user agents).

 

Let’s first make sure the filter area of the main screen is visible. The filter area is the main section underneath the dark gray horizontal line which runs across the entire program screen. Refer to the user interface section for more information. You can enlarge the filter area if desired to make working on filters easier by dragging the horizontal bar up. Likewise when working mostly on browsers, you may want to lower the bar to increase your view of the browsers and properties.

 

image\filterad_shg.gif

 

The completed form that we are about to walk you through is shown above. Here’s how the filter that does what we want was created. You can follow along on your screen, but you probably do not want to save the filter when complete because it would create a duplicate in your BDF (because this filter already exists). First we select Add from the Filters menu. Then in the Add New Filter dialog box, we set the property value to "Language". This tells the filter which property we will be setting in the event of a match.

 

For the match condition, we need to specify a search string which represents the pattern or keywords/characters, which if present, indicate that we want to override the property’s value. In this case, the search string we are looking for is "[fr]". Note however, that we need to tell the filter that the [fr] will be somewhere inside the user agent, but we’re not exactly sure of its starting and ending position. In this case, we surround the [fr] with the ’r;*’ wildcard character to make our string "*[fr]*". There is one catch though to this particular example. Brackets appearing in a search string such as above have special meaning. In this case, we don’t want to use that special meaning – but rather want the bracket to represent an actual bracket. We do this by placing a "\" character in front of each bracket. So with this in mind, the correct search string we use for this filter is "*\[fr\]*".

 

Then for the "Value to set" prompt, we enter "French". This represents the value that BrowserHawk will override Language with in the event that the search string matches the current user agent. Lastly, we specify a priority – which will usually be 1 to indicate top priority (high numbers represent lower priority). Assigning priority numbers other than "1" is sometimes necessary if you have more than one filter set up for the same property, with search strings which may match for each filter. Examine the maindefs.bdf for more information and examples on how and why this may be necessary.

 

So, now that the filter is defined, let’s quickly review it. It is best understood by reading it as "if the search string *\[fr\]* is contained anywhere in a user agent, set the Language property equal to French".

 

See Also:

Understanding filters

Working with filters

Using the Filter form