use of org.xwiki.observation.event.CancelableEvent in project xwiki-platform by xwiki.
the class NestedScriptMacroValidatorTest method testNoNestedScriptInHtml.
@Test
public void testNoNestedScriptInHtml() throws Exception {
MacroTransformationContext context = buildContext("script", "html", "script");
CancelableEvent event = new ScriptEvaluatingEvent();
this.validator.onEvent(event, context, null);
Assert.assertTrue(event.isCanceled());
}
use of org.xwiki.observation.event.CancelableEvent 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.observation.event.CancelableEvent 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.observation.event.CancelableEvent 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());
}
use of org.xwiki.observation.event.CancelableEvent in project xwiki-platform by xwiki.
the class DocumentsDeletingListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
Job job = (Job) source;
if (!job.getRequest().isInteractive()) {
logger.warn("XAR Extension Documents Deleting Listener will not check the document in non-interactive mode.");
return;
}
// Check if some pages belong to extensions
Map<EntityReference, EntitySelection> concernedEntities = (Map<EntityReference, EntitySelection>) data;
ExtensionBreakingQuestion question = new ExtensionBreakingQuestion(concernedEntities);
for (EntitySelection entitySelection : concernedEntities.values()) {
if (entitySelection.getEntityReference() instanceof DocumentReference) {
checkIfPageBelongToExtensions(entitySelection, question);
}
}
// Ask a confirmation to the user if some pages belong to extensions
if (!question.getExtensions().isEmpty()) {
// Conservative choice: we let the user enable the pages to delete.
question.unselectAll();
try {
// The user can modify the question so it could disable some EntitySelection.
// We add a timeout because when a refactoring job is running, it prevents others to run.
// 5 minutes is probably enough for the user to decide if the process should go on.
boolean ack = job.getStatus().ask(question, 5, TimeUnit.MINUTES);
if (!ack) {
// Without any confirmation, we must cancel the operation.
String message = "The question has been asked, however no answer has been received.";
this.logger.warn(message);
CancelableEvent cancelableEvent = (CancelableEvent) event;
cancelableEvent.cancel(message);
}
} catch (InterruptedException e) {
this.logger.warn("Confirm question has been interrupted.");
CancelableEvent cancelableEvent = (CancelableEvent) event;
cancelableEvent.cancel("Question has been interrupted.");
}
}
}
Aggregations