EFX Toolkit for Java Developers
The EFX Toolkit for Java developers is a library that enables the transpilation of EFX expressions and templates to different target languages. The library, which is created and used by the Publications Office in its TED applications, is available on Github, for eForms application developers that work with Java. You are encouraged to use the library in your applications as well as to contribute to its development with pull requests, any improvements or fixes you want to share with us and other developers.
EfxExpressionTranslator class is intended to translate EFX expressions to any target scripting language. It extends the
EfxBaseListener generated by ANTLR4, and uses the
EfxParser to process any given EFX expression.
To enable translation to different target scripting languages, it relies on implementations of the
ScriptGenerator interfaces. The
SymbolResolver is responsible for resolving field names to their metadata (XPaths, data types etc.). The
ScriptGenerator is responsible for providing the target scripting language’s syntax for a set of common expressions (performing calculations, logical operations, string concatenation etc.).
EfxTemplateTranslator extends the
EfxExpressionTranslator to add the capability of transpiling EFX templates to a target markup language.
Apart from the dependencies of its base class, the
EfxTemplateTranslator relies on implementations of the
MarkupGenerator interface to provide the target markup language’s syntax for specific parts of the final output (rendering content blocks, labels, variables, etc.).
The EFX Toolkit contains the
XPathScriptGenerator class which is an implementation of the
ScriptGenerator interface in your own class. This will allow you to reuse the provided
EfxExpressionTranslator, and retarget it to the scripting language of your choice with minimal effort.
An implementation of the
MarkupGenerator interface that targets XSLT can also be found in the Notice Viewer sample application (
XslMarkupGenerator). For other target markup languages you can implement the interface in your own class so that you can reuse the existing
Finally, an implementation of the
SymbolResolver interface that uses directly the eForms SDK can also be found in the Notice Viewer Sample application. If however, you organise the eForms metadata provided with the SDK to your own custom metadata repository, then you can implement the same interface in your own class and reuse the existing translators.
Implementing these three interfaces (or reusing the existing ones) should be enough for you to be able to translate EFX expressions and templates for your target runtime environment. For more details on implementing these interfaces follow this link.
The EFX Toolkit is designed to be used with all versions of the eForms SDK starting from version 0.6.0. To make the selection of the required version of the SDK for each transpilation call, the
EfxTranslator class is provided. It’s purpose is to make the whole complexity of loading and using the correct metadata transparent to the developer. You only need to pass the version number of the SDK that you need as a parameter to each transpilation call. The eForms SDK version number used to create a specific notice for example can be found inside the
<cbc:CustomizationID> tag inside the notice XML. If you pass this to the transpiler, the proper version of the SDK will be used automatically to process the notice.
|Currently there is only one version of the eForms SDK that supports EFX. For this reason the implementation of the automatic SDK version selection system in the EFX Toolkit is not yet fully implemented. It will be fully in place when SDK 0.7.0 will be released.|