File Source: I18nUtils.java
/*
P/P * Method: org.apache.roller.weblogger.util.I18nUtils__static_init
*/
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.util;
20
21 import java.util.Locale;
22 import org.apache.commons.lang.StringUtils;
23
24
25 /**
26 * A utility class for dealing with i18n.
27 */
/*
P/P * Method: void org.apache.roller.weblogger.util.I18nUtils()
*/
28 public final class I18nUtils {
29
30 public static final Locale toLocale(String locale) {
/*
P/P * Method: Locale toLocale(String)
*
* Presumptions:
* org.apache.commons.lang.StringUtils:split(...)@32 != null
*
* Postconditions:
* init'ed(return_value)
* new Locale(toLocale#1) num objects <= 1
* new Locale(toLocale#2) num objects <= 1
* new Locale(toLocale#3) num objects <= 1
*
* Test Vectors:
* locale: Addr_Set{null}, Inverse{null}
* localeStr.length@32: {0, 4..+Inf}, {1}, {2}, {3}
*/
31 if (locale != null) {
32 String[] localeStr = StringUtils.split(locale,"_");
33 if (localeStr.length == 1) {
+ 34 if (localeStr[0] == null) localeStr[0] = "";
35 return new Locale(localeStr[0]);
36 } else if (localeStr.length == 2) {
+ 37 if (localeStr[0] == null) localeStr[0] = "";
+ 38 if (localeStr[1] == null) localeStr[1] = "";
39 return new Locale(localeStr[0], localeStr[1]);
40 } else if (localeStr.length == 3) {
+ 41 if (localeStr[0] == null) localeStr[0] = "";
+ 42 if (localeStr[1] == null) localeStr[1] = "";
+ 43 if (localeStr[2] == null) localeStr[2] = "";
44 return new Locale(localeStr[0], localeStr[1], localeStr[2]);
45 }
46 }
47 return Locale.getDefault();
48 }
49
50 }
SofCheck Inspector Build Version : 2.18479
| I18nUtils.java |
2009-Jan-02 14:24:44 |
| I18nUtils.class |
2009-Sep-04 03:12:32 |