Class LayoutBuilder


  • public class LayoutBuilder
    extends Object
    A builder to create a layout. A layout is a configuration map consisting a set of properties. A layout at very least requires a name property.
    • Constructor Detail

      • LayoutBuilder

        public LayoutBuilder()
    • Method Detail

      • from

        @Nonnull
        public static LayoutBuilder from​(@Nonnull
                                         Config config,
                                         @Nonnull
                                         String defaultResourceType)
        Builds a layout from the given config. The actual layout resource is retrieved based on Config.LAYOUT path. The given defaultResourceType will be used when sling:resourceType property of the resource is not set.
        Parameters:
        config - the config
        defaultResourceType - the default resource type
        Returns:
        the layout builder
      • from

        @Nonnull
        public static LayoutBuilder from​(@CheckForNull
                                         Resource resource,
                                         @CheckForNull
                                         String defaultResourceType)
        Builds a layout from the given resource. The given defaultResourceType will be used when sling:resourceType property of the resource is not set.
        Parameters:
        resource - the resource
        defaultResourceType - the default resource type
        Returns:
        the layout builder
      • hasName

        public boolean hasName()
        true if this layout has name. false otherwise.
        Returns:
        true if this layout has a name, false otherwise
      • getName

        @CheckForNull
        public String getName()
        Returns the name of this layout.
        Returns:
        returns the name of this layout
      • setName

        public void setName​(@CheckForNull
                            String name)
        Sets the name of this layout.
        Parameters:
        name - the name to set
      • getResourceType

        @CheckForNull
        public String getResourceType()
        Returns the resource type of this layout. This will be used to point to the renderer of the layout using standard Sling mechanism.
        Returns:
        the resource type as a string
      • setResourceType

        public void setResourceType​(@CheckForNull
                                    String resourceType)
        Sets the resource type of this layout.
        Parameters:
        resourceType - the resource type to set
      • add

        public void add​(@Nonnull
                        String key,
                        @CheckForNull
                        Object value)
        Adds the given key-value pair of property to this layout.
        Parameters:
        key - the property key
        value - the property value
      • add

        public void add​(@Nonnull
                        Map<String,​Object> data)
        Adds a map of properties to this layout. Entry with key having a namespace (e.g. jcr:primaryType) will be excluded.
        Parameters:
        data - the map of properties to add
      • toJSON

        @Nonnull
        public JSONObject toJSON()
        Returns this layout as JSON.
        Returns:
        the layout as JSON