01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TemplateEncoder.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.template;
09:
10: /**
11: * Encodes <code>String</code>s into a corresponding template output format,
12: * so they will be displayed correctly in the resulting file. For example, a
13: * <code>TemplateEncoder</code> for a template file will {@link #encode encode}
14: * <code>></code> as <code>&gt</code>.
15: *
16: * @author Keith Lea <keith[remove] at cs dot oswego dot edu>
17: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
18: * @version $Revision: 3634 $
19: * @since 1.0
20: */
21: public interface TemplateEncoder {
22: /**
23: * Encodes the given value, returning a string which contains only valid
24: * characters and represents the given <code>value</code> correctly in the
25: * output format.
26: * <p>For example, an HTML template's encoder will encode
27: * <code>></code> as <code>&gt;</code>.
28: *
29: * @param value a string
30: * @return an encoded version of the given string
31: * @since 1.0
32: */
33: public String encode(String value);
34:
35: /**
36: * Encodes the given value in a looser fashion than {@link #encode}'s,
37: * only converting patterns which are explicitly not allowed by the output
38: * format, but not guaranteeing that the output value exactly represents
39: * the given <code>value</code> in the output format.
40: * <p>For example, an HTML template's encoder will encode some Unicode
41: * characters to corresponding XML entities (such as
42: * <code>&eacute;</code>) when this method is called but not encode
43: * <code><</code> or <code>&</code>.
44: *
45: * @param value a string
46: * @return a loosely encoded version of the given <code>value</code>
47: * @since 1.0
48: */
49: public String encodeDefensive(String value);
50: }
|