cogGenerates a MindMap of the wiki
Developed by

Vincent Massol

0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents


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. 

You'll need to have programming rights to execute this snippet as it's in Groovy

A more advanced MindMap application also allows to import MindMap to wiki pages.

This snippet doesn't work for versions greater than 3.0M3 since the Velocity Mindmap macro has been removed in 3.0M3. If you still wish to use it you'll need to add the following macro before the Groovy snippet:

#macro(mindmap $mindmap $width $height)
#set($mindmap = "")
#set($mmurl = "")
#set($mmurl = $mindmap)
#set($mmurl1 = $doc.getAttachmentURL($mindmap,"download"))
#set($mmurl = "${escapetool.url(${request.scheme})}://${escapetool.url(${request.serverName})}:${escapetool.url(${request.serverPort})}${mmurl1}")
<applet code="freemind.main.FreeMindApplet.class" archive="${escapetool.xml(${request.contextPath})}/freemind/freemind.jar" width="${escapetool.xml(${width})}" height="${escapetool.xml(${height})}">
<param name="type" value="application/x-java-applet;version=1.4" />
<param name="scriptable" value="false" />
<param name="modes" value="freemind.modes.browsemode.BrowseMode" />
<param name="browsemode_initial_map" value="$mmurl" />
<param name="initial_mode" value="Browse" />
<param name="selection_method" value="selection_method_direct" />

You'll also need to download the freemind JAR and copy it in XWiki's WEB-INF/lib directory (or attach it to the page where you've put this snippet and use the jars parameter of the groovy macro).


Add the following in a page, using the XWiki Syntax 2.1:

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.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)
{ {
        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 = ""

        def attachment = doc.getDocument().getAttachment(attachmentName)
        if (!attachment)
            attachment = doc.getDocument().addAttachment(attachmentName, writer.toString().getBytes(), xcontext.context)
        } else {
        doc.getDocument().saveAttachmentContent(attachment, xcontext.context)

        println "done"

#if ($doc.attachmentList.size() > 0)
  #mindmap("" "100%" "500")



Tags: groovy mindmap

Get Connected