3. More on configuration

While we're at it, we might as well show some more features of the configuration system in RIFE.

3.1. Accessing parameters from within the configuration file

In our Friends example we might want to have custom titles for all of our pages (Display, Add, Remove, ...). The Add page, for example, could be "Add a Friend of Mikael". In case there are many pages where the title should include the user's name, it will soon get very tedious to change them all when the name of the user changes. RIFE has a solution for this: it is possible to access parameters from the configuration file itself.

Example 6.4. Using the values from within the configuration file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE config SYSTEM "/dtd/config.dtd">

<config>
  <param name="USERNAME">Mikael</param>
  <param name="DISPLAY_TITLE">Friends of <value name="USERNAME"/></param>
  <param name="ADD_TITLE">Add a Friend of <value name="USERNAME"/></param>
</config>

The parameter "USERNAME" is used to construct the title for both the Display page and the Add page. If someone else wants to change the name, they just have to do it in one place.

3.2. Configuration selectors

When developing an application, it is often necessary to have a different set of configuration options than when the application is deployed. It is also useful during the development process, since there may be several developers, all testing the software on different computers with different setups.

The configuration system in RIFE has a solution for this as well. The Config participant is able to choose from a set of different configuration files depending on the host name, operating system or user name.

<participant param="XmlSelectorHostname">ParticipantConfig</participant>

Here the configuration participant is going to look for the file config-{host}.xml. In other situations it might be different configure settings depending on operating system, where the selector name would be XmlSelectorOs. If configure settings depend on the username the selector XmlSelectorUser is used.

When using a configuration selector, the different configuration files must be named according to a certain pattern:

Example 6.5. Filename convention when using selectors

Host name:        rep/config-{host}.xml
Operation system: rep/config-{OS}.xml
User name:        rep/config-{user}.xml

The host, OS, and user strings are normalized to use all lower case letters and with any dots and spaces ('.' and ' ') replaced with underscore ('_') characters.

3.3. Configuration file inclusion

When using configuration selectors, not all parameters are necessarily different between different setups. In those cases it's often preferred to keep those common settings in a separate file that is shared by the different configuration files. RIFE supports inclusion of files in configuration files. This makes it possible for all the selector specific files to include the same common configuration file.

<include file="rep/config-common.xml"/>

Now only one file has to be edited to change the common options instead of each of the selector specific files.

OK, now we have looked at displaying the friends, and visited a little side-track to explain participants and configuration in RIFE a bit more in detail. Let's move on to adding the actual data layer.