use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class DefaultTranslationBundleContextTest method before.
@Before
public void before() throws Exception {
this.mockExecutionContext = new ExecutionContext();
Execution mockExecution = this.mocker.getInstance(Execution.class);
when(mockExecution.getContext()).thenReturn(mockExecutionContext);
this.mockModelContext = this.mocker.getInstance(ModelContext.class);
when(this.mockModelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki"));
this.mockContextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class XWikiDocument method backupContext.
public static void backupContext(Map<String, Object> backup, XWikiContext context) {
// The XWiki Context isn't recreated when the Execution Context is cloned so we have to backup some of its data.
// Backup the current document on the XWiki Context.
backup.put("doc", context.getDoc());
backup.put("cdoc", context.get("cdoc"));
backup.put("tdoc", context.get("tdoc"));
// Backup the secure document
backup.put(CKEY_SDOC, context.get(CKEY_SDOC));
// Clone the Execution Context to provide isolation. The clone will have a new Velocity and Script Context.
Execution execution = Utils.getComponent(Execution.class);
try {
execution.pushContext(Utils.getComponent(ExecutionContextManager.class).clone(execution.getContext()));
} catch (ExecutionContextException e) {
throw new RuntimeException("Failed to clone the Execution Context", e);
}
// Bridge with old XWiki Context, required for legacy code.
execution.getContext().setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, context);
}
Aggregations