This is a collection of mini-recipes for doing JCR queries. Please add your own!
|
SQL |
XPath (deprecated in JCR 2.0) |
||
---|---|---|---|---|
Get all pages |
select * from mgnl:content |
//element(*, mgnl:content) |
||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="656b83b9-0429-4665-ae64-8cfceab95827"><ac:plain-text-body><![CDATA[ |
Get all pages with "News" in the title |
select * from mgnl:content where title like '%News%' |
//element(*, mgnl:content)[jcr:like(@title, '%News%')] |
]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="1b0248e9-0bb8-4d92-9502-a08fc32d4825"><ac:plain-text-body><![CDATA[ |
Get all pages where the title exactly matches "News" (case sensitive) |
select * from mgnl:content where title like 'News' |
//element(*, mgnl:content)[@title = 'News'] |
]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8fe70be8-c75c-4bab-8975-78e7a886eee8"><ac:plain-text-body><![CDATA[ |
Get all STK pages that have a header image |
select * from mgnl:content where image is not null |
//element(*, mgnl:content)[@image] |
]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="f34321cf-12b2-41c1-b467-6b9f295df40c"><ac:plain-text-body><![CDATA[ |
Get all instances of a "Teaser" paragraph |
select * from nt:base where mgnl:template = 'stkTeaser' |
//*[@mgnl:template = 'stkTeaser'] |
]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="d40c4416-3dd8-47e6-9336-9f6896946583"><ac:plain-text-body><![CDATA[ |
Get listing of available paragraph types |
select * from nt:base where jcr:path like '/modules/%/paragraphs/%' and type is not null |
/jcr:root/modules[1]//*/paragraphs[1]//*[@type] |
]]></ac:plain-text-body></ac:structured-macro> |
|
|
|
||
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5b30c6fa-3407-4894-84d7-26d569138365"><ac:plain-text-body><![CDATA[ |
Get user with email 'eric@example.com' |
select * from mgnl:user where email = 'eric@example.com' |
//element(*, mgnl:user)[@email = 'eric@example.com'] |
]]></ac:plain-text-body></ac:structured-macro> |
Note: you can use the translator to convert from one format to another.