Content Fragment as Java APIs | AEM Community Blog Seeding | Community
Skip to main content
kautuk_sahni
Community Manager
Community Manager
October 12, 2020

Content Fragment as Java APIs | AEM Community Blog Seeding

  • October 12, 2020
  • 0 replies
  • 1764 views

BlogImage.jpg

Content Fragment as Java APIs by AEM Queries & Solutions

Abstract

In this article we will go through different APIs of content fragment which we can use while exposing or customizing the behavior of CF.
To start with lets understand how we get the related content fragment of a specific model using a query builder.

First we start with adding the specific properties to the map and running a query:

Map<String, String> map = new HashMap<>();


map.put("type", "dam:Asset");
map.put("path", "/content/dam");
map.put("First_property", "jcr:content/contentFragment");
map.put("First_property.value", "true");
map.put("Second_property", "jcr:content/data/cq:model");
map.put("Second_property.value", "conf/fragmentexamples/settings/dam/cfm/models/");
map.put("property.and", "true");
map.put("p.limit", "-1");

Once we are done creating the map we will create our query variable using the request:

QueryBuilder queryBuilder = request.getResourceResolver().adaptTo(QueryBuilder.class);

Now we will get the results using query and the map using Predicategroup:

Query query = queryBuilder.createQuery(PredicateGroup.create(map),
request.getResourceResolver().adaptTo(Session.class));
final SearchResult result = query.getResult();

This result variable will hold all the Content fragment used by the specified content model at location /content/dam(we defined while creating the map).

Now we can iterate on the results and get the specified resource and adapt it to ContentFragment interface which holds all the content fragment related APIs.

Read Full Blog

Content Fragment as Java APIs

Q&A

Please use this thread to ask the related questions.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.