001: /*
002: *******************************************************************************
003: * Copyright (C) 2002-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */
007:
008: package com.ibm.icu.dev.tool.localeconverter;
009:
010: import java.io.*;
011: import java.util.*;
012:
013: public class ICU2LocaleWriter extends LocaleWriter {
014: public ICU2LocaleWriter(PrintStream out) {
015: super (out);
016: //{{INIT_CONTROLS
017: //}}
018: }
019:
020: public ICU2LocaleWriter(PrintStream out, PrintStream err) {
021: super (out, err);
022: }
023:
024: protected void open(Locale locale) {
025: print(locale.toString());
026: println(" {");
027: indent();
028: }
029:
030: protected void write(String tag, String value) {
031: print(tag);
032: print(" { ");
033: printString(value);
034: println(" }");
035: }
036:
037: protected void write(String tag, String[] value) {
038: if (tag != null) {
039: print(tag);
040: println(" { ");
041: } else {
042: println("{");
043: }
044: indent();
045: for (int i = 0; i < value.length; i++) {
046: printString(value[i]);
047: println(",");
048: }
049: outdent();
050: println("}");
051: }
052:
053: protected void write(String tag, Object o) {
054: if ("collations".equals(tag)) {
055: writeTagged(tag, (Object[][]) o);
056: } else if (!(o instanceof CollationItem[])) {
057: super .write(tag, o);
058: } else {
059: CollationItem[] items = (CollationItem[]) o;
060: if (items[0] != null) {
061: print("Sequence");
062: println(" { ");
063: for (int i = 0; i < items.length; i++) {
064: if (items[i] != null) {
065: printRuleString(items[i].toString());
066: if (items[i].comment != null) {
067: tabTo(30);
068: print("//");
069: println(items[i].comment);
070: }
071: }
072: }
073: println("}");
074: }
075: }
076: }
077:
078: protected void writeTagged(String tag, Object[][] value) {
079: print(tag);
080: println(" { ");
081: indent();
082: for (int i = 0; i < value.length; i++) {
083: write((String) value[i][0], value[i][1]);
084: }
085: outdent();
086: println("}");
087: }
088:
089: protected void write2D(String tag, String[][] value) {
090: print(tag);
091: println(" { ");
092: indent();
093: for (int i = 0; i < value.length; i++) {
094: write(null, value[i]);
095: }
096: outdent();
097: println("}");
098: }
099:
100: protected void writeTagged(String tag, String[][] value) {
101: print(tag);
102: println(" { ");
103: indent();
104: for (int i = 0; i < value.length; i++) {
105: write(value[i][0], value[i][1]);
106: }
107: outdent();
108: println("}");
109: }
110:
111: protected void close() {
112: outdent();
113: println("}");
114: }
115:
116: protected String getStringJoiningCharacter() {
117: return "";
118: }
119:
120: protected boolean isEscapeChar(final char c) {
121: return true;
122: }
123:
124: protected String getEscapeChar() {
125: return "\\u";
126: }
127: //{{DECLARE_CONTROLS
128: //}}
129: }
|