01: /*
02: * Created on Mar 9, 2005
03: *
04: */
05: package net.sf.thingamablog.generator;
06:
07: import java.util.Hashtable;
08:
09: /**
10: */
11: public class EmailTag extends TextTag {
12:
13: public static final String MUNG = "mung";
14:
15: private final static String ASCII_CODE = new String(
16: " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
17:
18: /**
19: * @param name
20: */
21: public EmailTag(String name) {
22: super (name);
23: Hashtable ht = getDefaultAttributes();
24: ht.put(MUNG, "0");
25: }
26:
27: public String process(Object val, Hashtable attribs) {
28: String s = super .process(val, attribs);
29: if (!attribs.get(MUNG).equals(FALSE))
30: return mung(s);
31:
32: return s;
33: }
34:
35: private String mung(String source) {
36: int n, length = source.length();
37: int everyOther = 0;
38: StringBuffer dest = new StringBuffer();
39:
40: for (int i = 0; i < length; i++) {
41: n = ASCII_CODE.indexOf(source.charAt(i));
42: if (n == -1)
43: dest.append(source.charAt(i));
44: else if (everyOther != 0)
45: dest.append(source.charAt(i));
46: else {
47: Integer entity = new Integer(n + 32);
48: dest.append("&#" + entity.toString() + ";");
49: }
50:
51: everyOther++;
52: if (everyOther > 1)
53: everyOther = 0;
54: }
55:
56: return dest.toString();
57: }
58:
59: }
|