use of org.xwiki.rendering.macro.velocity.filter.VelocityMacroFilter in project xwiki-platform by xwiki.
the class VelocityMacro method getFilter.
/**
* @param parameters the velocity macros parameters
* @return the velocity content filter
* @since 2.0M1
*/
private VelocityMacroFilter getFilter(VelocityMacroParameters parameters) {
String filterName = parameters.getFilter();
if (StringUtils.isEmpty(filterName)) {
filterName = this.configuration.getFilter();
if (StringUtils.isEmpty(filterName)) {
filterName = null;
}
}
VelocityMacroFilter filter = null;
if (filterName != null) {
try {
filter = getComponentManager().getInstance(VelocityMacroFilter.class, filterName);
} catch (ComponentLookupException e) {
this.logger.error("Can't find velocity macro filter", e);
}
}
return filter;
}
use of org.xwiki.rendering.macro.velocity.filter.VelocityMacroFilter in project xwiki-platform by xwiki.
the class VelocityMacro method evaluateString.
@Override
protected String evaluateString(VelocityMacroParameters parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
String result = "";
try {
VelocityContext velocityContext = this.velocityManager.getCurrentVelocityContext();
VelocityMacroFilter filter = getFilter(parameters);
String cleanedContent = content;
// Execute pre filter
if (filter != null) {
cleanedContent = filter.before(cleanedContent, velocityContext);
}
StringWriter writer = new StringWriter();
// Use the Transformation id as the name passed to the Velocity Engine. This name is used internally
// by Velocity as a cache index key for caching macros.
String key = context.getTransformationContext().getId();
if (key == null) {
key = "unknown namespace";
}
// Execute Velocity context
this.velocityManager.evaluate(writer, key, new StringReader(cleanedContent));
result = writer.toString();
// Execute post filter
if (filter != null) {
result = filter.after(result, velocityContext);
}
} catch (XWikiVelocityException e) {
throw new MacroExecutionException("Failed to evaluate Velocity Macro for content [" + content + "]", e);
}
return result;
}
Aggregations