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.om.folder.impl;
018:
019: import java.util.Collection;
020: import java.util.Locale;
021:
022: import org.apache.jetspeed.om.common.GenericMetadata;
023: import org.apache.jetspeed.om.page.PageMetadataImpl;
024: import org.apache.jetspeed.page.impl.DatabasePageManagerUtils;
025:
026: /**
027: * BaseMenuDefinitionMetadata
028: *
029: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
030: * @version $Id:$
031: */
032: public abstract class BaseMenuDefinitionMetadata extends
033: BaseMenuDefinitionElement {
034: private Collection metadataFields;
035:
036: private PageMetadataImpl pageMetadata;
037:
038: /**
039: * newPageMetadata
040: *
041: * Construct page manager specific metadata implementation.
042: *
043: * @param fields mutable fields collection
044: * @return page metadata
045: */
046: public abstract PageMetadataImpl newPageMetadata(Collection fields);
047:
048: /**
049: * getPageMetadata
050: *
051: * Get page manager specific metadata implementation.
052: *
053: * @return page metadata
054: */
055: public PageMetadataImpl getPageMetadata() {
056: if (pageMetadata == null) {
057: if (metadataFields == null) {
058: metadataFields = DatabasePageManagerUtils
059: .createCollection();
060: }
061: pageMetadata = newPageMetadata(metadataFields);
062: }
063: return pageMetadata;
064: }
065:
066: /* (non-Javadoc)
067: * @see org.apache.jetspeed.om.folder.MenuDefinition#getTitle()
068: * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getTitle()
069: */
070: public String getTitle() {
071: // no title available by default
072: return null;
073: }
074:
075: /* (non-Javadoc)
076: * @see org.apache.jetspeed.om.folder.MenuDefinition#getShortTitle()
077: */
078: public String getShortTitle() {
079: // no short title available by default
080: return null;
081: }
082:
083: /* (non-Javadoc)
084: * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getText()
085: */
086: public String getText() {
087: // no text available by default
088: return null;
089: }
090:
091: /* (non-Javadoc)
092: * @see org.apache.jetspeed.om.folder.MenuDefinition#getTitle(java.util.Locale)
093: * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getTitle(java.util.Locale)
094: */
095: public String getTitle(Locale locale) {
096: // get title from metadata or use default title
097: String title = getPageMetadata().getText("title", locale);
098: if (title == null) {
099: title = getTitle();
100: }
101: return title;
102: }
103:
104: /* (non-Javadoc)
105: * @see org.apache.jetspeed.om.folder.MenuDefinition#getShortTitle(java.util.Locale)
106: */
107: public String getShortTitle(Locale locale) {
108: // get short title from metadata or use title from metadata,
109: // default short title, or default title
110: String shortTitle = getPageMetadata().getText("short-title",
111: locale);
112: if (shortTitle == null) {
113: shortTitle = getPageMetadata().getText("title", locale);
114: if (shortTitle == null) {
115: shortTitle = getShortTitle();
116: if (shortTitle == null) {
117: shortTitle = getTitle();
118: }
119: }
120: }
121: return shortTitle;
122: }
123:
124: /* (non-Javadoc)
125: * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getText(java.util.Locale)
126: */
127: public String getText(Locale locale) {
128: // get title from metadata or use default title
129: String text = getPageMetadata().getText("text", locale);
130: if (text == null) {
131: text = getText();
132: }
133: return text;
134: }
135:
136: /* (non-Javadoc)
137: * @see org.apache.jetspeed.om.folder.MenuDefinition#getMetadata()
138: * @see org.apache.jetspeed.om.folder.MenuSeparatorDefinition#getMetadata()
139: */
140: public GenericMetadata getMetadata() {
141: return getPageMetadata();
142: }
143: }
|