When we need to return all the properties of an Asset (or a Node, Asset is also a node), there is no single method that will return all the properties. We have to do this in a combination. This article details the steps.
Step-by-step guide
For each found result/node, we have to do the following:
- Get all the top level properties (Node root level). These include `jcr:created`, `jcr:createdBy`, etc.
- Get all `jcr:content` level properties. These include `cq:name`, `cq:lastModified`, etc
- Get all `jcr:content\metadata` level properties. These include `dc:title`, any custom metadata etc.
- You can add all these to another new `ValueMap` that can hold all the properties of a particular Node/Asset.
Below is a code snippet:
Note
- `jcr:path` is not returned by any of the above. So i had to explicitly add it using `hit.getPath`
- The name of the node or Asset name can be pulled from `hit.getTitle()`. Ofcourse this is also returned as part of `cq:name`.
- There are other ways to get the properties as well. One aother way is to get the `Node` and retrieve the properties. `com.day.cq.search.result.Hit` has a method `getNode()` that returns a `java.jcr.Node` interface and you can use that get to fetch the properties.