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.impl;
18  
19  import java.util.Locale;
20  
21  import org.apache.jetspeed.util.JetspeedLocale;
22  import org.apache.jetspeed.om.common.MutableDisplayName;
23  
24  /***
25   * DisplayNameImpl
26   * 
27   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
28   * @version $Id: DisplayNameImpl.java 516448 2007-03-09 16:25:47Z ate $
29   *
30   */
31  public abstract class DisplayNameImpl implements MutableDisplayName
32  {
33      private String displayName;
34      private Locale locale;
35  	/***
36  	* Tells OJB which class to use to materialize.  
37  	*/
38  	protected String ojbConcreteClass = DisplayNameImpl.class.getName();
39  	
40  	protected long parentId;
41      
42  	protected long id;
43      
44   
45      public DisplayNameImpl()
46      {
47          super();
48          // always init to default locale
49          locale = JetspeedLocale.getDefaultLocale();
50      }
51  
52      /***
53       * 
54       * @param locale Locale of this DisaplyName.
55       * @param name The actual text of the display name.
56       */
57      public DisplayNameImpl(Locale locale, String name)
58      {
59          this();
60          this.locale = locale;
61          this.displayName = name;        
62      }
63  
64      /***
65       * @see org.apache.pluto.om.common.DisplayName#getDisplayName()
66       */
67      public String getDisplayName()
68      {
69          return displayName;
70      }
71  
72      /***
73       * @see org.apache.pluto.om.common.DisplayName#getLocale()
74       */
75      public Locale getLocale()
76      {
77          return locale;
78      }
79  
80      /***
81       * @see org.apache.jetspeed.om.common.MutableDisplayName#setDisplayName(java.lang.String)
82       */
83      public void setDisplayName(String displayName)
84      {
85          this.displayName = displayName;
86      }
87  
88      /***
89       * @see org.apache.jetspeed.om.common.MutableDisplayName#setLocale(java.util.Locale)
90       */
91      public void setLocale(Locale locale)
92      {
93          this.locale = locale;
94      }
95  
96      public void setLanguage(String lang)
97      {
98          String[] localeArray = lang.split("[-|_]");
99          String country = "";
100         String variant = "";
101         for (int i = 0; i < localeArray.length; i++)
102         {
103             if (i == 0)
104             {
105                 lang = localeArray[i];
106             }
107             else if (i == 1)
108             {
109                 country = localeArray[i];
110             }
111             else if (i == 2)
112             {
113                 variant = localeArray[i];
114             }
115         }
116         this.locale = new Locale(lang, country, variant);
117     }
118 
119 }