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.util.regex.*;
13: import java.util.*;
14: import org.mmbase.util.Entry;
15:
16: /**
17: * Replaces certain 'forbidden' words by something more decent. Of course, censoring is evil, but
18: * sometimes it can be amusing too. This is only an example implementation.
19: *
20: * @author Michiel Meeuwissen
21: * @since MMBase-1.7
22: * @version $Id: Censor.java,v 1.7 2007/02/24 21:57:50 nklasens Exp $
23: */
24:
25: public class Censor extends RegexpReplacer {
26:
27: protected static Collection<Entry<Pattern, String>> forbidden = new ArrayList<Entry<Pattern, String>>();
28:
29: static {
30: new Censor().readPatterns(forbidden);
31: }
32:
33: protected Collection<Entry<Pattern, String>> getPatterns() {
34: return forbidden;
35: }
36:
37: protected String getConfigFile() {
38: return "censor.xml";
39: }
40:
41: protected void readDefaultPatterns(
42: Collection<Entry<Pattern, String>> patterns) {
43: patterns.add(new Entry<Pattern, String>(Pattern
44: .compile("(?i)mmbase"), "MMBase"));
45: patterns.add(new Entry<Pattern, String>(Pattern
46: .compile("(?i)microsoft"), "Micro$soft"));
47: patterns.add(new Entry<Pattern, String>(Pattern
48: .compile("(?i)fuck"), "****"));
49: }
50:
51: public String toString() {
52: return "CENSOR";
53: }
54: }
|