protected String getCurrentSiteUid() {
    final CMSSiteModel siteModel = getCmsSiteService().getCurrentSite();
    Preconditions.checkNotNull(siteModel, "Could not find current site");

    final String siteUid = siteModel.getUid();
    Preconditions.checkNotNull(siteUid, "Site uid for  current site " + siteModel + " is empty");
    return siteUid;
  }
 @Override
 public void setModel(final BrowserModel model) {
   if (model instanceof DefaultLiveEditBrowserModel) {
     final CMSSiteModel currentSite =
         ((DefaultLiveEditBrowserArea) model.getArea()).getCurrentSite();
     if (currentSite != null) {
       ((DefaultLiveEditBrowserModel) model).setCurrentUrl(currentSite.getPreviewURL());
     }
   }
   super.setModel(model);
 }
  protected String determineDefaultThemeName() {
    final UiExperienceLevel uiExperienceLevel = getUiExperienceService().getUiExperienceLevel();

    // Resolve Theme from CMSSiteService
    final CMSSiteModel currentSite = getCmsSiteService().getCurrentSite();
    if (currentSite != null) {
      return combineSiteAndTheme(
          uiExperienceLevel.getCode(), currentSite.getUid(), getThemeNameForSite(currentSite));
    }
    return null;
  }
Пример #4
0
  public void init(final CMSSiteModel site, final SiteMapPageEnum siteMapPageEnum) {
    final String currentUrlEncodingPattern = getUrlEncoderService().getCurrentUrlEncodingPattern();
    this.put(
        BASE_URL,
        getSiteBaseUrlResolutionService()
            .getWebsiteUrlForSite(site, currentUrlEncodingPattern, false, ""));
    this.put(MEDIA_URL, getSiteBaseUrlResolutionService().getMediaUrlForSite(site, false, ""));

    final Collection<SiteMapPageModel> siteMapPages = site.getSiteMapConfig().getSiteMapPages();
    final SiteMapPageModel siteMapPageModel =
        (SiteMapPageModel)
            CollectionUtils.find(
                siteMapPages,
                new Predicate() {
                  @Override
                  public boolean evaluate(final Object o) {
                    return ((SiteMapPageModel) o).getCode().equals(siteMapPageEnum);
                  }
                });

    if (siteMapPageModel != null) {
      this.put(CHANGE_FREQ, siteMapPageModel.getFrequency().getCode());
      this.put(PRIORITY, siteMapPageModel.getPriority());
    } else {
      this.put(CHANGE_FREQ, SiteMapChangeFrequencyEnum.DAILY.getCode());
      this.put(PRIORITY, Double.valueOf(0.5D));
    }
  }
 protected String getThemeNameForSite(final CMSSiteModel site) {
   final SiteTheme theme = site.getTheme();
   if (theme != null) {
     final String themeCode = theme.getCode();
     if (themeCode != null && !themeCode.isEmpty()) {
       return themeCode;
     }
   }
   return getDefaultThemeName();
 }
  /**
   * Processing normal request (i.e. when user goes directly to that application - not from
   * cmscockpit)
   *
   * <p><b>Note:</b> <br>
   * We preparing application by setting correct:
   *
   * <ul>
   *   <li>Current Site
   *   <li>Current Catalog Versions
   *   <li>Enabled language fallback
   * </ul>
   *
   * @see ContextInformationLoader#initializeSiteFromRequest(String)
   * @see ContextInformationLoader#setCatalogVersions()
   * @param httpRequest current request
   * @param httpResponse the http response
   * @throws java.io.IOException
   */
  protected boolean processNormalRequest(
      final HttpServletRequest httpRequest, final HttpServletResponse httpResponse)
      throws IOException {
    final String queryString = httpRequest.getQueryString();
    final String currentRequestURL = httpRequest.getRequestURL().toString();

    // set current site
    CMSSiteModel cmsSiteModel = getCurrentCmsSite();
    if (cmsSiteModel == null || StringUtils.contains(queryString, CLEAR_CMSSITE_PARAM)) {
      final String absoluteURL =
          StringUtils.removeEnd(currentRequestURL, "/")
              + (StringUtils.isBlank(queryString) ? "" : "?" + queryString);

      cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
    }

    if (cmsSiteModel == null) {
      // Failed to lookup CMS site
      httpResponse.sendError(MISSING_CMS_SITE_ERROR_STATUS, MISSING_CMS_SITE_ERROR_MESSAGE);
      return false;
    } else if (!SiteChannel.B2C.equals(cmsSiteModel.getChannel())) // Restrict to B2C channel
    {
      // CMS site that we looked up was for an unsupported channel
      httpResponse.sendError(
          MISSING_CMS_SITE_ERROR_STATUS, INCORRECT_CMS_SITE_CHANNEL_ERROR_MESSAGE);
      return false;
    }

    if (!isActiveSite(cmsSiteModel)) {
      throw new IllegalStateException(
          "Site is not active. Active flag behaviour must be implement for this project.");
    }

    getContextInformationLoader().setCatalogVersions();
    // set fall back language enabled
    setFallbackLanguage(httpRequest, Boolean.TRUE);

    return true;
  }
Пример #7
0
  public static void createHomepage(
      final String uid,
      final String label,
      final CatalogVersionModel catVersion,
      final ContentCatalogModel contentCatalog,
      final CMSSiteModel cmsSiteModel,
      final List<PageTemplateModel> clonedTemplates) {
    final PageTemplateModel firstTemplate = clonedTemplates.iterator().next();
    final ModelService modelService = UISessionUtils.getCurrentSession().getModelService();

    final ContentPageModel contentPage = modelService.create(CONTENT_PAGE);
    contentPage.setUid(uid);
    contentPage.setName(uid);
    contentPage.setLabel(label);
    contentPage.setHomepage(true);
    contentPage.setCatalogVersion(catVersion);
    contentPage.setMasterTemplate(firstTemplate);
    contentPage.setDefaultPage(Boolean.TRUE);
    cmsSiteModel.setStartingPage(contentPage);
    adjustHomePageTemplate(contentPage, clonedTemplates);
    modelService.save(contentPage);
  }
  protected void executeSiteImport(
      final AddOnDataImportEventContext context,
      final ImportData importData,
      final ImpexMacroParameterData parameterData) {
    final CatalogModel productCatalog =
        getCatalogService().getCatalogForId(importData.getProductCatalogName() + "ProductCatalog");
    context.setProductCatalog(productCatalog);
    populate(context, parameterData, getSelectedProductCatalogImpexMacroParametersPopulators());
    final boolean productFilesImported =
        getAddonConfigDataImportService()
            .executeImport(
                parameterData.getConfigExtensionName(),
                AddonConfigDataImportType.PRODUCT,
                parameterData);
    if (productFilesImported
        && getAddonSystemSetupSupport()
            .getBooleanSystemSetupParameter(
                context.getSourceEvent().getContext(),
                AddOnSystemSetupSupport.IMPORT_SYNC_CATALOGS)) {
      getAddonSystemSetupSupport()
          .synchronizeProductCatalog(context.getSourceEvent().getContext(), productCatalog.getId());
    }

    for (final String store : importData.getStoreNames()) {

      final BaseSiteModel baseSite = getBaseSiteService().getBaseSiteForUID(store);
      if (getSupportedChannels().contains(baseSite.getChannel())) {
        if (LOG.isInfoEnabled()) {
          LOG.info(
              "importing addon ["
                  + parameterData.getConfigExtensionName()
                  + "] configuration for ["
                  + store
                  + "]");
        }

        context.setBaseSite(baseSite);
        populate(context, parameterData, getSelectedBaseSiteImpexMacroParametersPopulators());

        if (baseSite instanceof CMSSiteModel) {
          final CMSSiteModel cmsSite = (CMSSiteModel) baseSite;
          for (final String contentCatalogName : importData.getContentCatalogNames()) {
            final CatalogModel contentCatalog =
                getCatalogService().getCatalogForId(contentCatalogName + "ContentCatalog");
            if (cmsSite.getContentCatalogs().contains(contentCatalog)) {
              context.setContentCatalog((ContentCatalogModel) contentCatalog);
              populate(
                  context,
                  parameterData,
                  getSelectedContentCatalogImpexMacroParametersPopulators());
              final boolean contentFilesImported =
                  getAddonConfigDataImportService()
                      .executeImport(
                          parameterData.getConfigExtensionName(),
                          AddonConfigDataImportType.CONTENT,
                          parameterData);
              if (contentFilesImported
                  && getAddonSystemSetupSupport()
                      .getBooleanSystemSetupParameter(
                          context.getSourceEvent().getContext(),
                          AddOnSystemSetupSupport.IMPORT_SYNC_CATALOGS)) {
                getAddonSystemSetupSupport()
                    .synchronizeContentCatalog(
                        context.getSourceEvent().getContext(), contentCatalog.getId());
              }
              // import stores
              getAddonConfigDataImportService()
                  .executeImport(
                      parameterData.getConfigExtensionName(),
                      AddonConfigDataImportType.STORE,
                      parameterData);
            }
          }
        }

        final boolean solrFilesImported =
            getAddonConfigDataImportService()
                .executeImport(
                    parameterData.getConfigExtensionName(),
                    AddonConfigDataImportType.SOLR,
                    parameterData);
        if ((solrFilesImported || productFilesImported)
            && getAddonSystemSetupSupport()
                .getBooleanSystemSetupParameter(
                    context.getSourceEvent().getContext(),
                    AddOnSystemSetupSupport.ACTIVATE_SOLR_CRON_JOBS)) {
          getAddonSystemSetupSupport()
              .executeSolrIndexerCronJob(parameterData.getSiteUid() + "Index", true);
        }
      }
    }
  }
 @ModelAttribute("siteName")
 public String getSiteName() {
   final CMSSiteModel site = cmsSiteService.getCurrentSite();
   return site != null ? site.getName() : "";
 }
  @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));
  }
 protected boolean isActiveSite(final CMSSiteModel site) {
   return site.getActive() != null && site.getActive().booleanValue();
 }