org.apache.sling.resourcebuilder.api

## Interface ResourceBuilder

All Known Implementing Classes:
  ResourceBuilderImpl

    @ProviderType
    public interface ResourceBuilder

Builds Sling Resources using a simple fluent API

### Field Summary

Fields
`static String` `DEFAULT_PRIMARY_TYPE` Default primary type for resources created by this builder

### Method Summary

All Methods Instance Methods Abstract Methods
`@NotNull ResourceBuilder` `atParent()` Reset the current parent Resource to the original one.
`@NotNull ResourceBuilder` `commit()` Commit created resources
`@NotNull ResourceBuilder` `file(@NotNull String filename, @NotNull InputStream data)` Create a file under the current parent resource.
`@NotNull ResourceBuilder` `file(@NotNull String filename, @NotNull InputStream data, @Nullable String mimeType, long lastModified)` Create a file under the current parent resource
`@NotNull org.apache.sling.api.resource.Resource` `getCurrentParent()` Return the current parent resource
`@NotNull ResourceBuilder` `hierarchyMode()` Set hierarchy mode (as opposed to siblings mode) where creating a resource sets it as the current parent.
`@NotNull ResourceBuilder` `resource(@NotNull String path, @NotNull Map<String,Object> properties)` Create a Resource, which optionally becomes the current parent Resource.
`@NotNull ResourceBuilder` `resource(@NotNull String path, Object... properties)` Create a Resource, which optionally becomes the current parent Resource.
`@NotNull ResourceBuilder` `siblingsMode()` Set siblings mode (as opposed to hierarchy mode) where creating a resource doesn't change the current parent.
`@NotNull ResourceBuilder` `withIntermediatePrimaryType(@Nullable String primaryType)` Set the primary type for intermediate resources created when the parent of resource being created does not exist.

### Field Detail

#### DEFAULT_PRIMARY_TYPE

    static final String DEFAULT_PRIMARY_TYPE

Default primary type for resources created by this builder

See Also:
  Constant Field Values

### Method Detail

#### resource

    @NotNull
    @NotNull ResourceBuilder resource(@NotNull
                                                @NotNull String path,
                                                @NotNull
                                                Object... properties)

Create a Resource, which optionally becomes the current parent Resource.

Parameters:
  `path` - The path of the Resource to create. If it's a relative path this builder's current resource is used as parent. Otherwise the resource is created ad the given absolute path.
  `properties` - optional name-value pairs
Returns:
  this builder

#### resource

    @NotNull
    @NotNull ResourceBuilder resource(@NotNull
                                                @NotNull String path,
                                                @NotNull
                                                @NotNull Map<String,Object> properties)

Create a Resource, which optionally becomes the current parent Resource.

Parameters:
  `path` - The path of the Resource to create. If it's a relative path this builder's current resource is used as parent. Otherwise the resource is created ad the given absolute path.
  `properties` - Name-value pairs
Returns:
  this builder

#### file

    @NotNull
    @NotNull ResourceBuilder file(@NotNull
                                            @NotNull String filename,
                                            @NotNull
                                            @NotNull InputStream data,
                                            @Nullable
                                            @Nullable String mimeType,
                                            long lastModified)

Create a file under the current parent resource

Parameters:
  `filename` - The name of the created file
  `data` - The file data
  `mimeType` - If null, use the Sling MimeTypeService to set the mime type
  `lastModified` - if < 0, current time is used
Returns:
  this builder

#### file

    @NotNull
    @NotNull ResourceBuilder file(@NotNull
                                            @NotNull String filename,
                                            @NotNull
                                            @NotNull InputStream data)

Create a file under the current parent resource. Mime type is set using the Sling MimeTypeService, and last modified is set to current time.

Parameters:
  `filename` - The name of the created file
  `data` - The file data
Returns:
  this builder

#### commit

    @NotNull
    @NotNull ResourceBuilder commit()

Commit created resources

#### withIntermediatePrimaryType

    @NotNull
    @NotNull ResourceBuilder withIntermediatePrimaryType(@Nullable
                                                                   @Nullable String primaryType)

Set the primary type for intermediate resources created when the parent of resource being created does not exist.

Parameters:
  `primaryType` - If null the DEFAULT_PRIMARY_TYPE is used.
Returns:
  this builder

#### siblingsMode

    @NotNull
    @NotNull ResourceBuilder siblingsMode()

Set siblings mode (as opposed to hierarchy mode) where creating a resource doesn't change the current parent. Used to create flat structures. This is off by default.

Returns:
  this builder

#### hierarchyMode

    @NotNull
    @NotNull ResourceBuilder hierarchyMode()

Set hierarchy mode (as opposed to siblings mode) where creating a resource sets it as the current parent. Used to create tree structures. This is on by default.

Returns:
  this builder

#### getCurrentParent

    @NotNull
    @NotNull org.apache.sling.api.resource.Resource getCurrentParent()

Return the current parent resource

#### atParent

    @NotNull
    @NotNull ResourceBuilder atParent()

Reset the current parent Resource to the original one. Also activates hierarchyMode which is the default mode.