org.apache.sling.resourcebuilder.impl

## Class ResourceBuilderImpl

- java.lang.Object
- - org.apache.sling.resourcebuilder.impl.ResourceBuilderImpl

All Implemented Interfaces:
  ResourceBuilder

    public class ResourceBuilderImpl
    extends Object
    implements ResourceBuilder

ResourceBuilder implementation

### Field Summary

Fields
`static String` `CANNOT_RESTART`
`static String` `JCR_CONTENT`
`static String` `JCR_DATA`
`static String` `JCR_LASTMODIFIED`
`static String` `JCR_MIMETYPE`
`static String` `JCR_PRIMARYTYPE`
`static String` `NT_FILE`
`static String` `NT_RESOURCE`

### Fields inherited from interface org.apache.sling.resourcebuilder.api.ResourceBuilder

`DEFAULT_PRIMARY_TYPE`

### Constructor Summary

Constructors
Constructor and Description
`ResourceBuilderImpl(@NotNull org.apache.sling.api.resource.Resource parent, @NotNull org.apache.sling.commons.mime.MimeTypeService mts)`

### Method Summary

All Methods Instance Methods Concrete Methods
`@NotNull ResourceBuilder` `atParent()` Reset the current parent Resource to the original one.
`@NotNull ResourceBuilder` `commit()` Commit created resources
`protected org.apache.sling.api.resource.Resource` `ensureResourceExists(String path)` Create a Resource at the specified path if none exists yet, using the current intermediate primary type.
`@NotNull ResourceBuilder` `file(@NotNull String filename, @NotNull InputStream data)` Create a file under the current parent resource.
`@NotNull ResourceBuilder` `file(@NotNull String relativePath, @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
`protected long` `getLastModified(long userSuppliedValue)`
`protected String` `getMimeType(String filename, String userSuppliedMimeType)`
`@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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### JCR_PRIMARYTYPE

    public static final String JCR_PRIMARYTYPE

See Also:
  Constant Field Values

#### JCR_MIMETYPE

    public static final String JCR_MIMETYPE

See Also:
  Constant Field Values

#### JCR_LASTMODIFIED

    public static final String JCR_LASTMODIFIED

See Also:
  Constant Field Values

#### JCR_DATA

    public static final String JCR_DATA

See Also:
  Constant Field Values

#### JCR_CONTENT

    public static final String JCR_CONTENT

See Also:
  Constant Field Values

#### NT_RESOURCE

    public static final String NT_RESOURCE

See Also:
  Constant Field Values

#### NT_FILE

    public static final String NT_FILE

See Also:
  Constant Field Values

#### CANNOT_RESTART

    public static final String CANNOT_RESTART

See Also:
  Constant Field Values

### Constructor Detail

#### ResourceBuilderImpl

    public ResourceBuilderImpl(@NotNull
                               @NotNull org.apache.sling.api.resource.Resource parent,
                               @NotNull
                               @NotNull org.apache.sling.commons.mime.MimeTypeService mts)

### Method Detail

#### getCurrentParent

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

Description copied from interface: `ResourceBuilder`
Return the current parent resource

Specified by:
  `getCurrentParent` in interface `ResourceBuilder`

#### atParent

    @NotNull
    public @NotNull ResourceBuilder atParent()

Description copied from interface: `ResourceBuilder`
Reset the current parent Resource to the original one. Also activates hierarchyMode which is the default mode.

Specified by:
  `atParent` in interface `ResourceBuilder`

#### resource

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

Description copied from interface: `ResourceBuilder`
Create a Resource, which optionally becomes the current parent Resource.

Specified by:
  `resource` in interface `ResourceBuilder`
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

#### resource

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

Description copied from interface: `ResourceBuilder`
Create a Resource, which optionally becomes the current parent Resource.

Specified by:
  `resource` in interface `ResourceBuilder`
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

#### ensureResourceExists

    protected final org.apache.sling.api.resource.Resource ensureResourceExists(String path)

Create a Resource at the specified path if none exists yet, using the current intermediate primary type. "Stolen" from the sling-mock module's ContentBuilder class.

Parameters:
  `path` - Resource path
Returns:
  Resource at path (existing or newly created)

#### getMimeType

    protected String getMimeType(String filename,
                                 String userSuppliedMimeType)

#### getLastModified

    protected long getLastModified(long userSuppliedValue)

#### file

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

Description copied from interface: `ResourceBuilder`
Create a file under the current parent resource

Specified by:
  `file` in interface `ResourceBuilder`
Parameters:
  `relativePath` - 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
    public @NotNull ResourceBuilder file(@NotNull
                                                   @NotNull String filename,
                                                   @NotNull
                                                   @NotNull InputStream data)

Description copied from interface: `ResourceBuilder`
Create a file under the current parent resource. Mime type is set using the Sling MimeTypeService, and last modified is set to current time.

Specified by:
  `file` in interface `ResourceBuilder`
Parameters:
  `filename` - The name of the created file
  `data` - The file data
Returns:
  this builder

#### withIntermediatePrimaryType

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

Description copied from interface: `ResourceBuilder`
Set the primary type for intermediate resources created when the parent of resource being created does not exist.

Specified by:
  `withIntermediatePrimaryType` in interface `ResourceBuilder`
Parameters:
  `primaryType` - If null the DEFAULT_PRIMARY_TYPE is used.
Returns:
  this builder

#### siblingsMode

    @NotNull
    public @NotNull ResourceBuilder siblingsMode()

Description copied from interface: `ResourceBuilder`
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.

Specified by:
  `siblingsMode` in interface `ResourceBuilder`
Returns:
  this builder

#### hierarchyMode

    @NotNull
    public @NotNull ResourceBuilder hierarchyMode()

Description copied from interface: `ResourceBuilder`
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.

Specified by:
  `hierarchyMode` in interface `ResourceBuilder`
Returns:
  this builder

#### commit

    @NotNull
    public @NotNull ResourceBuilder commit()

Description copied from interface: `ResourceBuilder`
Commit created resources

Specified by:
  `commit` in interface `ResourceBuilder`