BaseXmlWriterFactory.java
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one
00003  * or more contributor license agreements.  See the NOTICE file
00004  * distributed with this work for additional information
00005  * regarding copyright ownership.  The ASF licenses this file
00006  * to you under the Apache License, Version 2.0 (the
00007  * "License"); you may not use this file except in compliance
00008  * with the License.  You may obtain a copy of the License at
00009  *
00010  *   http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing,
00013  * software distributed under the License is distributed on an
00014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
00015  * KIND, either express or implied.  See the License for the
00016  * specific language governing permissions and limitations
00017  * under the License.    
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 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49