View Javadoc

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(1);
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 setParent(final NavigationNode parentPage) {
32          this.parent = parentPage;
33      }
34  
35      public void setSiblings(final String siblingsTitle, final List siblingPages) {
36          throw new UnsupportedOperationException("Cannot set siblings for PageGroup");
37      }
38  
39      public void setShowLinkToPreviousSibling(final boolean showLink) {
40          this.showLinkToPreviousSibling = showLink;
41      }
42  
43      public String getFullTitle() {
44          return this.title;
45      }
46  
47      public String getShortTitle() {
48          return this.title;
49      }
50  
51      public String getURL() {
52          if (mainPage != null) {
53              return this.mainPage.getURL();
54          }
55          
56          new Exception("Dummy Exception please report to bx").printStackTrace();
57          
58          return "no-page-defined-yet";
59      }
60  
61      public void write() {
62          final Iterator it = this.pages.iterator();
63          while (it.hasNext()) {
64              final NavigationNode page = (NavigationNode) it.next();
65              if (this.showLinkToPreviousSibling) {
66                  page.setShowLinkToPreviousSibling(this.showLinkToPreviousSibling);
67              }
68              if (this.parent != null) {
69                  page.setParent(this.parent);
70              }
71              if (this.connectSiblings) {
72                  page.setSiblings(this.title, this.pages);
73              }
74              page.write();
75          }
76          if (this.mainPage != null && !this.pages.contains(this.mainPage)) {
77              this.mainPage.write();
78          }
79      }
80  
81      public String asLinkList() {
82          final StringBuffer s = new StringBuffer();
83          s.append("<ul class=\"linklist\">\n");
84          final Iterator it = this.pages.iterator();
85          while (it.hasNext()) {
86              final NavigationNode page = (NavigationNode) it.next();
87              s.append("    <li>" + HTML.getLink(page.getURL(), page.getShortTitle()) + "</li>\n");
88          }
89          s.append("</ul>");
90          return s.toString();
91      }
92  
93      public String asParentLink() {
94          return this.mainPage.asParentLink();
95      }
96  }