Hi,
I really need help with this, using java I need to search for a page via property value.
Thanks.
I don't know if this performs well, but this snippet traverses a branch with root "node", finds jcr:content nodes, and gets a specific child node. You could use the node.getproperty() method in your case and traverse the /content branch (or wherever your pages are stored). See the javax.jcr.node (http://www.day.com/maven/jsr170/javadocs/jcr-1.0/javax/jcr/Node.html). Also see org.apache.sling.jcr.api.SlingRepository (http://dev.day.com/docs/en/cq/current/javadoc/index.html)
NodeIterator iter = node.getNodes();
while (iter.hasNext()) {
Node n = iter.nextNode();
//Look for "jcr:content" nodes
if (n.getName().equals("jcr:content")) {
//get the path of the model node and save it
if(n.hasNode(MODEL_NODE)){
modelIds.add(n.getNode(MODEL_NODE).getPath());
}
} else{
//Scan child nodes
getModelIds(n);
}
}
scott
Since CQ 5.4 XPath is deprecated for queries.
To execute an SQL2 query for all pages where the cq:template property contains the value '/apps/geometrixx-outdoors/templates/page_sidebar' you need the following code:
final String queryString = "SELECT pc.* FROM [cq:PageContent] where [cq:template] = '/apps/geometrixx-outdoors/templates/page_sidebar'";
final QueryManager qm = getSession().getWorkspace().getQueryManager();
final Query query = qm.createQuery(queryString, Query.JCR_SQL2);
For more information regarding JCR queries see the documentation for the javax.jcr.query package.
Hi Matthias,
this is another subject, but Xpath is only deprecated from JCR 2.0 specifications, not jackrabbit, nor CRX, nor CQ. You don't need to specify N querying languages, just one human and one programmatic.
Then you can create/use as many languages as you want (there is also querybuilder for example).
If you like xpath, use it, it is NOT deprecated.
Hi
You can use QueryBuilder API.For example :
http://localhost:4502/bin/querybuilder.json?property=[property_name]&property.value=[property_value]&type=cq:Page
For more information, please refer below link :
http://dev.day.com/docs/en/cq/current/dam/customizing_and_extendingcq5 dam/query_builder.html
North America
Europe, Middle East and Africa
Asia Pacific