eForms Core Library for Java developers
The eForms Core Library is a Java library for the tasks that every eForms application has to perform as soon as it works with real notices. This page explains why these tasks are needed, shows how the library performs them, and shows how an application prepares to display a notice. The other pages of this guide give the details.
If eForms and the eForms SDK are new to you, read Understanding the SDK first.
What the library is for
An eForms notice is an XML document that describes a public procurement procedure. Its content is defined by the eForms SDK: the fields that a notice can contain, the codelists of their values, the notice subtypes, the validation rules and the templates that display a notice. Your application needs these files to create, check or display a notice.
The SDK is not a fixed set of files. The Publications Office publishes new versions regularly, and TED accepts each
version for at least twelve months (see Active SDK versions). So
several versions are in use at the same time. Each notice states the version that it was made with, in its element
cbc:CustomizationID, and it must be read with that version. As a result, your application:
-
needs the files of several SDK versions side by side, including versions published after your application;
-
must find out which version each notice uses, before it does anything else with the notice;
-
must read the metadata of the right version: the fields, nodes and codelists of one version differ from those of the next;
-
must sometimes run different code for different versions. Between SDK 1 and SDK 2 the files and the EFX language changed, so part of the code of an application differs between the two.
Every eForms application has to do these tasks. The library does them once, so that you do not have to. The Publications Office develops it and uses it in its own applications: the EFX Toolkit and the Notice Viewer are built on it.
The parts of the library
For each of these tasks, the library has a part that does it:
- Finding out the SDK version of a notice
-
NoticeDocumentreads the SDK version, the notice subtype and the languages from the XML of a notice. See Notices, XPath and other tools. - Having the files of each SDK version
-
SdkDownloaderdownloads a version of the SDK when your application needs it, into a folder of its own, andSdkResourceLoadergives you the path to any of its files. See Downloading and loading SDKs. - Reading the metadata of a version
-
The repositories read the fields, nodes, data types, codelists and notice subtypes of a version into Java objects. They give the same objects for SDK 1 and SDK 2, although the files differ. See Reading the SDK metadata.
- Running the right code for each major version
-
You write one class for each major version and mark it with the annotation
@SdkComponent. A factory then creates the right one for the version of the notice. See Components for each SDK version.
Preparing to display a notice
The example below prepares what an application needs to display a notice: the files and the metadata of its SDK version, and the code written for its major version. It uses the four parts in the order in which an application needs them:
// 1. Find out which SDK version the notice uses, for example "1.16" or "2.0".
NoticeDocument notice = new NoticeDocument(Path.of("notice.xml"));
String sdkVersion = notice.getEformsSdkVersion();
// 2. Make sure that the files of this version are on disk.
Path sdkRoot = Path.of("eforms-sdk");
SdkDownloader.downloadSdk(sdkVersion, sdkRoot);
Path sdkPath = SdkResourceLoader.getResourceAsPath(sdkVersion, null, sdkRoot);
// 3. Read the fields and nodes of this version.
SdkNodeRepository nodes = SdkRepositoryFactory.getSdkNodeRepository(sdkVersion, sdkPath);
SdkFieldRepository fields = SdkRepositoryFactory.getSdkFieldRepository(sdkVersion, sdkPath, nodes);
// 4. Create the generator written for the major version of the notice.
HtmlGenerator generator = HtmlGeneratorFactory.getHtmlGenerator(sdkVersion, "en");
HtmlGenerator and HtmlGeneratorFactory stand for code of your own application: an interface, one implementation
for each major version, and a factory (see
Components for each SDK version). The same code
handles a notice of SDK 1.16 and a notice of SDK 2.0: the first time, the library downloads each version, and from
then on each notice is read with its own version.
Your application then uses the XML of the notice, the metadata and the generator to display the notice. The library does not display notices itself: it gives your application what it needs to do so.
Versions
Version 2 of the library goes with SDK 2. It is still a pre-release: the final version 2.0.0 will come with the final release of SDK 2.0.0. Version 2 requires Java 21 or later.
Version 2 reads the files of both major versions of the SDK, 1 and 2: it has its own classes for each of them. Version 1.10.0 is the last release of version 1, which receives no more updates.
Adding the library to your project
The library is published on Maven Central. Add the dependency to the pom.xml file of your project, with the version
that you need, for example the pre-release 2.0.0-alpha.1:
<dependency>
<groupId>eu.europa.ted.eforms</groupId>
<artifactId>eforms-core-java</artifactId>
<version>2.0.0-alpha.1</version>
</dependency>
The source code is available on GitHub. You can propose improvements and corrections there through pull requests.