use of org.xwiki.script.event.ScriptEvaluatingEvent in project xwiki-platform by xwiki.
the class AbstractScriptMacro method execute.
@Override
public List<Block> execute(P parameters, String content, MacroTransformationContext context) throws MacroExecutionException {
List<Block> result = Collections.emptyList();
if (StringUtils.isNotEmpty(content)) {
try {
// send evaluation starts event
ScriptEvaluatingEvent event = new ScriptEvaluatingEvent(getDescriptor().getId().getId());
this.observation.notify(event, context, parameters);
if (event.isCanceled()) {
throw new MacroExecutionException(event.getReason());
}
// 2) Run script engine on macro block content
List<Block> blocks = evaluateBlock(parameters, content, context);
if (parameters.isOutput()) {
result = blocks;
}
} finally {
// send evaluation finished event
this.observation.notify(new ScriptEvaluatedEvent(getDescriptor().getId().getId()), context, parameters);
}
}
return result;
}
use of org.xwiki.script.event.ScriptEvaluatingEvent in project xwiki-platform by xwiki.
the class NestedScriptMacroValidatorTest method testNoNestedScript.
@Test
public void testNoNestedScript() throws Exception {
MacroTransformationContext context = buildContext("script", "script");
CancelableEvent event = new ScriptEvaluatingEvent();
this.validator.onEvent(event, context, null);
Assert.assertTrue(event.isCanceled());
}
use of org.xwiki.script.event.ScriptEvaluatingEvent in project xwiki-platform by xwiki.
the class NestedScriptMacroValidatorTest method testNestedScriptMacroEnabledInterceptsNestedChain.
@Test
public void testNestedScriptMacroEnabledInterceptsNestedChain() throws Exception {
MacroTransformationContext context = buildContext("script", "nestedscriptmacroenabled", "script");
CancelableEvent event = new ScriptEvaluatingEvent();
this.validator.onEvent(event, context, null);
Assert.assertFalse(event.isCanceled());
}
use of org.xwiki.script.event.ScriptEvaluatingEvent in project xwiki-platform by xwiki.
the class NestedScriptMacroValidatorTest method testIncludeInterceptsNestedChain.
@Test
public void testIncludeInterceptsNestedChain() throws Exception {
MacroTransformationContext context = buildContext("script", "include", "script");
CancelableEvent event = new ScriptEvaluatingEvent();
this.validator.onEvent(event, context, null);
Assert.assertFalse(event.isCanceled());
}
Aggregations