-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,091 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
...les/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/VideoImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2021 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.internal.models.v1; | ||
|
||
import com.adobe.cq.export.json.ComponentExporter; | ||
import com.adobe.cq.export.json.ExporterConstants; | ||
import com.adobe.cq.wcm.core.components.commons.link.Link; | ||
import com.adobe.cq.wcm.core.components.internal.link.LinkHandler; | ||
import com.adobe.cq.wcm.core.components.models.Video; | ||
import com.adobe.cq.wcm.core.components.models.datalayer.AssetData; | ||
import com.adobe.cq.wcm.core.components.models.datalayer.ComponentData; | ||
import com.adobe.cq.wcm.core.components.models.datalayer.builder.AssetDataBuilder; | ||
import com.adobe.cq.wcm.core.components.models.datalayer.builder.DataLayerBuilder; | ||
import com.day.cq.dam.api.Asset; | ||
import com.day.cq.rewriter.linkchecker.LinkChecker; | ||
import com.day.cq.rewriter.linkchecker.LinkValidity; | ||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.resource.ValueMap; | ||
import org.apache.sling.models.annotations.Default; | ||
import org.apache.sling.models.annotations.Exporter; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.injectorspecific.*; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.osgi.service.component.annotations.Reference; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.inject.Inject; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
@Model( | ||
adaptables = SlingHttpServletRequest.class, | ||
adapters = {Video.class, ComponentExporter.class}, | ||
resourceType = VideoImpl.RESOURCE_TYPE | ||
) | ||
@Exporter( | ||
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, | ||
extensions = ExporterConstants.SLING_MODEL_EXTENSION | ||
) | ||
public class VideoImpl extends AbstractComponentImpl implements Video { | ||
|
||
public static final String RESOURCE_TYPE = "core/wcm/components/video/v1/video"; | ||
|
||
@OSGiService | ||
private LinkChecker checker; | ||
|
||
@ValueMapValue(name = "videoFileReference", injectionStrategy = InjectionStrategy.OPTIONAL) | ||
@Nullable | ||
private String fileReference; | ||
|
||
@ValueMapValue(name = "posterImageReference", injectionStrategy = InjectionStrategy.OPTIONAL) | ||
@Nullable | ||
private String posterImageReference; | ||
|
||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) | ||
@Default(booleanValues = false) | ||
private boolean hideControl; | ||
|
||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) | ||
@Default(booleanValues = false) | ||
private boolean loopEnabled; | ||
|
||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL) | ||
@Default(booleanValues = false) | ||
private boolean autoplayEnabled; | ||
|
||
/** | ||
* The current resource properties. | ||
*/ | ||
@ScriptVariable | ||
protected ValueMap properties; | ||
|
||
/** | ||
* Initialize the model. | ||
*/ | ||
@PostConstruct | ||
private void initModel() { | ||
posterImageReference = properties.get(Video.PN_POSTER_REFERENCE, posterImageReference); | ||
hideControl = properties.get(Video.PN_HIDE_CONTROL, hideControl); | ||
loopEnabled = properties.get(Video.PN_LOOP_ENABLED, loopEnabled); | ||
autoplayEnabled = properties.get(Video.PN_AUTOPLAY_ENABLED, autoplayEnabled); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public String getFileReference() { | ||
final LinkValidity validity = checker.getLink(fileReference, checker.createSettings(this.request)).getValidity(); | ||
if (validity.equals(LinkValidity.VALID)) { | ||
return fileReference; | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public String getPosterImageReference() { | ||
return posterImageReference; | ||
} | ||
|
||
@Override | ||
public boolean isHideControl() { | ||
return hideControl; | ||
} | ||
|
||
@Override | ||
public boolean isLoopEnabled() { | ||
return loopEnabled; | ||
} | ||
|
||
@Override | ||
public boolean isAutoplayEnabled() { | ||
return autoplayEnabled; | ||
} | ||
|
||
@Override | ||
@NotNull | ||
protected ComponentData getComponentData() { | ||
return DataLayerBuilder.extending(super.getComponentData()) | ||
.asVideoComponent() | ||
.withAssetData(dataSupplier) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public @NotNull String getExportedType() { | ||
return resource.getResourceType(); | ||
} | ||
|
||
private final Supplier<AssetData> dataSupplier = () -> | ||
Optional.ofNullable(this.fileReference) | ||
.map(reference -> this.request.getResourceResolver().getResource(reference)) | ||
.map(assetResource -> assetResource.adaptTo(Asset.class)) | ||
.map(DataLayerBuilder::forAsset) | ||
.map(AssetDataBuilder::build) | ||
.orElse(null); | ||
} |
55 changes: 55 additions & 0 deletions
55
...ain/java/com/adobe/cq/wcm/core/components/internal/models/v1/datalayer/VideoDataImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2020 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.internal.models.v1.datalayer; | ||
|
||
import com.adobe.cq.wcm.core.components.models.datalayer.AssetData; | ||
import com.adobe.cq.wcm.core.components.models.datalayer.VideoData; | ||
import com.adobe.cq.wcm.core.components.models.datalayer.builder.DataLayerSupplier; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* {@link DataLayerSupplier} backed video component data implementation. | ||
*/ | ||
public class VideoDataImpl extends ComponentDataImpl implements VideoData { | ||
/** | ||
* The asset field value. | ||
*/ | ||
private AssetData assetData; | ||
|
||
/** | ||
* Construct the data layer model. | ||
* | ||
* @param supplier The data layer supplier. | ||
*/ | ||
public VideoDataImpl(@NotNull DataLayerSupplier supplier) { | ||
super(supplier); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public AssetData getAssetData() { | ||
if (this.assetData == null) { | ||
this.assetData = this.getDataLayerSupplier() | ||
.getAssetData() | ||
.map(Supplier::get) | ||
.orElse(null); | ||
} | ||
return this.assetData; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
bundles/core/src/main/java/com/adobe/cq/wcm/core/components/models/Video.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2021 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.models; | ||
|
||
import org.osgi.annotation.versioning.ConsumerType; | ||
|
||
@ConsumerType | ||
public interface Video extends Component { | ||
|
||
/** | ||
* Name of the property that defines the image to be shown while the video is downloading. | ||
* | ||
*/ | ||
String PN_POSTER_REFERENCE = "posterImageReference"; | ||
|
||
/** | ||
* Name of the property that defines if video controls should be hidden. | ||
* | ||
*/ | ||
String PN_HIDE_CONTROL = "hideControl"; | ||
|
||
/** | ||
* Name of the property that defines if video looping is enabled. | ||
* | ||
*/ | ||
String PN_LOOP_ENABLED = "loopEnabled"; | ||
|
||
/** | ||
* Name of the property that defines if video autoplay is enabled. | ||
* | ||
*/ | ||
String PN_AUTOPLAY_ENABLED = "autoplayEnabled"; | ||
|
||
/** | ||
* Returns the file reference of the current video, if one exists. | ||
* | ||
* @return Returns the file reference of the current video, if one exists, or {@code null} otherwise | ||
*/ | ||
default String getFileReference() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns the file reference of the image used as a poser for the video | ||
* | ||
* @return Returns the file reference of the image used as a poser for the video, or {@code null} if it doesn't exist | ||
*/ | ||
default String getPosterImageReference() { | ||
return null; | ||
} | ||
|
||
/** | ||
* Returns weather the video controls should be hidden or not | ||
* | ||
* @return Returns true if video controls should be hidden, false otherwise | ||
*/ | ||
default boolean isHideControl() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns weather the video loop should be enabled or not | ||
* | ||
* @return Returns true if video loop should be enabled, false otherwise | ||
*/ | ||
default boolean isLoopEnabled() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns weather the video autoplay should be enabled or not | ||
* | ||
* @return Returns true if video autoplay should be enabled, false otherwise | ||
*/ | ||
default boolean isAutoplayEnabled() { | ||
return false; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
bundles/core/src/main/java/com/adobe/cq/wcm/core/components/models/datalayer/VideoData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2020 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.models.datalayer; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public interface VideoData extends ComponentData { | ||
/** | ||
* Returns the asset associated with the video. | ||
* | ||
* @return Asset data model | ||
* | ||
* @since com.adobe.cq.wcm.core.components.models.datalayer 1.0.0 | ||
*/ | ||
@JsonProperty("video") | ||
default AssetData getAssetData() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.