Class RenderingAttributeValueToRepresentationStrategy

  • All Implemented Interfaces:
    AttributeValueToRepresentationStrategy

    public class RenderingAttributeValueToRepresentationStrategy
    extends java.lang.Object
    implements AttributeValueToRepresentationStrategy
    This class is used by the DefaultCMSItemConverter to convert items into a representation suited for rendering purposes. The transformation strategy is be based on the following rules: - Simple Value: -> If it's a Cms Component it needs to be converted into an AbstractCMSComponentData (through the cmsComponentModelToDataRenderingConverter) -> Otherwise, use the default transformation function. - Collection: -> If the collection contains Cms Components, get simple representation (uid). -> Otherwise, use the default transformation function for each item. - Localized Value: -> Get value for current language, and use same approach as Simple Value. - Localized Collection: -> For each element, do the same as Localized Value.
    • Constructor Detail

      • RenderingAttributeValueToRepresentationStrategy

        public RenderingAttributeValueToRepresentationStrategy()
    • Method Detail

      • getSimpleGetter

        public java.util.function.Supplier<java.lang.Object> getSimpleGetter​(AttributeDescriptorModel attribute,
                                                                             ItemModel sourceModel,
                                                                             java.util.function.Function<java.lang.Object,​java.lang.Object> goDeeperOrSerialize)
        Description copied from interface: AttributeValueToRepresentationStrategy
        This function is used to retrieve a Supplier that can be used to get the representation of the value of an attribute. This representation is generated by applying the provided transformation function.
        Specified by:
        getSimpleGetter in interface AttributeValueToRepresentationStrategy
        Parameters:
        attribute - The object describing the attribute whose value will be transformed.
        sourceModel - The model containing the value that will be transformed.
        goDeeperOrSerialize - The function that will be used to transform the value into the expected object.
        Returns:
        A Supplier. Use get() to retrieve the transformed object.
      • getCollectionGetter

        public java.util.function.Supplier<java.lang.Object> getCollectionGetter​(AttributeDescriptorModel attribute,
                                                                                 ItemModel sourceModel,
                                                                                 java.util.function.Function<java.lang.Object,​java.lang.Object> goDeeperOrSerialize)
        Description copied from interface: AttributeValueToRepresentationStrategy
        This function is used to retrieve a Supplier that can be used to get the representation of a collection stored in an attribute. This representation is generated by leveraging the provided transformation function.
        Specified by:
        getCollectionGetter in interface AttributeValueToRepresentationStrategy
        Parameters:
        attribute - The object describing the attribute whose value will be transformed.
        sourceModel - The model containing the collection that will be transformed.
        goDeeperOrSerialize - The function that will be used to transform the collection into the expected representation.
        Returns:
        A Supplier. Use get() to retrieve the transformed collection.
      • getLocalizedGetter

        public java.util.function.Supplier<java.lang.Object> getLocalizedGetter​(AttributeDescriptorModel attribute,
                                                                                ItemModel sourceModel,
                                                                                java.util.function.Function<java.lang.Object,​java.lang.Object> goDeeperOrSerialize)
        Description copied from interface: AttributeValueToRepresentationStrategy
        This function is used to retrieve a Supplier that can be used to get the representation of a localized value stored in an attribute. This representation is generated by leveraging the provided transformation function.
        Specified by:
        getLocalizedGetter in interface AttributeValueToRepresentationStrategy
        Parameters:
        attribute - The object describing the attribute whose value will be transformed.
        sourceModel - The model containing the localized value that will be transformed.
        goDeeperOrSerialize - The function that will be used to transform the localized value into the expected representation.
        Returns:
        A Supplier. Use get() to retrieve the transformed localized value.
      • getLocalizedCollectionGetter

        public java.util.function.Supplier<java.lang.Object> getLocalizedCollectionGetter​(AttributeDescriptorModel attribute,
                                                                                          ItemModel sourceModel,
                                                                                          java.util.function.Function<java.lang.Object,​java.lang.Object> goDeeperOrSerialize)
        Description copied from interface: AttributeValueToRepresentationStrategy
        This function is used to retrieve a Supplier that can be used to get the representation of a localized collection value stored in an attribute. This representation is generated by leveraging the provided transformation function.
        Specified by:
        getLocalizedCollectionGetter in interface AttributeValueToRepresentationStrategy
        Parameters:
        attribute - The object describing the attribute whose value will be transformed.
        sourceModel - The model containing the localized collection value that will be transformed.
        goDeeperOrSerialize - The function that will be used to transform the localized collection value into the expected representation.
        Returns:
        A Supplier. Use get() to retrieve the transformed localized collection value.
      • attributeContainsCmsComponents

        protected boolean attributeContainsCmsComponents​(AttributeDescriptorModel attributeDescriptorModel)
        Helper method to determine whether an attribute contains cms components.
        Parameters:
        attributeDescriptorModel - The attribute to analyze.
        Returns:
        True if the attribute contains cms components, false otherwise.
      • getCmsComponentRenderingDataTransformationFunction

        protected java.util.function.Function<java.lang.Object,​java.lang.Object> getCmsComponentRenderingDataTransformationFunction()
        This method returns the transformation function to use to render CMS components.
        Returns:
        The transformation function to use for CMS components.
      • getElementToRenderingDataTransformationFunction

        protected java.util.function.Function<java.lang.Object,​java.lang.Object> getElementToRenderingDataTransformationFunction​(AttributeDescriptorModel attributeDescriptorModel,
                                                                                                                                       java.util.function.Function<java.lang.Object,​java.lang.Object> defaultTransformationFunction)
        This method receives a transformation function, and wraps it in a new function that contains necessary logic for rendering purposes.
        Parameters:
        attributeDescriptorModel - The model that describes the attribute whose element(s) will be transformed with the provided transformation function.
        defaultTransformationFunction - The default function used to transform element(s) in the provided attribute.
        Returns:
        The new function that contains the extra logic needed for rendering purposes.
      • isElementEligibleForRendering

        protected boolean isElementEligibleForRendering​(AttributeDescriptorModel attributeDescriptorModel,
                                                        java.lang.Object element)
        This method is used to determine if an element is allowed to be rendered. - If the element is not a component, it's always allowed. - If it's a component, it must be explicitly allowed (visible and no restrictions in effect).
        Parameters:
        attributeDescriptorModel - The model describing the attribute to analyze.
        element - The item to analyze.
        Returns:
        true if the element is allowed to be rendered. False otherwise.
      • getAttributeValue

        protected <T> T getAttributeValue​(AttributeDescriptorModel attribute,
                                          ItemModel sourceModel)
        This method is used to get the value of the desired attribute in the provided source model.
        Type Parameters:
        T - The type of the returned value.
        Parameters:
        attribute - The attribute to retrieve from the model
        sourceModel - The model where to retrieve the value from.
        Returns:
        The value of the attribute in the provided source model.
      • getModelService

        protected ModelService getModelService()
      • setModelService

        public void setModelService​(ModelService modelService)
      • setSimpleCmsComponentAttributeConverter

        public void setSimpleCmsComponentAttributeConverter​(Converter<AbstractCMSComponentModel,​java.lang.String> simpleCmsComponentAttributeConverter)
      • getCollectionToRepresentationConverter

        protected AttributeValueToRepresentationConverter<java.util.Collection<java.lang.Object>,​java.util.Collection<java.lang.Object>> getCollectionToRepresentationConverter()
      • setCollectionToRepresentationConverter

        public void setCollectionToRepresentationConverter​(AttributeValueToRepresentationConverter<java.util.Collection<java.lang.Object>,​java.util.Collection<java.lang.Object>> collectionToRepresentationConverter)
      • setRenderingVisibilityService

        public void setRenderingVisibilityService​(RenderingVisibilityService renderingVisibilityService)