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:
11: package org.mmbase.util.transformers;
12:
13: import java.io.Reader;
14: import java.io.Writer;
15:
16: import org.mmbase.util.logging.Logger;
17: import org.mmbase.util.logging.Logging;
18:
19: /**
20: * Any non-ASCII character will be replaced by an XML-entity.
21: *
22: * @author Michiel Meeuwissen
23: * @since MMBase-1.7
24: * @version $Id: XmlEntities.java,v 1.4 2003/07/01 11:03:33 michiel Exp $
25: */
26: public class XmlEntities extends ReaderTransformer implements
27: CharTransformer {
28: private static Logger log = Logging
29: .getLoggerInstance(XmlEntities.class);
30:
31: public Writer transform(Reader r, Writer w) {
32: try {
33: while (true) {
34: int c = r.read();
35: if (c == -1)
36: break;
37: if ( // c >= '\u0020' && Control character
38: c <= '\u007f') {
39: w.write(c); // ASCII character, simply write
40: } else {
41: w.write("&#" + c + ";"); // construct XML style unicode escaping
42: }
43: }
44: } catch (java.io.IOException e) {
45: log.error(e.toString());
46: }
47: return w;
48: }
49:
50: public String toString() {
51: return "XMLENTITIES";
52: }
53: }
|