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

com.icfolson.aem.library.api.Accessible Maven / Gradle / Ivy

There is a newer version: 13.0.1-beta
Show newest version
package com.icfolson.aem.library.api;

import com.google.common.base.Optional;
import com.icfolson.aem.library.api.link.Link;
import com.icfolson.aem.library.api.page.PageDecorator;
import org.apache.sling.api.resource.ValueMap;

import java.util.List;

/**
 * Definition of accessor methods for content resources for Node and Page instances.
 */
public interface Accessible {

    /**
     * @return map of property names to values, or empty map if underlying resource is null or nonexistent
     */
    ValueMap asMap();

    /**
     * Get a property value from the current node, returning the default value if the property does not exist.
     *
     * @param  property type
     * @param propertyName property name
     * @param defaultValue default value
     * @return property value or default value if it does not exist
     */
     T get(String propertyName, T defaultValue);

    /**
     * Get a property value from the current node.  This returns the same value as the underlying ValueMap
     * wrapped in an Optional instance instead of returning null.
     *
     * @param propertyName property name
     * @param type property type
     * @param  property type
     * @return Optional of the given type containing the property value or absent if the property does not
     * exist
     */
     Optional get(String propertyName, Class type);

    /**
     * Given a property on this resource containing the path of another resource, get an Optional
     * containing the href to the resource (i.e. the content path with ".html" appended).
     *
     * @param propertyName name of property containing a valid content path
     * @return href value wrapped in an Optional
     */
    Optional getAsHref(String propertyName);

    /**
     * Given a property on this resource containing the path of another resource, get an Optional
     * containing the href to the resource.  Use this method with a true argument when appending ".html" to
     * the resource path is desired only for valid CQ pages and not external paths.
     *
     * @param propertyName name of property containing a valid content path
     * @param strict if true, strict resource resolution will be applied and only valid CQ content paths will have
     * ".html" appended
     * @return href value wrapped in an Optional
     */
    Optional getAsHref(String propertyName, boolean strict);

    /**
     * Given a property on this resource containing the path of another resource, get an Optional
     * containing the href to the resource.  Use this method with a true argument when appending ".html" to
     * the resource path is desired only for valid CQ pages and not external paths.  Setting mapped to
     * true will map the path value, if it exists, through the Sling Resource Resolver.
     *
     * @param propertyName name of property containing a valid content path
     * @param strict if true, strict resource resolution will be applied and only valid CQ content paths will have
     * ".html" appended
     * @param mapped if true, the property value will be routed through the Resource Resolver to determine the mapped
     * path for the value.  For example, if a mapping from "/content/" to "/" exists in the Apache Sling Resource
     * Resolver Factory OSGi configuration, getting the mapped href for the path "/content/citytechinc" will return
     * "/citytechinc.html".
     * @return href value wrapped in an Optional
     */
    Optional getAsHref(String propertyName, boolean strict, boolean mapped);

    /**
     * Given a property on this resource containing the path of another resource, get a link to the resource.
     *
     * @param propertyName name of property containing a valid content path
     * @return Optional link object, absent if property does not contain a valid content path
     */
    Optional getAsLink(String propertyName);

    /**
     * Given a property on this resource containing the path of another resource, get a link to the resource.  Use this
     * method with a true argument when including an extension for the link is desired only for valid CQ
     * pages and not external paths.
     *
     * @param propertyName name of property containing a valid content path
     * @param strict if true, strict resource resolution will be applied and only valid CQ content paths will have an
     * extension
     * @return Optional link object, absent if property does not contain a valid content path
     */
    Optional getAsLink(String propertyName, boolean strict);

    /**
     * Given a property on this resource containing the path of another resource, get a link to the resource.  Use this
     * method with a true argument when including an extension for the link is desired only for valid CQ
     * pages and not external paths.  Setting mapped to true will map the path value, if it
     * exists, through the Sling Resource Resolver.
     *
     * @param propertyName name of property containing a valid content path
     * @param strict if true, strict resource resolution will be applied and only valid CQ content paths will have an
     * extension
     * @param mapped if true, the property value will be routed through the Resource Resolver to determine the mapped
     * path for the value.  For example, if a mapping from "/content/" to "/" exists in the Apache Sling Resource
     * Resolver Factory OSGi configuration, the Link path will be "/citytechinc" rather than
     * "/content/citytechinc".
     * @return Optional link object, absent if property does not contain a valid content path
     */
    Optional getAsLink(String propertyName, boolean strict, boolean mapped);

    /**
     * Get a multi-valued property from the current node as a list of the given type.
     *
     * @param propertyName name of multi-valued property
     * @param type property type
     * @param  property type, must be supported by ValueMap
     * @return list of property values or an empty list if the property does not exist
     */
     List getAsList(String propertyName, Class type);

    /**
     * Get a page instance from the value of the given property.  Will return an absent Optional if the
     * path value for the given property name does not resolve to a valid CQ page.
     *
     * @param propertyName property name
     * @return Optional page for property value
     */
    Optional getAsPage(String propertyName);

    /**
     * Get an Optional type instance for a property on this resource containing the path of another
     * Resource in the repository.
     *
     * @param propertyName name of property containing a resource path
     * @param type type to adapt from resource
     * @param  adapter class that is adaptable from Resource
     * @return Optional instance of the specified type, or absent if either the property does not exist or
     * the resource does not adapt to the provided type
     */
     Optional getAsType(String propertyName, Class type);

    /**
     * Get the referenced DAM asset path for the default image (named "image") for this component.
     *
     * @param isSelf if true, image reference property will be accessed from the current resource rather than a child
     * @return Optional image reference path
     */
    Optional getImageReference(boolean isSelf);

    /**
     * Get the referenced DAM asset path for the default image (named "image") for this component.
     *
     * @return Optional image reference path
     */
    Optional getImageReference();

    /**
     * @param name image name
     * @return Optional image reference path
     */
    Optional getImageReference(String name);

    /**
     * Get the DAM asset rendition path for the default image (named "image") for this component.
     *
     * @param renditionName rendition name for this asset (e.g. "cq5dam.thumbnail.140.100.png")
     * @return Optional image rendition path
     */
    Optional getImageRendition(String renditionName);

    /**
     * @param name image name
     * @param renditionName rendition name for this asset
     * @return Optional image rendition path
     */
    Optional getImageRendition(String name, String renditionName);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy