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: import org.mmbase.util.logging.*;
16:
17: /**
18: * Transforms the input to the characters which are alowed in Sitestat keys for
19: * page statistics, being: "A-Z, a-z, 0-9, - . _".
20: *
21: * @author Andre van Toly
22: * @since MMBase-1.7
23: * @version $Id: Sitestat.java,v 1.3 2007/08/15 14:43:12 andre Exp $
24: */
25:
26: public class Sitestat extends ReaderTransformer implements
27: CharTransformer {
28: private static Logger log = Logging
29: .getLoggerInstance(Sitestat.class);
30: private static String alowedChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-.";
31:
32: public Writer transform(Reader r, Writer w) {
33: try {
34: if (log.isDebugEnabled())
35: log.debug("Starting transforming string for Sitestat");
36: int d = -1;
37: while (true) {
38: int c = r.read();
39: if (c == -1)
40: break;
41: if (alowedChars.indexOf((char) c) > -1) {
42: w.write((char) c);
43: d = c;
44: } else if (d != '_') {
45: w.write('_');
46: d = '_';
47: }
48: }
49: if (log.isDebugEnabled())
50: log.debug("Finished transforming string for Sitestat");
51: } catch (java.io.IOException e) {
52: log.error(e.toString());
53: }
54: return w;
55: }
56:
57: public String toString() {
58: return "sitestat";
59: }
60: }
|