Package com.adobe.granite.ui.components
Class LayoutBuilder
- java.lang.Object
-
- com.adobe.granite.ui.components.LayoutBuilder
-
public class LayoutBuilder extends java.lang.Object
A builder to create a layout. A layout is a configuration map consisting a set of properties. A layout at very least requires aname
property.
-
-
Constructor Summary
Constructors Constructor Description LayoutBuilder()
LayoutBuilder(Resource resource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.String key, java.lang.Object value)
Adds the given key-value pair of property to this layout.void
add(java.util.Map<java.lang.String,java.lang.Object> data)
Adds a map of properties to this layout.static LayoutBuilder
from(Config config)
Builds a layout from the given config.static LayoutBuilder
from(Config config, java.lang.String defaultResourceType)
Builds a layout from the given config.static LayoutBuilder
from(Resource resource)
Builds a layout from the given resource.static LayoutBuilder
from(Resource resource, java.lang.String defaultResourceType)
Builds a layout from the given resource.java.lang.String
getName()
Returns the name of this layout.java.lang.String
getResourceType()
Returns the resource type of this layout.boolean
hasName()
true
if this layout has name.void
setName(java.lang.String name)
Sets the name of this layout.void
setResourceType(java.lang.String resourceType)
Sets the resource type of this layout.JSONObject
toJSON()
Returns this layout as JSON.
-
-
-
Constructor Detail
-
LayoutBuilder
public LayoutBuilder()
-
LayoutBuilder
public LayoutBuilder(@CheckForNull Resource resource)
-
-
Method Detail
-
from
@Nonnull public static LayoutBuilder from(@Nonnull Config config)
Builds a layout from the given config. The actual layout resource is retrieved based onConfig.LAYOUT
path. This method doesn't set default resource type of layout, usefrom(Config, String)
orComponentHelper.getLayout()
instead.- Parameters:
config
- the config- Returns:
- the layout builder
-
from
@Nonnull public static LayoutBuilder from(@Nonnull Config config, @Nonnull java.lang.String defaultResourceType)
Builds a layout from the given config. The actual layout resource is retrieved based onConfig.LAYOUT
path. The given defaultResourceType will be used when sling:resourceType property of the resource is not set.- Parameters:
config
- the configdefaultResourceType
- the default resource type- Returns:
- the layout builder
-
from
@Nonnull public static LayoutBuilder from(@CheckForNull Resource resource)
Builds a layout from the given resource. This method doesn't set default resource type of layout, usefrom(Resource, String)
orComponentHelper.getLayout()
instead.- Parameters:
resource
- the resource- Returns:
- the layout builder
-
from
@Nonnull public static LayoutBuilder from(@CheckForNull Resource resource, @CheckForNull java.lang.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 resourcedefaultResourceType
- 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 java.lang.String getName()
Returns the name of this layout.- Returns:
- returns the name of this layout
-
setName
public void setName(@CheckForNull java.lang.String name)
Sets the name of this layout.- Parameters:
name
- the name to set
-
getResourceType
@CheckForNull public java.lang.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 java.lang.String resourceType)
Sets the resource type of this layout.- Parameters:
resourceType
- the resource type to set
-
add
public void add(@Nonnull java.lang.String key, @CheckForNull java.lang.Object value)
Adds the given key-value pair of property to this layout.- Parameters:
key
- the property keyvalue
- the property value
-
add
public void add(@Nonnull java.util.Map<java.lang.String,java.lang.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
-
-