01: /***
02: * jwma Java WebMail
03: * Copyright (c) 2000-2003 jwma team
04: *
05: * jwma is free software; you can distribute and use this source
06: * under the terms of the BSD-style license received along with
07: * the distribution.
08: ***/package dtw.webmail.util;
09:
10: import net.wimpi.text.*;
11:
12: /**
13: * Utility class for handling entities.<br>
14: * Exposes a method for encoding HTML unsafe characters
15: * into entities. In the future it might also expose
16: * a method for decoding entities into characters.
17: *
18: * @author Dieter Wimberger
19: * @version 0.9.7 07/02/2003
20: */
21: public class EntityHandler {
22:
23: /*
24: private static CharacterSubstitution c_Charsub=
25: new CharacterSubstitution();
26: private static Pattern c_Pattern=JwmaKernel.getReference()
27: .getCharMatchPattern();
28: */
29:
30: //class members
31: //FIXME: get the Processor name from setting
32: private static Processor m_EntityEncoder = ProcessingKernel
33: .getReference().getProcessor("entityencoder");
34:
35: /**
36: * Returns a <tt>String</tt> with all occurences of
37: * HTML unsafe characters replaced by their respective entities.
38: *
39: * @param input the <tt>String</tt> to be encoded.
40: * @return a <tt>String</tt> without HTML unsafe chars.
41: */
42: public static String encode(String input) {
43: //outsourced
44: return m_EntityEncoder.process(input);
45:
46: /*
47: //do not waste cycles on nulls or empty strings
48: if(input==null || input.equals("")) {
49: return "";
50: }
51:
52: PatternMatcher matcher=null;
53: try {
54: matcher=JwmaKernel.getReference().getMatcher();
55: return Util.substitute(
56: matcher,
57: c_Pattern,
58: c_Charsub,
59: input,
60: Util.SUBSTITUTE_ALL
61: );
62: } catch (Exception ex) {
63: return input;
64: } finally {
65: JwmaKernel.getReference().releaseMatcher(matcher);
66: }
67: */
68: }//encode
69:
70: }//EntityHandler
|