Search in sources :

Example 46 with Page

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

the class HiddenImplTest method prepareHiddenFieldForTest.

private Field prepareHiddenFieldForTest(String resourcePath) {
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
    request.setResource(resource);
    Page currentPage = CONTEXT.pageManager().getPage(CONTAINING_PAGE);
    SlingBindings slingBindings = new SlingBindings();
    slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
    slingBindings.put(SlingBindings.RESOURCE, resource);
    slingBindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
    request.setAttribute(SlingBindings.class.getName(), slingBindings);
    return request.adaptTo(Field.class);
}
Also used : SlingBindings(org.apache.sling.api.scripting.SlingBindings) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page)

Example 47 with Page

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

the class BreadcrumbImplTest method setUp.

@Before
public void setUp() throws Exception {
    Page page = context.currentPage(CURRENT_PAGE);
    slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
    slingBindings.put(WCMBindings.CURRENT_PAGE, page);
}
Also used : SlingBindings(org.apache.sling.api.scripting.SlingBindings) Page(com.day.cq.wcm.api.Page) Before(org.junit.Before)

Example 48 with Page

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

the class TextImplTest method setUp.

@Before
public void setUp() {
    Page page = context.currentPage(CONTAINING_PAGE);
    slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
    slingBindings.put(WCMBindings.CURRENT_PAGE, page);
    context.registerService(FormStructureHelperFactory.class, new FormStructureHelperFactory() {

        @Override
        public FormStructureHelper getFormStructureHelper(Resource formElement) {
            return null;
        }
    });
    FormsHelperStubber.createStub();
}
Also used : FormStructureHelper(com.day.cq.wcm.foundation.forms.FormStructureHelper) SlingBindings(org.apache.sling.api.scripting.SlingBindings) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) FormStructureHelperFactory(com.day.cq.wcm.foundation.forms.FormStructureHelperFactory) Before(org.junit.Before)

Example 49 with Page

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

the class SocialMediaHelperImpl method findExperienceFragmentSocialVariation.

private ExperienceFragmentSocialVariation findExperienceFragmentSocialVariation() {
    Page variantPage = currentPage.getPageManager().getPage(variantPath);
    if (variantPage == null)
        return null;
    ExperienceFragmentSocialVariation socialVariant = variantPage.adaptTo(ExperienceFragmentSocialVariation.class);
    return socialVariant;
}
Also used : ExperienceFragmentSocialVariation(com.adobe.cq.xf.social.ExperienceFragmentSocialVariation) Page(com.day.cq.wcm.api.Page)

Example 50 with Page

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

the class ImageImpl method initModel.

@PostConstruct
private void initModel() {
    boolean hasContent = false;
    if (StringUtils.isNotEmpty(fileReference)) {
        int dotIndex;
        if ((dotIndex = fileReference.lastIndexOf(DOT)) != -1) {
            extension = fileReference.substring(dotIndex + 1);
        }
        hasContent = true;
    } else {
        Resource file = resource.getChild(DownloadResource.NN_FILE);
        if (file != null) {
            extension = mimeTypeService.getExtension(PropertiesUtil.toString(file.getResourceMetadata().get(ResourceMetadata.CONTENT_TYPE), MIME_TYPE_IMAGE_JPEG));
            hasContent = true;
        }
    }
    if (hasContent) {
        long lastModifiedDate = 0;
        if (!wcmmode.isDisabled()) {
            ValueMap properties = resource.getValueMap();
            Calendar lastModified = properties.get(JcrConstants.JCR_LASTMODIFIED, Calendar.class);
            if (lastModified == null) {
                lastModified = properties.get(NameConstants.PN_PAGE_LAST_MOD, Calendar.class);
            }
            if (lastModified != null) {
                lastModifiedDate = lastModified.getTimeInMillis();
            }
        }
        if (extension.equalsIgnoreCase("tif") || extension.equalsIgnoreCase("tiff")) {
            extension = DEFAULT_EXTENSION;
        }
        ResourceResolver resourceResolver = request.getResourceResolver();
        ContentPolicyManager policyManager = resourceResolver.adaptTo(ContentPolicyManager.class);
        ContentPolicy contentPolicy = policyManager.getPolicy(resource);
        if (contentPolicy != null) {
            disableLazyLoading = contentPolicy.getProperties().get(PN_DESIGN_LAZY_LOADING_ENABLED, false);
        }
        Set<Integer> supportedRenditionWidths = getSupportedRenditionWidths(contentPolicy);
        smartImages = new String[supportedRenditionWidths.size()];
        smartSizes = new int[supportedRenditionWidths.size()];
        int index = 0;
        String escapedResourcePath = Text.escapePath(resource.getPath());
        for (Integer width : supportedRenditionWidths) {
            smartImages[index] = request.getContextPath() + escapedResourcePath + DOT + AdaptiveImageServlet.DEFAULT_SELECTOR + DOT + width + DOT + extension + (!wcmmode.isDisabled() && lastModifiedDate > 0 ? "/" + lastModifiedDate + DOT + extension : "");
            smartSizes[index] = width;
            index++;
        }
        if (smartSizes.length == 0 || smartSizes.length >= 2) {
            src = request.getContextPath() + escapedResourcePath + DOT + AdaptiveImageServlet.DEFAULT_SELECTOR + DOT + extension + (!wcmmode.isDisabled() && lastModifiedDate > 0 ? "/" + lastModifiedDate + DOT + extension : "");
        } else if (smartSizes.length == 1) {
            src = request.getContextPath() + escapedResourcePath + DOT + AdaptiveImageServlet.DEFAULT_SELECTOR + DOT + smartSizes[0] + DOT + extension + (!wcmmode.isDisabled() && lastModifiedDate > 0 ? "/" + lastModifiedDate + DOT + extension : "");
        }
        if (!isDecorative) {
            Page page = pageManager.getPage(linkURL);
            if (page != null) {
                String vanityURL = page.getVanityUrl();
                linkURL = (vanityURL == null ? linkURL + ".html" : vanityURL);
            }
        } else {
            linkURL = null;
            alt = null;
        }
        buildJson();
    }
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Calendar(java.util.Calendar) DownloadResource(com.day.cq.commons.DownloadResource) Resource(org.apache.sling.api.resource.Resource) ImageResource(com.day.cq.commons.ImageResource) ContentPolicy(com.day.cq.wcm.api.policies.ContentPolicy) Page(com.day.cq.wcm.api.Page) ContentPolicyManager(com.day.cq.wcm.api.policies.ContentPolicyManager) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Page (com.day.cq.wcm.api.Page)100 Resource (org.apache.sling.api.resource.Resource)45 PageManager (com.day.cq.wcm.api.PageManager)34 Test (org.junit.jupiter.api.Test)22 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)18 ValueMap (org.apache.sling.api.resource.ValueMap)15 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)12 SlingBindings (org.apache.sling.api.scripting.SlingBindings)12 NotNull (org.jetbrains.annotations.NotNull)10 Test (org.junit.Test)9 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Optional (java.util.Optional)6 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)6 Nullable (org.jetbrains.annotations.Nullable)6 LinkHandler (com.adobe.cq.wcm.core.components.internal.link.LinkHandler)5 Template (com.day.cq.wcm.api.Template)5 StringUtils (org.apache.commons.lang3.StringUtils)5 Before (org.junit.Before)5