use of com.adobe.cq.wcm.core.components.models.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImageThumbnail method initModel.
@PostConstruct
protected void initModel() {
configPath = request.getRequestPathInfo().getResourcePath();
componentPath = request.getRequestPathInfo().getSuffix();
if (StringUtils.isBlank(componentPath)) {
RequestParameter itemParam = request.getRequestParameter("item");
if (itemParam == null) {
log.error("Suffix and 'item' param are blank");
return;
}
componentPath = itemParam.getString();
}
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
if (pageManager == null) {
log.error("pagemanager is null");
return;
}
Resource component = resourceResolver.getResource(componentPath);
if (component == null) {
log.error("the component at {} does not exist", componentPath);
return;
}
Page currentPage = pageManager.getContainingPage(component);
if (currentPage != null) {
currentPagePath = currentPage.getPath();
}
Page targetPage = null;
RequestParameter pageLinkParam = request.getRequestParameter("pageLink");
if (pageLinkParam != null) {
// retrieve the page link from the request parameter
String pageLink = pageLinkParam.getString();
targetPage = pageManager.getPage(pageLink);
} else {
// retrieve the page link from the component model
Teaser teaserModel = modelFactory.getModelFromWrappedRequest(request, component, Teaser.class);
Link link = null;
if (teaserModel != null) {
link = teaserModel.getLink();
} else {
Image imageModel = modelFactory.getModelFromWrappedRequest(request, component, Image.class);
if (imageModel != null) {
link = imageModel.getImageLink();
}
}
if (link != null) {
targetPage = (Page) link.getReference();
} else {
targetPage = currentPage;
}
}
if (targetPage == null) {
log.info("A target page cannot be found for the link defined in the request parameter or on the server at {}.", component.getPath());
return;
}
Resource featuredImage = ComponentUtils.getFeaturedImage(targetPage);
if (featuredImage == null) {
log.info("No featured image defined for the page at {}", targetPage.getPath());
return;
}
Image imageModel = modelFactory.getModelFromWrappedRequest(request, featuredImage, Image.class);
if (imageModel == null) {
log.info("the image model of {} is null", featuredImage.getPath());
return;
}
this.alt = imageModel.getAlt();
this.src = imageModel.getSrc();
}
use of com.adobe.cq.wcm.core.components.models.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ImageImplTest method testLocalFileWithoutFileNameParameter.
@Test
@SuppressWarnings("deprecation")
protected void testLocalFileWithoutFileNameParameter() {
context.contentPolicyMapping(resourceType, "allowedRenditionWidths", new int[] { 600 }, "disableLazyLoading", true);
String escapedResourcePath = IMAGE27_PATH.replace("jcr:content", "_jcr_content");
Image image = getImageUnderTest(IMAGE27_PATH);
assertNull(image.getFileReference(), "Did not expect a file reference.");
assertEquals(CONTEXT_PATH + escapedResourcePath + "." + selector + ".82.600.png/1490005239000.png", image.getSrc());
String expectedJson = "{\"smartImages\":[\"/core/content/test/_jcr_content/root/image27." + selector + "." + jpegQuality + ".600.png/1490005239000.png\"],\"smartSizes\":[600],\"lazyEnabled\":false}";
compareJSON(expectedJson, image.getJson());
Utils.testJSONExport(image, Utils.getTestExporterJSONPath(testBase, IMAGE27_PATH));
}
use of com.adobe.cq.wcm.core.components.models.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ImageImplTest method testGetDataLayerJson.
@Test
void testGetDataLayerJson() throws Exception {
Image image = getImageUnderTest(IMAGE6_PATH);
assertNotNull(image.getData());
String expected = "{\"image-db7ae5b54e\":{\"image\":{\"repo:id\":\"60a1a56e-f3f4-4021-a7bf-ac7a51f0ffe5\",\"@type\":\"image/gif\",\"repo:modifyDate\":\"2017-03-20T10:20:39Z\",\"repo:path\":\"/content/dam/core/images/Adobe_Systems_logo_and_wordmark.gif\",\"xdm:smartTags\":{\"nature\":0.74,\"lake\":0.79,\"water\":0.78,\"landscape\":0.75}},\"dc:title\":\"Adobe Logo\",\"@type\":\"core/wcm/components/image/v1/image\",\"xdm:linkURL\":\"/core/content/test-image.html\",\"repo:modifyDate\":\"2017-03-20T10:20:39Z\"}}";
assertEquals(Json.createReader(new StringReader(expected)).read(), Json.createReader(new StringReader(image.getData().getJson())).read());
}
use of com.adobe.cq.wcm.core.components.models.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ImageImplTest method testExportedType.
@Test
protected void testExportedType() {
Image image = getImageUnderTest(IMAGE0_PATH);
assertEquals(resourceType, (image).getExportedType());
}
use of com.adobe.cq.wcm.core.components.models.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ImageImplTest method testImageFromTemplateStructure.
@Test
@SuppressWarnings("deprecation")
protected void testImageFromTemplateStructure() {
context.contentPolicyMapping("core/wcm/components/image", "allowedRenditionWidths", new int[] { 600, 700, 800, 2000, 2500 });
Image image = getImageUnderTest(TEMPLATE_IMAGE_PATH);
assertEquals(CONTEXT_PATH + "/conf/coretest/settings/wcm/templates/testtemplate/structure." + selector + ".png/structure/jcr" + "%3acontent/root/image_template/1490005239000/" + ASSET_NAME + ".png", image.getSrc());
assertEquals(IMAGE_TITLE_ALT, image.getAlt());
assertEquals(IMAGE_TITLE_ALT, image.getTitle());
assertEquals(IMAGE_FILE_REFERENCE, image.getFileReference());
String expectedJson = "{" + "\"smartImages\":[\"/core/conf/coretest/settings/wcm/templates/testtemplate/structure." + selector + "." + jpegQuality + ".600.png/structure/jcr%3acontent/root/image_template/1490005239000/" + ASSET_NAME + ".png\",\"/core/conf/coretest/settings/wcm/templates/testtemplate/structure." + selector + "." + jpegQuality + ".700.png/structure/jcr%3acontent/root/image_template/1490005239000/" + ASSET_NAME + ".png\", \"/core/conf/coretest/settings/wcm/templates/testtemplate/structure." + selector + "." + jpegQuality + ".800.png/structure/jcr%3acontent/root/image_template/1490005239000/" + ASSET_NAME + ".png\"," + "\"/core/conf/coretest/settings/wcm/templates/testtemplate/structure." + selector + "." + jpegQuality + ".2000.png/structure/jcr%3acontent/root/image_template/1490005239000/" + ASSET_NAME + ".png\",\"/core/conf/coretest/settings/wcm/templates/testtemplate/structure." + selector + "." + jpegQuality + ".2500.png/structure/jcr%3acontent/root/image_template/1490005239000/" + ASSET_NAME + ".png\"]," + "\"smartSizes\":[600,700,800,2000,2500]," + "\"lazyEnabled\":true" + "}";
compareJSON(expectedJson, image.getJson());
assertFalse(image.displayPopupTitle());
assertEquals(CONTEXT_PATH + "/content/test-image.html", image.getLink());
Utils.testJSONExport(image, Utils.getTestExporterJSONPath(testBase, TEMPLATE_IMAGE_PATH));
}
Aggregations