1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.portalsite.menu;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.Locale;
22 import java.util.MissingResourceException;
23 import java.util.ResourceBundle;
24
25 import org.apache.jetspeed.om.folder.Folder;
26 import org.apache.jetspeed.om.folder.impl.StandardMenuDefinitionImpl;
27 import org.apache.jetspeed.om.folder.impl.StandardMenuIncludeDefinitionImpl;
28 import org.apache.jetspeed.om.folder.impl.StandardMenuOptionsDefinitionImpl;
29 import org.apache.jetspeed.om.folder.impl.StandardMenuSeparatorDefinitionImpl;
30 import org.apache.jetspeed.om.page.Link;
31 import org.apache.jetspeed.portalsite.view.SiteView;
32
33 /***
34 * This class provides a menu definition for the standard
35 * navigations menu.
36 *
37 * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
38 * @version $Id: StandardNavigationsMenuDefinition.java 568811 2007-08-23 03:00:37Z woonsan $
39 */
40 public class StandardNavigationsMenuDefinition extends StandardMenuDefinitionImpl
41 {
42 /***
43 * menuElements - ordered polymorphic list of menu option, nested
44 * menu, separator, include, and exclude definitions
45 */
46 private List menuElements;
47
48 /***
49 * StandardNavigationsMenuDefinition - constructor
50 */
51 public StandardNavigationsMenuDefinition()
52 {
53 super();
54 }
55
56 /***
57 * getName - get menu name
58 *
59 * @return menu name
60 */
61 public String getName()
62 {
63 return SiteView.STANDARD_NAVIGATIONS_MENU_NAME;
64 }
65
66 /***
67 * getMenuElements - get ordered list of menu options,
68 * nested menus, separators, included
69 * menu, and excluded menu elements
70 *
71 * @return element list
72 */
73 public synchronized List getMenuElements()
74 {
75
76 if (menuElements == null)
77 {
78 menuElements = new ArrayList(4);
79 menuElements.add(new StandardMenuSeparatorDefinitionImpl()
80 {
81 /***
82 * getText - get default text for separator
83 *
84 * @return text
85 */
86 public String getText()
87 {
88
89 return getMenuSeparatorText(null, "menu.separator.folders");
90 }
91
92 /***
93 * getText - get locale specific text for separator from metadata
94 *
95 * @param locale preferred locale
96 * @return text
97 */
98 public String getText(Locale locale)
99 {
100
101 return getMenuSeparatorText(locale, "menu.separator.folders");
102 }
103 });
104 menuElements.add(new StandardMenuOptionsDefinitionImpl()
105 {
106 /***
107 * getOptions - get comma separated menu options
108 *
109 * @return option paths specification
110 */
111 public String getOptions()
112 {
113 return "." + Folder.PATH_SEPARATOR + "*" + Folder.PATH_SEPARATOR;
114 }
115
116 /***
117 * isRegexp - get regexp flag for interpreting option
118 *
119 * @return regexp flag
120 */
121 public boolean isRegexp()
122 {
123 return true;
124 }
125 });
126 menuElements.add(new StandardMenuIncludeDefinitionImpl()
127 {
128 /***
129 * getName - get menu name to nest or with options to include
130 *
131 * @return menu name
132 */
133 public String getName()
134 {
135 return SiteView.CUSTOM_PAGE_NAVIGATIONS_MENU_NAME;
136 }
137 });
138 menuElements.add(new StandardMenuSeparatorDefinitionImpl()
139 {
140 /***
141 * getText - get default text for separator
142 *
143 * @return text
144 */
145 public String getText()
146 {
147
148 return getMenuSeparatorText(null, "menu.separator.links");
149 }
150
151 /***
152 * getText - get locale specific text for separator from metadata
153 *
154 * @param locale preferred locale
155 * @return text
156 */
157 public String getText(Locale locale)
158 {
159
160 return getMenuSeparatorText(locale, "menu.separator.links");
161 }
162 });
163 menuElements.add(new StandardMenuOptionsDefinitionImpl()
164 {
165 /***
166 * getOptions - get comma separated menu options
167 *
168 * @return option paths specification
169 */
170 public String getOptions()
171 {
172 return Folder.PATH_SEPARATOR + "*" + Link.DOCUMENT_TYPE;
173 }
174
175 /***
176 * isRegexp - get regexp flag for interpreting option
177 *
178 * @return regexp flag
179 */
180 public boolean isRegexp()
181 {
182 return true;
183 }
184 });
185 }
186 return menuElements;
187 }
188
189 /***
190 * getSkin - get skin name for menu element
191 *
192 * @return skin name
193 */
194 public String getSkin()
195 {
196 return "left-navigations";
197 }
198
199 /***
200 * getMenuSeparatorText - lookup resource bundle based on locale
201 * and use to extract menu separator text
202 *
203 * @param locale preferred locale
204 * @param key message key for text
205 */
206 protected String getMenuSeparatorText(Locale locale, String key)
207 {
208 try
209 {
210
211 ResourceBundle bundle = null;
212 if (locale != null)
213 {
214 bundle = ResourceBundle.getBundle("org.apache.jetspeed.portalsite.menu.resources.MenuSeparators",locale);
215 }
216 else
217 {
218 bundle = ResourceBundle.getBundle("org.apache.jetspeed.portalsite.menu.resources.MenuSeparators");
219 }
220
221
222 return bundle.getString(key);
223 }
224 catch (MissingResourceException mre)
225 {
226 }
227 return null;
228 }
229 }