KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > transformers > Censor


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

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.6 2005/05/04 22:23:31 michiel Exp $
23  */

24
25 public class Censor extends RegexpReplacer {
26
27     protected static Collection forbidden = new ArrayList();
28     
29     static {
30         new Censor().readPatterns(forbidden);
31     }
32
33     protected Collection getPatterns() {
34         return forbidden;
35     }
36
37     protected String JavaDoc getConfigFile() {
38         return "censor.xml";
39     }
40
41
42
43     protected void readDefaultPatterns(Collection patterns) {
44         patterns.add(new Entry(Pattern.compile("(?i)mmbase"), "MMBase"));
45         patterns.add(new Entry(Pattern.compile("(?i)microsoft"), "Micro$soft"));
46         patterns.add(new Entry(Pattern.compile("(?i)fuck"), "****"));
47     }
48     
49
50     public String JavaDoc toString() {
51         return "CENSOR";
52     }
53 }
54
Popular Tags