Package org.apache.sling.api.resource

# Class ResourceMetadata

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,Object>
org.apache.sling.api.resource.ResourceMetadata

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Map<String,Object>`

public class ResourceMetadata extends HashMap<String,Object>
The `ResourceMetadata` interface defines the API for the metadata of a Sling `Resource`. Essentially the resource's metadata is just a map of objects indexed by string keys.

The actual contents of the meta data map is implementation specific with the exception of the `sling.resolutionPath` property which must be provided by all implementations and contain the part of the request URI used to resolve the resource. The type of this property value is defined to be `String`.

Note, that the prefix sling. to key names is reserved for the Sling implementation. Once a resource is returned by the `ResourceResolver`, the resource metadata is made read-only and therefore can't be changed by client code!

See Also:
  - Serialized Form

## Nested Class Summary

## Nested classes/interfaces inherited from class java.util.AbstractMap

`AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>`

## Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<K extends Object,V extends Object>`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`CHARACTER_ENCODING`
The name of the optional property providing the character encoding of the resource if the resource is streamable and contains character data (value is "sling.characterEncoding").
`static final String`
`CONTENT_LENGTH`
The name of the optional property providing the content length of the resource if the resource is streamable (value is "sling.contentLength").
`static final String`
`CONTENT_TYPE`
The name of the optional property providing the content type of the resource if the resource is streamable (value is "sling.contentType").
`static final String`
`CREATION_TIME`
Returns the creation time of this resource in the repository in milliseconds (value is "sling.creationTime").
`static final String`
`INTERNAL_CONTINUE_RESOLVING`
Deprecated.
This flag is not supported anymore when implementing the SPI based `org.apache.sling.spi.resource.provider.ResourceProvider`
`static final String`
`MODIFICATION_TIME`
Returns the last modification time of this resource in the repository in milliseconds (value is "sling.modificationTime").
`static final String`
`PARAMETER_MAP`
Returns a map containing parameters added to path after semicolon.
`static final String`
`RESOLUTION_PATH`
The name of the required property providing the part of the request URI which was used to the resolve the resource to which the meta data instance belongs (value is "sling.resolutionPath").
`static final String`
`RESOLUTION_PATH_INFO`
The name of the required property providing the part of the request URI which was not used to the resolve the resource to which the meta data instance belongs (value is "sling.resolutionPathInfo").

## Constructor Summary

Constructors
Constructor
Description
`ResourceMetadata()`

## Method Summary

Modifier and Type
Method
Description
`void`
`clear()`
`Object`
`clone()`
`@NotNull Set<Map.Entry<String,Object>>`
`entrySet()`
`@Nullable String`
`getCharacterEncoding()`
Returns the `CHARACTER_ENCODING` property if not `null` and a `String` instance.
`long`
`getContentLength()`
Returns the `CONTENT_LENGTH` property if not `null` and a `long`.
`@Nullable String`
`getContentType()`
Returns the `CONTENT_TYPE` property if not `null` and a `String` instance.
`long`
`getCreationTime()`
Returns the `CREATION_TIME` property if not `null` and a `long`.
`long`
`getModificationTime()`
Returns the `MODIFICATION_TIME` property if not `null` and a `long`.
`@Nullable Map<String,String>`
`getParameterMap()`
Returns the `PARAMETER_MAP` property if not `null` and a `Map` instance.
`@Nullable String`
`getResolutionPath()`
Returns the `RESOLUTION_PATH` property if not `null` and a `String` instance.
`@Nullable String`
`getResolutionPathInfo()`
Returns the `RESOLUTION_PATH_INFO` property if not `null` and a `String` instance.
`protected void`
`internalPut(@NotNull String key, Object value)`
`@NotNull Set<String>`
`keySet()`
`void`
`lock()`
Make this object read-only.
`Object`
`put(@NotNull String key, Object value)`
`void`
`putAll(@NotNull Map<? extends String,? extends Object> m)`
`Object`
`remove(@NotNull Object key)`
`void`
`setCharacterEncoding(String encoding)`
Sets the `CHARACTER_ENCODING` property to `encoding` if not `null`.
`void`
`setContentLength(long contentLength)`
Sets the `CONTENT_LENGTH` property to `contentType` if not `null`.
`void`
`setContentType(String contentType)`
Sets the `CONTENT_TYPE` property to `contentType` if not `null`.
`void`
`setCreationTime(long creationTime)`
Sets the `CREATION_TIME` property to `creationTime` if not negative.
`void`
`setModificationTime(long modificationTime)`
Sets the `MODIFICATION_TIME` property to `modificationTime` if not negative.
`void`
`setParameterMap(Map<String,String> parameterMap)`
Sets the `PARAMETER_MAP` property to `parameterMap` if not `null`.
`void`
`setResolutionPath(String resolutionPath)`
Sets the `RESOLUTION_PATH` property to `resolutionPath` if not `null`.
`void`
`setResolutionPathInfo(String resolutionPathInfo)`
Sets the `RESOLUTION_PATH_INFO` property to `resolutionPathInfo` if not `null`.
`@NotNull Collection<Object>`
`values()`

### Methods inherited from class java.util.HashMap

`compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, forEach, get, getOrDefault, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size`

### Methods inherited from class java.util.AbstractMap

`equals, hashCode, toString`

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

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.util.Map

`equals, hashCode`

## Field Details

### RESOLUTION_PATH

public static final String RESOLUTION_PATH
The name of the required property providing the part of the request URI which was used to the resolve the resource to which the meta data instance belongs (value is "sling.resolutionPath").

See Also:
  - Constant Field Values

### RESOLUTION_PATH_INFO

public static final String RESOLUTION_PATH_INFO
The name of the required property providing the part of the request URI which was not used to the resolve the resource to which the meta data instance belongs (value is "sling.resolutionPathInfo"). The value of this property concatenated to the value of the `sling.resolutionPath` property returns the original request URI leading to the resource.

This property is optional. If missing, it should be assumed equal to an empty string.

Since:
  2.0.4 (Sling API Bundle 2.0.4)
See Also:
  - Constant Field Values

### CONTENT_TYPE

public static final String CONTENT_TYPE
The name of the optional property providing the content type of the resource if the resource is streamable (value is "sling.contentType"). This property may be missing if the resource is not streamable or if the content type is not known.

See Also:
  - Constant Field Values

### CONTENT_LENGTH

public static final String CONTENT_LENGTH
The name of the optional property providing the content length of the resource if the resource is streamable (value is "sling.contentLength"). This property may be missing if the resource is not streamable or if the content length is not known.

Note, that unlike the other properties, this property may be set only after the resource has successfully been adapted to an `InputStream` for performance reasons.

See Also:
  - Constant Field Values

### CHARACTER_ENCODING

public static final String CHARACTER_ENCODING
The name of the optional property providing the character encoding of the resource if the resource is streamable and contains character data (value is "sling.characterEncoding"). This property may be missing if the resource is not streamable or if the character encoding is not known.

See Also:
  - Constant Field Values

### CREATION_TIME

public static final String CREATION_TIME
Returns the creation time of this resource in the repository in milliseconds (value is "sling.creationTime"). The type of this property is `java.lang.Long`. The property may be missing if the resource is not streamable or if the creation time is not known.

See Also:
  - Constant Field Values

### MODIFICATION_TIME

public static final String MODIFICATION_TIME
Returns the last modification time of this resource in the repository in milliseconds (value is "sling.modificationTime"). The type of this property is `java.lang.Long`. The property may be missing if the resource is not streamable or if the last modification time is not known.

See Also:
  - Constant Field Values

### INTERNAL_CONTINUE_RESOLVING

@Deprecated public static final String INTERNAL_CONTINUE_RESOLVING
Deprecated.
This flag is not supported anymore when implementing the SPI based `org.apache.sling.spi.resource.provider.ResourceProvider`
Returns whether the resource resolver should continue to search for a resource. A resource provider can set this flag to indicate that the resource resolver should search for a provider with a lower priority. If it finds a resource using such a provider, that resource is returned instead. If none is found this resource is returned. This flag should never be manipulated by application code! The value of this property has no meaning, the resource resolver just checks whether this flag is set or not.

Since:
  2.2 (Sling API Bundle 2.2.0)
See Also:
  - Constant Field Values

### PARAMETER_MAP

public static final String PARAMETER_MAP
Returns a map containing parameters added to path after semicolon. For instance, map for path `/content/test;v='1.2.3'.html` will contain one entry key `v` and value `1.2.3`.

See Also:
  - Constant Field Values

## Constructor Details

### ResourceMetadata

public ResourceMetadata()

## Method Details

### setCharacterEncoding

public void setCharacterEncoding(String encoding)
Sets the `CHARACTER_ENCODING` property to `encoding` if not `null`.

Parameters:
  `encoding` - The encoding

### getCharacterEncoding

@Nullable public @Nullable String getCharacterEncoding()
Returns the `CHARACTER_ENCODING` property if not `null` and a `String` instance. Otherwise `null` is returned.

Returns:
  The character encoding

### setContentType

public void setContentType(String contentType)
Sets the `CONTENT_TYPE` property to `contentType` if not `null`.

Parameters:
  `contentType` - The content type

### getContentType

@Nullable public @Nullable String getContentType()
Returns the `CONTENT_TYPE` property if not `null` and a `String` instance. Otherwise `null` is returned.

Returns:
  The content type

### setContentLength

public void setContentLength(long contentLength)
Sets the `CONTENT_LENGTH` property to `contentType` if not `null`.

Parameters:
  `contentLength` - The content length

### getContentLength

public long getContentLength()
Returns the `CONTENT_LENGTH` property if not `null` and a `long`. Otherwise `-1` is returned.

Returns:
  The content length

### setCreationTime

public void setCreationTime(long creationTime)
Sets the `CREATION_TIME` property to `creationTime` if not negative.

Parameters:
  `creationTime` - The creation time

### getCreationTime

public long getCreationTime()
Returns the `CREATION_TIME` property if not `null` and a `long`. Otherwise `-1` is returned.

Returns:
  The creation time

### setModificationTime

public void setModificationTime(long modificationTime)
Sets the `MODIFICATION_TIME` property to `modificationTime` if not negative.

Parameters:
  `modificationTime` - The modification time

### getModificationTime

public long getModificationTime()
Returns the `MODIFICATION_TIME` property if not `null` and a `long`. Otherwise `-1` is returned.

Returns:
  The modification time

### setResolutionPath

public void setResolutionPath(String resolutionPath)
Sets the `RESOLUTION_PATH` property to `resolutionPath` if not `null`.

Parameters:
  `resolutionPath` - The resolution path

### getResolutionPath

@Nullable public @Nullable String getResolutionPath()
Returns the `RESOLUTION_PATH` property if not `null` and a `String` instance. Otherwise `null` is returned.

Returns:
  The resolution path

### setResolutionPathInfo

public void setResolutionPathInfo(String resolutionPathInfo)
Sets the `RESOLUTION_PATH_INFO` property to `resolutionPathInfo` if not `null`.

Parameters:
  `resolutionPathInfo` - The resolution path info

### getResolutionPathInfo

@Nullable public @Nullable String getResolutionPathInfo()
Returns the `RESOLUTION_PATH_INFO` property if not `null` and a `String` instance. Otherwise `null` is returned.

Returns:
  The resolution path info

### setParameterMap

public void setParameterMap(Map<String,String> parameterMap)
Sets the `PARAMETER_MAP` property to `parameterMap` if not `null`.

Parameters:
  `parameterMap` - The parameter map

### getParameterMap

@Nullable public @Nullable Map<String,String> getParameterMap()
Returns the `PARAMETER_MAP` property if not `null` and a `Map` instance. Otherwise `null` is returned.

Returns:
  The parameter map

### lock

public void lock()
Make this object read-only. All method calls trying to modify this object result in an exception!

Since:
  2.3 (Sling API Bundle 2.4.0)

### clear

public void clear()

Specified by:
  `clear` in interface `Map<String,Object>`
Overrides:
  `clear` in class `HashMap<String,Object>`

### put

public Object put(@NotNull @NotNull String key, Object value)

Specified by:
  `put` in interface `Map<String,Object>`
Overrides:
  `put` in class `HashMap<String,Object>`

### putAll

public void putAll(@NotNull @NotNull Map<? extends String,? extends Object> m)

Specified by:
  `putAll` in interface `Map<String,Object>`
Overrides:
  `putAll` in class `HashMap<String,Object>`

### remove

public Object remove(@NotNull @NotNull Object key)

Specified by:
  `remove` in interface `Map<String,Object>`
Overrides:
  `remove` in class `HashMap<String,Object>`

### internalPut

protected void internalPut(@NotNull @NotNull String key, Object value)

### clone

public Object clone()

Overrides:
  `clone` in class `HashMap<String,Object>`

### entrySet

@NotNull public @NotNull Set<Map.Entry<String,Object>> entrySet()

Specified by:
  `entrySet` in interface `Map<String,Object>`
Overrides:
  `entrySet` in class `HashMap<String,Object>`

### keySet

@NotNull public @NotNull Set<String> keySet()

Specified by:
  `keySet` in interface `Map<String,Object>`
Overrides:
  `keySet` in class `HashMap<String,Object>`

### values

@NotNull public @NotNull Collection<Object> values()

Specified by:
  `values` in interface `Map<String,Object>`
Overrides:
  `values` in class `HashMap<String,Object>`