The recommended way to add support for a configuration file to your ALcyAddOn
is to let your add-on extend from ALcyPreferencesAddOn
or one of its subclasses.
The ALcyPreferencesAddOn
exposes a TLcyPreferencesTool
which reads its preferences from a configuration file. For more information about the preferences tool, see Working with the TLcyPreferencesTool.
For example:
public class AddOnWithConfigFile extends ALcyPreferencesAddOn {
public AddOnWithConfigFile() {
super(ALcyTool.getLongPrefix(AddOnWithConfigFile.class),
ALcyTool.getShortPrefix(AddOnWithConfigFile.class));
}
@Override
public void plugInto(ILcyLucyEnv aLucyEnv) {
super.plugInto(aLucyEnv);
//Obtain a reference to the preferences
//This will contain all key-value pairs present in the configuration file of the add-on
ALcyProperties preferences = getPreferences();
//Obtain a value from the preferences
String value = preferences.getString(getShortPrefix() + "myKey", null);
}
}
The location of the configuration file is specified in the <configFile>
element of the addons.xml
file.
See Working with Lucy add-ons for more information about the addons.xml
file.