Equo Contributions
Equo contributions are a mechanism to contribute new resources or configurations to an app. This resources can be web pages, js scripts or css styles injections, or functions to execute at application start.
There are two ways to define a contribution. The most complex but powerful is to define it in a new Component
using EquoContributionBuilder. The other way is by just creating an equoConfig.json
file in the resources
folder of your app with settings in it.
Contributing from a equoConfig.json
File
Create a equoConfig.json
file in the resources
folder of your app and write in it the contributions you want to add.
For example, you can add the following contributions:
{
"contributions" : [
{
"contributionName" : "Contribution1",
"contributedScripts" : ["script1.js", "script2.js","script3.js"]
},
{
"contributionName" : "Contribution2",
"contributionHtmlName" : "example.html",
"contributedScripts" : ["script01.js", "script02.js","script03.js"]
}
]
}
This will inject all the script*.js
files of the resources
folder inside the Equo app frontend (the web). Additionally, the example.html
file will be loaded when the app browser goes to http://contribution2
.
Check ConfigContribution to see all the available keys for JSON contributions.
Contributing using EquoContributionBuilder
First, create a new component (a Java class with @Component
annotation), get a reference to a EquoContributionBuilder
instance, and define a method to execute at start (@Activate
annotation):
@Component
public class CustomContribution {
@Reference
private EquoContributionBuilder builder;
@Activate
protected void activate() {
}
}
Then, use the builder to define a contribution. It’s important to always set a contribution name and an UrlResolver
to be able to resolve resource paths with it.
For example, let’s say you want to add a custom "script.js" that you have in the resources
folder of our app. The code then will be like:
@Component
public class CustomContribution {
@Reference
private EquoContributionBuilder builder;
@Activate
protected void activate() {
builder.withContributionName("mycustomcontribution").withScriptFile("script.js")
.withUrlResolver(new EquoGenericUrlResolver(CustomContribution.class.getClassLoader()))
.build();
}
}
Real examples can be found in the Equo SDK project, in contributions such as link: LoggingApiContribution.