01: /*
02: * ============================================================================
03: * GNU Lesser General Public License
04: * ============================================================================
05: *
06: * JasperReports - Free Java report-generating library.
07: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
08: *
09: * This library is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Lesser General Public
11: * License as published by the Free Software Foundation; either
12: * version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * Lesser General Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser General Public
20: * License along with this library; if not, write to the Free Software
21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22: *
23: * JasperSoft Corporation
24: * 303 Second Street, Suite 450 North
25: * San Francisco, CA 94107
26: * http://www.jaspersoft.com
27: */
28: package net.sf.jasperreports.engine.util;
29:
30: import java.util.Locale;
31: import java.util.TimeZone;
32:
33: /**
34: * @author Lucian Chirita (lucianc@users.sourceforge.net)
35: * @version $Id: JRDataUtils.java 1489 2006-11-14 20:38:10Z teodord $
36: */
37: public class JRDataUtils {
38:
39: public static String getLocaleCode(Locale locale) {
40: return locale.toString();
41: }
42:
43: public static Locale getLocale(String code) {
44: String language;
45: String country;
46: String variant;
47:
48: int firstSep = code.indexOf('_');
49: if (firstSep < 0) {
50: language = code;
51: country = variant = "";
52: } else {
53: language = code.substring(0, firstSep);
54:
55: int secondSep = code.indexOf('_', firstSep + 1);
56: if (secondSep < 0) {
57: country = code.substring(firstSep + 1);
58: variant = "";
59: } else {
60: country = code.substring(firstSep + 1, secondSep);
61: variant = code.substring(secondSep + 1);
62: }
63: }
64:
65: return new Locale(language, country, variant);
66: }
67:
68: public static String getTimeZoneId(TimeZone tz) {
69: return tz.getID();
70: }
71:
72: public static TimeZone getTimeZone(String id) {
73: return TimeZone.getTimeZone(id);
74: }
75:
76: }
|