Get ParagraphSystem of a resource inside another resource | Community
Skip to main content
elizabethp60981
Level 3
February 28, 2018
Solved

Get ParagraphSystem of a resource inside another resource

  • February 28, 2018
  • 3 replies
  • 2079 views

Hi,

I'm need to read a text that is on a parsys inside a text component.

I have a page that shows a list of news, this page has a resourceType list-news, for example.

each one of my news has a resource type "News".

When I am on my list-news reading each one of my content new, and I do a hit.getResourceType, I am getting the resourceType of my "list-news" item,

How can I get the parsys, of my item that has another resource type???

I can't find a similar case on the internet

I am using this:

for (Hit hit : result.getHits()) {

        if(null != hit.getProperties() ) {

           SlingHttpServletRequest slingReq = getRequest();

           ParagraphSystem parSys = ParagraphSystem.create(hit.getResource(), slingRequest);

          

           for (Paragraph par: parSys.paragraphs()) {

                   String myType = par.getType().toString() ;

               }

} }

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

That is a strange requirement - never really heard of that one before. Not sure why you need to read text that is part of another component.

Anyhow - Text is simply node property typically under a par node.

For example - assume we put text on page like this:

OK - now we can access this in the JCR Here:

/content/AEMWatchFolder/en/jcr:content/par/text_1816859244

Look at the text prop:

You can access HTML by reading node props like that.

3 replies

Rima_Mittal
Level 4
February 28, 2018

get a Resource Iterator from result and work on resource thereafter.

Iterator<Resource> itr = result.getResources();

while (itr.hasNext()) {

Resource resource = itr.next();

....

}

Iterate the resource and use resource.listChildren() to get all its sub nodes.

elizabethp60981
Level 3
March 1, 2018

Hi Riman,

Thank you for your reply.

But I had tried a lot of things, but I am not able to retrieve the content. I want to retrieve the text that is created inside the parsys.

Does anyone had already done that?

I am trying a lot of things and I can go to the "par" node, but I can't read the text inside of it:

Things that I am trying:

ParagraphSystem parSys = ParagraphSystem.create(res, slingRequest);

          

           for (Paragraph par: parSys.paragraphs()) {

                   String myType = par.getType().toString() ;

                   Resource resPar = par.getResource();

                   String type = resPar.getName();

                  

                   ResourceResolver  resourceResolverText = resPar.getResourceResolver();

                   Resource resText = resourceResolverText.getResource(resPar.getPath());

                   ValueMap valueMap = resText.getValueMap();

                   String texto = valueMap.get("Text", String.class);

Thank you!

smacdonald2008
smacdonald2008Accepted solution
Level 10
March 1, 2018

That is a strange requirement - never really heard of that one before. Not sure why you need to read text that is part of another component.

Anyhow - Text is simply node property typically under a par node.

For example - assume we put text on page like this:

OK - now we can access this in the JCR Here:

/content/AEMWatchFolder/en/jcr:content/par/text_1816859244

Look at the text prop:

You can access HTML by reading node props like that.