01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.util.transformers;
11:
12: import java.io.Reader;
13: import java.io.Writer;
14:
15: /**
16: * Turns a Transformer around. This only works if this Tranformer
17: * implements transform(Reader, Writer) and/or transformBack(Reader,
18: * Writer);
19: *
20: * @author Michiel Meeuwissen
21: * @since MMBase-1.7
22: */
23:
24: public class InverseCharTransformer implements CharTransformer {
25:
26: private CharTransformer ct;
27:
28: /**
29: * The constructor
30: * @param c The CharTransformed to be turned around.
31: */
32:
33: public InverseCharTransformer(CharTransformer c) {
34: super ();
35: ct = c;
36: }
37:
38: public String transform(String s) {
39: return ct.transformBack(s);
40: }
41:
42: public String transformBack(String s) {
43: return ct.transform(s);
44: }
45:
46: public Writer transform(Reader r) {
47: return ct.transformBack(r);
48: }
49:
50: public Writer transformBack(Reader r) {
51: return ct.transform(r);
52: }
53:
54: public Writer transform(Reader r, Writer w) {
55: return ct.transformBack(r, w);
56: }
57:
58: public Writer transformBack(Reader r, Writer w) {
59: return ct.transform(r, w);
60: }
61:
62: public String toString() {
63: return "INVERSE " + ct;
64: }
65: }
|