@Test public void getServletContext() { this.oldcore.getXWikiContext().setRequest(new XWikiServletRequestStub() { @Override public ServletContext getServletContext() { return mock(ServletContext.class); } }); this.initializer.initialize(this.scriptContext); XWikiRequest request = (XWikiRequest) this.scriptContext.getAttribute("request"); when(authorization.hasAccess(Right.PROGRAM)).thenReturn(true); assertNotNull(request.getServletContext()); when(authorization.hasAccess(Right.PROGRAM)).thenReturn(false); assertNull(request.getServletContext()); }
@Override public void initialize(ScriptContext scriptContext) { XWikiContext xcontext = this.xcontextProvider.get(); if (scriptContext.getAttribute("util") == null) { scriptContext.setAttribute("util", new com.xpn.xwiki.api.Util(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xwiki", new XWiki(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("request", new ScriptXWikiServletRequest(xcontext.getRequest(), this.authorization), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("response", xcontext.getResponse(), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xcontext", new Context(xcontext), ScriptContext.ENGINE_SCOPE); } Document docAPI = null; XWikiDocument doc = xcontext.getDoc(); if (doc != null) { docAPI = setDocument(scriptContext, "doc", doc, xcontext); XWikiDocument tdoc = (XWikiDocument) xcontext.get("tdoc"); if (tdoc == null) { try { tdoc = doc.getTranslatedDocument(xcontext); } catch (XWikiException e) { this.logger.warn("Failed to retrieve the translated document for [{}]. " + "Continue using the default translation.", doc.getDocumentReference(), e); tdoc = doc; } } Document tdocAPI = setDocument(scriptContext, "tdoc", tdoc, xcontext); XWikiDocument cdoc = (XWikiDocument) xcontext.get("cdoc"); if (cdoc == null) { Document cdocAPI = tdocAPI; if (cdocAPI == null) { cdocAPI = docAPI; } scriptContext.setAttribute("cdoc", cdocAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "cdoc", cdoc, xcontext); } } XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc"); if (sdoc == null) { scriptContext.setAttribute("sdoc", docAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "sdoc", sdoc, xcontext); } scriptContext.setAttribute("locale", xcontext.getLocale(), ScriptContext.ENGINE_SCOPE); }
XWikiScriptContextInitializer implements ScriptContextInitializer { @Override public void initialize(ScriptContext scriptContext) { XWikiContext xcontext = this.xcontextProvider.get(); if (scriptContext.getAttribute("util") == null) { scriptContext.setAttribute("util", new com.xpn.xwiki.api.Util(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xwiki", new XWiki(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("request", new ScriptXWikiServletRequest(xcontext.getRequest(), this.authorization), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("response", xcontext.getResponse(), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xcontext", new Context(xcontext), ScriptContext.ENGINE_SCOPE); } Document docAPI = null; XWikiDocument doc = xcontext.getDoc(); if (doc != null) { docAPI = setDocument(scriptContext, "doc", doc, xcontext); XWikiDocument tdoc = (XWikiDocument) xcontext.get("tdoc"); if (tdoc == null) { try { tdoc = doc.getTranslatedDocument(xcontext); } catch (XWikiException e) { this.logger.warn("Failed to retrieve the translated document for [{}]. " + "Continue using the default translation.", doc.getDocumentReference(), e); tdoc = doc; } } Document tdocAPI = setDocument(scriptContext, "tdoc", tdoc, xcontext); XWikiDocument cdoc = (XWikiDocument) xcontext.get("cdoc"); if (cdoc == null) { Document cdocAPI = tdocAPI; if (cdocAPI == null) { cdocAPI = docAPI; } scriptContext.setAttribute("cdoc", cdocAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "cdoc", cdoc, xcontext); } } XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc"); if (sdoc == null) { scriptContext.setAttribute("sdoc", docAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "sdoc", sdoc, xcontext); } scriptContext.setAttribute("locale", xcontext.getLocale(), ScriptContext.ENGINE_SCOPE); } }
XWikiScriptContextInitializer implements ScriptContextInitializer { @Override public void initialize(ScriptContext scriptContext) { XWikiContext xcontext = this.xcontextProvider.get(); if (scriptContext.getAttribute("util") == null) { scriptContext.setAttribute("util", new com.xpn.xwiki.api.Util(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xwiki", new XWiki(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("request", new ScriptXWikiServletRequest(xcontext.getRequest(), this.authorization), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("response", xcontext.getResponse(), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xcontext", new Context(xcontext), ScriptContext.ENGINE_SCOPE); } Document docAPI = null; XWikiDocument doc = xcontext.getDoc(); if (doc != null) { docAPI = setDocument(scriptContext, "doc", doc, xcontext); XWikiDocument tdoc = (XWikiDocument) xcontext.get("tdoc"); if (tdoc == null) { try { tdoc = doc.getTranslatedDocument(xcontext); } catch (XWikiException e) { this.logger.warn("Failed to retrieve the translated document for [{}]. " + "Continue using the default translation.", doc.getDocumentReference(), e); tdoc = doc; } } Document tdocAPI = setDocument(scriptContext, "tdoc", tdoc, xcontext); XWikiDocument cdoc = (XWikiDocument) xcontext.get("cdoc"); if (cdoc == null) { Document cdocAPI = tdocAPI; if (cdocAPI == null) { cdocAPI = docAPI; } scriptContext.setAttribute("cdoc", cdocAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "cdoc", cdoc, xcontext); } } XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc"); if (sdoc == null) { scriptContext.setAttribute("sdoc", docAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "sdoc", sdoc, xcontext); } scriptContext.setAttribute("locale", xcontext.getLocale(), ScriptContext.ENGINE_SCOPE); }  }
XWikiScriptContextInitializer implements ScriptContextInitializer { @Override public void initialize(ScriptContext scriptContext) { XWikiContext xcontext = this.xcontextProvider.get(); if (scriptContext.getAttribute("util") == null) { scriptContext.setAttribute("util", new com.xpn.xwiki.api.Util(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xwiki", new XWiki(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("request", new ScriptXWikiServletRequest(xcontext.getRequest(), this.authorization), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("response", xcontext.getResponse(), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xcontext", new Context(xcontext), ScriptContext.ENGINE_SCOPE); } Document docAPI = null; XWikiDocument doc = xcontext.getDoc(); if (doc != null) { docAPI = setDocument(scriptContext, "doc", doc, xcontext); XWikiDocument tdoc = (XWikiDocument) xcontext.get("tdoc"); if (tdoc == null) { try { tdoc = doc.getTranslatedDocument(xcontext); } catch (XWikiException e) { this.logger.warn("Failed to retrieve the translated document for [{}]. " + "Continue using the default translation.", doc.getDocumentReference(), e); tdoc = doc; } } Document tdocAPI = setDocument(scriptContext, "tdoc", tdoc, xcontext); XWikiDocument cdoc = (XWikiDocument) xcontext.get("cdoc"); if (cdoc == null) { Document cdocAPI = tdocAPI; if (cdocAPI == null) { cdocAPI = docAPI; } scriptContext.setAttribute("cdoc", cdocAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "cdoc", cdoc, xcontext); } } XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc"); if (sdoc == null) { scriptContext.setAttribute("sdoc", docAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "sdoc", sdoc, xcontext); } scriptContext.setAttribute("locale", xcontext.getLocale(), ScriptContext.ENGINE_SCOPE); }  @Override void initialize(ScriptContext scriptContext); }
XWikiScriptContextInitializer implements ScriptContextInitializer { @Override public void initialize(ScriptContext scriptContext) { XWikiContext xcontext = this.xcontextProvider.get(); if (scriptContext.getAttribute("util") == null) { scriptContext.setAttribute("util", new com.xpn.xwiki.api.Util(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xwiki", new XWiki(xcontext.getWiki(), xcontext), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("request", new ScriptXWikiServletRequest(xcontext.getRequest(), this.authorization), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("response", xcontext.getResponse(), ScriptContext.ENGINE_SCOPE); scriptContext.setAttribute("xcontext", new Context(xcontext), ScriptContext.ENGINE_SCOPE); } Document docAPI = null; XWikiDocument doc = xcontext.getDoc(); if (doc != null) { docAPI = setDocument(scriptContext, "doc", doc, xcontext); XWikiDocument tdoc = (XWikiDocument) xcontext.get("tdoc"); if (tdoc == null) { try { tdoc = doc.getTranslatedDocument(xcontext); } catch (XWikiException e) { this.logger.warn("Failed to retrieve the translated document for [{}]. " + "Continue using the default translation.", doc.getDocumentReference(), e); tdoc = doc; } } Document tdocAPI = setDocument(scriptContext, "tdoc", tdoc, xcontext); XWikiDocument cdoc = (XWikiDocument) xcontext.get("cdoc"); if (cdoc == null) { Document cdocAPI = tdocAPI; if (cdocAPI == null) { cdocAPI = docAPI; } scriptContext.setAttribute("cdoc", cdocAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "cdoc", cdoc, xcontext); } } XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc"); if (sdoc == null) { scriptContext.setAttribute("sdoc", docAPI, ScriptContext.ENGINE_SCOPE); } else { setDocument(scriptContext, "sdoc", sdoc, xcontext); } scriptContext.setAttribute("locale", xcontext.getLocale(), ScriptContext.ENGINE_SCOPE); }  @Override void initialize(ScriptContext scriptContext);  }