1 /*
2 * $Id$
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21 package org.apache.tiles.request.locale;
22
23 import java.util.Locale;
24
25 /**
26 * Utilities for locale manipulation.
27 *
28 * @version $Rev$ $Date$
29 */
30 public final class LocaleUtil {
31
32 /**
33 * The "null" Locale, i.e. a Locale that points to no real locale.
34 *
35 * @deprecated use Locale.ROOT instead.
36 */
37 @Deprecated
38 public static final Locale NULL_LOCALE = Locale.ROOT;
39
40 /**
41 * Private constructor to avoid instantiation.
42 */
43 private LocaleUtil() {
44 }
45
46 /**
47 * <p>
48 * Returns the "parent" locale of a given locale.
49 * </p>
50 * <p>
51 * If the original locale is only language-based, the {@link #NULL_LOCALE}
52 * object is returned.
53 * </p>
54 * <p>
55 * If the original locale is {@link #NULL_LOCALE}, then <code>null</code>
56 * is returned.
57 * </p>
58 *
59 * @param locale The original locale.
60 * @return The parent locale.
61 */
62 public static Locale getParentLocale(Locale locale) {
63 Locale retValue = null;
64 String language = locale.getLanguage();
65 String country = locale.getCountry();
66 String variant = locale.getVariant();
67 if (!"".equals(variant)) {
68 retValue = new Locale(language, country);
69 } else if (!"".equals(country)) {
70 retValue = new Locale(language);
71 } else if (!"".equals(language)) {
72 retValue = Locale.ROOT;
73 }
74
75 return retValue;
76 }
77 }