All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.day.cq.personalization.TeaserUtils Maven / Gradle / Ivy

/*************************************************************************
 *
 * ADOBE CONFIDENTIAL
 * __________________
 *
 *  Copyright 2011 Adobe Systems Incorporated
 *  All Rights Reserved.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Adobe Systems Incorporated and its suppliers,
 * if any.  The intellectual and technical concepts contained
 * herein are proprietary to Adobe Systems Incorporated and its
 * suppliers and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Adobe Systems Incorporated.
 **************************************************************************/

package com.day.cq.personalization;

import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;

import com.day.cq.wcm.api.Page;

public class TeaserUtils {

    /**
     * Returns a image for the teaser, based on the following logic:
    *
  • check for page image
  • *
  • check for first par image component
  • *
  • check for first par textimage component
  • *
  • fallback, return page template thumbnail
  • *
* @param teaser Teaser page * @return A URL to the image. */ public static String getImage(Page teaser) { if( teaser != null ) { ResourceResolver resourceResolver = teaser.adaptTo(Resource.class).getResourceResolver(); Resource imgRes = resourceResolver.getResource(resourceResolver.map(teaser.getPath()) + "/jcr:content/image"); if( imgRes != null) { ValueMap properties = imgRes.adaptTo(ValueMap.class); if( properties.get("fileReference", String.class) != null) { //page image return resourceResolver.map(teaser.getPath()) + ".img.png"; } imgRes = resourceResolver.getResource(imgRes.getPath() + "/file/jcr:content"); if( imgRes != null) { //page image return resourceResolver.map(teaser.getPath()) + ".img.png"; } } imgRes = resourceResolver.getResource(teaser.getPath() + "/jcr:content/par/image"); if (imgRes != null) { //first par image return resourceResolver.map(imgRes.getPath()) + ".img.png"; } imgRes = resourceResolver.getResource(teaser.getPath() + "/jcr:content/par/textimage/image"); if (imgRes != null) { //first textimage image return resourceResolver.map(imgRes.getPath()) + ".img.png"; } //fallback, template image return resourceResolver.map(teaser.getPath()) + ".thumb.png"; } return null; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy