* Implemenation of configurable interface.
* Configure this transformer.
*/
public void configure(Configuration conf) throws ConfigurationException {
if (factory == null) {
throw new ConfigurationException("BundleFactory component is not found.");
}
// read in the config options from the transformer definition
// there are two possible configuration methods:
// (1) the one dating from before multiple catalogues were supported:
// in this case the elements catalogue-name and catalogue-location specify
// the catalogue to be used
// (2) the new one supporting mulitple catalogues
// obtain the base name of the message catalogue
Configuration child = conf.getChild(I18N_CATALOGUE_NAME);
catalogueName = child.getValue(null);
// obtain the directory location of message catalogues
child = conf.getChild(I18N_CATALOGUE_LOCATION);
catalogueLocation = child.getValue(null);
Configuration cataloguesConf = conf.getChild("catalogues", false);
if ((catalogueName != null || catalogueLocation != null) && cataloguesConf != null) {
// if old and new style configuration are used at the same time...
throw new ConfigurationException("I18nTransformer: old and new configuration style are used at the same time. Use either the 'catalogue-name' and 'catalogue-location' elements or use the 'catalogues' element, but don't use both at the same time.");
} else if (catalogueName != null || catalogueLocation != null) {
if (!(catalogueName != null && catalogueLocation != null))
throw new ConfigurationException("I18nTransformer: catalogue-name and catalogue-location must both be specified");
if (getLogger().isDebugEnabled())
getLogger().debug("using old-style configuration: name = " + catalogueName
+ ", location = " + catalogueLocation);
} else if (cataloguesConf == null) {
// if both old and new style configuration are missing ...
throw new ConfigurationException("Missing configuration for the I18nTransformer: a 'catalogues' element specifying the catalogues is required.");
} else {
// new configuration style
Configuration[] catalogueConfs = cataloguesConf.getChildren("catalogue");
for (int i = 0; i < catalogueConfs.length; i++) {
String id = catalogueConfs[i].getAttribute("id");
String name = catalogueConfs[i].getAttribute("name");
String location = catalogueConfs[i].getAttribute("location");
CatalogueInfo newCatalogueInfo;
try {
newCatalogueInfo = new CatalogueInfo(name, location);
} catch (PatternException e) {
throw new ConfigurationException("I18nTransformer: error in name or location attribute on catalogue element with id " + id, e);
}
catalogues.put(id, newCatalogueInfo);
}
defaultCatalogueId = cataloguesConf.getAttribute("default");
if (!catalogues.containsKey(defaultCatalogueId))
throw new ConfigurationException("I18nTransformer: default catalogue id '" + defaultCatalogueId + "' denotes a nonexisting catalogue");
}
// obtain default text to use for untranslated messages
child = conf.getChild(I18N_UNTRANSLATED);
untranslated = child.getValue(null);