Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Dec 10, 2024
2 parents 8a5f003 + e14b858 commit 71fb33a
Show file tree
Hide file tree
Showing 24 changed files with 679 additions and 454 deletions.
18 changes: 18 additions & 0 deletions changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@
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.3.0" date="2024-12-10">
<action type="add" dev="sseifert" issue="69">
Add new GraniteUI validator 'wcmio.handler.media.mediaFormat' which can be set on Media Handler File Upload or Path Field components to hook the media format validation into the GraniteUI dialog validation.
</action>
<action type="update" dev="sseifert" issue="71">
Dynamic Media with Open API: Use remote metadata call to validate and get metadata for local assets as well.
</action>
<action type="update" dev="sseifert" issue="73">
Dynamic Media with Open API: Optional IMS Authentication for metadata requests to get full asset metadata.
</action>
<action type="fix" dev="sseifert" issue="72">
Dynamic Media with OpenAPI: Respect Image Dimension from SVG asset metadata.
</action>
<action type="fix" dev="sseifert" issue="74">
GraniteUI validator: Use data-foundation-validation instead of data-validation HTML attribute, the latter is deprecated.
</action>
</release>

<release version="2.2.2" date="2024-09-16">
<action type="update" dev="sseifert" issue="67">
Dynamic Media with Open API: Correctly calculate rendition width/height based on requested dimension or original dimension.
Expand Down
19 changes: 10 additions & 9 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.2</version>
<version>2.3.4</version>
<relativePath/>
</parent>

<groupId>io.wcm</groupId>
<artifactId>io.wcm.handler.media</artifactId>
<version>2.2.2</version>
<version>2.3.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-09-16T09:04:34Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2024-12-10T08:03:27Z</project.build.outputTimestamp>
</properties>

<dependencies>
Expand Down Expand Up @@ -144,7 +144,7 @@
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<version>5.6.0</version>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -204,18 +204,19 @@
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.8.0</version>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>2.8.0</version>
<version>2.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock</artifactId>
<!-- Stich with version 3.4.0 because recent versions require a newer Jackson version -->
<version>3.4.0</version>
<scope>test</scope>
</dependency>
Expand All @@ -224,20 +225,20 @@
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-tiff</artifactId>
<version>3.10.1</version>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
<!-- Java ImageIO Support for SVG -->
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-batik</artifactId>
<version>3.10.1</version>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.17</version>
<version>1.18</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package io.wcm.handler.mediasource.ngdm;

import static com.day.cq.dam.api.DamConstants.DC_DESCRIPTION;
import static com.day.cq.dam.api.DamConstants.DC_TITLE;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.sling.api.resource.Resource;
Expand All @@ -32,37 +35,50 @@
import io.wcm.handler.media.UriTemplate;
import io.wcm.handler.media.UriTemplateType;
import io.wcm.handler.mediasource.ngdm.impl.NextGenDynamicMediaContext;
import io.wcm.handler.mediasource.ngdm.impl.metadata.NextGenDynamicMediaMetadata;

/**
* {@link Asset} implementation for Next Gen. Dynamic Media remote assets.
*/
final class NextGenDynamicMediaAsset implements Asset {

private final NextGenDynamicMediaContext context;
private final MediaArgs defaultMediaArgs;
private final ValueMap properties;

NextGenDynamicMediaAsset(@NotNull NextGenDynamicMediaContext context) {
this.context = context;
this.defaultMediaArgs = context.getDefaultMediaArgs();

NextGenDynamicMediaMetadata metadata = context.getMetadata();
if (metadata != null) {
this.properties = metadata.getProperties();
}
else {
this.properties = ValueMap.EMPTY;
}
}

@Override
public @Nullable String getTitle() {
return context.getReference().getFileName();
return StringUtils.defaultString(properties.get(DC_TITLE, String.class),
context.getReference().getFileName());
}

@Override
public @Nullable String getAltText() {
if (context.getDefaultMediaArgs().isDecorative()) {
if (defaultMediaArgs.isDecorative()) {
return "";
}
else {
return context.getDefaultMediaArgs().getAltText();
if (!defaultMediaArgs.isForceAltValueFromAsset() && StringUtils.isNotEmpty(defaultMediaArgs.getAltText())) {
return defaultMediaArgs.getAltText();
}
return StringUtils.defaultString(getDescription(), getTitle());
}

@Override
public @Nullable String getDescription() {
// not supported
return null;
return properties.get(DC_DESCRIPTION, String.class);
}

@Override
Expand All @@ -72,12 +88,12 @@ final class NextGenDynamicMediaAsset implements Asset {

@Override
public @NotNull ValueMap getProperties() {
return ValueMap.EMPTY;
return properties;
}

@Override
public @Nullable Rendition getDefaultRendition() {
return getRendition(this.context.getDefaultMediaArgs());
return getRendition(defaultMediaArgs);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.day.cq.dam.api.Asset;
import com.day.cq.wcm.api.WCMMode;
import com.day.cq.wcm.api.components.ComponentContext;
import com.day.cq.wcm.api.components.EditConfig;
Expand Down Expand Up @@ -136,11 +135,7 @@ private boolean isDamAssetReference(@Nullable String mediaRef) {

// If enabled: Fetch asset metadata to validate existence and get original dimensions
NextGenDynamicMediaMetadata metadata = null;
Asset localAsset = reference.getAsset();
if (localAsset != null) {
metadata = getMetadataFromAsset(localAsset);
}
else if (metadataService != null && metadataService.isEnabled()) {
if (metadataService != null && metadataService.isEnabled()) {
metadata = metadataService.fetchMetadata(reference);
if (metadata == null) {
media.setMediaInvalidReason(MediaInvalidReason.MEDIA_REFERENCE_INVALID);
Expand Down Expand Up @@ -194,14 +189,6 @@ else if (nextGenDynamicMediaConfig.isEnabledLocalAssets() && isDamAssetReference
return null;
}

private @Nullable NextGenDynamicMediaMetadata getMetadataFromAsset(@NotNull Asset asset) {
NextGenDynamicMediaMetadata metadata = NextGenDynamicMediaMetadata.fromAsset(asset);
if (metadata.isValid()) {
return metadata;
}
return null;
}

@Override
public void enableMediaDrop(@NotNull HtmlElement element, @NotNull MediaRequest mediaRequest) {
if (wcmMode == WCMMode.DISABLED || wcmMode == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ final class NextGenDynamicMediaRendition implements Rendition {
this.fileExtension = FilenameUtils.getExtension(reference.getFileName());
}

if (isVectorImage() || !isImage() || mediaArgs.isDownload()) {
if (!isImage() || mediaArgs.isDownload()) {
// deliver as binary
this.url = buildBinaryUrl();
}
else if (isVectorImage()) {
// calculate width/height for rendition metadata
calculateWidthHeight();
// deliver as binary
this.url = buildBinaryUrl();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ public NextGenDynamicMediaReference(@NotNull String assetId, @NotNull String fil
return asset;
}

/**
* @return True if reference points to local asset.
*/
public boolean isLocal() {
return asset != null;
}

/**
* @return Reference
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* #%L
* wcm.io
* %%
* Copyright (C) 2024 wcm.io
* %%
* 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.
* #L%
*/
package io.wcm.handler.mediasource.ngdm.impl.metadata;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Used for Jackson Object mapping of JSON response from IMS Token v3 API.
*/
@SuppressWarnings({ "checkstyle:VisibilityModifierCheck", "java:S1104" })
@SuppressFBWarnings("UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD")
@JsonIgnoreProperties(ignoreUnknown = true)
final class AccessTokenResponse {

@JsonProperty("access_token")
public String accessToken;

@JsonProperty("token_type")
public String tokenType;

@JsonProperty("expires_in")
public long expiresInSec;

}
Loading

0 comments on commit 71fb33a

Please sign in to comment.