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.impl;
018:
019: import java.util.Locale;
020:
021: import org.apache.jetspeed.util.JetspeedLocale;
022: import org.apache.jetspeed.om.common.MutableDisplayName;
023:
024: /**
025: * DisplayNameImpl
026: *
027: * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
028: * @version $Id: DisplayNameImpl.java 516448 2007-03-09 16:25:47Z ate $
029: *
030: */
031: public abstract class DisplayNameImpl implements MutableDisplayName {
032: private String displayName;
033: private Locale locale;
034: /**
035: * Tells OJB which class to use to materialize.
036: */
037: protected String ojbConcreteClass = DisplayNameImpl.class.getName();
038:
039: protected long parentId;
040:
041: protected long id;
042:
043: public DisplayNameImpl() {
044: super ();
045: // always init to default locale
046: locale = JetspeedLocale.getDefaultLocale();
047: }
048:
049: /**
050: *
051: * @param locale Locale of this DisaplyName.
052: * @param name The actual text of the display name.
053: */
054: public DisplayNameImpl(Locale locale, String name) {
055: this ();
056: this .locale = locale;
057: this .displayName = name;
058: }
059:
060: /**
061: * @see org.apache.pluto.om.common.DisplayName#getDisplayName()
062: */
063: public String getDisplayName() {
064: return displayName;
065: }
066:
067: /**
068: * @see org.apache.pluto.om.common.DisplayName#getLocale()
069: */
070: public Locale getLocale() {
071: return locale;
072: }
073:
074: /**
075: * @see org.apache.jetspeed.om.common.MutableDisplayName#setDisplayName(java.lang.String)
076: */
077: public void setDisplayName(String displayName) {
078: this .displayName = displayName;
079: }
080:
081: /**
082: * @see org.apache.jetspeed.om.common.MutableDisplayName#setLocale(java.util.Locale)
083: */
084: public void setLocale(Locale locale) {
085: this .locale = locale;
086: }
087:
088: public void setLanguage(String lang) {
089: String[] localeArray = lang.split("[-|_]");
090: String country = "";
091: String variant = "";
092: for (int i = 0; i < localeArray.length; i++) {
093: if (i == 0) {
094: lang = localeArray[i];
095: } else if (i == 1) {
096: country = localeArray[i];
097: } else if (i == 2) {
098: variant = localeArray[i];
099: }
100: }
101: this .locale = new Locale(lang, country, variant);
102: }
103:
104: }
|