-
Notifications
You must be signed in to change notification settings - Fork 732
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of https://github.com/adobe/aem-core-wcm-c…
…omponents into issue/1367
- Loading branch information
Showing
1,222 changed files
with
44,238 additions
and
13,020 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
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
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
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
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
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
122 changes: 122 additions & 0 deletions
122
.../main/java/com/adobe/cq/wcm/core/components/commons/editor/dialog/PageImageThumbnail.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,122 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ 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.commons.editor.dialog; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.inject.Inject; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.request.RequestParameter; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.injectorspecific.Self; | ||
import org.apache.sling.models.annotations.injectorspecific.SlingObject; | ||
import org.apache.sling.models.factory.ModelFactory; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.adobe.cq.wcm.core.components.models.Image; | ||
import com.adobe.cq.wcm.core.components.util.ComponentUtils; | ||
import com.day.cq.wcm.api.Page; | ||
import com.day.cq.wcm.api.PageManager; | ||
|
||
/** | ||
* Defines a Sling Model used by the {@code core/wcm/components/commons/editor/dialog/pageimagethumbnail/v1/pageimagethumbnail} dialog component. | ||
* | ||
* @since com.adobe.cq.wcm.core.components.commons.editor.dialog 1.0.0 | ||
*/ | ||
@Model( | ||
adaptables = SlingHttpServletRequest.class | ||
) | ||
public class PageImageThumbnail { | ||
|
||
private final static Logger log = LoggerFactory.getLogger(PageImageThumbnail.class); | ||
|
||
@Self | ||
private SlingHttpServletRequest request; | ||
|
||
@SlingObject | ||
private ResourceResolver resourceResolver; | ||
|
||
@Inject | ||
private ModelFactory modelFactory; | ||
|
||
private String alt; | ||
private String src; | ||
|
||
@PostConstruct | ||
protected void initModel() { | ||
String path = request.getRequestPathInfo().getSuffix(); | ||
if (StringUtils.isBlank(path)) { | ||
RequestParameter itemParam = request.getRequestParameter("item"); | ||
if (itemParam == null) { | ||
log.error("Suffix and 'item' param are blank"); | ||
return; | ||
} | ||
path = itemParam.getString(); | ||
} | ||
|
||
PageManager pageManager = resourceResolver.adaptTo(PageManager.class); | ||
if (pageManager == null) { | ||
log.error("pagemanager is null"); | ||
return; | ||
} | ||
|
||
Resource component = resourceResolver.getResource(path); | ||
Page containingPage = pageManager.getContainingPage(component); | ||
if (containingPage == null) { | ||
log.error("page is null"); | ||
return; | ||
} | ||
|
||
Resource featuredImage = ComponentUtils.getFeaturedImage(containingPage); | ||
if (featuredImage == null) { | ||
log.error("the featured image is null"); | ||
return; | ||
} | ||
|
||
Image imageModel = modelFactory.getModelFromWrappedRequest(request, featuredImage, Image.class); | ||
if (imageModel == null) { | ||
log.error("the image model is null"); | ||
return; | ||
} | ||
|
||
alt = imageModel.getAlt(); | ||
src = imageModel.getSrc(); | ||
} | ||
|
||
|
||
/** | ||
* Returns the alternative text of the featured image of the page, which the component belongs to. | ||
* | ||
* @return the alternative text of the page image | ||
*/ | ||
public String getAlt() { | ||
return alt; | ||
} | ||
|
||
/** | ||
* Returns the src attribute of the featured image of the page, which the component belongs to. | ||
* | ||
* @return the alternative text of the page image | ||
*/ | ||
public String getSrc() { | ||
return src; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...re/src/main/java/com/adobe/cq/wcm/core/components/commons/editor/dialog/package-info.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,25 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ 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. | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ | ||
/** | ||
* <p> | ||
* This package defines the Sling Models exposed for the dialog widgets. | ||
* </p> | ||
* | ||
*/ | ||
@Version("1.0.0") | ||
package com.adobe.cq.wcm.core.components.commons.editor.dialog; | ||
|
||
import org.osgi.annotation.versioning.Version; |
Oops, something went wrong.