Content Fragment as Java APIs | AEM Community Blog Seeding


Community Manager



Content Fragment as Java APIs by AEM Queries & Solutions


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),
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


Please use this thread to ask the related questions.

AEM AEMEBlogSeeding Experience Manager