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.om.folder.impl;
18  
19  import java.util.Collection;
20  import java.util.Locale;
21  
22  import org.apache.jetspeed.om.common.GenericMetadata;
23  import org.apache.jetspeed.om.page.PageMetadataImpl;
24  import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
25  
26  /***
27   * BaseMenuDefinitionMetadata
28   * 
29   * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
30   * @version $Id:$
31   */
32  public abstract class BaseMenuDefinitionMetadata extends BaseMenuDefinitionElement 
33  {
34      private Collection metadataFields;
35  
36      private PageMetadataImpl pageMetadata;
37  
38      /***
39       * newPageMetadata
40       *
41       * Construct page manager specific metadata implementation.
42       *
43       * @param fields mutable fields collection
44       * @return page metadata
45       */
46      public abstract PageMetadataImpl newPageMetadata(Collection fields);
47  
48      /***
49       * getPageMetadata
50       *
51       * Get page manager specific metadata implementation.
52       *
53       * @return page metadata
54       */
55      public PageMetadataImpl getPageMetadata()
56      {
57          if (pageMetadata == null)
58          {
59              if (metadataFields == null)
60              {
61                  metadataFields = DatabasePageManagerUtils.createCollection();
62              }
63              pageMetadata = newPageMetadata(metadataFields);
64          }
65          return pageMetadata;
66      }
67  
68      /* (non-Javadoc)
69       * @see org.apache.jetspeed.om.folder.MenuDefinition#getTitle()
70       * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getTitle()
71       */
72      public String getTitle()
73      {
74          // no title available by default
75          return null;
76      }
77  
78      /* (non-Javadoc)
79       * @see org.apache.jetspeed.om.folder.MenuDefinition#getShortTitle()
80       */
81      public String getShortTitle()
82      {
83          // no short title available by default
84          return null;
85      }
86  
87      /* (non-Javadoc)
88       * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getText()
89       */
90      public String getText()
91      {
92          // no text available by default
93          return null;
94      }
95  
96      /* (non-Javadoc)
97       * @see org.apache.jetspeed.om.folder.MenuDefinition#getTitle(java.util.Locale)
98       * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getTitle(java.util.Locale)
99       */
100     public String getTitle(Locale locale)
101     {
102         // get title from metadata or use default title
103         String title = getPageMetadata().getText("title", locale);
104         if (title == null)
105         {
106             title = getTitle();
107         }
108         return title;
109     }
110 
111     /* (non-Javadoc)
112      * @see org.apache.jetspeed.om.folder.MenuDefinition#getShortTitle(java.util.Locale)
113      */
114     public String getShortTitle(Locale locale)
115     {
116         // get short title from metadata or use title from metadata,
117         // default short title, or default title
118         String shortTitle = getPageMetadata().getText("short-title", locale);
119         if (shortTitle == null)
120         {
121             shortTitle = getPageMetadata().getText("title", locale);
122             if (shortTitle == null)
123             {
124                 shortTitle = getShortTitle();
125                 if (shortTitle == null)
126                 {
127                     shortTitle = getTitle();
128                 }
129             }
130         }
131         return shortTitle;
132     }
133 
134     /* (non-Javadoc)
135      * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getText(java.util.Locale)
136      */
137     public String getText(Locale locale)
138     {
139         // get title from metadata or use default title
140         String text = getPageMetadata().getText("text", locale);
141         if (text == null)
142         {
143             text = getText();
144         }
145         return text;
146     }
147 
148     /* (non-Javadoc)
149      * @see org.apache.jetspeed.om.folder.MenuDefinition#getMetadata()
150      * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getMetadata()
151      */
152     public GenericMetadata getMetadata()
153     {
154         return getPageMetadata();
155     }
156 }