Improvement for implementation velocity in FraSCAti. Add the possibility to use templates in a tree organisation.
Improvement for implementation velocity in FraSCAti (ProxyImplementationVelocity.java).
Here is the original code : http://websvn.ow2.org/filedetails.php?repname=frascati&path=%2Ftrunk%2Ffrascati%2Fmodules%2Ffrascati-implementation-velocity%2Fsrc%2Fmain%2Fjava%2Forg%2Fow2%2Ffrascati%2Fimplementation%2Fvelocity%2FServletImplementationVelocity.java
The proposition is to add this portion of code to offer the possibility to load Velocity templates not only in a base folder but also in a folder tree.
Here is the code addition to solve this problem (can be found also on GitHub : https://github.com/easysoa/EasySOA/blob/master/easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy/src/main/java/org/ow2/frascati/implementation/velocity/ProxyImplementationVelocity.java)
.... protected final String invoke(String method, VelocityContext context, String[] args, Object... parameters) { // VelocityContext context = new VelocityContext(this.velocityContext); context.put(params, parameters); // FIXME: should not be called but @Lifecycle does not work as expected. registerScaProperties(); StringWriter sw = new StringWriter();
// **** EasySOA Hack begin
int pathArgIndex = Integer.parseInt((String) context.get("pathArgIndex")); // pathArgIndex has been set as an SCA xsd:int property
int storeIndex = Integer.parseInt((String) context.get("storeIndex")); // storeIndex has been set as an SCA xsd:int property
Template template = null;
if (parameters.length > pathArgIndex) {
Object templatePathFound = parameters[pathArgIndex];
Object storeNameFound = parameters[storeIndex];
if (templatePathFound instanceof String) {
template = this.velocityEngine.getTemplate((String)storeNameFound + "/" + (String) templatePathFound);
}
}
// *** EasySOA Hack end
if (template == null) {
String name = this.velocityEngine.templateExists(method + ".vm") ? method + ".vm" : this.defaultResource;
template = this.velocityEngine.getTemplate(name);
}
if (!this.velocityEngine.invokeVelocimacro(method, method, args, context, sw)) {
template.merge(context, sw);
.....
Currently, the method parameter contains the name of the velocity template to use. It is not possible to call templates in an other folder or in a folder tree organisation.
The hack uses 2 properties to set the array position of 2 parameters "pathArgIndex" and "storeIndex". The "pathArgIndex" parameter contains the folder where to find the "storeIndex" template.
An other solution is to have a special method name (eg : folder1_folder2_template) to pass the informations.
A third solution is to use a special method name, allowing to pass special params, to be able get templates in a tree folder organisation.