use of com.adobe.cq.wcm.core.components.commons.link.Link in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class TeaserImplTest method testImageFromPage_withoutLink.
@Test
protected void testImageFromPage_withoutLink() {
Teaser teaser = getTeaserUnderTest(TEASER_21);
Link link = teaser.getLink();
assertNull(link);
Utils.testJSONExport(teaser, Utils.getTestExporterJSONPath(testBase, "teaser21"));
}
use of com.adobe.cq.wcm.core.components.commons.link.Link in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ImageImpl method buildAreas.
protected void buildAreas() {
areas = new ArrayList<>();
String mapProperty = properties.get(Image.PN_MAP, String.class);
if (StringUtils.isNotEmpty(mapProperty)) {
// Parse the image map areas as defined at {@code Image.PN_MAP}
String[] mapAreas = StringUtils.split(mapProperty, "][");
for (String area : mapAreas) {
int coordinatesEndIndex = area.indexOf(')');
if (coordinatesEndIndex < 0) {
break;
}
String shapeAndCoords = StringUtils.substring(area, 0, coordinatesEndIndex + 1);
String shape = StringUtils.substringBefore(shapeAndCoords, "(");
String coordinates = StringUtils.substringBetween(shapeAndCoords, "(", ")");
String remaining = StringUtils.substring(area, coordinatesEndIndex + 1);
String[] remainingTokens = StringUtils.split(remaining, "|");
if (StringUtils.isBlank(shape) || StringUtils.isBlank(coordinates)) {
break;
}
if (remainingTokens.length > 0) {
String href = StringUtils.removeAll(remainingTokens[0], "\"");
String target = remainingTokens.length > 1 ? StringUtils.removeAll(remainingTokens[1], "\"") : "";
Link link = linkHandler.getLink(href, target).orElse(null);
if (link == null || !link.isValid()) {
break;
}
String alt = remainingTokens.length > 2 ? StringUtils.removeAll(remainingTokens[2], "\"") : "";
String relativeCoordinates = remainingTokens.length > 3 ? remainingTokens[3] : "";
relativeCoordinates = StringUtils.substringBetween(relativeCoordinates, "(", ")");
areas.add(newImageArea(shape, coordinates, relativeCoordinates, link, alt));
}
}
}
}
use of com.adobe.cq.wcm.core.components.commons.link.Link in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContainerImpl method initModel.
@PostConstruct
private void initModel() {
FormStructureHelper formStructureHelper = formStructureHelperFactory.getFormStructureHelper(resource);
request.setAttribute(FormsHelper.REQ_ATTR_FORM_STRUCTURE_HELPER, formStructureHelper);
this.action = linkHandler.getLink(currentPage).map(Link::getURL).orElse(null);
String formId = FormsHelper.getFormId(request);
if (StringUtils.isBlank(id)) {
id = formId;
}
request.setAttribute(FormsHelper.REQ_ATTR_FORMID, getId());
this.name = id;
this.dropAreaResourceType = "wcm/foundation/components/responsivegrid/new";
if (redirect != null) {
String contextPath = request.getContextPath();
if (StringUtils.isNotBlank(contextPath) && redirect.startsWith("/")) {
redirect = contextPath + redirect;
}
}
if (!StringUtils.equals(request.getRequestPathInfo().getExtension(), ExporterConstants.SLING_MODEL_EXTENSION)) {
runActionTypeInit(formStructureHelper);
}
final ValidationInfo info = ValidationInfo.getValidationInfo(request);
if (info != null) {
this.errorMessages = info.getErrorMessages(null);
}
}
use of com.adobe.cq.wcm.core.components.commons.link.Link in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class DownloadImpl method initAssetDownload.
private void initAssetDownload(String fileReference) {
Resource downloadResource = resourceResolver.getResource(fileReference);
if (downloadResource != null) {
Asset downloadAsset = downloadResource.adaptTo(Asset.class);
if (downloadAsset != null) {
Calendar resourceLastModified = properties.get(JcrConstants.JCR_LASTMODIFIED, Calendar.class);
if (resourceLastModified != null) {
lastModified = resourceLastModified.getTimeInMillis();
}
long assetLastModified = downloadAsset.getLastModified();
if (assetLastModified > lastModified) {
lastModified = assetLastModified;
}
filename = downloadAsset.getName();
format = downloadAsset.getMetadataValue(DamConstants.DC_FORMAT);
if (StringUtils.isNoneEmpty(format)) {
extension = mimeTypeService.getExtension(format);
}
if (StringUtils.isEmpty(extension)) {
extension = FilenameUtils.getExtension(filename);
}
url = linkHandler.getLink(getDownloadUrl(downloadResource), null).map(Link::getURL).orElse(null);
if (titleFromAsset) {
title = downloadAsset.getMetadataValue(DamConstants.DC_TITLE);
}
if (descriptionFromAsset) {
String assetDescription = downloadAsset.getMetadataValue(DamConstants.DC_DESCRIPTION);
if (StringUtils.isNotBlank(assetDescription)) {
description = assetDescription;
}
}
long rawFileSize;
Object rawFileSizeObject = downloadAsset.getMetadata(DamConstants.DAM_SIZE);
if (rawFileSizeObject != null) {
rawFileSize = (Long) rawFileSizeObject;
} else {
rawFileSize = downloadAsset.getOriginal().getSize();
}
size = FileUtils.byteCountToDisplaySize(rawFileSize);
}
}
}
use of com.adobe.cq.wcm.core.components.commons.link.Link in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class LinkImplTest method testValidLinkWithoutTarget.
@Test
void testValidLinkWithoutTarget() {
Link link = new LinkImpl(URL, URL, MockExternalizerFactory.ROOT + URL, null, null);
assertValidLink(link, URL, (String) null);
assertNull(link.getReference());
}
Aggregations