Custom Factories - Mura Docs v7.0

Custom Factories

Mura allows you to create your own resource bundle factories, and fall back to Mura's original lookup hierarchy when a requested key-value is not found. This is especially useful when creating plugins, or integrating a custom application.

The code example below demonstrates how you could go about creating a custom resource bundle factory.

customResourceBundleDirectory = ExpandPath('#m.globalConfig('context')#/path/to/your/RBFactory/');
customFactory = new mura.resourceBundle.resourceBundleFactory(
  parentFactory = m.siteConfig('rbFactory')
  , resourceDirectory = customResourceBundleDirectory
  , locale = m.siteConfig('JavaLocale')
);

You could wrap this up into a custom method to obtain a reference to your custom factory using something similar to the following example.

public any function getResourceBundleFactory(required struct m) {
var resourceDirectory = ExpandPath('#arguments.m.globalConfig('context')#/plugins/MyPlugin/rb/');
  return new mura.resourceBundle.resourceBundleFactory(
parentFactory = arguments.m.siteConfig('rbFactory')
  , resourceDirectory = resourceDirectory
  , locale = arguments.m.siteConfig('JavaLocale')
  );
}

Once you've created your custom resource bundle factory, simply use {yourCustomFactoryVariableName}.getKey({yourKey})

So, for example, to output a key of "myCustomString", with a custom factory variable named "customFactory", use the following syntax.

<cfoutput>
#customFactory.getKey('myCustomString')#
</cfoutput>

Lookup Hierarchy

As previously mentioned, Mura will use the following lookup hierarchy when searching for key-value pairs in target ".properties" files.

  1. {customResourceBundleDirectory}/
  2. {context}/{SiteID}/includes/themes/{ThemeName}/resourceBundles/
  3. {context}/{SiteID}/includes/resourceBundles/
  4. {context}/requirements/mura/resourceBundles/resources/