Last active
October 7, 2015 06:39
-
-
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
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 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 += " " | |
} | |
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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on 5.3.10 and 5.4.2 (tho there might be paths which still breaks, if you find one, please report back.