Mindmap Sitemap
Last modified by Andreea Popescu on 2021/03/18 11:28
![]() | Generates a MindMap of the wiki |
Type | Snippet |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
Generates a MindMap of the wiki using the Mindmap Macro (you'll need to make sure you enable it first!)
This snippet offers a "update" button for admin users which generates a MindMap of the current site and attaches the generated MindMap to the page it's executed in.
Code
Add the following in a page, using the XWiki Syntax 2.1:
{{groovy}}
import java.io.StringReader
import java.util.HashMap
import com.xpn.xwiki.doc.XWikiAttachment
import groovy.xml.MarkupBuilder
def generateXmlForChildNode(nodeName, xmlBuilder)
{
xmlBuilder.node(link:xwiki.getURL(nodeName, "view"), text:nodeName) {
services.query.xwql("select distinct doc.web, doc.name, doc.parent from XWikiDocument as doc where doc.parent = :parent").bindValue("parent", nodeName).execute().each() {
def docRef = services.model.createDocumentReference("", it[0], it[1])
def serializedDocRef = services.model.serialize(docRef, "local")
generateXmlForChildNode(serializedDocRef, xmlBuilder)
}
}
}
def generateMap(firstNodeName, xmlBuilder)
{
xmlBuilder.map() {
generateXmlForChildNode(firstNodeName, xmlBuilder)
}
}
if (xwiki.hasAdminRights())
{
println "[[Update the Map>>||queryString='update=1']]"
if (request.update) {
print "Start mindmap generation... "
def writer = new StringWriter()
def xmlBuilder = new MarkupBuilder(writer)
generateMap("Main.WebHome", xmlBuilder)
def attachmentName = "sitemap.mm"
def attachment = doc.getDocument().getAttachment(attachmentName)
if (!attachment)
{
attachment = doc.getDocument().addAttachment(attachmentName, writer.toString().getBytes(), xcontext.context)
} else {
attachment.setContent(writer.toString().getBytes())
}
doc.getDocument().saveAttachmentContent(attachment, xcontext.context)
doc.save()
println "done"
}
}
{{/groovy}}
{{velocity}}
#if ($doc.attachmentList.size() > 0)
{{html}}
#mindmap("sitemap.mm" "100%" "500")
{{/html}}
#end
{{/velocity}}
import java.io.StringReader
import java.util.HashMap
import com.xpn.xwiki.doc.XWikiAttachment
import groovy.xml.MarkupBuilder
def generateXmlForChildNode(nodeName, xmlBuilder)
{
xmlBuilder.node(link:xwiki.getURL(nodeName, "view"), text:nodeName) {
services.query.xwql("select distinct doc.web, doc.name, doc.parent from XWikiDocument as doc where doc.parent = :parent").bindValue("parent", nodeName).execute().each() {
def docRef = services.model.createDocumentReference("", it[0], it[1])
def serializedDocRef = services.model.serialize(docRef, "local")
generateXmlForChildNode(serializedDocRef, xmlBuilder)
}
}
}
def generateMap(firstNodeName, xmlBuilder)
{
xmlBuilder.map() {
generateXmlForChildNode(firstNodeName, xmlBuilder)
}
}
if (xwiki.hasAdminRights())
{
println "[[Update the Map>>||queryString='update=1']]"
if (request.update) {
print "Start mindmap generation... "
def writer = new StringWriter()
def xmlBuilder = new MarkupBuilder(writer)
generateMap("Main.WebHome", xmlBuilder)
def attachmentName = "sitemap.mm"
def attachment = doc.getDocument().getAttachment(attachmentName)
if (!attachment)
{
attachment = doc.getDocument().addAttachment(attachmentName, writer.toString().getBytes(), xcontext.context)
} else {
attachment.setContent(writer.toString().getBytes())
}
doc.getDocument().saveAttachmentContent(attachment, xcontext.context)
doc.save()
println "done"
}
}
{{/groovy}}
{{velocity}}
#if ($doc.attachmentList.size() > 0)
{{html}}
#mindmap("sitemap.mm" "100%" "500")
{{/html}}
#end
{{/velocity}}