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.portalsite.impl;
018:
019: import java.util.Locale;
020:
021: import org.apache.jetspeed.om.common.GenericMetadata;
022: import org.apache.jetspeed.om.folder.MenuSeparatorDefinition;
023: import org.apache.jetspeed.portalsite.MenuSeparator;
024:
025: /**
026: * This class implements the portal-site menu separator
027: * elements constructed and returned to decorators.
028: *
029: * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
030: * @version $Id: MenuSeparatorImpl.java 516448 2007-03-09 16:25:47Z ate $
031: */
032: public class MenuSeparatorImpl extends MenuElementImpl implements
033: MenuSeparator, Cloneable {
034: /**
035: * definition - menu separator definition
036: */
037: private MenuSeparatorDefinition definition;
038:
039: /**
040: * MenuSeparatorImpl - constructor
041: *
042: * @param parent containing menu implementation
043: * @param definition menu separator definition
044: */
045: public MenuSeparatorImpl(MenuImpl parent,
046: MenuSeparatorDefinition definition) {
047: super (parent);
048: this .definition = definition;
049: }
050:
051: /**
052: * getElementType - get type of menu element
053: *
054: * @return SEPARATOR_ELEMENT_TYPE
055: */
056: public String getElementType() {
057: return SEPARATOR_ELEMENT_TYPE;
058: }
059:
060: /**
061: * getTitle - get default title for menu element
062: *
063: * @return title text
064: */
065: public String getTitle() {
066: // return definition title
067: String title = definition.getTitle();
068: if (title != null) {
069: return title;
070: }
071:
072: // return node or default title
073: return super .getTitle();
074: }
075:
076: /**
077: * getText - get default text for menu separator
078: *
079: * @return text
080: */
081: public String getText() {
082: // return definition text
083: return definition.getText();
084: }
085:
086: /**
087: * getTitle - get locale specific title for menu element
088: * from metadata
089: *
090: * @param locale preferred locale
091: * @return title text
092: */
093: public String getTitle(Locale locale) {
094: // return definition short title for preferred locale
095: String title = definition.getTitle(locale);
096: if (title != null) {
097: return title;
098: }
099:
100: // return node or default title for preferred locale
101: return super .getTitle(locale);
102: }
103:
104: /**
105: * getText - get locale specific text for menu separator
106: * from metadata
107: *
108: * @param locale preferred locale
109: * @return text
110: */
111: public String getText(Locale locale) {
112: // return definition text
113: return definition.getText(locale);
114: }
115:
116: /**
117: * getMetadata - get generic metadata for menu element
118: *
119: * @return metadata
120: */
121: public GenericMetadata getMetadata() {
122: // return definition metadata
123: GenericMetadata metadata = definition.getMetadata();
124: if ((metadata != null) && (metadata.getFields() != null)
125: && !metadata.getFields().isEmpty()) {
126: return metadata;
127: }
128:
129: // return node metadata
130: return super .getMetadata();
131: }
132:
133: /**
134: * getSkin - get skin name for menu element
135: *
136: * @return skin name
137: */
138: public String getSkin() {
139: // get skin from definition or inherit from parent menu
140: String skin = definition.getSkin();
141: if (skin == null) {
142: skin = super.getSkin();
143: }
144: return skin;
145: }
146: }
|