Search in sources :

Example 1 with NN_CONTENT

use of com.day.cq.wcm.api.NameConstants.NN_CONTENT in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class ExperienceFragmentDataImpl method getLocalizedFragmentVariationPath.

/**
 * Returns the localized path of the experience fragment variation if the experience fragment resource is defined
 * in a template.
 *
 * @return Localized experience fragment variation path
 * @see ExperienceFragment#getLocalizedFragmentVariationPath()
 */
@Nullable
public String getLocalizedFragmentVariationPath() {
    if (localizedFragmentVariationPath != null) {
        return localizedFragmentVariationPath;
    }
    // get the configured fragment variation path
    String fragmentVariationPath = resource.getValueMap().get(ExperienceFragment.PN_FRAGMENT_VARIATION_PATH, String.class);
    if (currentPage != null && inTemplate()) {
        final Resource pageResource = Optional.ofNullable(currentPage).map(p -> p.adaptTo(Resource.class)).orElse(null);
        final String currentPageRootPath = pageResource != null ? LocalizationUtils.getLocalizationRoot(pageResource, resourceResolver, languageManager, relationshipManager) : null;
        // we should use getLocalizationRoot instead of getXfLocalizationRoot once the XF UI supports creating Live and Language Copies
        String xfRootPath = getXfLocalizationRoot(fragmentVariationPath, currentPageRootPath);
        if (StringUtils.isNotEmpty(currentPageRootPath) && StringUtils.isNotEmpty(xfRootPath)) {
            String xfRelativePath = StringUtils.substring(fragmentVariationPath, xfRootPath.length());
            String localizedXfRootPath = StringUtils.replace(currentPageRootPath, CONTENT_ROOT, ExperienceFragmentsConstants.CONTENT_PATH, 1);
            localizedFragmentVariationPath = StringUtils.join(localizedXfRootPath, xfRelativePath, PATH_DELIMITER_CHAR, NN_CONTENT);
        }
    }
    String xfContentPath = String.join(Character.toString(PATH_DELIMITER_CHAR), fragmentVariationPath, NN_CONTENT);
    if (!resourceExists(localizedFragmentVariationPath) && resourceExists(xfContentPath)) {
        localizedFragmentVariationPath = xfContentPath;
    }
    if (!isExperienceFragmentVariation(localizedFragmentVariationPath)) {
        localizedFragmentVariationPath = null;
    }
    return localizedFragmentVariationPath;
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ExperienceFragmentsConstants(com.adobe.cq.xf.ExperienceFragmentsConstants) Resource(org.apache.sling.api.resource.Resource) ExperienceFragment(com.adobe.cq.wcm.core.components.models.ExperienceFragment) Text(com.day.text.Text) LanguageManager(com.day.cq.wcm.api.LanguageManager) NN_CONTENT(com.day.cq.wcm.api.NameConstants.NN_CONTENT) StringUtils(org.apache.commons.lang3.StringUtils) Page(com.day.cq.wcm.api.Page) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) LiveRelationshipManager(com.day.cq.wcm.msm.api.LiveRelationshipManager) LocalizationUtils(com.adobe.cq.wcm.core.components.util.LocalizationUtils) PageManager(com.day.cq.wcm.api.PageManager) Nullable(org.jetbrains.annotations.Nullable) ScriptVariable(org.apache.sling.models.annotations.injectorspecific.ScriptVariable) InjectionStrategy(org.apache.sling.models.annotations.injectorspecific.InjectionStrategy) Template(com.day.cq.wcm.api.Template) Model(org.apache.sling.models.annotations.Model) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) OSGiService(org.apache.sling.models.annotations.injectorspecific.OSGiService) SlingObject(org.apache.sling.models.annotations.injectorspecific.SlingObject) Resource(org.apache.sling.api.resource.Resource) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ExperienceFragment (com.adobe.cq.wcm.core.components.models.ExperienceFragment)1 LocalizationUtils (com.adobe.cq.wcm.core.components.util.LocalizationUtils)1 ExperienceFragmentsConstants (com.adobe.cq.xf.ExperienceFragmentsConstants)1 LanguageManager (com.day.cq.wcm.api.LanguageManager)1 NN_CONTENT (com.day.cq.wcm.api.NameConstants.NN_CONTENT)1 Page (com.day.cq.wcm.api.Page)1 PageManager (com.day.cq.wcm.api.PageManager)1 Template (com.day.cq.wcm.api.Template)1 LiveRelationshipManager (com.day.cq.wcm.msm.api.LiveRelationshipManager)1 Text (com.day.text.Text)1 Optional (java.util.Optional)1 PostConstruct (javax.annotation.PostConstruct)1 StringUtils (org.apache.commons.lang3.StringUtils)1 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)1 Resource (org.apache.sling.api.resource.Resource)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 Model (org.apache.sling.models.annotations.Model)1 InjectionStrategy (org.apache.sling.models.annotations.injectorspecific.InjectionStrategy)1 OSGiService (org.apache.sling.models.annotations.injectorspecific.OSGiService)1 ScriptVariable (org.apache.sling.models.annotations.injectorspecific.ScriptVariable)1