Skip to content

Commit

Permalink
Merge 51447af into 8dc70ab
Browse files Browse the repository at this point in the history
  • Loading branch information
georgecamilar authored Jun 14, 2021
2 parents 8dc70ab + 51447af commit deb6f7e
Show file tree
Hide file tree
Showing 31 changed files with 1,091 additions and 12 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ Please help us making the Core Components better by responding to our **[short u
18. [Experience Fragment](content/src/content/jcr_root/apps/core/wcm/components/experiencefragment/v1/experiencefragment)
19. [Content Fragment](content/src/content/jcr_root/apps/core/wcm/components/contentfragment/v1/contentfragment)
20. [Content Fragment List](content/src/content/jcr_root/apps/core/wcm/components/contentfragmentlist/v1/contentfragmentlist)

21. [Video](content/src/content/jcr_root/apps/core/wcm/components/video/v1/video)
### Container Components

21. [Container](content/src/content/jcr_root/apps/core/wcm/components/container/v1/container)
22. [Carousel](content/src/content/jcr_root/apps/core/wcm/components/carousel/v1/carousel)
23. [Tabs](content/src/content/jcr_root/apps/core/wcm/components/tabs/v1/tabs)
24. [Accordion](content/src/content/jcr_root/apps/core/wcm/components/accordion/v1/accordion)
22. [Container](content/src/content/jcr_root/apps/core/wcm/components/container/v1/container)
23. [Carousel](content/src/content/jcr_root/apps/core/wcm/components/carousel/v1/carousel)
24. [Tabs](content/src/content/jcr_root/apps/core/wcm/components/tabs/v1/tabs)
25. [Accordion](content/src/content/jcr_root/apps/core/wcm/components/accordion/v1/accordion)

### Form Components

25. [Core Form container](content/src/content/jcr_root/apps/core/wcm/components/form/container/v2/container)
26. [Form text field](content/src/content/jcr_root/apps/core/wcm/components/form/text/v2/text)
27. [Form options field](content/src/content/jcr_root/apps/core/wcm/components/form/options/v2/options)
28. [Form hidden field](content/src/content/jcr_root/apps/core/wcm/components/form/hidden/v2/hidden)
29. [Form button](content/src/content/jcr_root/apps/core/wcm/components/form/button/v2/button)
26. [Core Form container](content/src/content/jcr_root/apps/core/wcm/components/form/container/v2/container)
27. [Form text field](content/src/content/jcr_root/apps/core/wcm/components/form/text/v2/text)
28. [Form options field](content/src/content/jcr_root/apps/core/wcm/components/form/options/v2/options)
29. [Form hidden field](content/src/content/jcr_root/apps/core/wcm/components/form/hidden/v2/hidden)
30. [Form button](content/src/content/jcr_root/apps/core/wcm/components/form/button/v2/button)

### Roadmap

Expand Down
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);
}
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;
}
}
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;
}

}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ public ImageComponentDataBuilder asImageComponent() {
return new ImageComponentDataBuilder(DataLayerSupplierImpl.extend(this.componentData));
}

/**
* Get a VideoComponentDataBuilder that extends existing component data.
*
* @return A new VideoComponentDataBuilder pre-initialized with the existing image component data.
*/
@NotNull
public VideoComponentDataBuilder asVideoComponent() {
return new VideoComponentDataBuilder(DataLayerSupplierImpl.extend(this.componentData));
}

/**
* Get a ContentFragmentDataBuilder that extends existing component data.
*
Expand Down
Loading

0 comments on commit deb6f7e

Please sign in to comment.