ImageImpl extends com.adobe.cq.wcm.core.components.internal.models.v1.ImageImpl implements Image { @Override public List<ImageArea> getAreas() { if (areas == null ) { areas = new ArrayList<>(); if (hasContent) { String mapProperty = properties.get(Image.PN_MAP, String.class); if (StringUtils.isNotEmpty(mapProperty)) { String[] mapAreas = StringUtils.split(mapProperty, "]["); for (String area : mapAreas) { int coordinatesEndIndex = area.indexOf(')'); if (coordinatesEndIndex < 0) { break; } String shapeAndCoords = StringUtils.substring(area, 0, coordinatesEndIndex + 1); String shape = StringUtils.substringBefore(shapeAndCoords, "("); String coordinates = StringUtils.substringBetween(shapeAndCoords, "(", ")"); String remaining = StringUtils.substring(area, coordinatesEndIndex + 1); String[] remainingTokens = StringUtils.split(remaining, "|"); if (StringUtils.isBlank(shape) || StringUtils.isBlank(coordinates)) { break; } if (remainingTokens.length > 0) { String href = StringUtils.removeAll(remainingTokens[0], "\""); if (StringUtils.isBlank(href)) { break; } String target = remainingTokens.length > 1 ? StringUtils.removeAll(remainingTokens[1], "\"") : ""; String alt = remainingTokens.length > 2 ? StringUtils.removeAll(remainingTokens[2], "\"") : ""; String relativeCoordinates = remainingTokens.length > 3 ? remainingTokens[3] : ""; relativeCoordinates = StringUtils.substringBetween(relativeCoordinates, "(", ")"); if (href.startsWith("/")) { href = Utils.getURL(request, pageManager, href); } areas.add(new ImageAreaImpl(shape, coordinates, relativeCoordinates, href, target, alt)); } } } } } return Collections.unmodifiableList(areas); } ImageImpl(); @NotNull @Override int[] getWidths(); @Override String getSrcUriTemplate(); @Override boolean isLazyEnabled(); @Override int getLazyThreshold(); @Override List<ImageArea> getAreas(); @Override String getUuid(); static final String RESOURCE_TYPE; }
@Test void testImageWithMap() { context.contentPolicyMapping(ImageImpl.RESOURCE_TYPE, "uuidDisabled", true); com.adobe.cq.wcm.core.components.models.Image image = getImageUnderTest(AbstractImageTest.IMAGE24_PATH); Object[][] expectedAreas = { {"circle", "256,256,256", "0.2000,0.3001,0.2000", "http: {"rect", "256,171,1023,682", "0.1992,0.2005,0.7992,0.7995", "http: {"poly", "917,344,1280,852,532,852", "0.7164,0.4033,1.0000,0.9988,0.4156,0.9988", "http: }; List<ImageArea> areas = image.getAreas(); int index = 0; while (areas.size() > index) { ImageArea area = areas.get(index); assertEquals(expectedAreas[index][0], area.getShape(), "The image area's shape is not as expected."); assertEquals(expectedAreas[index][1], area.getCoordinates(), "The image area's coordinates are not as expected."); assertEquals(expectedAreas[index][2], area.getRelativeCoordinates(), "The image area's relative coordinates are not as expected."); assertEquals(expectedAreas[index][3], area.getHref(), "The image area's href is not as expected."); assertEquals(expectedAreas[index][4], area.getTarget(), "The image area's target is not as expected."); assertEquals(expectedAreas[index][5], area.getAlt(), "The image area's alt text is not as expected."); index++; } Utils.testJSONExport(image, Utils.getTestExporterJSONPath(TEST_BASE, AbstractImageTest.IMAGE24_PATH)); }