01: /*
02:
03: Derby - Class org.apache.derbyTesting.functionTests.tests.i18n.DefaultLocale
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: 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, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derbyTesting.functionTests.tests.i18n;
23:
24: import java.util.Locale;
25:
26: import java.security.AccessController;
27: import java.security.PrivilegedAction;
28: import java.sql.DriverManager;
29: import java.sql.Connection;
30: import java.sql.SQLException;
31:
32: public class DefaultLocale {
33:
34: static String savedLocale;
35:
36: static {
37: savedLocale = java.util.Locale.getDefault().toString();
38: setDefaultLocale("rr", "TT");
39: }
40:
41: // used in messageLocale test
42: public static void checkDefaultLocale() throws SQLException {
43: String defLocale = java.util.Locale.getDefault().toString();
44: //System.out.println(defLocale);
45: if (!defLocale.equals("rr_TT"))
46: throw new SQLException("wrong_locale");
47: }
48:
49: // used in urlLocale test
50: public static void checkRDefaultLocale() throws SQLException {
51: String dbLocale = org.apache.derby.iapi.db.Factory
52: .getDatabaseOfConnection().getLocale().toString();
53: //System.out.println(savedLocale);
54: //System.out.println(dbLocale);
55: if (!savedLocale.equals(dbLocale))
56: throw new SQLException("wrong_locale");
57: }
58:
59: // used in urlLocale test and messageLocale test
60: public static void checkDatabaseLocale(String Locale)
61: throws SQLException {
62: String dbLocale = org.apache.derby.iapi.db.Factory
63: .getDatabaseOfConnection().getLocale().toString();
64: //System.out.println(dbLocale + "-");
65: //System.out.println(Locale + "-");
66: if (!dbLocale.toUpperCase().equals(Locale.toUpperCase().trim()))
67: throw new SQLException("wrong locale");
68: }
69:
70: // used in messageLocale test
71: public static void setDefaultLocale(final String Locale,
72: final String Code) {
73: // needs to run in a privileged block as it will be
74: // called through a SQL statement and thus a generated
75: // class. The generated class on the stack has no permissions
76: // granted to it. Needs write permission on user.language
77: AccessController.doPrivileged(new PrivilegedAction() {
78: public Object run() {
79: java.util.Locale.setDefault(new java.util.Locale(Locale
80: .trim(), Code.trim()));
81: return null; // nothing to return
82: }
83: });
84:
85: }
86:
87: }
|