Metadata
Metadata
A Metadata describes one reference that embeds an entry or asset in a JSON Rich Text Editor (JSON RTE) field. It holds seven values, such as the item UID and the display style. Use this class to
- pass the details of an embedded item to DefaultOption renderOptions
- read the UID and display style of an embedded item
SDKUtil.jsonToHTML builds one Metadata for each reference node in a JSON RTE field. To call renderOptions yourself, create one with the public constructor, which takes the seven arguments below:
| Name | Type | Description |
|---|---|---|
| text | String | Text of the reference. |
| itemType | String | Type of the embedded item, for example entry or asset. |
| itemUid | String | UID of the embedded entry or asset. |
| contentTypeUid | String | Content type UID of the embedded item. |
| styleType | String | Display style: block, inline, link, display or download, in any letter case. |
| outerHTML | String | Outer HTML of the reference. |
| attributes | Attributes | Extra attributes, as a java.util.jar.Attributes map. |
getAttributes
getAttributes returns the attributes stored for the embedded item.
Returns: Attributes. The attributes of the embedded item.
Validation
- There is no client-side validation, and getAttributes does not throw.
Behavior
- Client-side only. getAttributes returns a value stored in the object and makes no request.
- The value is the attributes argument of the constructor, a java.util.jar.Attributes map.
- Inside SDKUtil.jsonToHTML, the SDK always passes a new, empty Attributes. It does not copy the attrs of the reference node into it.
Example
Basic usage: count the attributes
import android.util.Log;
import com.contentstack.sdk.Metadata;
import java.util.jar.Attributes;
Metadata metadata = new Metadata("Jane Doe", "entry", "<ENTRY_UID>", "<CONTENT_TYPE_UID>",
"INLINE", "", new Attributes());
Attributes attributes = metadata.getAttributes();
Log.d("Contentstack", "Attributes: " + attributes.size()); // Attributes: 0getContentTypeUid
getContentTypeUid returns the content type UID of the embedded item.
Returns: String. The content type UID of the embedded item.
Validation
- There is no client-side validation, and getContentTypeUid does not throw.
Behavior
- Client-side only. getContentTypeUid returns a value stored in the object and makes no request.
- The value is the contentTypeUid argument of the constructor.
- Inside SDKUtil.jsonToHTML, the SDK passes the content-type-uid attribute for an embedded entry, and the fixed string asset for an embedded asset. See How the SDK fills a Metadata on the Metadata class page.
Example
Basic usage: read the content type of the embedded item
import android.util.Log;
import com.contentstack.sdk.Metadata;
import java.util.jar.Attributes;
Metadata metadata = new Metadata("Jane Doe", "entry", "<ENTRY_UID>", "<CONTENT_TYPE_UID>",
"INLINE", "", new Attributes());
Log.d("Contentstack", "Content type: " + metadata.getContentTypeUid());getItemType
getItemType returns whether the embedded item is an entry or an asset.
Returns: String. The type of the embedded item.
Validation
- There is no client-side validation, and getItemType does not throw.
Behavior
- Client-side only. getItemType returns a value stored in the object and makes no request.
- The value is the itemType argument of the constructor.
- Inside SDKUtil.jsonToHTML, the SDK passes the type attribute of the reference node, for example entry or asset. See How the SDK fills a Metadata on the Metadata class page.
Example
Basic usage: check whether the item is an asset
import android.util.Log;
import com.contentstack.sdk.Metadata;
import java.util.jar.Attributes;
Metadata metadata = new Metadata("Jane Doe", "entry", "<ENTRY_UID>", "<CONTENT_TYPE_UID>",
"INLINE", "", new Attributes());
if ("asset".equals(metadata.getItemType())) {
Log.d("Contentstack", "The reference embeds an asset");
} else {
Log.d("Contentstack", "The reference embeds an entry");
}getItemUid
getItemUid returns the UID of the embedded entry or asset.
Returns: String. The UID of the embedded item.
Validation
- There is no client-side validation, and getItemUid does not throw.
Behavior
- Client-side only. getItemUid returns a value stored in the object and makes no request.
- The value is the itemUid argument of the constructor.
- Inside SDKUtil.jsonToHTML, the SDK reads the value from the entry-uid attribute for an embedded entry. For an embedded asset, it reads the asset-uid attribute. See How the SDK fills a Metadata on the Metadata class page.
Example
Basic usage: read the UID of the embedded item
import android.util.Log;
import com.contentstack.sdk.Metadata;
import java.util.jar.Attributes;
Metadata metadata = new Metadata("Jane Doe", "entry", "<ENTRY_UID>", "<CONTENT_TYPE_UID>",
"INLINE", "", new Attributes());
Log.d("Contentstack", "Embedded item: " + metadata.getItemUid());getOuterHTML
getOuterHTML returns the outer HTML stored for the embedded item.
Returns: String. The outer HTML of the embedded item.
Validation
- There is no client-side validation, and getOuterHTML does not throw.
Behavior
- Client-side only. getOuterHTML returns a value stored in the object and makes no request.
- The value is the outerHTML argument of the constructor.
- Inside SDKUtil.jsonToHTML, the SDK always passes an empty string, so the value is empty for every Metadata that the SDK builds.
Example
Basic usage: read the outer HTML
import android.util.Log;
import com.contentstack.sdk.Metadata;
import java.util.jar.Attributes;
Metadata metadata = new Metadata("Jane Doe", "entry", "<ENTRY_UID>", "<CONTENT_TYPE_UID>",
"INLINE", "", new Attributes());
Log.d("Contentstack", "Outer HTML is empty: " + metadata.getOuterHTML().isEmpty()); // truegetStyleType
getStyleType returns the display style of the embedded item, for example inline or block.
Returns: StyleType. The display style of the embedded item.
Validation
- There is no client-side validation, and getStyleType does not throw.
Behavior
- Client-side only. getStyleType returns a value stored in the object and makes no request.
- The value is one of the five StyleType values: BLOCK, INLINE, LINK, DISPLAY or DOWNLOAD. The constructor converts its styleType string to this value.
- StyleType is package-private, so code outside com.contentstack.sdk cannot name the type or call its methods. Pass the result to String.valueOf and compare the string, as the example below shows.
- DefaultOption renderOptions picks its HTML by this value.
- Inside SDKUtil.jsonToHTML, the SDK sets this value from the display-type attribute of the reference node. See How the SDK fills a Metadata on the Metadata class page.
Example
Basic usage: compare the display style
import android.util.Log;
import com.contentstack.sdk.Metadata;
import java.util.jar.Attributes;
Metadata metadata = new Metadata("Jane Doe", "entry", "<ENTRY_UID>", "<CONTENT_TYPE_UID>",
"INLINE", "", new Attributes());
String style = String.valueOf(metadata.getStyleType());
if ("INLINE".equals(style)) {
Log.d("Contentstack", "The item sits inside a line of text");
}getText
getText returns the text of the reference that embeds an item in a JSON Rich Text Editor field.
Returns: String. The text of the embedded item.
Validation
- There is no client-side validation, and getText does not throw.
Behavior
- Client-side only. getText returns a value stored in the object and makes no request.
- The value is the text argument of the constructor.
- Inside SDKUtil.jsonToHTML, the SDK sets this value from the text attribute of the reference node. See How the SDK fills a Metadata on the Metadata class page.
Example
Basic usage: read the text
import android.util.Log;
import com.contentstack.sdk.Metadata;
import java.util.jar.Attributes;
Metadata metadata = new Metadata("Jane Doe", "entry", "<ENTRY_UID>", "<CONTENT_TYPE_UID>",
"INLINE", "", new Attributes());
Log.d("Contentstack", "Text: " + metadata.getText()); // Text: Jane DoetoString
toString returns every value of the Metadata in one string, for logging.
Returns: String. The metadata as a readable string.
Validation
- There is no client-side validation, and toString does not throw.
Behavior
- Client-side only. toString returns a value stored in the object and makes no request.
- The string has the form EmbeddedObject{text='...'type='...', uid='...', contentTypeUid='...', sysStyleType=..., outerHTML='...', attributes='...'}.
- No comma separates the text and type values. Call the getters, not a parser on this string, to read one value.
Example
Basic usage: log the metadata
import android.util.Log;
import com.contentstack.sdk.Metadata;
import java.util.jar.Attributes;
Metadata metadata = new Metadata("Jane Doe", "entry", "<ENTRY_UID>", "<CONTENT_TYPE_UID>",
"INLINE", "", new Attributes());
Log.d("Contentstack", metadata.toString());