@Override
 public boolean beforeController(
     final HttpServletRequest request,
     final HttpServletResponse response,
     final HandlerMethod handler) {
   // Detect the device information for the current request
   deviceDetectionFacade.initializeRequest(request);
   return true;
 }
  @Override
  public void beforeView(
      final HttpServletRequest request,
      final HttpServletResponse response,
      final ModelAndView modelAndView) {
    final CMSSiteModel currentSite = cmsSiteService.getCurrentSite();

    final String siteName = currentSite.getUid();
    final String themeName = getThemeNameForSite(currentSite);
    final String uiExperienceCode = uiExperienceService.getUiExperienceLevel().getCode();
    final String uiExperienceCodeLower =
        uiExperienceViewResolver.getUiExperienceViewPrefix().isEmpty()
            ? uiExperienceCode.toLowerCase()
            : StringUtils.remove(
                uiExperienceViewResolver
                    .getUiExperienceViewPrefix()
                    .get(uiExperienceService.getUiExperienceLevel()),
                "/");
    final Object urlEncodingAttributes = request.getAttribute(WebConstants.URL_ENCODING_ATTRIBUTES);
    final String contextPath =
        StringUtils.remove(
            request.getContextPath(),
            (urlEncodingAttributes != null) ? urlEncodingAttributes.toString() : "");

    final String siteRootUrl = contextPath + "/_ui/" + uiExperienceCodeLower;
    final String sharedResourcePath = contextPath + "/_ui/" + SHARED;
    final String siteResourcePath = siteRootUrl + "/site-" + siteName;
    final String themeResourcePath = siteRootUrl + "/theme-" + themeName;
    final String commonResourcePath = siteRootUrl + "/" + COMMON;
    final String encodedContextPath = request.getContextPath();
    final LanguageModel currentLanguage = commerceCommonI18NService.getCurrentLanguage();

    modelAndView.addObject("contextPath", contextPath);
    modelAndView.addObject("sharedResourcePath", sharedResourcePath);
    modelAndView.addObject("siteResourcePath", siteResourcePath);
    modelAndView.addObject("themeResourcePath", themeResourcePath);
    modelAndView.addObject("commonResourcePath", commonResourcePath);
    modelAndView.addObject("encodedContextPath", encodedContextPath);
    modelAndView.addObject("siteRootUrl", siteRootUrl);
    modelAndView.addObject(
        "language", (currentLanguage != null ? currentLanguage.getIsocode() : "en"));
    modelAndView.addObject("CSRFToken", CSRFTokenManager.getTokenForSession(request.getSession()));

    modelAndView.addObject("uiExperienceLevel", uiExperienceCode);

    final String detectedUiExperienceCode =
        uiExperienceService.getDetectedUiExperienceLevel().getCode();
    modelAndView.addObject("detectedUiExperienceCode", detectedUiExperienceCode);

    final UiExperienceLevel overrideUiExperienceLevel =
        uiExperienceService.getOverrideUiExperienceLevel();
    if (overrideUiExperienceLevel == null) {
      modelAndView.addObject("uiExperienceOverride", Boolean.FALSE);
    } else {
      modelAndView.addObject("uiExperienceOverride", Boolean.TRUE);
      modelAndView.addObject("overrideUiExperienceCode", overrideUiExperienceLevel.getCode());
    }

    final DeviceData currentDetectedDevice = deviceDetectionFacade.getCurrentDetectedDevice();
    modelAndView.addObject("detectedDevice", currentDetectedDevice);

    final List<String> dependantAddOns =
        requiredAddOnsNameProvider.getAddOns(
            request.getSession().getServletContext().getServletContextName());

    modelAndView.addObject(
        "addOnCommonCssPaths",
        getAddOnCommonCSSPaths(contextPath, uiExperienceCodeLower, dependantAddOns));
    modelAndView.addObject(
        "addOnThemeCssPaths",
        getAddOnThemeCSSPaths(contextPath, themeName, uiExperienceCodeLower, dependantAddOns));
    modelAndView.addObject(
        "addOnJavaScriptPaths",
        getAddOnJSPaths(contextPath, siteName, uiExperienceCodeLower, dependantAddOns));
  }