001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010:
011: package org.mmbase.util.transformers;
012:
013: import java.io.Reader;
014: import java.io.Writer;
015: import java.util.*;
016:
017: import org.mmbase.util.logging.Logger;
018: import org.mmbase.util.logging.Logging;
019:
020: /**
021: * The ISO-8859-3 ('South European') unibyte encoding is used for languages like maltese and
022: * esperanto. If characters from this set are missing on your presentation device, this Transformer can
023: * provide (ASCII) surrogates for a bunch of characters.
024: *
025: * @author Michiel Meeuwissen
026: * @since MMBase-1.7
027: * @version $Id: Latin3Surrogator.java,v 1.4 2007/02/24 21:57:50 nklasens Exp $
028: */
029: public class Latin3Surrogator extends ConfigurableReaderTransformer
030: implements CharTransformer {
031: private static Logger log = Logging
032: .getLoggerInstance(Latin3Surrogator.class);
033:
034: // esperanto
035: public static final int XMETODO = 1; // faru iksojn
036: public static final int HMETODO = 2; // faru hojn
037:
038: public Latin3Surrogator() {
039: super ();
040: }
041:
042: public Latin3Surrogator(int c) {
043: super (c);
044: }
045:
046: protected Writer iksoj(Reader r, Writer w) {
047: try {
048: while (true) {
049: int c = r.read();
050: if (c == -1)
051: break;
052: switch (c) {
053: case '\u0108':
054: w.write("Cx");
055: break;
056: case '\u0109':
057: w.write("cx");
058: break;
059: case '\u011C':
060: w.write("Gx");
061: break;
062: case '\u011D':
063: w.write("gx");
064: break;
065: case '\u0124':
066: w.write("Hx");
067: break;
068: case '\u0125':
069: w.write("hx");
070: break;
071: case '\u0134':
072: w.write("Jx");
073: break;
074: case '\u0135':
075: w.write("jx");
076: break;
077: case '\u015C':
078: w.write("Sx");
079: break;
080: case '\u015D':
081: w.write("sx");
082: break;
083: case '\u016C':
084: w.write("Ux");
085: break;
086: case '\u016D':
087: w.write("ux");
088: break;
089: default:
090: w.write(c);
091: }
092: }
093: } catch (java.io.IOException e) {
094: log.error(e.toString());
095: }
096: return w;
097: }
098:
099: protected Writer hoj(Reader r, Writer w) {
100: try {
101: while (true) {
102: int c = r.read();
103: if (c == -1)
104: break;
105: switch (c) {
106: case '\u0108':
107: w.write("Ch");
108: break;
109: case '\u0109':
110: w.write("ch");
111: break;
112: case '\u011C':
113: w.write("Gh");
114: break;
115: case '\u011D':
116: w.write("gh");
117: break;
118: case '\u0124':
119: w.write("Hh");
120: break;
121: case '\u0125':
122: w.write("hh");
123: break;
124: case '\u0134':
125: w.write("Jh");
126: break;
127: case '\u0135':
128: w.write("jh");
129: break;
130: case '\u015C':
131: w.write("Sh");
132: break;
133: case '\u015D':
134: w.write("sh");
135: break;
136: case '\u016C':
137: w.write('U');
138: break;
139: case '\u016D':
140: w.write('u');
141: break;
142: default:
143: w.write(c);
144: }
145: }
146: } catch (java.io.IOException e) {
147: log.error(e.toString());
148: }
149: return w;
150: }
151:
152: public Writer transform(Reader r, Writer w) {
153: switch (to) {
154: case XMETODO:
155: return iksoj(r, w);
156: case HMETODO:
157: return hoj(r, w);
158: default:
159: throw new UnknownCodingException(getClass(), to);
160: }
161: }
162:
163: public String getEncoding() {
164: switch (to) {
165: case XMETODO:
166: return "xmetodo";
167: case HMETODO:
168: return "hmetodo";
169: default:
170: throw new UnknownCodingException(getClass(), to);
171: }
172: }
173:
174: public Map<String, Config> transformers() {
175: Map<String, Config> h = new HashMap<String, Config>();
176: h.put("xmetodo".toUpperCase(), new Config(getClass(), XMETODO));
177: h.put("hmetodo".toUpperCase(), new Config(getClass(), HMETODO));
178: return h;
179: }
180:
181: }
|