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 ICULocaleWriter extends LocaleWriter {
013: public ICULocaleWriter(PrintStream out) {
014: super (out);
015: }
016:
017: public ICULocaleWriter(PrintStream out, PrintStream err) {
018: super (out, err);
019: }
020:
021: protected void open(Locale locale) {
022: print(locale.toString());
023: println(" {");
024: indent();
025: }
026:
027: protected void write(String tag, Object o) {
028: if ("collations".equals(tag)) {
029: if (o instanceof Object[][]) {
030: writeTagged(tag, (Object[][]) o);
031: } else {
032: write(tag, (String) o);
033: }
034: } else if (!(o instanceof CollationItem[])) {
035: super .write(tag, o);
036: } else {
037: CollationItem[] items = (CollationItem[]) o;
038: if (items[0] != null) {
039: print("Sequence");
040: println(" { ");
041: for (int i = 0; i < items.length; i++) {
042: if (items[i] != null) {
043: printString(items[i].toString());
044: if (items[i].comment != null) {
045: tabTo(30);
046: print("//");
047: println(items[i].comment);
048: }
049: }
050: }
051: println("}");
052: }
053: }
054: }
055:
056: protected void write(String tag, String value) {
057: print(tag);
058: print(" { ");
059: printString(value);
060: println(" }");
061: }
062:
063: protected void writeIntVector(String tag, String[] value) {
064: if (tag != null) {
065: print(tag);
066: println(":intvector { ");
067: } else {
068: println(":intvector{");
069: }
070: indent();
071: for (int i = 0; i < value.length; i++) {
072: printUnquotedString(value[i]);
073: println(",");
074: }
075: outdent();
076: println("}");
077: }
078:
079: protected void write(String tag, String[] value) {
080: if (tag != null && tag.equals("DateTimeElements")) {
081: writeIntVector(tag, value);
082: return;
083: }
084: if (tag != null) {
085: print(tag);
086: println(" { ");
087: } else {
088: println("{");
089: }
090: indent();
091: for (int i = 0; i < value.length; i++) {
092: printString(value[i]);
093: println(",");
094: }
095: outdent();
096: println("}");
097: }
098:
099: protected void write2D(String tag, String[][] value) {
100: print(tag);
101: println(" { ");
102: indent();
103: for (int i = 0; i < value.length; i++) {
104: write(null, value[i]);
105: }
106: outdent();
107: println("}");
108: }
109:
110: protected void writeTagged(String tag, Object[][] value) {
111: print(tag);
112: println(" { ");
113: indent();
114: for (int i = 0; i < value.length; i++) {
115: write((String) value[i][0], value[i][1]);
116: }
117: outdent();
118: println("}");
119: }
120:
121: protected void writeTagged(String tag, String[][] value) {
122: print(tag);
123: println(" { ");
124: indent();
125: for (int i = 0; i < value.length; i++) {
126: write(value[i][0], value[i][1]);
127: }
128: outdent();
129: println("}");
130: }
131:
132: protected void close() {
133: outdent();
134: println("}");
135: // super.closeFileHandle();
136: }
137:
138: protected String getStringJoiningCharacter() {
139: return "";
140: }
141: }
|