001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.portalsite.menu;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021: import java.util.Locale;
022: import java.util.MissingResourceException;
023: import java.util.ResourceBundle;
024:
025: import org.apache.jetspeed.om.folder.Folder;
026: import org.apache.jetspeed.om.folder.impl.StandardMenuDefinitionImpl;
027: import org.apache.jetspeed.om.folder.impl.StandardMenuIncludeDefinitionImpl;
028: import org.apache.jetspeed.om.folder.impl.StandardMenuOptionsDefinitionImpl;
029: import org.apache.jetspeed.om.folder.impl.StandardMenuSeparatorDefinitionImpl;
030: import org.apache.jetspeed.om.page.Link;
031: import org.apache.jetspeed.portalsite.view.SiteView;
032:
033: /**
034: * This class provides a menu definition for the standard
035: * navigations menu.
036: *
037: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
038: * @version $Id: StandardNavigationsMenuDefinition.java 568811 2007-08-23 03:00:37Z woonsan $
039: */
040: public class StandardNavigationsMenuDefinition extends
041: StandardMenuDefinitionImpl {
042: /**
043: * menuElements - ordered polymorphic list of menu option, nested
044: * menu, separator, include, and exclude definitions
045: */
046: private List menuElements;
047:
048: /**
049: * StandardNavigationsMenuDefinition - constructor
050: */
051: public StandardNavigationsMenuDefinition() {
052: super ();
053: }
054:
055: /**
056: * getName - get menu name
057: *
058: * @return menu name
059: */
060: public String getName() {
061: return SiteView.STANDARD_NAVIGATIONS_MENU_NAME;
062: }
063:
064: /**
065: * getMenuElements - get ordered list of menu options,
066: * nested menus, separators, included
067: * menu, and excluded menu elements
068: *
069: * @return element list
070: */
071: public synchronized List getMenuElements() {
072: // instantiate menu elements if necessary
073: if (menuElements == null) {
074: menuElements = new ArrayList(4);
075: menuElements.add(new StandardMenuSeparatorDefinitionImpl() {
076: /**
077: * getText - get default text for separator
078: *
079: * @return text
080: */
081: public String getText() {
082: // use locale defaults
083: return getMenuSeparatorText(null,
084: "menu.separator.folders");
085: }
086:
087: /**
088: * getText - get locale specific text for separator from metadata
089: *
090: * @param locale preferred locale
091: * @return text
092: */
093: public String getText(Locale locale) {
094: // use specified locale
095: return getMenuSeparatorText(locale,
096: "menu.separator.folders");
097: }
098: });
099: menuElements.add(new StandardMenuOptionsDefinitionImpl() {
100: /**
101: * getOptions - get comma separated menu options
102: *
103: * @return option paths specification
104: */
105: public String getOptions() {
106: return "." + Folder.PATH_SEPARATOR + "*"
107: + Folder.PATH_SEPARATOR;
108: }
109:
110: /**
111: * isRegexp - get regexp flag for interpreting option
112: *
113: * @return regexp flag
114: */
115: public boolean isRegexp() {
116: return true;
117: }
118: });
119: menuElements.add(new StandardMenuIncludeDefinitionImpl() {
120: /**
121: * getName - get menu name to nest or with options to include
122: *
123: * @return menu name
124: */
125: public String getName() {
126: return SiteView.CUSTOM_PAGE_NAVIGATIONS_MENU_NAME;
127: }
128: });
129: menuElements.add(new StandardMenuSeparatorDefinitionImpl() {
130: /**
131: * getText - get default text for separator
132: *
133: * @return text
134: */
135: public String getText() {
136: // use locale defaults
137: return getMenuSeparatorText(null,
138: "menu.separator.links");
139: }
140:
141: /**
142: * getText - get locale specific text for separator from metadata
143: *
144: * @param locale preferred locale
145: * @return text
146: */
147: public String getText(Locale locale) {
148: // use specified locale
149: return getMenuSeparatorText(locale,
150: "menu.separator.links");
151: }
152: });
153: menuElements.add(new StandardMenuOptionsDefinitionImpl() {
154: /**
155: * getOptions - get comma separated menu options
156: *
157: * @return option paths specification
158: */
159: public String getOptions() {
160: return Folder.PATH_SEPARATOR + "*"
161: + Link.DOCUMENT_TYPE;
162: }
163:
164: /**
165: * isRegexp - get regexp flag for interpreting option
166: *
167: * @return regexp flag
168: */
169: public boolean isRegexp() {
170: return true;
171: }
172: });
173: }
174: return menuElements;
175: }
176:
177: /**
178: * getSkin - get skin name for menu element
179: *
180: * @return skin name
181: */
182: public String getSkin() {
183: return "left-navigations";
184: }
185:
186: /**
187: * getMenuSeparatorText - lookup resource bundle based on locale
188: * and use to extract menu separator text
189: *
190: * @param locale preferred locale
191: * @param key message key for text
192: */
193: protected String getMenuSeparatorText(Locale locale, String key) {
194: try {
195: // get resource bundle
196: ResourceBundle bundle = null;
197: if (locale != null) {
198: bundle = ResourceBundle
199: .getBundle(
200: "org.apache.jetspeed.portalsite.menu.resources.MenuSeparators",
201: locale);
202: } else {
203: bundle = ResourceBundle
204: .getBundle("org.apache.jetspeed.portalsite.menu.resources.MenuSeparators");
205: }
206:
207: // lookup and return keyed message
208: return bundle.getString(key);
209: } catch (MissingResourceException mre) {
210: }
211: return null;
212: }
213: }
|