1
2
3
4
5 package net.sf.tacos.components;
6
7 import java.util.List;
8 import net.sf.tacos.services.CategoryInfo;
9 import net.sf.tacos.services.SiteMap;
10 import org.apache.tapestry.BaseComponent;
11
12
13
14
15
16 public abstract class SiteMapComponent extends BaseComponent
17 {
18 public abstract SiteMap getSiteMap();
19 public abstract String getName();
20 public abstract String getCategory();
21
22 public abstract boolean getShowAll();
23 public abstract boolean getIgnoreCurrentPage();
24
25
26
27
28 public boolean getShowSiteMap()
29 {
30 return getIgnoreCurrentPage()
31 || (getCurrentPageCategory() != null);
32 }
33
34
35
36
37 public CategoryInfo getCategoryOf(String page)
38 {
39 return getSiteMap().getCategoryFromPage(page);
40 }
41
42
43
44
45 public CategoryInfo getCurrentPageCategory()
46 {
47 return getCategoryOf(getPage().getPageName());
48 }
49
50
51
52
53 public boolean isPageInCategory(String page)
54 {
55 return getSiteMap().inCategory(page, getCategory());
56 }
57
58
59
60
61 public boolean isCurrentPageInCategory()
62 {
63 return isPageInCategory(getPage().getPageName());
64 }
65
66
67
68
69 public String getDefaultPage()
70 {
71 return getSiteMap().getDefaultPage(getCategory()).getName();
72 }
73
74
75
76
77
78 public String getCategoryClass()
79 {
80 return isCurrentPageInCategory() ? "current" : null;
81 }
82
83
84
85
86 public String getCategoryDisplayName()
87 {
88 if (getShowAll())
89 return getSiteMap().getCategoryInfo(getCategory()).getName();
90 else
91 return getSiteMap().getDefaultPageDesc(getCategory());
92 }
93
94
95
96
97 public String getPageDisplayName()
98 {
99 return getSiteMap().getPageInfo(getName()).getDesc();
100 }
101
102
103
104
105 public List getPagesOfCategoryOfPage(String page)
106 {
107 return getSiteMap().getCategoryPages(page);
108 }
109
110
111
112
113 public List getPagesOfCategoryOfCurrentPage()
114 {
115 return getPagesOfCategoryOfPage(getPage().getPageName());
116 }
117
118
119
120
121 public List getPagesOfCategory(String category)
122 {
123 return getSiteMap().getCategoryInfo(category).getPageNames();
124 }
125
126
127
128
129 public List getPagesOfCurrentCategory()
130 {
131 return getPagesOfCategory(getCategory());
132 }
133
134 public boolean getShowPage()
135 {
136 if (getShowAll())
137 return true;
138 else
139 return !getName().equals( getCategoryOf(getPage().getPageName()).getDefaultPage() );
140 }
141
142
143
144
145
146 public String getPageClass()
147 {
148 String name = getName();
149 String pageName = getPage().getPageName();
150
151 boolean selected = name.equals(pageName)
152 || getSiteMap().contains(name, pageName);
153 return selected ? "here" : null;
154 }
155 }