This topic explains the macro language that is used by the COSMOS UI infrastructure.
The COSMOSUI infrastructure makes use of a macro language to allow users to externalize strings found in configuration files into a resource bundle. This provides the following benefit.
Examine the sample configuration file and see how you would use the macro language to externalize strings and use global values.
1 { 2 clazz: "org.eclipse.cosmos.provisional.dr.ps.components.widget.QueryNavigator", 3 query: {nodeClass:'*'}, 4 id:"myTree", 5 initQueryHandler: "json?service=org/eclipse/cosmos/internal/dr/drs/service/outputter/ DomainOutputter&query=initDM&nodeDecorator=org.eclipse.cosmos.examples.dr.drs.service.outputter.NodeDecorator", 6 queriesHandler: "json?service=org/eclipse/cosmos/internal/dr/drs/service/handler/common/QueriesOutputter", 7 cmdbfQueryHandler:"json?service=org/eclipse/cosmos/internal/dr/drs/service/outputter/CMDBfQuery", 8 progressDescription: "Loading Data Managers", 9 publish: ['properties', 'detail'] 10 }
On line 8 a hard-coded English string specifies the progress indicator description. We want to externalize this string so that we can substitute different sting values based on the locale. We accomplish this by changing the configuration file on line 8 and specifying the {$progressDesciprtion} macro as shown in the next sample.
1 { 2 clazz: "org.eclipse.cosmos.provisional.dr.ps.components.widget.QueryNavigator", 3 query: {nodeClass:'*'}, 4 id:"myTree", 5 initQueryHandler: "json?service=org/eclipse/cosmos/internal/dr/drs/service/outputter/ DomainOutputter&query=initDM&nodeDecorator=org.eclipse.cosmos.examples.dr.drs.service.outputter.NodeDecorator", 6 queriesHandler: "json?service=org/eclipse/cosmos/internal/dr/drs/service/handler/common/QueriesOutputter", 7 cmdbfQueryHandler:"json?service=org/eclipse/cosmos/internal/dr/drs/service/outputter/CMDBfQuery", 8 progressDescription: "${progressDescription}", 9 publish: ['properties', 'detail'] 10 }
Macros are defined in properties files that are deployed in the classpath of the web application. These properties files will be loaded as java resource bundles. As a result, a set of property files can be created that are associated with different locales. Following the example you would define a properties file with the following content.
progressDescription = "Loading Data Managers..."
You can use this mechanism to define global macros that can be applied to configuration files. Consider a case where you deployed your data feeds on a server named http://foo:8080. It is cumbersome to change all the configuration files to point to http://foo:8080. However, you can use macros to reference a global configuration value. Consider the following changes to the previous configuration file.
1 { 2 clazz: "org.eclipse.cosmos.provisional.dr.ps.components.widget.QueryNavigator", 3 query: {nodeClass:'*'}, 4 id:"myTree", 5 initQueryHandler: "${baseURL}json?service=org/eclipse/cosmos/internal/dr/drs/service/outputter/ DomainOutputter&query=initDM&nodeDecorator=org.eclipse.cosmos.examples.dr.drs.service.outputter.NodeDecorator", 6 queriesHandler: "${baseURL}json?service=org/eclipse/cosmos/internal/dr/drs/service/handler/common/QueriesOutputter", 7 cmdbfQueryHandler:"${baseURL}json?service=org/eclipse/cosmos/internal/dr/drs/service/outputter/CMDBfQuery", 8 progressDescription: "${progressDescription}", 9 publish: ['properties', 'detail'] 10 }
A ${baseURL} macro is defined to reference the base URL. You can then define a properties file that contains this type of configuration value as follows:
baseURL=http://foo:8080