Last active
November 16, 2015 09:50
-
-
Save rah003/2cb0110d94a99d4e4832 to your computer and use it in GitHub Desktop.
List all components used in specified page and all it's subpages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import info.magnolia.repository.RepositoryConstants | |
import javax.jcr.Node | |
import info.magnolia.jcr.util.NodeUtil | |
import org.apache.commons.lang.StringUtils | |
import info.magnolia.cms.util.QueryUtil | |
website = ctx.getJCRSession("website") | |
listComponents(website.getNode("/some-path")) | |
def listComponents(node) { | |
pages = NodeUtil.getNodes(node, "mgnl:page") | |
for (Node page : pages) { | |
if (page.hasProperty("mgnl:template")) { | |
path = page.getPath().trim() | |
title = page.getProperty("title").getString() | |
println("Page:" + title + ", with path:" + path) | |
components = QueryUtil.search(RepositoryConstants.WEBSITE, "select * from [mgnl:component] where ISDESCENDANTNODE(["+path+"])") | |
for (Node component : components) { | |
println (" " + component.getProperty("mgnl:template").string + ", at " + component.path) | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment