Tridion (or SDL Web as it’s called nowadays) allows many extension points. You can extend the content editor GUI, you can extend events, and you can also extend a lot of things on the content delivery side, for example Ambient data claimprocessors, TCDL tag handlers, storage extensions, …
These content delivery extension points are usually written in Java.
This blog post will show you how you can easily add your own configuration files for your code.
We all know the default configuration files from our standard content delivery setup, files like cd_storage_conf.xml, cd_ambient_conf.xml, …
These files allow you to add any custom code to the different blocks of a Tridion ecosystem – ADF cartridges can be added in the cd_ambient_conf.xml, TCDL tag handlers can be added in the cd_dynamic_conf.xml
But what if we have to build our own custom claim processor code (or any other code), and we want to add some custom configuration ?
The folks at SDL have provided some useful classes to read any configuration file.
Here’s some sample code:
It’s all pretty simple
In the constructor of your custom class, you call
new XMLConfigurationReader().readConfiguration("CONFIG_FILE_NAME");. the name of the config file should off course correspond to an xml file that can be found in the classpath of your application (you can just put it next to your other tridion config files. The readConfiguration function gives you a Configuration object.
Once you have this new Configuration object, you can easily get items from your configuration files with the functions ConfigurationHelper.getStringValue(), ConfigurationHelper.getIntValue() or ConfigurationHelper.getBooleanValue(). These functions take a configuration object, an xpath string to read a specific configuration value in the xml, and a default value (that is used as a fallback value).
Also, it’s possible to get attribute values of a configuration element by using the configuratio.getAttribute(“name”) function.
This allows you, with just a minimum of code, to make all of your settings of your custom code configurable.