Search in sources :

Example 6 with ScriptEvaluatingEvent

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;
}
Also used : ScriptEvaluatedEvent(org.xwiki.script.event.ScriptEvaluatedEvent) ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) MacroBlock(org.xwiki.rendering.block.MacroBlock) Block(org.xwiki.rendering.block.Block)

Example 7 with ScriptEvaluatingEvent

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());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Example 8 with ScriptEvaluatingEvent

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());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Example 9 with ScriptEvaluatingEvent

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());
}
Also used : ScriptEvaluatingEvent(org.xwiki.script.event.ScriptEvaluatingEvent) MacroTransformationContext(org.xwiki.rendering.transformation.MacroTransformationContext) CancelableEvent(org.xwiki.observation.event.CancelableEvent) Test(org.junit.Test)

Aggregations

ScriptEvaluatingEvent (org.xwiki.script.event.ScriptEvaluatingEvent)9 CancelableEvent (org.xwiki.observation.event.CancelableEvent)5 MacroTransformationContext (org.xwiki.rendering.transformation.MacroTransformationContext)5 Test (org.junit.Test)4 ScriptEvaluatedEvent (org.xwiki.script.event.ScriptEvaluatedEvent)3 Event (org.xwiki.observation.event.Event)2 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 LinkedList (java.util.LinkedList)1 Expectations (org.jmock.Expectations)1 Mockery (org.jmock.Mockery)1 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)1 ExtendedURLClassLoader (org.xwiki.classloader.ExtendedURLClassLoader)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EventListener (org.xwiki.observation.EventListener)1 Block (org.xwiki.rendering.block.Block)1 MacroBlock (org.xwiki.rendering.block.MacroBlock)1 ScriptMacroParameters (org.xwiki.rendering.macro.script.ScriptMacroParameters)1