Coverage Report - org.apache.xmlrpc.serializer.BaseXmlWriterFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseXmlWriterFactory
86% 
100% 
2,5
 
 1  
 /*
 2  
  * Copyright 1999,2005 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
 /** The default instance of {@link XmlWriterFactory} creates
 31  
  * instances of {@link org.apache.ws.commons.serialize.XMLWriterImpl}.
 32  
  * This works for any Java version since 1.2
 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  
 }