1 package net.sf.statcvs.pages; 2 3 import java.util.ArrayList; 4 import java.util.Iterator; 5 import java.util.List; 6 7 public class PageGroup implements NavigationNode { 8 private final String title; 9 private final boolean connectSiblings; 10 private final List pages = new ArrayList(); 11 private NavigationNode mainPage = null; 12 private NavigationNode parent = null; 13 private boolean showLinkToPreviousSibling = false; 14 15 public PageGroup(final String title) { 16 this(title, true); 17 } 18 19 public PageGroup(final String title, final boolean connectSiblings) { 20 this.title = title; 21 this.connectSiblings = connectSiblings; 22 } 23 24 public void add(final NavigationNode page) { 25 this.pages.add(page); 26 if (this.mainPage == null) { 27 this.mainPage = page; 28 } 29 } 30 31 public void setMainPage(final NavigationNode page) { 32 this.mainPage = page; 33 } 34 35 public void setParent(final NavigationNode parentPage) { 36 this.parent = parentPage; 37 } 38 39 public void setSiblings(final String siblingsTitle, final List siblingPages) { 40 throw new UnsupportedOperationException("Cannot set siblings for PageGroup"); 41 } 42 43 public void setShowLinkToPreviousSibling(final boolean showLink) { 44 this.showLinkToPreviousSibling = showLink; 45 } 46 47 public String getFullTitle() { 48 return this.title; 49 } 50 51 public String getShortTitle() { 52 return this.title; 53 } 54 55 public String getURL() { 56 return this.mainPage.getURL(); 57 } 58 59 public void write() { 60 final Iterator it = this.pages.iterator(); 61 while (it.hasNext()) { 62 final NavigationNode page = (NavigationNode) it.next(); 63 if (this.showLinkToPreviousSibling) { 64 page.setShowLinkToPreviousSibling(this.showLinkToPreviousSibling); 65 } 66 if (this.parent != null) { 67 page.setParent(this.parent); 68 } 69 if (this.connectSiblings) { 70 page.setSiblings(this.title, this.pages); 71 } 72 page.write(); 73 } 74 if (this.mainPage != null && !this.pages.contains(this.mainPage)) { 75 this.mainPage.write(); 76 } 77 } 78 79 public String asLinkList() { 80 final StringBuffer s = new StringBuffer(); 81 s.append("<ul class=\"linklist\">\n"); 82 final Iterator it = this.pages.iterator(); 83 while (it.hasNext()) { 84 final NavigationNode page = (NavigationNode) it.next(); 85 s.append(" <li>" + HTML.getLink(page.getURL(), page.getShortTitle()) + "</li>\n"); 86 } 87 s.append("</ul>"); 88 return s.toString(); 89 } 90 91 public String asParentLink() { 92 return this.mainPage.asParentLink(); 93 } 94 }