Skip to content

Commit

Permalink
Merge branch 'main' into issue/2526
Browse files Browse the repository at this point in the history
  • Loading branch information
ky940819 authored Sep 5, 2023
2 parents 2a4cf6c + e8fc23a commit 9fd670b
Show file tree
Hide file tree
Showing 91 changed files with 1,933 additions and 169 deletions.
3 changes: 1 addition & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Before making a PR please make sure to read our contributing guidelines
https://github.com/adobe/aem-core-wcm-components/blob/master/CONTRIBUTING.md
IMPORTANT: Please base your pull request on the **development** branch! The maintainers will cherry-pick the change to
master after it's successfully integrated and tested.
IMPORTANT: Please base your pull request on the **main** branch and make sure to check you have incorporated or merged the latest changes!
For issue references: Add a comma-separated list of a [closing word](https://help.github.com/articles/closing-issues-via-commit-messages/)
followed by the ticket number fixed by the PR. It should be underlined in the preview if done correctly.
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
with:
languages: ${{ matrix.language }}
queries: +security-and-quality
paths-ignore:
- '**/jcr_root/apps/system/config/**'

- name: Autobuild
uses: github/codeql-action/autobuild@v2
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ For existing projects, take example from the [AEM Project Archetype](https://git

Core Components | AEM as a Cloud Service | AEM 6.5 | Java SE | Maven
----------------|------------------------|-----------|---------|---------
[2.23.0](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.23.0) | Continual | 6.5.17.0+ | 8, <br/>11 | 3.3.9+
[2.23.2](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.23.2) | Continual | 6.5.17.0+ | 8, <br/>11 | 3.3.9+

For the requirements from previous Core Component releases, see [Historical System Requirements](VERSIONS.md).

Expand All @@ -117,7 +117,7 @@ With AEM as a Cloud Service SDK, use the `cloud` profile as follows to deploy th

Note that:
* `-pl/-projects` option specifies the list of projects that you want to install
* `-am/-also-make` options specifies that dependencies should also be built
* `-am/-also-make` option specifies the dependencies that should also be built

For detailed informations see [BUILDING.md](BUILDING.md).

Expand Down
1 change: 1 addition & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ See below for a full list of system requirements for historical versions of the

Core Components | Extension | AEM 6.5 | AEM 6.4 | AEM 6.3 | Java | Maven
----------------|-----------|-----------|---------|---------|------|------
[2.23.2](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.23.2) | - | 6.5.17.0+ | - | - | 8, 11 | 3.3.9+
[2.23.0](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.23.0) | - | 6.5.17.0+ | - | - | 8, 11 | 3.3.9+
[2.22.12](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.22.12) | - | 6.5.14.0+ | - | - | 8, 11 | 3.3.9+
[2.22.10](https://github.com/adobe/aem-core-wcm-components/releases/tag/core.wcm.components.reactor-2.22.10) | - | 6.5.14.0+ | - | - | 8, 11 | 3.3.9+
Expand Down
4 changes: 2 additions & 2 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
<parent>
<artifactId>core.wcm.components.parent</artifactId>
<groupId>com.adobe.cq</groupId>
<version>2.23.1-SNAPSHOT</version>
<version>2.23.3-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>

<!-- ====================================================================== -->
<!-- P R O J E C T D E S C R I P T I O N -->
<!-- ====================================================================== -->
<artifactId>core.wcm.components.all</artifactId>
<version>2.23.1-SNAPSHOT</version>
<version>2.23.3-SNAPSHOT</version>
<packaging>content-package</packaging>

<name>Adobe Experience Manager Core WCM Components Full Package</name>
Expand Down
4 changes: 2 additions & 2 deletions bundles/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<parent>
<groupId>com.adobe.cq</groupId>
<artifactId>core.wcm.components.parent</artifactId>
<version>2.23.1-SNAPSHOT</version>
<version>2.23.3-SNAPSHOT</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>

<artifactId>core.wcm.components.core</artifactId>
<version>2.23.1-SNAPSHOT</version>
<version>2.23.3-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>Adobe Experience Manager Core WCM Components Core Bundle</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2023 Adobe
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.wcm.core.components.commons.editor.nextgendm;

import org.osgi.annotation.versioning.ProviderType;

@ProviderType
/**
* Thumbnails for Next Generation Dynamic Media Images.
*/
public interface NextGenDMThumbnail {
/**
* Get thumbnail source url for the next generation dynamic media image.
* @return {String} - the url of image thumbnail.
*/
default public String getSrc() {
return null;
}

/**
* Get thumbnail alternative text for the next generation dynamic media image.
* @return {String - the alternative text.
*/
default public String getAlt() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright 2023 Adobe
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
/**
* This package defines next generation dynamic media image thumbnail model.
*/
@Version("1.0.0")
package com.adobe.cq.wcm.core.components.commons.editor.nextgendm;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public static Resource getComponentCandidate(@NotNull String suffix, Resource co
.map(Page::getTemplate)
.map(template -> ResourceUtil.normalize(template.getPath() + suffixPath))
.map(resourceResolver::getResource).orElse(null);
} else {
}

if (componentCandidate == null) {
// image coming from external resource
Resource externalImageResource = resourceResolver.getResource(suffixPath);
if (externalImageResource != null && externalImageResource.isResourceType(IMAGE_RESOURCE_TYPE)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.wcm.core.components.internal.helper.image;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.imageio.ImageIO;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
Expand All @@ -32,12 +36,15 @@
import com.adobe.cq.wcm.spi.AssetDelivery;
import com.day.cq.commons.DownloadResource;
import com.day.cq.commons.ImageResource;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.Rendition;

public class AssetDeliveryHelper {

private static final Logger LOGGER = LoggerFactory.getLogger(AssetDeliveryHelper.class);

private static String COMMA = ",";
private static String PERCENTAGE = "p";
private static String WIDTH_PARAMETER = "width";
private static String QUALITY_PARAMETER = "quality";
private static String CROP_PARAMETER = "c";
Expand Down Expand Up @@ -104,6 +111,32 @@ public static String getSrc(@NotNull AssetDelivery assetDelivery, @NotNull Reso
return null;
}

// we have to get the with and height of the web rendition to calculate relative crop parameter
if (StringUtils.isNotEmpty(componentProperties.get(ImageResource.PN_IMAGE_CROP, String.class))) {
Asset asset = assetResource.adaptTo(Asset.class);
if (asset != null) {

Rendition assetRendition = asset.getRendition(asset1 -> {
for (Rendition rendition : asset1.getRenditions()) {
if (rendition.getName().startsWith("cq5dam.web")) {
return rendition;
}
}
return null;
});
if (assetRendition != null) {
try {
BufferedImage image = ImageIO.read(assetRendition.getStream());
int imageHeight = image.getHeight();
int imageWidth = image.getWidth();
params.put("imageHeight", imageHeight);
params.put("imageWidth", imageWidth);
} catch (IOException e) {
LOGGER.error(e.getMessage());
}
}
}
}
params.put(PATH_PARAMETER, assetPath);
params.put(SEO_PARAMETER, imageName);
params.put(FORMAT_PARAMETER, extension);
Expand Down Expand Up @@ -136,7 +169,7 @@ private static void addWidthParameter(@NotNull Map<String, Object> params, @NotN
}

private static void addCropParameter(@NotNull Map<String, Object> params, @NotNull ValueMap componentProperties) {
String cropParameter = getCropRect(componentProperties);
String cropParameter = getCropRect(componentProperties, params);
if (!StringUtils.isEmpty(cropParameter)) {
params.put(CROP_PARAMETER, cropParameter);
}
Expand All @@ -160,31 +193,49 @@ private static void addFlipParameter(@NotNull Map<String, Object> params, @NotNu
* Retrieves the cropping rectangle, if one is defined for the image.
*
* @param properties the image component's properties
* @param params image parameter
* @return the cropping parameters, if one is found, {@code null} otherwise
*/
private static String getCropRect(@NotNull ValueMap properties) {
private static String getCropRect(@NotNull ValueMap properties, Map<String, Object> params) {
String csv = properties.get(ImageResource.PN_IMAGE_CROP, String.class);
String cropRect = StringUtils.EMPTY;
if (StringUtils.isNotEmpty(csv)) {
try {
int ratio = csv.indexOf('/');
if (ratio >= 0) {
// skip ratio
csv = csv.substring(0, ratio);
}
int imageHeight = (int)params.getOrDefault("imageHeight", 0);
int imageWidth = (int)params.getOrDefault("imageWidth", 0);

String[] coords = csv.split(",");
int x1 = Integer.parseInt(coords[0]);
int y1 = Integer.parseInt(coords[1]);
int x2 = Integer.parseInt(coords[2]);
int y2 = Integer.parseInt(coords[3]);
int width = x2-x1;
int height = y2-y1;
return x1 + COMMA + y1 + COMMA + width + COMMA + height;
double x1 = Integer.parseInt(coords[0]);
double y1 = Integer.parseInt(coords[1]);
double x2 = Integer.parseInt(coords[2]);
double y2 = Integer.parseInt(coords[3]);
if (imageHeight > 0 && imageWidth > 0) {
double width = round( (x2 - x1) / imageWidth * 100);
double height = round((y2-y1) / imageHeight * 100);
x1 = round(( x1 / imageWidth * 100));
y1 = round( y1 / imageHeight * 100);
cropRect = x1 + PERCENTAGE + COMMA + y1 + PERCENTAGE + COMMA + width + PERCENTAGE + COMMA + height + PERCENTAGE;
}
else {
double width = round(x2-x1);
double height = round(y2-y1);
cropRect = x1 + COMMA + y1 + COMMA + width + COMMA + height;
}
} catch (RuntimeException e) {
LOGGER.warn(String.format("Invalid cropping rectangle %s.", csv), e);
}
}
return null;
return cropRect;
}

private static double round(double value) {
int scale = (int) Math.pow(10, 1);
return (double) Math.round(value * scale) / scale;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
package com.adobe.cq.wcm.core.components.internal.link;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -146,11 +148,13 @@ public boolean accepts(@NotNull String path, @NotNull SlingHttpServletRequest re
public @NotNull String map(@NotNull String path, @NotNull SlingHttpServletRequest request) {
ResourceResolver resourceResolver = request.getResourceResolver();
String mappedPath;
Map<String, String> placeholders = new HashMap<>();
String maskedPath = LinkUtil.mask(path, placeholders);
try {
if (vanityConfig == VanityConfig.MAPPING || vanityConfig == VanityConfig.ALWAYS) {
mappedPath = StringUtils.defaultString(resourceResolver.map(request, getPathOrVanityUrl(path, resourceResolver)));
mappedPath = LinkUtil.unmask(StringUtils.defaultString(resourceResolver.map(request, getPathOrVanityUrl(maskedPath, resourceResolver))), placeholders);
} else {
mappedPath = StringUtils.defaultString(resourceResolver.map(request, path));
mappedPath = LinkUtil.unmask(StringUtils.defaultString(resourceResolver.map(request, maskedPath)), placeholders);
}
} catch (Exception e) {
mappedPath = path;
Expand Down
Loading

0 comments on commit 9fd670b

Please sign in to comment.