{groovy:output=wiki|showErrorOutput=true} import com.atlassian.confluence.pages.Page; import bucket.container.ContainerManager; def index = null //request.getSession(true).getServletContext().getAttribute("climb.index") if (index == null ) { 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.index", index) // for (c in index.climbs) // out.println c } def grades = ["17","18" ] def stars = ["***"] def pages = ["Northern Buttress"] out.println ''' h2. Search Criteria: {html}<table><tr> <th>Stars</th> <th>Grades</th> <th>Areas</th> </tr> <tr> <td> </td> <td> </td> <td><select multiple='true' size='20' name='climb.area' >''' for (a in index.pages) { out.println "<option value='" + a + "'>" + a + "</option>" } out.println ''' </select> </td> </tr> </table> {html}''' def filtered = new ArrayList(); for (c in index.climbs) { if ( pages.contains(c.page) && grades.contains(c.grade) && stars.contains(c.stars) ) filtered.add c } for (c in filtered) out.println c def addChildren(Page page, Index index) { for (child in page.children) { doPage(child, index) } } def doPage (Page page, Index index) { int index1 = page.content.indexOf("{guide}") if (index1 > -1) { index.pages.add page.title int index2 = page.content.indexOf("{guide}",index1+1) String xml = page.content.substring(index1+7, index2) out.println ("Page:" + page ) def x = new XmlParser().parseText(xml) def climbs = x.climb for (climb in climbs) { Climb c = new Climb( name: climb.@name , grade: climb.@grade , stars: climb.@stars, length: climb.@length, page: page.title) index.climbs.add( c ) } } addChildren(page, index) } class Index { List climbs = [] List pages = [] } class Climb { String name String grade String stars String length //String extra //String number String page; String toString() { return stars==null?"":stars + " " + " " + length + " " + grade } } {groovy} |