code: public CmsTemplateContextInfo getContextInfoBean(CmsObject cms, HttpServletRequest request) {
  
          CmsTemplateContextInfo result = new CmsTemplateContextInfo();
          CmsTemplateContext context = (CmsTemplateContext)request.getAttribute(ATTR_TEMPLATE_CONTEXT);
          if (context != null) {
              result.setCurrentContext(context.getKey());
  
              I_CmsTemplateContextProvider provider = context.getProvider();
              Locale locale = OpenCms.getWorkplaceManager().getWorkplaceLocale(cms);
              CmsXmlContentProperty settingDefinition = createTemplateContextsPropertyDefinition(provider, locale);
              result.setSettingDefinition(settingDefinition);
              String cookieName = context.getProvider().getOverrideCookieName();
              if (cookieName != null) {
                  String cookieValue = CmsRequestUtil.getCookieValue(request.getCookies(), cookieName);
                  result.setSelectedContext(cookieValue);
              }
              result.setCookieName(cookieName);
              Map<String, String> niceNames = new LinkedHashMap<String, String>();
              for (Map.Entry<String, CmsTemplateContext> entry : provider.getAllContexts().entrySet()) {
                  CmsTemplateContext otherContext = entry.getValue();
                  String niceName = otherContext.getLocalizedName(locale);
                  niceNames.put(otherContext.getKey(), niceName);
                  for (CmsClientVariant variant : otherContext.getClientVariants().values()) {
                      CmsClientVariantInfo info = new CmsClientVariantInfo(
                          variant.getName(),
                          variant.getNiceName(locale),
                          variant.getScreenWidth(),
                          variant.getScreenHeight(),
                          variant.getParameters());
                      result.setClientVariant(otherContext.getKey(), variant.getName(), info);
                  }
              }
              result.setContextLabels(niceNames);
              result.setContextProvider(provider.getClass().getName());
          }
          Map<String, CmsDefaultSet<String>> allowedContextMap = safeGetAllowedContextMap();
          result.setAllowedContexts(allowedContextMap);
          return result;
      }
docs: Creates a bean with information about the current template context, for use in the client-side code.<p>
  
  @param cms the current CMS context
  @param request the current request
  
  @return the bean with the template context information