001: /*
002:
003: Derby - Class org.apache.derbyBuild.splitmessages
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derbyBuild;
023:
024: import java.io.*;
025: import java.util.*;
026:
027: import org.apache.derby.iapi.services.i18n.MessageService;
028: import org.apache.derby.shared.common.reference.SQLState;
029:
030: public class splitmessages {
031: /**
032: arg[0] is the destination directory
033: arg[1] is the source file.
034: */
035:
036: /**
037: * This is the list of message ids that are shared between
038: * the network client and the engine. This is used to generate
039: * a set of 'shared' messages. This avoids us having to maintain
040: * two separate message files.
041: *
042: * NOTE: We already assume all message ids starting with XJ are shared.
043: * This covers 90% of the cases. Only add ids here if you have a
044: * message id that is not in the XJ class.
045: */
046: private static TreeSet clientMessageIds = new TreeSet();
047:
048: /**
049: * Initialize the set of message ids that the network client will use.
050: * <p>
051: * Note that all message ids that start with "XJ" are automatically added,
052: * these are just for message ids that have a different prefix.
053: */
054: static void initClientMessageIds() {
055: // Add message ids that don't start with XJ here
056: clientMessageIds.add(SQLState.NO_CURRENT_CONNECTION);
057: clientMessageIds.add(SQLState.NOT_IMPLEMENTED);
058: clientMessageIds.add(SQLState.CANNOT_CLOSE_ACTIVE_CONNECTION);
059: clientMessageIds
060: .add(SQLState.XACT_SAVEPOINT_RELEASE_ROLLBACK_FAIL);
061: clientMessageIds.add(SQLState.UNSUPPORTED_ENCODING);
062: clientMessageIds.add(SQLState.LANG_FORMAT_EXCEPTION);
063: clientMessageIds.add(SQLState.LANG_DATA_TYPE_GET_MISMATCH);
064: clientMessageIds.add(SQLState.LANG_DATA_TYPE_SET_MISMATCH);
065: clientMessageIds.add(SQLState.LANG_DATE_SYNTAX_EXCEPTION);
066: clientMessageIds
067: .add(SQLState.CHARACTER_CONVERTER_NOT_AVAILABLE);
068: clientMessageIds.add(SQLState.LANG_OUTSIDE_RANGE_FOR_DATATYPE);
069: clientMessageIds.add(SQLState.LANG_STATEMENT_CLOSED_NO_REASON);
070: clientMessageIds.add(SQLState.LANG_INVALID_COLUMN_POSITION);
071: clientMessageIds.add(SQLState.INVALID_COLUMN_NAME);
072: clientMessageIds
073: .add(SQLState.HOLDABLE_RESULT_SET_NOT_AVAILABLE);
074: clientMessageIds
075: .add(SQLState.LANG_RETURN_OUTPUT_PARAM_CANNOT_BE_SET);
076: clientMessageIds.add(SQLState.LANG_NULL_INTO_NON_NULL);
077: clientMessageIds.add(SQLState.JDBC_METHOD_NOT_IMPLEMENTED);
078: clientMessageIds
079: .add(SQLState.JDBC_METHOD_NOT_SUPPORTED_BY_SERVER);
080: clientMessageIds.add(SQLState.DRDA_NO_AUTOCOMMIT_UNDER_XA);
081: clientMessageIds
082: .add(SQLState.DRDA_INVALID_XA_STATE_ON_COMMIT_OR_ROLLBACK);
083: clientMessageIds
084: .add(SQLState.HOLDABLE_RESULT_SET_NOT_AVAILABLE);
085: clientMessageIds.add(SQLState.INVALID_RESULTSET_TYPE);
086: clientMessageIds.add(SQLState.INVALID_RESULTSET_CONCURRENCY);
087: clientMessageIds.add(SQLState.SCROLL_SENSITIVE_NOT_SUPPORTED);
088: clientMessageIds
089: .add(SQLState.INSENSITIVE_UPDATABLE_NOT_SUPPORTED);
090: clientMessageIds
091: .add(SQLState.UNABLE_TO_OBTAIN_MESSAGE_TEXT_FROM_SERVER);
092: clientMessageIds.add(SQLState.NUMBER_OF_ROWS_TOO_LARGE_FOR_INT);
093: clientMessageIds
094: .add(SQLState.NOGETCONN_ON_CLOSED_POOLED_CONNECTION);
095: clientMessageIds.add(SQLState.LOB_METHOD_ON_CLOSED_CONNECTION);
096: clientMessageIds
097: .add(SQLState.QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET);
098: clientMessageIds
099: .add(SQLState.MULTIPLE_RESULTS_ON_EXECUTE_QUERY);
100: clientMessageIds
101: .add(SQLState.USE_EXECUTE_UPDATE_WITH_NO_RESULTS);
102: clientMessageIds
103: .add(SQLState.LANG_INVALID_CALL_TO_EXECUTE_UPDATE);
104: clientMessageIds
105: .add(SQLState.LANG_CANT_INVALIDATE_OPEN_RESULT_SET);
106: clientMessageIds.add(SQLState.YEAR_EXCEEDS_MAXIMUM);
107: clientMessageIds.add(SQLState.LANG_INVALID_PARAM_POSITION);
108: clientMessageIds.add(SQLState.LANG_MISSING_PARMS);
109: clientMessageIds.add(SQLState.LANG_NO_CURRENT_ROW);
110: clientMessageIds.add(SQLState.LANG_STREAM_RETRIEVED_ALREADY);
111: clientMessageIds.add(SQLState.CONNECTION_FAILED_ON_RESET);
112: clientMessageIds.add(SQLState.DECIMAL_TOO_MANY_DIGITS);
113: clientMessageIds.add(SQLState.NUMERIC_OVERFLOW);
114: clientMessageIds.add(SQLState.UNSUPPORTED_HOLDABILITY_PROPERTY);
115: clientMessageIds.add(SQLState.CANCEL_NOT_SUPPORTED_BY_SERVER);
116: clientMessageIds.add(SQLState.LANG_INVALID_CALL_STATEMENT);
117: clientMessageIds.add(SQLState.LOSS_OF_PRECISION_EXCEPTION);
118: clientMessageIds.add(SQLState.LANG_INVALID_SQL_IN_BATCH);
119: clientMessageIds.add(SQLState.CLIENT_RESULT_SET_NOT_OPEN);
120: clientMessageIds.add(SQLState.CANT_CONVERT_UNICODE_TO_EBCDIC);
121: clientMessageIds.add(SQLState.SECMECH_NOT_SUPPORTED);
122: clientMessageIds.add(SQLState.DRDA_COMMAND_NOT_IMPLEMENTED);
123: clientMessageIds.add(SQLState.DATA_TYPE_NOT_SUPPORTED);
124: clientMessageIds.add(SQLState.JDBC_DRIVER_REGISTER);
125: clientMessageIds.add(SQLState.NO_CURRENT_ROW);
126: clientMessageIds.add(SQLState.LANG_IDENTIFIER_TOO_LONG);
127: clientMessageIds.add(SQLState.DRDA_CURSOR_NOT_OPEN);
128: clientMessageIds.add(SQLState.PROPERTY_UNSUPPORTED_CHANGE);
129: clientMessageIds.add(SQLState.NET_INVALID_JDBC_TYPE_FOR_PARAM);
130: clientMessageIds.add(SQLState.UNRECOGNIZED_JAVA_SQL_TYPE);
131: clientMessageIds.add(SQLState.NET_UNRECOGNIZED_JDBC_TYPE);
132: clientMessageIds.add(SQLState.NET_SQLCDTA_INVALID_FOR_RDBCOLID);
133: clientMessageIds.add(SQLState.NET_SQLCDTA_INVALID_FOR_PKGID);
134: clientMessageIds.add(SQLState.NET_PGNAMCSN_INVALID_AT_SQLAM);
135: clientMessageIds.add(SQLState.NET_VCM_VCS_LENGTHS_INVALID);
136: clientMessageIds.add(SQLState.LANG_STRING_TOO_LONG);
137: }
138:
139: public static void main(String[] args) throws Exception {
140:
141: initClientMessageIds();
142:
143: Properties p = new Properties();
144:
145: File dir = new File(args[0]);
146:
147: File source = new File(args[1]);
148: File clientDir = new File(args[2]);
149:
150: String s = source.getName();
151: // loose the suffix
152: s = s.substring(0, s.lastIndexOf('.'));
153: // now get the locale
154: String locale = s.substring(s.indexOf('_'));
155:
156: boolean addBase = "_en".equals(locale);
157:
158: InputStream is = new BufferedInputStream(new FileInputStream(
159: source), 64 * 1024);
160:
161: p.load(is);
162: is.close();
163:
164: Properties[] c = new Properties[50];
165: for (int i = 0; i < 50; i++) {
166: c[i] = new Properties();
167: }
168:
169: Properties clientProps = new Properties();
170:
171: String clientPropsFileName = "clientmessages" + locale
172: + ".properties";
173:
174: for (Enumeration e = p.keys(); e.hasMoreElements();) {
175: String key = (String) e.nextElement();
176:
177: c[MessageService.hashString50(key)].put(key, p
178: .getProperty(key));
179:
180: // If we have a match, add it to the list of client messages
181: if (isClientMessage(key)) {
182: clientProps.put(key, p.getProperty(key));
183: }
184: }
185:
186: for (int i = 0; i < 50; i++) {
187: if (c[i].size() == 0)
188: continue;
189: OutputStream fos = new BufferedOutputStream(
190: new FileOutputStream(new File(dir, "m" + i + locale
191: + ".properties")), 16 * 1024);
192:
193: c[i].save(fos, (String) null);
194: fos.flush();
195: fos.close();
196:
197: if (addBase) {
198: // add duplicate english file as the base
199: fos = new BufferedOutputStream(new FileOutputStream(
200: new File(dir, "m" + i + ".properties")),
201: 16 * 1024);
202: c[i].save(fos, (String) null);
203: fos.flush();
204: fos.close();
205: }
206:
207: }
208:
209: System.out.println("split messages" + locale);
210:
211: // Save the client messages (the combination of what was already
212: // there and what we added from the engine properties file) into
213: // the Derby locales directory
214: OutputStream clientOutStream = new BufferedOutputStream(
215: new FileOutputStream(new File(dir, clientPropsFileName)),
216: 16 * 1024);
217:
218: clientProps.save(clientOutStream, (String) null);
219: clientOutStream.flush();
220: clientOutStream.close();
221:
222: if (addBase) {
223: // Save the English messages as the base
224: clientOutStream = new BufferedOutputStream(
225: new FileOutputStream(new File(dir,
226: "clientmessages.properties")), 16 * 1024);
227:
228: clientProps.save(clientOutStream, (String) null);
229: clientOutStream.flush();
230: clientOutStream.close();
231: }
232: System.out.println("Copied client messages for " + locale);
233: }
234:
235: /**
236: * Determine if this is a message that the client is using
237: *
238: * There are some classes of ids that we assume are client messages
239: * (see code below for the definitive list).
240: *
241: * All other shared message ids should be added to the static array
242: * clientMessageIds, defined at the top of this class
243: */
244: static boolean isClientMessage(String messageId) {
245: // Look for message ids that we assume are likely to be used
246: // on the client. These ones don't need to be explicitly added
247: // to clientMessageIds
248: if (messageId.startsWith("XJ") || messageId.startsWith("J")
249: || messageId.startsWith("XN")
250: || messageId.startsWith("58")
251: || messageId.startsWith("57")
252: || messageId.startsWith("08")) {
253: return true;
254: }
255:
256: if (clientMessageIds.contains(messageId)) {
257: return true;
258: }
259:
260: return false;
261: }
262: }
|