Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Jul 8, 2024
2 parents 5bdc919 + 92e5e44 commit 9cc0608
Show file tree
Hide file tree
Showing 84 changed files with 1,613 additions and 358 deletions.
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Declare text files with unix file ending
*.any text eol=lf
*.cfg text eol=lf
*.conf text eol=lf
*.config text eol=lf
*.css text eol=lf
*.dtd text eol=lf
*.esp text eol=lf
*.ecma text eol=lf
*.farm text eol=lf
*.gdsl text eol=lf
*.groovy text eol=lf
*.hbrs text eol=lf
*.hbs text eol=lf
Expand All @@ -15,6 +19,7 @@
*.js text eol=lf
*.json text eol=lf
*.jsp text eol=lf
*.md text eol=lf
*.mustache text eol=lf
*.tld text eol=lf
*.launch text eol=lf
Expand All @@ -24,14 +29,19 @@
*.project text eol=lf
*.properties text eol=lf
*.props text eol=lf
*.py text eol=lf
*.rules text eol=lf
*.sass text eol=lf
*.scss text eol=lf
*.sh text eol=lf
*.shtm text eol=lf
*.shtml text eol=lf
*.sql text eol=lf
*.svg text eol=lf
*.tf text eol=lf
*.ts text eol=lf
*.txt text eol=lf
*.vhost text eol=lf
*.vm text eol=lf
*.xml text eol=lf
*.xsd text eol=lf
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ npm-debug.log
.vlt
.vlt-sync*
.brackets.json
.aio
dependency-reduced-pom.xml
39 changes: 33 additions & 6 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@
xsi:schemaLocation="http://maven.apache.org/changes/1.0.0 http://maven.apache.org/plugins/maven-changes-plugin/xsd/changes-1.0.0.xsd">
<body>

<release version="2.1.0" date="2024-07-08">
<action type="add" dev="sseifert" issue="52">
Dynamic Media with OpenAPI: Support Dynamic Media with OpenAPI also for local assets.
</action>
<action type="update" dev="sseifert" issue="56">
Dynamic Media with OpenAPI: Download original binary when resolving media with download flag.
</action>
<action type="update" dev="sseifert" issue="54">
Dynamic Media with OpenAPI: Remove experimental URL parameters from default configuration.
</action>
<action type="update" dev="sseifert" issue="55">
Dynamic Media with OpenAPI: Remove experimental HTTP header for metadata request from default configuration.
</action>
<action type="update" dev="sseifert" issue="58">
Dynamic Media with OpenAPI: Prefer named smart crops over auto-cropped smart renditions.
</action>
<action type="update" dev="sseifert" issue="59">
Dynamic Media with OpenAPI: Enable metadata service by default.
</action>
<action type="update" dev="sseifert" issue="60">
Dynamic Media with OpenAPI: Support setting "Content Disposition Header" to attachment for binary URLs
</action>
<action type="update" dev="sseifert" issue="53">
Improve trace logging: Make log messages involving value maps and resource/page objects more compact and better readable.
</action>
</release>

<release version="2.0.8" date="2024-05-22">
<action type="update" dev="sseifert" issue="51">
Dynamic Media Support: Append fmt=png-alpha for PNG assets to ensure that the alpha channel is preserved in the Dynamic Media rendition.
Expand All @@ -44,16 +71,16 @@

<release version="2.0.2" date="2024-03-13">
<action type="update" dev="sseifert" issue="44">
Next Generation Dynamic Media: Support non-image assets and SVG assets.
Dynamic Media with OpenAPI: Support non-image assets and SVG assets.
</action>
<action type="update" dev="sseifert" issue="45">
Next Generation Dynamic Media: Use latest NextGen Dynamic Media Asset URLs and make them configurable via OSGi config.
Dynamic Media with OpenAPI: Use latest NextGen Dynamic Media Asset URLs and make them configurable via OSGi config.
</action>
<action type="update" dev="sseifert" issue="47">
Next Generation Dynamic Media: Replace fileupload default pick/remote trigger with customized one to display the customized asset selector dialog.
Dynamic Media with OpenAPI: Replace fileupload default pick/remote trigger with customized one to display the customized asset selector dialog.
</action>
<action type="update" dev="sseifert" issue="48">
Next Generation Dynamic Media: Optionally fetch metadata of NGDM asset reference to check for validity and maximum possible resolution.
Dynamic Media with OpenAPI: Optionally fetch metadata of NGDM asset reference to check for validity and maximum possible resolution.
</action>
</release>

Expand All @@ -62,11 +89,11 @@
Version 2.0.0 contains minor breaking API changes, see <a href=https://wcm-io.atlassian.net/wiki/x/AYBxsw">Migrate from wcm.io Handler 1.x to 2.x</a> for details.
]]></action>
<action type="add" dev="sseifert" issue="30"><![CDATA[
Add support for Web-Optimized Image Delivery (part of Next Generation Dynamic Media) - rendering asset renditions from AEM Sites instance on the edge.<br/>
Add support for Web-Optimized Image Delivery (part of Dynamic Media with OpenAPI) - rendering asset renditions from AEM Sites instance on the edge.<br/>
<b>This feature is active by default on AEMaaCS cloud instances, can be disabled via OSGi configuration</b>.
]]></action>
<action type="add" dev="sseifert" issue="38">
Add support for Next Generation Dynamic Media remote assets. This is a first experimental support and will be finalized in release 2.0.2.
Add support for Dynamic Media with OpenAPI (also known as Next Generation Dynamic Media) remote assets. This is a first experimental support and will be finalized in release 2.0.2.
</action>
<action type="add" dev="sseifert" issue="33">
Allow to set image quality per media request.
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
<parent>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.parent_toplevel</artifactId>
<version>2.3.0</version>
<version>2.3.2</version>
<relativePath/>
</parent>

<groupId>io.wcm</groupId>
<artifactId>io.wcm.handler.media</artifactId>
<version>2.0.8</version>
<version>2.1.0</version>
<packaging>jar</packaging>

<name>Media Handler</name>
Expand All @@ -49,7 +49,7 @@
<site.url.module.prefix>handler/media</site.url.module.prefix>

<!-- Enable reproducible builds -->
<project.build.outputTimestamp>2024-05-22T07:37:48Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2024-07-08T08:50:40Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand Down Expand Up @@ -82,7 +82,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.wcm.commons</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/wcm/handler/media/Media.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public void setMediaInvalidReasonCustomMessage(@Nullable String mediaInvalidReas
@Override
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
sb.append("valid", isValid());
if (isValid()) {
sb.append("url", getUrl());
}
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/io/wcm/handler/media/MediaArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.wcm.handler.mediasource.dam.AemRenditionType;
import io.wcm.handler.url.UrlMode;
import io.wcm.wcm.commons.contenttype.FileExtension;
import io.wcm.wcm.commons.util.AemObjectReflectionToStringBuilder;

/**
* Holds parameters to influence the media resolving process.
Expand Down Expand Up @@ -843,7 +844,7 @@ public String toString() {
sb.append("webOptimizedImageDeliveryDisabled", webOptimizedImageDeliveryDisabled);
}
if (properties != null && !properties.isEmpty()) {
sb.append("properties", properties);
sb.append("properties", AemObjectReflectionToStringBuilder.filteredValueMap(properties));
}
return sb.build();
}
Expand Down Expand Up @@ -918,14 +919,23 @@ public MediaFormatOption(@NotNull String mediaFormatName, boolean mandatory) {
this.mandatory = mandatory;
}

/**
* @return Media format
*/
public @Nullable MediaFormat getMediaFormat() {
return this.mediaFormat;
}

/**
* @return Media format name
*/
public @Nullable String getMediaFormatName() {
return this.mediaFormatName;
}

/**
* @return Resolution of this media format is mandatory
*/
public boolean isMandatory() {
return this.mandatory;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/wcm/handler/media/MediaFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private static Set<String> getFileExtensions(@NotNull EnumSet<MediaFileType> fil
return null;
}
String contentTypeLowerCase = StringUtils.toRootLowerCase(contentType);
return Stream.of(MediaFileType.values())
return Stream.of(values())
.filter(type -> type.getContentTypes().contains(contentTypeLowerCase))
.findFirst()
.orElse(null);
Expand All @@ -240,7 +240,7 @@ private static Set<String> getFileExtensions(@NotNull EnumSet<MediaFileType> fil
return null;
}
String extensionLowerCase = StringUtils.toRootLowerCase(extension);
return Stream.of(MediaFileType.values())
return Stream.of(values())
.filter(type -> type.getExtensions().contains(extensionLowerCase))
.findFirst()
.orElse(null);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/io/wcm/handler/media/MediaInvalidReason.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public enum MediaInvalidReason {
*/
MEDIA_REFERENCE_INVALID,

/**
* Media reference is valid, but the media is not approved.
* This is only relevant for assets served via Dynamic Media with OpenAPI.
*/
NOT_APPROVED,

/**
* No matching rendition: The media item exists, but no rendition matches for the requested media args.
*/
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/io/wcm/handler/media/MediaRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

import java.util.HashMap;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.wrappers.ValueMapDecorator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;

import io.wcm.wcm.commons.util.AemObjectReflectionToStringBuilder;

/**
* Holds all properties that are part of a media handling request.
*/
Expand Down Expand Up @@ -119,10 +119,11 @@ public MediaRequest(@Nullable Resource resource, @Nullable String mediaRef, @Nul

@Override
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
ToStringBuilder sb = new ToStringBuilder(this,
io.wcm.wcm.commons.util.ToStringStyle.SHORT_PREFIX_OMIT_NULL_STYLE);
if (resource != null) {
sb.append("resource", resource.getPath());
sb.append("resourceProperties", "[" + StringUtils.join(resource.getValueMap().entrySet(), ",") + "]");
sb.append("resourceProperties", AemObjectReflectionToStringBuilder.filteredValueMap(resource.getValueMap()));
}
if (mediaRef != null) {
sb.append("mediaRef", mediaRef);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/wcm/handler/media/format/MediaFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,9 @@ String getCombinedTitle() {

// add extended display parts
if (!extParts.isEmpty()) {
sb.append(" (");
sb.append(StringUtils.join(extParts, "; "));
sb.append(')');
sb.append(" (")
.append(StringUtils.join(extParts, "; "))
.append(')');
}

combinedTitle = sb.toString();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wcm/handler/media/format/Ratio.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static double get(double width, double height) {
* @return Ratio (returns 0 when ratio is invalid)
*/
public static double get(long width, long height) {
return Ratio.get((double)width, (double)height);
return get((double)width, (double)height);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private void setContentDisposition(SlingHttpServletRequest request, SlingHttpSer
*/
@SuppressWarnings("null")
private boolean accepts(SlingHttpServletRequest request) {
return request.getMethod().equalsIgnoreCase(METHOD_GET)
return StringUtils.equalsIgnoreCase(request.getMethod(), METHOD_GET)
&& request.getResource() != null
&& StringUtils.equals(request.getResource().getValueMap().get(JCR_PRIMARYTYPE, String.class), NT_FILE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public final HtmlElement build(@NotNull Media media) {
* @param media Media
* @return Media format or null if none found
*/
@SuppressWarnings("null")
protected final @Nullable MediaFormat getFirstMediaFormat(@NotNull Media media) {
return media.getRenditions().stream()
.map(Rendition::getMediaFormat)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/wcm/handler/media/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
/**
* Media Handler API.
*/
@org.osgi.annotation.versioning.Version("2.0.0")
@org.osgi.annotation.versioning.Version("2.1.0")
package io.wcm.handler.media;
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean matches(@NotNull Rendition rendition) {
*/
@SuppressWarnings("null")
public static @Nullable AemRenditionType forRendition(@NotNull String renditionName) {
return Stream.of(AemRenditionType.values())
return Stream.of(values())
.filter(type -> type.matches(renditionName))
.findFirst()
.orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.sling.api.adapter.Adaptable;
import org.apache.sling.api.adapter.SlingAdaptable;
import org.apache.sling.api.resource.Resource;
Expand All @@ -45,7 +44,7 @@
import io.wcm.handler.mediasource.dam.AssetRendition;
import io.wcm.handler.mediasource.dam.impl.dynamicmedia.DynamicMediaSupportService;
import io.wcm.handler.mediasource.dam.impl.weboptimized.WebOptimizedImageDeliveryService;
import io.wcm.wcm.commons.util.ToStringStyle;
import io.wcm.wcm.commons.util.AemObjectReflectionToStringBuilder;

/**
* {@link Asset} implementation for DAM assets.
Expand Down Expand Up @@ -225,7 +224,8 @@ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_OMIT_NULL_STYLE);
return new AemObjectReflectionToStringBuilder(this,
io.wcm.wcm.commons.util.ToStringStyle.SHORT_PREFIX_OMIT_NULL_STYLE).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,22 @@ public void setMediaFormat(MediaFormat mediaFormat) {
*/
public @NotNull String getMediaPath(boolean contentDispositionAttachment) {
if (contentDispositionAttachment) {
return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + MediaFileServletConstants.SELECTOR
return buildMediaPath(getRendition().getPath() + "." + MediaFileServletConstants.SELECTOR
+ "." + MediaFileServletConstants.SELECTOR_DOWNLOAD
+ "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment));
}
else if (MediaFileType.isVectorImage(getFileExtension())) {
return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + MediaFileServletConstants.SELECTOR
return buildMediaPath(getRendition().getPath() + "." + MediaFileServletConstants.SELECTOR
+ "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment));
}
else if (MediaFileType.isBrowserImage(getFileExtension()) || !MediaFileType.isImage(getFileExtension())) {
// use "deep URL" to reference rendition directly
// do not use Asset URL for original rendition because it creates conflicts for dispatcher cache (filename vs. directory for asset resource name)
return RenditionMetadata.buildMediaPath(this.rendition.getPath() + ".", getFileName(contentDispositionAttachment));
return buildMediaPath(this.rendition.getPath() + ".", getFileName(contentDispositionAttachment));
}
else {
// image rendition uses a file extension that cannot be displayed in browser directly - render via ImageFileServlet
return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + ImageFileServlet.SELECTOR
return buildMediaPath(getRendition().getPath() + "." + ImageFileServlet.SELECTOR
+ "." + getWidth() + "." + getHeight()
+ "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public long getHeight() {
// vector images can be scaled in browser without need of ImageFileServlet
return super.getMediaPath(contentDispositionAttachment);
}
return RenditionMetadata.buildMediaPath(getRendition().getPath()
return buildMediaPath(getRendition().getPath()
+ "." + ImageFileServletSelector.build(getWidth(), getHeight(),
null, null, this.imageQualityPercentage, contentDispositionAttachment)
+ "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public Integer getRotation() {

@Override
public @NotNull String getMediaPath(boolean contentDispositionAttachment) {
return RenditionMetadata.buildMediaPath(getRendition().getPath()
return buildMediaPath(getRendition().getPath()
+ "." + ImageFileServletSelector.build(getWidth(), getHeight(),
this.cropDimension, this.rotation, this.imageQualityPercentage, contentDispositionAttachment)
+ "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment));
Expand Down
Loading

0 comments on commit 9cc0608

Please sign in to comment.