Search in sources :

Example 1 with Link

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"));
}
Also used : Teaser(com.adobe.cq.wcm.core.components.models.Teaser) Link(com.adobe.cq.wcm.core.components.commons.link.Link) LinkTestUtils.assertValidLink(com.adobe.cq.wcm.core.components.internal.link.LinkTestUtils.assertValidLink) Test(org.junit.jupiter.api.Test)

Example 2 with Link

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));
            }
        }
    }
}
Also used : Link(com.adobe.cq.wcm.core.components.commons.link.Link)

Example 3 with Link

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);
    }
}
Also used : FormStructureHelper(com.day.cq.wcm.foundation.forms.FormStructureHelper) ValidationInfo(com.day.cq.wcm.foundation.forms.ValidationInfo) Link(com.adobe.cq.wcm.core.components.commons.link.Link) PostConstruct(javax.annotation.PostConstruct)

Example 4 with Link

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);
        }
    }
}
Also used : Calendar(java.util.Calendar) DownloadResource(com.day.cq.commons.DownloadResource) Resource(org.apache.sling.api.resource.Resource) Asset(com.day.cq.dam.api.Asset) SlingObject(org.apache.sling.models.annotations.injectorspecific.SlingObject) Link(com.adobe.cq.wcm.core.components.commons.link.Link)

Example 5 with Link

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());
}
Also used : LinkImpl(com.adobe.cq.wcm.core.components.internal.link.LinkImpl) LinkTestUtils.assertInvalidLink(com.adobe.cq.wcm.core.components.internal.link.LinkTestUtils.assertInvalidLink) Link(com.adobe.cq.wcm.core.components.commons.link.Link) LinkTestUtils.assertValidLink(com.adobe.cq.wcm.core.components.internal.link.LinkTestUtils.assertValidLink) Test(org.junit.jupiter.api.Test)

Aggregations

Link (com.adobe.cq.wcm.core.components.commons.link.Link)15 Resource (org.apache.sling.api.resource.Resource)11 LinkTestUtils.assertValidLink (com.adobe.cq.wcm.core.components.internal.link.LinkTestUtils.assertValidLink)9 Test (org.junit.jupiter.api.Test)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Teaser (com.adobe.cq.wcm.core.components.models.Teaser)3 DownloadResource (com.day.cq.commons.DownloadResource)3 Image (com.adobe.cq.wcm.core.components.models.Image)2 Page (com.day.cq.wcm.api.Page)2 PageManager (com.day.cq.wcm.api.PageManager)2 Calendar (java.util.Calendar)2 PostConstruct (javax.annotation.PostConstruct)2 ValueMap (org.apache.sling.api.resource.ValueMap)2 LinkHandler (com.adobe.cq.wcm.core.components.internal.link.LinkHandler)1 LinkImpl (com.adobe.cq.wcm.core.components.internal.link.LinkImpl)1 LinkTestUtils.assertInvalidLink (com.adobe.cq.wcm.core.components.internal.link.LinkTestUtils.assertInvalidLink)1 CoreResourceWrapper (com.adobe.cq.wcm.core.components.internal.resource.CoreResourceWrapper)1 ExperienceFragment (com.adobe.cq.wcm.core.components.models.ExperienceFragment)1 ComponentUtils (com.adobe.cq.wcm.core.components.util.ComponentUtils)1 ImageResource (com.day.cq.commons.ImageResource)1