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
Hide line numbers
1: 2: 3: /* 4: ** Link Finder Class 5: ** 6: ** This class is used to parse a wiki page and generate a list of links 7: ** 8: */ 9: 10: /* #* */ 11: 12: class linkFinder 13: { 14: def openLink = /\[/ 15: def closeLink = /\]/ 16: def regex = /${openLink}(.+?)\>(.+?)${closeLink}/ 17: def pattern = ~regex 18: 19: def xwiki 20: 21: void setXWiki(xwiki) 22: { 23: this.xwiki = xwiki 24: } 25: 26: Map getMap(String target) 27: { 28: def content = xwiki.getDocument(target).getContent() 29: 30: def space = target.split(/\./)[0] 31: 32: def result = [:] 33: 34: pattern.matcher(content).each 35: { 36: all, name, link -> 37: 38: if (link.indexOf("/") == -1 ) 39: { 40: if (link.indexOf(".") == -1) 41: { 42: link = space + '.' + link 43: } 44: 45: if (xwiki.exists(link)) 46: { 47: link = xwiki.getURL(link, "view") 48: result[name] = link 49: } 50: } 51: else 52: { 53: result[name] = link 54: } 55: } 56: 57: return result 58: } 59: 60: String listOutput(String target) 61: { 62: def result = "\n" 63: 64: def map = this.getMap(target) 65: 66: def names = map.keySet().toList() 67: 68: names.each 69: { 70: name -> 71: 72: result += '* <strong>Title: </strong>' + name + '<strong> Link: </strong>' + map[name] + "\n" 73: } 74: 75: return result 76: } 77: 78: } 79: 80: /* *# */