Search in sources :

Example 1 with XWikiServletContext

use of com.xpn.xwiki.web.XWikiServletContext in project xwiki-platform by xwiki.

the class XWikiContextInitializationFilter method initializeXWikiContext.

/**
 * Initializes the XWiki context.
 *
 * @param request the request being processed
 * @param response the response
 * @throws ServletException if the initialization fails
 */
protected void initializeXWikiContext(ServletRequest request, ServletResponse response) throws ServletException {
    try {
        // Not all request types specify an action (e.g. GWT-RPC) so we default to the empty string.
        String action = "";
        XWikiServletContext xwikiEngine = new XWikiServletContext(this.filterConfig.getServletContext());
        XWikiServletRequest xwikiRequest = new XWikiServletRequest((HttpServletRequest) request);
        XWikiServletResponse xwikiResponse = new XWikiServletResponse((HttpServletResponse) response);
        // Create the XWiki context.
        XWikiContext context = Utils.prepareContext(action, xwikiRequest, xwikiResponse, xwikiEngine);
        // parameter is specified.
        if (this.mode >= 0) {
            context.setMode(this.mode);
        }
        // Initialize the Container component which is the new way of transporting the Context in the new component
        // architecture. Further initialization might require the Container component.
        initializeContainerComponent(context);
        // Initialize the XWiki database. XWiki#getXWiki(XWikiContext) calls XWikiContext.setWiki(XWiki).
        XWiki xwiki = XWiki.getXWiki(context);
        // Initialize the URL factory.
        context.setURLFactory(xwiki.getURLFactoryService().createURLFactory(context.getMode(), context));
        // Prepare the localized resources, according to the selected language.
        xwiki.prepareResources(context);
        // Initialize the current user.
        XWikiUser user = context.getWiki().checkAuth(context);
        if (user != null) {
            DocumentReferenceResolver<String> documentReferenceResolver = Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "explicit");
            SpaceReference defaultUserSpace = new SpaceReference(XWiki.SYSTEM_SPACE, new WikiReference(context.getWikiId()));
            DocumentReference userReference = documentReferenceResolver.resolve(user.getUser(), defaultUserSpace);
            context.setUserReference(XWikiRightService.GUEST_USER.equals(userReference.getName()) ? null : userReference);
        }
    } catch (XWikiException e) {
        throw new ServletException("Failed to initialize the XWiki context.", e);
    }
}
Also used : XWikiServletRequest(com.xpn.xwiki.web.XWikiServletRequest) XWikiServletResponse(com.xpn.xwiki.web.XWikiServletResponse) SpaceReference(org.xwiki.model.reference.SpaceReference) XWikiServletContext(com.xpn.xwiki.web.XWikiServletContext) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) ServletException(javax.servlet.ServletException) XWikiUser(com.xpn.xwiki.user.api.XWikiUser) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with XWikiServletContext

use of com.xpn.xwiki.web.XWikiServletContext in project xwiki-platform by xwiki.

the class DefaultXWikiContextInitializer method initializeXWikiContext.

private static XWikiContext initializeXWikiContext(HttpServletRequest request, HttpServletResponse response) throws XWikiException {
    XWikiServletContext xwikiEngine = new XWikiServletContext(request.getServletContext());
    XWikiServletRequest xwikiRequest = new XWikiServletRequest(request);
    XWikiServletResponse xwikiResponse = new XWikiServletResponse(response);
    // Create the XWiki context.
    XWikiContext context = Utils.prepareContext("", xwikiRequest, xwikiResponse, xwikiEngine);
    // Initialize the XWiki database. XWiki#getXWiki(XWikiContext) calls XWikiContext.setWiki(XWiki).
    XWiki xwiki = XWiki.getXWiki(context);
    // Initialize the URL factory.
    context.setURLFactory(xwiki.getURLFactoryService().createURLFactory(context.getMode(), context));
    // Prepare the localized resources, according to the selected language.
    xwiki.prepareResources(context);
    return context;
}
Also used : XWikiServletRequest(com.xpn.xwiki.web.XWikiServletRequest) XWikiServletResponse(com.xpn.xwiki.web.XWikiServletResponse) XWikiServletContext(com.xpn.xwiki.web.XWikiServletContext) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki)

Aggregations

XWiki (com.xpn.xwiki.XWiki)2 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiServletContext (com.xpn.xwiki.web.XWikiServletContext)2 XWikiServletRequest (com.xpn.xwiki.web.XWikiServletRequest)2 XWikiServletResponse (com.xpn.xwiki.web.XWikiServletResponse)2 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiUser (com.xpn.xwiki.user.api.XWikiUser)1 ServletException (javax.servlet.ServletException)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 SpaceReference (org.xwiki.model.reference.SpaceReference)1 WikiReference (org.xwiki.model.reference.WikiReference)1