1 package net.sf.cantina.decorator;
2
3 import net.sf.cantina.Document;
4 import net.sf.cantina.util.XmlHelper;
5 import org.apache.log4j.Logger;
6
7 import java.io.UnsupportedEncodingException;
8 import java.util.Locale;
9
10 /***
11 * @author Stephane JAIS
12 */
13 public class EscapeXmlDecorator
14 extends DocumentDecorator
15 {
16 private static final Logger logger = Logger.getLogger(EscapeXmlDecorator.class);
17
18 public EscapeXmlDecorator(Document d)
19 {
20 super(d);
21 }
22
23 public byte[] getContent(Locale l)
24 {
25 byte[] content = getDocument().getContent(l);
26 try
27 {
28 String str = new String(content, "utf-8");
29 return XmlHelper.escapeXml(str).getBytes("utf-8");
30 } catch (UnsupportedEncodingException e)
31 {
32 logger.warn("Could not escape XML for document [" + getDocument().getDocumentId() + "]", e);
33 return getDocument().getContent(l);
34 }
35 }
36
37 public String getContentAsString(Locale l)
38 throws Exception
39 {
40 return XmlHelper.escapeXml(getDocument().getContentAsString(l));
41 }
42 }