Skip to content

Commit 5693ca0

Browse files
committed
Merge branch 'develop'
2 parents 07340a4 + 63fdba7 commit 5693ca0

29 files changed

+155
-74
lines changed

.github/workflows/release-from-tag.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ jobs:
1515
- uses: actions/checkout@v4
1616
- uses: ncipollo/release-action@v1
1717
with:
18-
body: 'Changes: https://wcm.io/wcm/core-components/changes-report.html'
18+
body: 'Changes: https://wcm.io/wcm/core-components/changes.html'
1919
token: ${{ secrets.GITHUB_TOKEN }}

build-deploy_aem65.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fi
2626
# install AEM 6.5 with service pack
2727
mvn --non-recursive wcmio-content-package:install \
2828
--activate-profiles=${MAVEN_PROFILES} \
29-
-Dvault.artifact=adobe.binary.aem.65.servicepack:aem-service-pkg:zip:6.5.20.0 \
29+
-Dvault.artifact=adobe.binary.aem.65.servicepack:aem-service-pkg:zip:6.5.22.0 \
3030
-Dvault.delayAfterInstallSec=30
3131

3232
if [ "$?" -ne "0" ]; then

bundles/core/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
<parent>
2626
<groupId>io.wcm</groupId>
2727
<artifactId>io.wcm.wcm.core.components.parent</artifactId>
28-
<version>2.0.4-2.25.4</version>
28+
<version>2.0.6-2.25.4</version>
2929
<relativePath>../../parent/pom.xml</relativePath>
3030
</parent>
3131

3232
<groupId>io.wcm</groupId>
3333
<artifactId>io.wcm.wcm.core.components</artifactId>
34-
<version>2.0.4-2.25.4</version>
34+
<version>2.0.6-2.25.4</version>
3535
<packaging>jar</packaging>
3636

3737
<name>WCM Core Components</name>

bundles/core/src/main/java/io/wcm/wcm/core/components/impl/models/helpers/PageListItemV4Impl.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ private Resource buildTeaserResource(@NotNull String delegateResourceType) {
192192
overriddenProperties.put(PN_LINK_CONTENT_REF, this.getPath());
193193
}
194194

195-
return new CoreResourceWrapper(resourceToBeWrapped, delegateResourceType, overriddenProperties, hiddenProperties);
195+
return new CoreResourceWrapper(resourceToBeWrapped, resourceToBeWrapped.getPath(),
196+
delegateResourceType, overriddenProperties, hiddenProperties);
196197
}
197198

198199
@JsonIgnore

bundles/core/src/main/java/io/wcm/wcm/core/components/impl/models/v2/ImageV2Impl.java

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
* <li>Build image using Media handler</li>
5151
* <li>Build link using Link handler</li>
5252
* </ul>
53+
*
5354
* <p>
5455
* This image component does not take full use of all wcm.io Media handler features, but rather emulates
5556
* the behavior of the original AEM core image component and it special behavior.

bundles/core/src/main/java/io/wcm/wcm/core/components/impl/models/v2/TeaserV2Impl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ private void activate() {
112112
boolean pretitleHidden = currentStyle.get(PN_PRETITLE_HIDDEN, false);
113113
boolean titleHidden = currentStyle.get(PN_TITLE_HIDDEN, false);
114114
boolean descriptionHidden = currentStyle.get(PN_DESCRIPTION_HIDDEN, false);
115-
titleType = currentStyle.get(PN_TITLE_TYPE, (String)null);
116-
showTitleType = currentStyle.get(Teaser.PN_SHOW_TITLE_TYPE, false);
115+
titleType = currentStyle.get(PN_TITLE_TYPE, String.class);
116+
showTitleType = currentStyle.get(PN_SHOW_TITLE_TYPE, false);
117117
imageLinkHidden = currentStyle.get(PN_IMAGE_LINK_HIDDEN, false);
118118
titleLinkHidden = currentStyle.get(PN_TITLE_LINK_HIDDEN, false);
119119
boolean actionsDisabled = currentStyle.get(PN_ACTIONS_DISABLED, false);
@@ -250,7 +250,7 @@ public String getDescription() {
250250
@Override
251251
public String getTitleType() {
252252
if (showTitleType) {
253-
titleType = resource.getValueMap().get(Teaser.PN_TITLE_TYPE, titleType);
253+
titleType = resource.getValueMap().get(PN_TITLE_TYPE, titleType);
254254
}
255255
return titleType;
256256
}

bundles/core/src/main/java/io/wcm/wcm/core/components/impl/models/v4/ListV4Impl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private Calendar getLastModifiedDate(ListItem item) {
199199
if (!link.isValid()) {
200200
return null;
201201
}
202-
String linkText = itemResource.getValueMap().get(List.PN_LINK_TEXT, String.class);
202+
String linkText = itemResource.getValueMap().get(PN_LINK_TEXT, String.class);
203203
if (StringUtils.isBlank(linkText)) {
204204
linkText = link.getUrl();
205205
}

bundles/core/src/main/java/io/wcm/wcm/core/components/impl/servlets/ImageWidthProxyServlet.java

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* This servlet acts as a "proxy" for the {@link io.wcm.handler.media.impl.ImageFileServlet}
4040
* that emulates support for the "widths" attributes of the core component and maps them
4141
* to media handler-URLs internally.
42+
*
4243
* <p>
4344
* Expected selectors:
4445
* </p>

bundles/core/src/main/java/io/wcm/wcm/core/components/impl/util/ComponentFeatureImageResolver.java

+11-16
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class ComponentFeatureImageResolver {
5656
private final MediaHandler mediaHandler;
5757
private final Map<String, Object> mediaHandlerProperties = new HashMap<>();
5858

59-
private boolean imageFromPageImage;
59+
private final Boolean imageFromPageImage;
6060
private final boolean altValueFromPageImage;
6161
private boolean altValueFromDam;
6262
private final boolean isDecorative;
@@ -78,7 +78,7 @@ public ComponentFeatureImageResolver(@NotNull Resource componentResource,
7878

7979
// component properties
8080
ValueMap props = componentResource.getValueMap();
81-
this.imageFromPageImage = props.get(PN_IMAGE_FROM_PAGE_IMAGE, false);
81+
this.imageFromPageImage = props.get(PN_IMAGE_FROM_PAGE_IMAGE, Boolean.class);
8282
this.altValueFromPageImage = props.get(PN_ALT_VALUE_FROM_PAGE_IMAGE, false);
8383
this.altValueFromDam = props.get(PN_ALT_VALUE_FROM_DAM, false);
8484
this.isDecorative = props.get(PN_IS_DECORATIVE, currentStyle.get(PN_IS_DECORATIVE, false));
@@ -106,15 +106,6 @@ public ComponentFeatureImageResolver mediaHandlerProperty(@NotNull String key, @
106106
return this;
107107
}
108108

109-
/**
110-
* @param value Image from page image
111-
* @return self
112-
*/
113-
public ComponentFeatureImageResolver imageFromPageImage(boolean value) {
114-
this.imageFromPageImage = value;
115-
return this;
116-
}
117-
118109
/**
119110
* @param value Alt Value from DAM
120111
* @return self
@@ -131,16 +122,17 @@ public ComponentFeatureImageResolver altValueFromDam(boolean value) {
131122
public @NotNull Media buildMedia() {
132123
Media media = mediaHandler.invalid();
133124

134-
if (!imageFromPageImage) {
125+
boolean useImageFromPageImage = imageFromPageImage != null && imageFromPageImage;
126+
if (imageFromPageImage == null) {
135127
// image from resource properties
136128
media = buildMedia(componentResource);
137129
if (!media.isValid() && media.getMediaInvalidReason() == MediaInvalidReason.MEDIA_REFERENCE_MISSING) {
138-
// fallback to image from page if no reference was given
139-
imageFromPageImage = true;
130+
// fallback to image from page if no reference was given and imageFromPageImage is neither enabled nor disabled
131+
useImageFromPageImage = true;
140132
}
141133
}
142134

143-
if (imageFromPageImage) {
135+
if (useImageFromPageImage) {
144136
// try to get feature image from target page
145137
if (targetPage != null) {
146138
Resource featuredImageResource = ComponentUtils.getFeaturedImage(targetPage);
@@ -168,7 +160,10 @@ public ComponentFeatureImageResolver altValueFromDam(boolean value) {
168160
if (resource == null) {
169161
return null;
170162
}
171-
return new CoreResourceWrapper(resource, HandlerUnwrapper.getResourceType(componentResource));
163+
return new CoreResourceWrapper(resource,
164+
// use path of component resource to get policy mappings for those
165+
componentResource.getPath(),
166+
HandlerUnwrapper.getResourceType(componentResource));
172167
}
173168

174169
/**

bundles/core/src/main/java/io/wcm/wcm/core/components/impl/util/CoreResourceWrapper.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,30 @@
4242
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION)
4343
public final class CoreResourceWrapper extends ResourceWrapper {
4444

45-
private ValueMap valueMap;
46-
private String overriddenResourceType;
45+
private final String path;
46+
private final ValueMap valueMap;
47+
private final String overriddenResourceType;
4748

4849
/**
4950
* @param resource Target resource
51+
* @param path Path of wrapped resource
5052
* @param overriddenResourceType New resource type
5153
*/
52-
public CoreResourceWrapper(@NotNull Resource resource, @NotNull String overriddenResourceType) {
53-
this(resource, overriddenResourceType, null, null);
54+
public CoreResourceWrapper(@NotNull Resource resource, @NotNull String path, @NotNull String overriddenResourceType) {
55+
this(resource, path, overriddenResourceType, null, null);
5456
}
5557

5658
/**
5759
* @param resource Target resource
60+
* @param path Path of wrapped resource
5861
* @param overriddenResourceType New resource type
5962
* @param overriddenProperties Properties to add/overwrite in value map
6063
* @param hiddenProperties Properties to hide from value map
6164
*/
62-
public CoreResourceWrapper(@NotNull Resource resource, @NotNull String overriddenResourceType,
65+
public CoreResourceWrapper(@NotNull Resource resource, @NotNull String path, @NotNull String overriddenResourceType,
6366
@Nullable Map<String, Object> overriddenProperties, @Nullable Set<String> hiddenProperties) {
6467
super(resource);
68+
this.path = path;
6569
if (StringUtils.isEmpty(overriddenResourceType)) {
6670
throw new IllegalArgumentException("The " + CoreResourceWrapper.class.getName() + " needs to override the resource type of " +
6771
"the wrapped resource, but the resourceType argument was null or empty.");
@@ -77,6 +81,11 @@ public CoreResourceWrapper(@NotNull Resource resource, @NotNull String overridde
7781
}
7882
}
7983

84+
@Override
85+
public String getPath() {
86+
return path;
87+
}
88+
8089
@Override
8190
@SuppressWarnings("unchecked")
8291
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {

bundles/core/src/test/java/io/wcm/wcm/core/components/impl/models/v1/LanguageNavigationV1ImplTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class LanguageNavigationV1ImplTest {
6060
private Page root_fr;
6161

6262
@BeforeEach
63-
void setUp() throws Exception {
63+
void setUp() {
6464
loadComponentDefinition(context, RESOURCE_TYPE);
6565

6666
root_en = context.pageManager().getPage(CONTENT_ROOT);

bundles/core/src/test/java/io/wcm/wcm/core/components/impl/models/v2/BreadcrumbV2ImplTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class BreadcrumbV2ImplTest {
5959
private Page page3;
6060

6161
@BeforeEach
62-
void setUp() throws Exception {
62+
void setUp() {
6363
loadComponentDefinition(context, RESOURCE_TYPE);
6464

6565
root = context.pageManager().getPage(CONTENT_ROOT);

bundles/core/src/test/java/io/wcm/wcm/core/components/impl/models/v2/TeaserV2ImplTest.java

+36
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
import static io.wcm.handler.link.LinkNameConstants.PN_LINK_EXTERNAL_REF;
4141
import static io.wcm.handler.link.LinkNameConstants.PN_LINK_TYPE;
4242
import static io.wcm.handler.link.LinkNameConstants.PN_LINK_WINDOW_TARGET;
43+
import static io.wcm.handler.media.MediaNameConstants.NN_COMPONENT_MEDIA_RESPONSIVEIMAGE_SIZES;
4344
import static io.wcm.handler.media.MediaNameConstants.PN_COMPONENT_MEDIA_AUTOCROP;
4445
import static io.wcm.handler.media.MediaNameConstants.PN_COMPONENT_MEDIA_FORMATS;
46+
import static io.wcm.handler.media.MediaNameConstants.PN_COMPONENT_MEDIA_RESPONSIVE_TYPE;
4547
import static io.wcm.handler.media.MediaNameConstants.PN_MEDIA_REF_STANDARD;
4648
import static io.wcm.wcm.core.components.impl.models.helpers.DataLayerTestUtils.enableDataLayer;
4749
import static io.wcm.wcm.core.components.impl.models.v2.TeaserV2Impl.RESOURCE_TYPE;
@@ -69,6 +71,7 @@
6971
import com.adobe.cq.wcm.core.components.models.datalayer.ComponentData;
7072
import com.day.cq.dam.api.Asset;
7173
import com.day.cq.wcm.api.Page;
74+
import com.day.cq.wcm.api.policies.ContentPolicyMapping;
7275

7376
import io.wcm.handler.link.type.ExternalLinkType;
7477
import io.wcm.handler.link.type.InternalLinkType;
@@ -199,6 +202,39 @@ void testTitleDescriptionImageFromPage() {
199202
assertValidMedia(underTest, "/content/dam/sample/sample.jpg/_jcr_content/renditions/original./sample.jpg");
200203
}
201204

205+
@Test
206+
void testTitleDescriptionImageFromPage_WithContentPolicy() {
207+
Page targetPage = context.create().page(page, "page1", null,
208+
JCR_TITLE, "Page Title",
209+
JCR_DESCRIPTION, "Page Description");
210+
context.create().resource(targetPage, NN_PAGE_FEATURED_IMAGE,
211+
PN_MEDIA_REF_STANDARD, asset.getPath());
212+
context.currentResource(context.create().resource(page, "teaser",
213+
PROPERTY_RESOURCE_TYPE, RESOURCE_TYPE,
214+
JCR_TITLE, "Teaser Title",
215+
JCR_DESCRIPTION, "Teaser Description",
216+
PN_LINK_TYPE, InternalLinkType.ID,
217+
PN_LINK_CONTENT_REF, targetPage.getPath(),
218+
PN_TITLE_FROM_PAGE, true,
219+
PN_DESCRIPTION_FROM_PAGE, true,
220+
PN_IMAGE_FROM_PAGE_IMAGE, true,
221+
PN_ALT_VALUE_FROM_PAGE_IMAGE, true));
222+
223+
ContentPolicyMapping policyMapping = context.contentPolicyMapping(RESOURCE_TYPE,
224+
JCR_TITLE, "Teaser Mock Policy",
225+
PN_COMPONENT_MEDIA_FORMATS, MediaFormats.SQUARE.getName(),
226+
PN_COMPONENT_MEDIA_AUTOCROP, Boolean.TRUE,
227+
PN_COMPONENT_MEDIA_RESPONSIVE_TYPE, "imageSizes");
228+
context.create().resource(policyMapping.getPolicy().getPath() + "/" + NN_COMPONENT_MEDIA_RESPONSIVEIMAGE_SIZES,
229+
"widths", "45,90");
230+
231+
Teaser underTest = AdaptTo.notNull(context.request(), Teaser.class);
232+
233+
assertEquals("Page Title", underTest.getTitle());
234+
assertEquals("Page Description", underTest.getDescription());
235+
assertValidMedia(underTest, "/content/dam/sample/sample.jpg/_jcr_content/renditions/original.image_file.90.90.35,0,125,90.file/sample.jpg");
236+
}
237+
202238
@Test
203239
void testTitleDescriptionFromPage_HtmlReservedChars() {
204240
Page targetPage = context.create().page(page, "page1", null,

bundles/core/src/test/java/io/wcm/wcm/core/components/impl/models/v3/BreadcrumbV3ImplTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class BreadcrumbV3ImplTest {
5959
private Page page3;
6060

6161
@BeforeEach
62-
void setUp() throws Exception {
62+
void setUp() {
6363
loadComponentDefinition(context, RESOURCE_TYPE);
6464

6565
root = context.pageManager().getPage(CONTENT_ROOT);

bundles/core/src/test/java/io/wcm/wcm/core/components/impl/servlets/ImageWidthProxyServletTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.junit.jupiter.api.Test;
4141
import org.junit.jupiter.api.extension.ExtendWith;
4242
import org.mockito.Mock;
43+
import org.mockito.Mock.Strictness;
4344
import org.mockito.junit.jupiter.MockitoExtension;
4445

4546
import com.day.cq.dam.api.Asset;
@@ -63,7 +64,7 @@ class ImageWidthProxyServletTest {
6364
private Page page;
6465
private Asset asset;
6566

66-
@Mock(lenient = true)
67+
@Mock(strictness = Strictness.LENIENT)
6768
private MockRequestDispatcherFactory requestDispatcherFactory;
6869
@Mock
6970
private RequestDispatcher requestDispatcher;

bundles/core/src/test/java/io/wcm/wcm/core/components/impl/util/ComponentFeatureImageResolverTest.java

+21
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,27 @@ void testComponentImageFromPage() {
208208
assertEquals("Feature Alt", media.getAsset().getAltText());
209209
}
210210

211+
@Test
212+
void testComponentImageFromPage_Disabled() {
213+
Resource component = context.create().resource(page1, "comp1",
214+
PROPERTY_RESOURCE_TYPE, COMPONENT_RESOURCE_TYPE,
215+
PN_MEDIA_REF_STANDARD, asset1.getPath(),
216+
PN_MEDIA_ALTTEXT_STANDARD, "My Alt",
217+
PN_IMAGE_FROM_PAGE_IMAGE, false,
218+
PN_ALT_VALUE_FROM_PAGE_IMAGE, true);
219+
220+
// create feature image in page2
221+
context.create().resource(page2, NN_PAGE_FEATURED_IMAGE,
222+
PN_MEDIA_REF_STANDARD, asset2.getPath(),
223+
PN_MEDIA_ALTTEXT_STANDARD, "Feature Alt");
224+
225+
Media media = newComponentFeatureImageResolver(component)
226+
.targetPage(page2)
227+
.buildMedia();
228+
229+
assertFalse(media.isValid());
230+
}
231+
211232
@Test
212233
@SuppressWarnings("null")
213234
void testComponentImageFromPage_FallbackCurrentPage() {

bundles/core/src/test/java/io/wcm/wcm/core/components/impl/util/CoreResourceWrapperTest.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ void testWrappingWithSimpleResource() {
5959
"a", 1,
6060
"b", 2,
6161
ResourceResolver.PROPERTY_RESOURCE_TYPE, "a/b/c");
62-
Resource wrappedResource = new CoreResourceWrapper(resource, "d/e/f");
62+
Resource wrappedResource = new CoreResourceWrapper(resource, resource.getPath(), "d/e/f");
63+
64+
assertEquals(resource.getPath(), wrappedResource.getPath());
6365

6466
Map<String, Object> expectedProperties = new HashMap<>(resource.getValueMap());
6567
expectedProperties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, "d/e/f");
@@ -74,7 +76,9 @@ void testWrappingWithHiddenProperties() {
7476
"a", 1,
7577
"b", 2,
7678
ResourceResolver.PROPERTY_RESOURCE_TYPE, "a/b/c");
77-
Resource wrappedResource = new CoreResourceWrapper(resource, "d/e/f", null, Set.of("b"));
79+
Resource wrappedResource = new CoreResourceWrapper(resource, "/content/test2", "d/e/f", null, Set.of("b"));
80+
81+
assertEquals("/content/test2", wrappedResource.getPath());
7882

7983
Map<String, Object> expectedProperties = new HashMap<>(resource.getValueMap());
8084
expectedProperties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, "d/e/f");
@@ -95,7 +99,7 @@ void testWrappingWithOverridenProperties() {
9599
Map<String, Object> overriddenProperties = ImmutableValueMap.of(
96100
"a", "1",
97101
"b", "2");
98-
Resource wrappedResource = new CoreResourceWrapper(resource, "a/b/c", overriddenProperties, null);
102+
Resource wrappedResource = new CoreResourceWrapper(resource, resource.getPath(), "a/b/c", overriddenProperties, null);
99103

100104
// isResourceType()
101105
assertTrue(wrappedResource.isResourceType("a/b/c"));
@@ -113,7 +117,7 @@ void testWrappingWithOverridenProperties() {
113117
@Test
114118
@SuppressWarnings("null")
115119
void testNulls() {
116-
assertThrows(IllegalArgumentException.class, () -> new CoreResourceWrapper(null, null));
120+
assertThrows(IllegalArgumentException.class, () -> new CoreResourceWrapper(null, null, null));
117121
}
118122

119123
@Test
@@ -124,7 +128,7 @@ void isResourceTypeDelegated() {
124128
when(toBeWrapped.getValueMap()).thenReturn(new ValueMapDecorator(Collections.emptyMap()));
125129
when(toBeWrapped.getResourceResolver()).thenReturn(resourceResolver);
126130
when(resourceResolver.isResourceType(any(CoreResourceWrapper.class), any(String.class))).thenReturn(true);
127-
Resource wrappedResource = new CoreResourceWrapper(toBeWrapped, "a/b/c");
131+
Resource wrappedResource = new CoreResourceWrapper(toBeWrapped, toBeWrapped.getPath(), "a/b/c");
128132
assertTrue(wrappedResource.isResourceType("a/b/c"));
129133
verify(resourceResolver).isResourceType(wrappedResource, "a/b/c");
130134
}

bundles/core/src/test/java/io/wcm/wcm/core/components/testcontext/AppAemContext.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.io.IOException;
3232
import java.util.Locale;
3333

34-
import org.apache.sling.api.resource.PersistenceException;
3534
import org.jetbrains.annotations.NotNull;
3635

3736
import io.wcm.handler.media.spi.MediaFormatProvider;
@@ -71,7 +70,7 @@ public static AemContext newAemContext() {
7170
*/
7271
private static final AemContextCallback SETUP_CALLBACK = new AemContextCallback() {
7372
@Override
74-
public void execute(@NotNull AemContext context) throws PersistenceException, IOException {
73+
public void execute(@NotNull AemContext context) throws IOException {
7574

7675
// context path strategy
7776
MockCAConfig.contextPathStrategyAbsoluteParent(context, ROOT_LEVEL - 1, ROOT_LEVEL);

0 commit comments

Comments
 (0)