Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
LocaleUtil |
|
| 2.5;2.5 |
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 | 1 | public static final Locale NULL_LOCALE = Locale.ROOT; |
39 | ||
40 | /** | |
41 | * Private constructor to avoid instantiation. | |
42 | */ | |
43 | 0 | private LocaleUtil() { |
44 | 0 | } |
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 | 4 | Locale retValue = null; |
64 | 4 | String language = locale.getLanguage(); |
65 | 4 | String country = locale.getCountry(); |
66 | 4 | String variant = locale.getVariant(); |
67 | 4 | if (!"".equals(variant)) { |
68 | 1 | retValue = new Locale(language, country); |
69 | 3 | } else if (!"".equals(country)) { |
70 | 1 | retValue = new Locale(language); |
71 | 2 | } else if (!"".equals(language)) { |
72 | 1 | retValue = Locale.ROOT; |
73 | } | |
74 | ||
75 | 4 | return retValue; |
76 | } | |
77 | } |