1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.apache.xmlrpc.serializer; |
17 |
|
|
18 |
|
import java.io.BufferedWriter; |
19 |
|
import java.io.OutputStream; |
20 |
|
import java.io.OutputStreamWriter; |
21 |
|
import java.io.UnsupportedEncodingException; |
22 |
|
|
23 |
|
import org.apache.ws.commons.serialize.XMLWriter; |
24 |
|
import org.apache.ws.commons.serialize.XMLWriterImpl; |
25 |
|
import org.apache.xmlrpc.XmlRpcException; |
26 |
|
import org.apache.xmlrpc.common.XmlRpcStreamConfig; |
27 |
|
import org.xml.sax.ContentHandler; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
422 |
public class BaseXmlWriterFactory implements XmlWriterFactory { |
35 |
|
protected XMLWriter newXmlWriter() { |
36 |
664 |
return new XMLWriterImpl(); |
37 |
|
} |
38 |
|
|
39 |
|
public ContentHandler getXmlWriter(XmlRpcStreamConfig pConfig, OutputStream pStream) |
40 |
|
throws XmlRpcException { |
41 |
664 |
XMLWriter xw = newXmlWriter(); |
42 |
664 |
xw.setDeclarating(true); |
43 |
664 |
String enc = pConfig.getEncoding(); |
44 |
664 |
if (enc == null) { |
45 |
664 |
enc = XmlRpcStreamConfig.UTF8_ENCODING; |
46 |
|
} |
47 |
664 |
xw.setEncoding(enc); |
48 |
664 |
xw.setIndenting(false); |
49 |
664 |
xw.setFlushing(true); |
50 |
|
try { |
51 |
664 |
xw.setWriter(new BufferedWriter(new OutputStreamWriter(pStream, enc))); |
52 |
0 |
} catch (UnsupportedEncodingException e) { |
53 |
0 |
throw new XmlRpcException("Unsupported encoding: " + enc, e); |
54 |
|
} |
55 |
664 |
return xw; |
56 |
|
} |
57 |
|
} |