Resolve rich text content
Is this page helpful?
<object type="application/kenticocloud" data-type="item" data-codename="my_tweet"></object>
<p>The used coffee grounds are retained in the filter, while the <a href="/articles/which-brewing-fits-you" data-item-id="65832c4e-8e9c-445f-a001-b9528d13dac8">brewed coffee</a> is collected in a vessel such as a carafe or pot.</p>
link
parameter to get more information about the linked content items.
IRichTextContent
(not string
).
{
"item": {
"system": {
"id": "f9b0fd1c-1b83-491a-9d64-2737faedf80d",
"name": "Bourbon Coffee",
"codename": "bourbon_coffee",
"language": "en-US",
"type": "simple_article",
"sitemap_locations": [],
"last_modified": "2019-01-11T11:46:18.2473895Z"
},
"elements": {
"title": {
"type": "text",
"name": "Title",
"value": "Bourbon Coffee"
},
"author": {
...
},
"body": {
"type": "rich_text",
"name": "Body",
"images": {},
"links": {},
"modular_content": [
"n44bfddb7_b088_01ef_e782_423deb064718"
],
"value": "<p>Arabica Bourbon is among the best coffee varieties you can find in Brazil, Salvador, and Rwanda. This widely known and popular coffee is cultivated in three color varieties: red, orange, and yellow. But what does it have in common with the American whiskey? </p>\n<p>The coffee, first called Café du Roy, then Café Leroy, was served to kings at the French court and was the brand of choice of the classic author, Honoré de Balzac, who enjoyed forty cups a day. Or so they say…</p>\n<object type=\"application/kenticocloud\" data-type=\"item\" data-rel=\"component\" data-codename=\"n44bfddb7_b088_01ef_e782_423deb064718\"></object>\n<p><br></p>"
}
}
},
"modular_content": {
...
"n44bfddb7_b088_01ef_e782_423deb064718": {
"system": {
"id": "44bfddb7-b088-01ef-e782-423deb064718",
"name": "44bfddb7-b088-01ef-e782-423deb064718",
"codename": "n44bfddb7_b088_01ef_e782_423deb064718",
"language": "en-US",
"type": "blockquote",
"sitemap_locations": [],
"last_modified": "2019-01-11T11:46:18.2473895Z"
},
"elements": {
"quote": {
"type": "rich_text",
"name": "Quote",
"images": {},
"links": {},
"modular_content": [],
"value": "<p>If I couldn't, three times a day,</p>\n<p>be allowed to drink my little cup of coffee,</p>\n<p>in my anguish I will turn into</p>\n<p>a shriveled-up roast goat. </p>"
},
"source": {
"type": "text",
"name": "Source",
"value": "Coffee Cantata by J. S. Bach"
}
}
}
}
}
// Tip: Find more about Java SDK at https://kontent.ai/learn/java
public class TweetInlineContentItemsResolver extends InlineContentItemsResolver<Tweet> {
@Override
String resolve() {
return "<blockquote class=\"twitter-tweet\" data-lang=\"en\" data-theme=\"" + tweet.theme[0].codename + "\"><a href=\"" + tweet.tweetLink.url + "\"></a></blockquote>"
}
}
// Tip: Find more about Java SDK at https://kontent.ai/learn/java
DeliveryClient client = new DeliveryClient("<YOUR_PROJECT_ID>");
client.registerInlineContentItemsResolver(new TweetInlineContentItemsResolver());
// Tip: Find more about Java SDK at https://kontent.ai/learn/java
SimpleArticle item = client.getItem("my_article", SimpleArticle.class);
String description = item.toCompletableFuture().get().getBodyCopy();
// Tip: Find more about Java SDK at https://kontent.ai/learn/java
public class CustomContentLinkUrlResolver implements ContentLinkUrlResolver {
@Override
String resolveLinkUrl(Link link) {
// Resolves URLs to content items based on the Article content type
if ("my_article".equals(link.getCodename())) {
return String.format("/articles/%s", link.getUrlSlug());
}
}
}
public class CustomBrokenContentLinkUrlResolver implements BrokenLinkUrlResolver {
@Override
String resolveBrokenLinkUrl() {
// Resolves URLs to unavailable content items
return "/404";
}
}
// You can also register lambdas with the DeliveryClient as the resolvers are functional interfaces: https://kontent.ai/learn/java-register-resolver
// Sets the resolver as an optional dependency of the DeliveryClient
DeliveryClient client = new DeliveryClient("<YOUR_PROJECT_ID>");
client.setContentLinkUrlResolver(new CustomContentLinkUrlResolver());
client.setBrokenLinkUrlResolver(new CustomBrokenContentLinkUrlResolver());
// Tip: Find more about Java SDK at https://kontent.ai/learn/java
SimpleArticle item = client.getItem("my_article", SimpleArticle.class);
String description = item.toCompletableFuture().get().getBodyCopy();
// Generate strongly typed models at https://github.com/kontent-ai/java-packages/tree/master/delivery-sdk-generators
// Tip: Find more about Java SDK at https://kontent.ai/learn/java
import java.lang.String;
import java.util.List;
import kontent.ai.delivery.ContentItemMapping;
import kontent.ai.delivery.ElementMapping;
import kontent.ai.delivery.Option;
import kontent.ai.delivery.System;
@ContentItemMapping("blockquote")
public class Homepage {
@ElementMapping("quote")
String quote;
@ElementMapping("source")
String source;
System system;
public String getQuote() {
return quote;
}
public void setQuote(String quote) {
this.quote = quote;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public System getSystem() {
return system;
}
public void setSystem(System system) {
this.system = system;
}
}
<!-- This makes use of Spring Book and the Thymeleaf templating engine. See more at: https://kontent.ai/blog/building-java-webservices-with-kentico-cloud-java-delivery-sdk -->
<!-- Place this in a file at a path similar to: resources/kontent-ai/templates/blockquote.html -->
<blockquote><div th:text="{model.quote}"</div> – <cite><div th:text="{model.source}"</div></cite></blockquote>