The handling of resources (searching, retrieving content and writing content) is abstracted through the ResourceFinder and ResourceWriter interfaces in the dedicated package : com.uwyn.rife.resources.
It's even possible to store and retrieve resources from a database by using the DatabaseResources class which implements both the ResourceFinder and ResourceWriter interfaces. A DatabaseResources instance can be obtained by providing DatabaseResourcesFactory.getInstance() with a Datasource object. Once you have the instance, you'll have to call the install() method before using it, for example:
Datasource ds = Datasources.getRepInstance().getDatasource("pgsql");
DatabaseResources mResources = DatabaseResourcesFactory.getInstance(ds);
mResources.install();
mResources.addResource(
"db_template_name.txt",
"[!B 'block1']a block with value [!V 'value1'/][!/B][!V 'value2'/]"
);
Afterwards, you can provide this resource finder to any class or method that needs it. Currently only templates have been made fully compatibile with pluggable resource finders, but work is underway to do the same for most of the other parts of RIFE.
An TemplateFactory example using the mResources from above:
TemplateFactory factory = new TemplateFactory(mResources, "databasetext",
TemplateFactory.CONFIGS_TXT, "text/txt", ".txt", new String[] {TemplateFactory.TAG_CONFIG,
TemplateFactory.TAG_L10N}, null, BeanHandlerPlainSingleton.INSTANCE, null, null);
Template template = null;
template = factory.get("db_template_name");
Versions
- Used source from Rife 1.4. The class DatabaseResources exists in the Rife 1.2 documentation, so it may work back that far.
References
- Rife/Base 1.4 source: rife-source-1.4.zip
Further examples, resources