001: /*
002: *******************************************************************************
003: * Copyright (C) 2002-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007: package com.ibm.icu.dev.tool.localeconverter;
008:
009: import java.io.*;
010: import java.util.*;
011:
012: public class Java1LocaleWriter extends LocaleWriter {
013: public Java1LocaleWriter(PrintStream out) {
014: super (out);
015: //{{INIT_CONTROLS
016: //}}
017: }
018:
019: public Java1LocaleWriter(PrintStream out, PrintStream err) {
020: super (out, err);
021: }
022:
023: public void write(Locale locale, Hashtable localeData) {
024: try {
025: Hashtable temp = new NeutralToJ1Converter(locale)
026: .convert(localeData);
027: super .write(locale, temp);
028: } catch (LocaleConverter.ConversionError e) {
029: err.println(e);
030: }
031: }
032:
033: protected void open(Locale locale) {
034: print(HEADER1);
035: print(locale.toString());
036: print(HEADER2);
037: print(locale.toString());
038: println(HEADER3);
039: indent(3);
040: }
041:
042: protected void write(String tag, String value) {
043: print("{ ");
044: printString(tag);
045: print(", ");
046: printString(value);
047: println(" },");
048: }
049:
050: protected void write(String tag, String[] value) {
051: print("{ ");
052: if (tag != null) {
053: printString(tag);
054: println(",");
055: } else {
056: println("");
057: }
058: indent();
059: println("new String[] {");
060: indent();
061: for (int i = 0; i < value.length; i++) {
062: printString(value[i]);
063: println(",");
064: }
065: outdent();
066: println("}");
067: outdent();
068: println("},");
069: }
070:
071: protected void write2D(String tag, String[][] value) {
072: print("{ ");
073: printString(tag);
074: println(",");
075: indent();
076: println("new String[][] {");
077: indent();
078: for (int i = 0; i < value.length; i++) {
079: println("{");
080: indent();
081: for (int j = 0; j < value[i].length; j++) {
082: printString(value[i][j]);
083: println(",");
084: }
085: outdent();
086: println("},");
087: }
088: outdent();
089: println("}");
090: outdent();
091: println("},");
092: }
093:
094: protected void writeTagged(String tag, String[][] value) {
095: print("{ ");
096: printString(tag);
097: println(",");
098: indent();
099: println("new String[][] {");
100: indent();
101: for (int i = 0; i < value.length; i++) {
102: write(value[i][0], value[i][1]);
103: }
104: outdent();
105: println("}");
106: outdent();
107: println("},");
108: }
109:
110: protected void close() {
111: outdent(3);
112: print(FOOTER);
113: }
114:
115: protected void appendEscapedChar(char c, StringBuffer buffer) {
116: if (c < '\u0020' || c == '"' || c == '\\') {
117: buffer.append('\\');
118: buffer.append(HEX_DIGIT[(c & 0700) >> 6]); // HEX_DIGIT works for octal
119: buffer.append(HEX_DIGIT[(c & 0070) >> 3]);
120: buffer.append(HEX_DIGIT[(c & 0007)]);
121: } else {
122: super .appendEscapedChar(c, buffer);
123: }
124: }
125:
126: protected String getStringJoiningCharacter() {
127: return "+";
128: }
129:
130: private static final String HEADER1 = "package java.text.resources;\n"
131: + "public class LocaleElements_";
132: private static final String HEADER2 = " extends LocaleData {\n"
133: + " public LocaleElements_";
134: private static final String HEADER3 = "() {\n"
135: + " super.init(table);\n" + " }\n"
136: + " static String table []=";
137:
138: private static final String FOOTER = " }\n" + "}";
139: //{{DECLARE_CONTROLS
140: //}}
141: }
|