QueryResult
wraps a collection of Node
s. Both these classes are part of the JCR API. On the other hand, Page
is a part of the CQ API. There is no direct way to transform a Node
into a Page
even if both objects represent the same physical thing. The only thing you can do is to take the Node
path and retrieve a Page
using this path:
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
QueryResult result = ...;
NodeIterator nodes = result.getNodes();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
Page page = pageManager.getPage(node.getPath());
// do anything you want with the Page
}
About the second question - you may use Page#getContentResource(String)
method to take any Resource
from the page jcr:content
, like:
Resource resource = page.getContentResource("parsys/text");
Resource
is a part of the Sling API. You may cast it to Node
using adaptTo()
method:
Node node = resource.adaptTo(Node.class);
However it's a good idea to learn how to use the Sling API. For starters, you may read resource/node properties by adapting the resource to the ValueMap
class:
ValueMap map = resource.adaptTo(ValueMap.class);
map.get("myProperty", ""); // the second argument is the default value