Skip to content

Instantly share code, notes, and snippets.

@rah003
Last active October 7, 2015 06:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rah003/517002eba12d2f468917 to your computer and use it in GitHub Desktop.
Save rah003/517002eba12d2f468917 to your computer and use it in GitHub Desktop.
Script to generate nice confluence image-like tables showing config tree from magnolia
import static info.magnolia.jcr.util.NodeUtil.isNodeType;
import static org.apache.commons.lang3.StringUtils.substringBeforeLast;
exportPath = "/modules/ui-admincentral/commands"
filterJCR = true
filterMGNL = true
session = MgnlContext.getJCRSession('config')
node = session.getNode(exportPath);
zeroDepth = node.getDepth()
generateHeader()
generate(node)
generateFooter()
// methods
def generate(node) {
generateTableRow(node)
node.properties.each {
generateTableRow(it)
}
node.nodes.each {
generate(it)
}
}
def generateTableRow(item) {
if ((filterJCR && item.name.startsWith("jcr:")) || (filterMGNL && item.name.startsWith("mgnl:"))) {
return
}
def depth = ""
int level = (item.getDepth()-zeroDepth) *4
for ( int i = 0; i <level; i++) {
depth += "&nbsp;"
}
def type = "p"
def value = ""
if (item.isNode()) {
type = isNodeType(item, "mgnl:contentNode") ? "n" : "f"
} else {
if (item.multiple) {
item.values.each { val ->
value = value + ", " + val.string
}
value = substringBeforeLast(value,",")
} else {
value = item.string
}
}
println "| "+depth+"{${type}}${item.name} | ${value} |"
}
def generateHeader() {
println "{table-plus:class=m5-configuration-tree}"
}
def generateFooter() {
println "{table-plus}"
}
return "Thank you for using Magnolia2ConfuenceTable Export Action today."
@rah003
Copy link
Author

rah003 commented Oct 7, 2015

Tested on 5.3.10 and 5.4.2 (tho there might be paths which still breaks, if you find one, please report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment