You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

groovy: Security restricted macro is not allowed on this page. A page edit restriction is required that matches the macro authorization list.

import com.atlassian.confluence.pages.Page;
import com.atlassian.spring.container.ContainerManager;

def index = request.getSession(true).getServletContext().getAttribute("climb.indexi5")

if (index == null )

Unknown macro: { out.println "Creating index..." index = new Index() String pageTitle="Climbing Guides" //String pageTitle="Hobart Craglets" Page page = ContainerManager.getComponent("pageManager").getPage(context.spaceKey,pageTitle); addChildren(page, index) request.getSession(true).getServletContext().setAttribute("climb.indexi5", index) }

def totalStars = ["","*","**","***"]
def totalGrades = ["10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","VE","V0","V1","V2","V3","V4","V5","V6","V7","V8","V9","V10","V11","V12","V13","V14","V15"]
def totalSorts = ["grade,stars,name","name","none"]

def sortBy = "grade,stars,name"
//def grades =["29","30","31","32","33","34","V10","V11","V12","V13","V14","V15"]
def stars =totalStars
def pages = null

def nameStartsWith = ""
def nameContains = ""

out.println "h2. Sport"
showList(["29","30","31","32","33","34"], false, index)
out.println "h2. Trad"
showList(["26","27","28", "29","30","31","32","33","34"], true, index)
out.println "h2. Bouldering"
showList(["V10","V11","V12","V13","V14","V15"], false, index)

def showList(def grades, boolean onlyTrad, def index)
{
def sortBy = "grade,stars,name"
def totalSorts = ["grade,stars,name","name","none"]
def filtered = new ArrayList();
for (c in index.climbs)
{
if ( c.grade!=null && grades.contains(c.grade) )
{
String boltchar = new String( [222] as char[] )

if (!onlyTrad || c.extra==null || (!c.extra.contains("B") && !c.extra.contains(boltchar) && !c.extra.contains("TR") ) )

Unknown macro: { filtered.add c }

}
}

if (sortBy!=null && !sortBy.equals("none"))
{
def compare = [ compare:

Unknown macro: {a,b-> a.name.toLowerCase().trim().compareTo(b.name.toLowerCase().trim()) }

] as Comparator

if (sortBy.equals(totalSorts[0]))
{
compare = [ compare:

Unknown macro: {a,b-> a.getGradeSort().compareTo(b.getGradeSort() ) }

] as Comparator
}
//out.println "sorting"
filtered.sort compare
}

//out.println "h2. Results"
out.print filtered.size + " results"
if (filtered.size > 600)

Unknown macro: { out.println ", 600 shown" filtered = filtered.subList(0,600) }

else
out.println ""

out.println "|| Stars || Name || Length || Grade || FA || Area ||"
for (c in filtered)

Unknown macro: { out.println " | !http}

}

def addChildren(Page page, Index index)
{
for (child in page.sortedChildren)

Unknown macro: { doPage(child, index) }

}

def doPage (Page page, Index index)
{
int index1 = page.content.indexOf("

",index1+1)
String xml = page.content.substring(index1+7, index2)
out.println ("Page:" + page )

def x = new XmlParser().parseText(xml)
def climbs = x.climb
climbs.addAll x.problem

if (climbs.size() > 0)
index.pages.add page.title

for (climb in climbs)
{
def grade = climb.@grade
if (grade!=null)
{
if (grade.indexOf('/') > 0)

Unknown macro: { grade = grade.substring(0, grade.indexOf('/')); }

grade = grade.replace('?', ' ');
grade = grade.replace('M', ' ');
grade = grade.replace('A', ' ');

grade = grade.trim();
if (grade.indexOf(' ') > 0)

Unknown macro: { grade = grade.substring(0, grade.indexOf(' ')); }

grade = grade.trim();
}
Climb c = new Climb( name: climb.@name ,
grade: grade ,
stars: climb.@stars,
length: climb.@length,
fa: climb.@fa,
extra: climb.@extra,
page: page.title)
c.stars = c.stars==null?"":c.stars
c.stars = c.stars.trim()
index.climbs.add( c )

}

}
addChildren(page, index)

}

def List toList

Unknown macro: { def ret = [] for (c in x) ret.add c return ret }

class Index

Unknown macro: { List climbs = [] List pages = [] }

class Climb
{
String name
String grade
String stars
String length
//String extra
//String number
String page
String fa
String extra

public String getGradeSort()

Unknown macro: { return grade.trim() + stars.trim() + name.toLowerCase().trim() }

String toString()

Unknown macro: { return stars==null?""}

}

  • No labels