Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 package org.apache.xmlrpc.serializer;
00020
00021 import java.io.BufferedWriter;
00022 import java.io.OutputStream;
00023 import java.io.OutputStreamWriter;
00024 import java.io.UnsupportedEncodingException;
00025
00026 import org.apache.ws.commons.serialize.XMLWriter;
00027 import org.apache.ws.commons.serialize.XMLWriterImpl;
00028 import org.apache.xmlrpc.XmlRpcException;
00029 import org.apache.xmlrpc.common.XmlRpcStreamConfig;
00030 import org.xml.sax.ContentHandler;
00031
00032
00037 public class BaseXmlWriterFactory implements XmlWriterFactory {
00038 protected XMLWriter newXmlWriter() {
00039 return new XMLWriterImpl();
00040 }
00041
00042 public ContentHandler getXmlWriter(XmlRpcStreamConfig pConfig, OutputStream pStream)
00043 throws XmlRpcException {
00044 XMLWriter xw = newXmlWriter();
00045 xw.setDeclarating(true);
00046 String enc = pConfig.getEncoding();
00047 if (enc == null) {
00048 enc = XmlRpcStreamConfig.UTF8_ENCODING;
00049 }
00050 xw.setEncoding(enc);
00051 xw.setIndenting(false);
00052 xw.setFlushing(true);
00053 try {
00054 xw.setWriter(new BufferedWriter(new OutputStreamWriter(pStream, enc)));
00055 } catch (UnsupportedEncodingException e) {
00056 throw new XmlRpcException("Unsupported encoding: " + enc, e);
00057 }
00058 return xw;
00059 }
00060 }