View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
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          // instantiate menu elements if necessary
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                          // use locale defaults
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                         // use specified locale
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                         // use locale defaults
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                         // use specified locale
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             // get resource bundle
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             // lookup and return keyed message
222             return bundle.getString(key);
223         }
224         catch (MissingResourceException mre)
225         {
226         }
227         return null;
228     }
229 }