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.psml;
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:
025: /**
026: * This class implements metadata protocols for menu
027: * definition implementations.
028: *
029: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
030: * @version $Id: MenuMetadataImpl.java 516448 2007-03-09 16:25:47Z ate $
031: */
032: public abstract class MenuMetadataImpl {
033: /**
034: * metadata - page metadata to hold title information
035: */
036: private PageMetadataImpl metadata;
037:
038: /**
039: * MenuDefinitionImpl - constructor
040: */
041: public MenuMetadataImpl() {
042: }
043:
044: /**
045: * getTitle - get default title protocol stub
046: *
047: * @return null
048: */
049: public String getTitle() {
050: return null;
051: }
052:
053: /**
054: * getShortTitle - get default short title protocol stub
055: *
056: * @return short title text
057: */
058: public String getShortTitle() {
059: return null;
060: }
061:
062: /**
063: * getText - get default text protocol stub
064: *
065: * @return text
066: */
067: public String getText() {
068: return null;
069: }
070:
071: /**
072: * getTitle - get locale specific title from metadata
073: *
074: * @param locale preferred locale
075: * @return title text
076: */
077: public String getTitle(Locale locale) {
078: // get title from metadata or use default title
079: String title = getPageMetadata().getText("title", locale);
080: if (title == null) {
081: title = getTitle();
082: }
083: return title;
084: }
085:
086: /**
087: * getShortTitle - get locale specific short title from metadata
088: *
089: * @param locale preferred locale
090: * @return short title text
091: */
092: public String getShortTitle(Locale locale) {
093: // get short title from metadata or use title from metadata,
094: // default short title, or default title
095: String shortTitle = getPageMetadata().getText("short-title",
096: locale);
097: if (shortTitle == null) {
098: shortTitle = getPageMetadata().getText("title", locale);
099: if (shortTitle == null) {
100: shortTitle = getShortTitle();
101: if (shortTitle == null) {
102: shortTitle = getTitle();
103: }
104: }
105: }
106: return shortTitle;
107: }
108:
109: /**
110: * getText - get locale specific text from metadata
111: *
112: * @param locale preferred locale
113: * @return text
114: */
115: public String getText(Locale locale) {
116: // get title from metadata or use default title
117: String text = getPageMetadata().getText("text", locale);
118: if (text == null) {
119: text = getText();
120: }
121: return text;
122: }
123:
124: /**
125: * getMetadata - get generic metadata instance
126: *
127: * @return metadata instance
128: */
129: public GenericMetadata getMetadata() {
130: return getPageMetadata();
131: }
132:
133: /**
134: * getMetadataFields - get metadata fields collection
135: *
136: * @return metadata fields collection
137: */
138: public Collection getMetadataFields() {
139: // return metadata fields collection that
140: // may in fact be side effected on unmarshall
141: return getPageMetadata().getFields();
142: }
143:
144: /**
145: * setMetadataFields - set metadata fields collection
146: *
147: * @param metadataFields metadata fields collection
148: */
149: public void setMetadataFields(Collection metadataFields) {
150: // set metadata fields collection that
151: // may in fact be side effected after
152: // invocation on unmarshall
153: getPageMetadata().setFields(metadataFields);
154: }
155:
156: /**
157: * getPageMetadata - get/construct page metadata instance
158: *
159: * @return metadata instance
160: */
161: private PageMetadataImpl getPageMetadata() {
162: if (metadata == null) {
163: metadata = new PageMetadataImpl();
164: }
165: return metadata;
166: }
167:
168: /**
169: * unmarshalled - notification that this instance has been
170: * loaded from the persistent store
171: */
172: public void unmarshalled() {
173: // force metadata update after unmarshalled since
174: // metadata collection can be side effected by
175: // unmarshalling colection accessors
176: Collection metadataFields = getMetadataFields();
177: if (metadataFields != null) {
178: setMetadataFields(metadataFields);
179: }
180: }
181: }
|