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.impl;
18  
19  import java.util.Locale;
20  
21  import org.apache.jetspeed.om.common.GenericMetadata;
22  import org.apache.jetspeed.om.folder.MenuSeparatorDefinition;
23  import org.apache.jetspeed.portalsite.MenuSeparator;
24  
25  /***
26   * This class implements the portal-site menu separator
27   * elements constructed and returned to decorators.
28   * 
29   * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
30   * @version $Id: MenuSeparatorImpl.java 516448 2007-03-09 16:25:47Z ate $
31   */
32  public class MenuSeparatorImpl extends MenuElementImpl implements MenuSeparator, Cloneable
33  {
34      /***
35       * definition - menu separator definition
36       */
37      private MenuSeparatorDefinition definition;
38  
39      /***
40       * MenuSeparatorImpl - constructor
41       *
42       * @param parent containing menu implementation
43       * @param definition menu separator definition
44       */
45      public MenuSeparatorImpl(MenuImpl parent, MenuSeparatorDefinition definition)
46      {
47          super(parent);
48          this.definition = definition;
49      }
50  
51      /***
52       * getElementType - get type of menu element
53       *
54       * @return SEPARATOR_ELEMENT_TYPE
55       */
56      public String getElementType()
57      {
58          return SEPARATOR_ELEMENT_TYPE;
59      }
60  
61      /***
62       * getTitle - get default title for menu element
63       *
64       * @return title text
65       */
66      public String getTitle()
67      {
68          // return definition title
69          String title = definition.getTitle();
70          if (title != null)
71          {
72              return title;
73          }
74  
75          // return node or default title
76          return super.getTitle();
77      }
78  
79      /***
80       * getText - get default text for menu separator
81       *
82       * @return text
83       */
84      public String getText()
85      {
86          // return definition text
87          return definition.getText();
88      }
89  
90      /***
91       * getTitle - get locale specific title for menu element
92       *            from metadata
93       *
94       * @param locale preferred locale
95       * @return title text
96       */
97      public String getTitle(Locale locale)
98      {
99          // return definition short title for preferred locale
100         String title = definition.getTitle(locale);
101         if (title != null)
102         {
103             return title;
104         }
105 
106         // return node or default title for preferred locale
107         return super.getTitle(locale);
108     }
109 
110     /***
111      * getText - get locale specific text for menu separator
112      *           from metadata
113      *
114      * @param locale preferred locale
115      * @return text
116      */
117     public String getText(Locale locale)
118     {
119         // return definition text
120         return definition.getText(locale);
121     }
122 
123     /***
124      * getMetadata - get generic metadata for menu element
125      *
126      * @return metadata
127      */    
128     public GenericMetadata getMetadata()
129     {
130         // return definition metadata
131         GenericMetadata metadata = definition.getMetadata();
132         if ((metadata != null) && (metadata.getFields() != null) && !metadata.getFields().isEmpty())
133         {
134             return metadata;
135         }
136 
137         // return node metadata
138         return super.getMetadata();
139     }
140 
141     /***
142      * getSkin - get skin name for menu element
143      *
144      * @return skin name
145      */
146     public String getSkin()
147     {
148         // get skin from definition or inherit from parent menu
149         String skin = definition.getSkin();
150         if (skin == null)
151         {
152             skin = super.getSkin();
153         }
154         return skin;
155     }
156 }