1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.webapp;
21
22 import org.apache.myfaces.tobago.internal.util.HtmlWriterHelper;
23 import org.apache.myfaces.tobago.internal.util.WriterHelper;
24
25 import javax.faces.context.ResponseWriter;
26 import java.io.IOException;
27 import java.io.Writer;
28 import java.nio.charset.Charset;
29 import java.util.Arrays;
30
31 public final class XmlResponseWriter extends TobagoResponseWriterBase {
32
33 private final WriterHelper helper;
34
35
36
37
38 @Deprecated
39 public XmlResponseWriter(
40 final Writer writer, final String contentType, final String characterEncoding) {
41 this(writer, contentType, Charset.forName(characterEncoding));
42 }
43
44 public XmlResponseWriter(
45 final Writer writer, final String contentType, final Charset charset) {
46 super(writer, contentType, charset);
47 this.helper = new HtmlWriterHelper(writer, charset);
48 }
49
50 @Override
51 public void writeText(final Object text, final String property)
52 throws IOException {
53 closeOpenTag();
54 final String value = findValue(text, property);
55 helper.writeText(value);
56 }
57
58 @Override
59 public void writeText(final char[] text, final int offset, final int length)
60 throws IOException {
61 closeOpenTag();
62 helper.writeText(text, offset, length);
63 }
64
65 @Override
66 public void write(final char[] cbuf, final int off, final int len) throws IOException {
67
68 if (Arrays.equals(cbuf, XML_VERSION_1_0_ENCODING_UTF_8_CHARS)) {
69
70 } else {
71 super.write(cbuf, off, len);
72 }
73 }
74
75 @Override
76 protected void closeEmptyTag() throws IOException {
77 getWriter().write("/>");
78 }
79
80 @Override
81 protected void writerAttributeValue(final String value, final boolean escape) throws IOException {
82 if (escape) {
83 helper.writeAttributeValue(value);
84 } else {
85 getWriter().write(value);
86 }
87 }
88
89 @Override
90 public ResponseWriter cloneWithWriter(final Writer originalWriter) {
91 return new XmlResponseWriter(originalWriter, getContentType(), Charset.forName(getCharacterEncoding()));
92 }
93
94 @Override
95 public void startDocument() throws IOException {
96 }
97
98 @Override
99 public void endDocument() throws IOException {
100 }
101 }