General Actions:
Log-in
Register
Wiki:
games
▼
:
Document Index
»
Space:
Main
▼
:
Document Index
»
Page:
linkFinder
Search
en
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
linkFinder
Wiki source code of
linkFinder
Last modified by
Administrator
on 2008/03/19 18:53
Content
·
Comments
(0)
·
Annotations
(0)
·
Attachments
(0)
·
History
·
Information
Show line numbers
/* ** Link Finder Class ** ** This class is used to parse a wiki page and generate a list of links ** */ /* #* */ class linkFinder { def openLink = /\[/ def closeLink = /\]/ def regex = /${openLink}(.+?)\>(.+?)${closeLink}/ def pattern = ~regex def xwiki void setXWiki(xwiki) { this.xwiki = xwiki } Map getMap(String target) { def content = xwiki.getDocument(target).getContent() def space = target.split(/\./)[0] def result = [:] pattern.matcher(content).each { all, name, link -> if (link.indexOf("/") == -1 ) { if (link.indexOf(".") == -1) { link = space + '.' + link } if (xwiki.exists(link)) { link = xwiki.getURL(link, "view") result[name] = link } } else { result[name] = link } } return result } String listOutput(String target) { def result = "\n" def map = this.getMap(target) def names = map.keySet().toList() names.each { name -> result += '* <strong>Title: </strong>' + name + '<strong> Link: </strong>' + map[name] + "\n" } return result } } /* *# */