1 /**
2 * Licensed under the Artistic License; you may not use this file
3 * except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://displaytag.sourceforge.net/license.html
7 *
8 * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 */
12 package org.displaytag.decorator;
13
14 import javax.servlet.jsp.PageContext;
15
16 import org.apache.commons.lang.StringEscapeUtils;
17 import org.displaytag.properties.MediaTypeEnum;
18
19
20 /**
21 * This takes the string that is passed in, and escapes html tags and entities. Only operates on "html" or "xml" media.
22 * @author Fabrizio Giustina
23 * @version $Revision$ ($Author$)
24 */
25 public class EscapeXmlColumnDecorator implements DisplaytagColumnDecorator
26 {
27
28 /**
29 * Instance used for the "escapeXml" tag attribute.
30 */
31 public static final DisplaytagColumnDecorator INSTANCE = new EscapeXmlColumnDecorator();
32
33 /**
34 * @see org.displaytag.decorator.DisplaytagColumnDecorator#decorate(Object, PageContext, MediaTypeEnum)
35 */
36 public Object decorate(Object columnValue, PageContext pageContext, MediaTypeEnum media)
37 {
38
39 if (columnValue == null || (!media.equals(MediaTypeEnum.HTML) && !media.equals(MediaTypeEnum.XML)))
40 {
41 return columnValue;
42 }
43
44 return StringEscapeUtils.escapeXml(columnValue.toString());
45 }
46
47 }