Coverage Report - org.apache.jackrabbit.webdav.client.methods.XmlRequestEntity
 
Classes in this File Line Coverage Branch Coverage Complexity
XmlRequestEntity
73%
16/22
N/A
1,4
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.jackrabbit.webdav.client.methods;
 18  
 
 19  
 import org.slf4j.Logger;
 20  
 import org.slf4j.LoggerFactory;
 21  
 import org.apache.commons.httpclient.methods.RequestEntity;
 22  
 import org.apache.commons.httpclient.methods.StringRequestEntity;
 23  
 import org.w3c.dom.Document;
 24  
 
 25  
 import java.io.OutputStream;
 26  
 import java.io.IOException;
 27  
 import java.io.ByteArrayOutputStream;
 28  
 
 29  
 import javax.xml.transform.OutputKeys;
 30  
 import javax.xml.transform.Transformer;
 31  
 import javax.xml.transform.TransformerException;
 32  
 import javax.xml.transform.TransformerFactory;
 33  
 import javax.xml.transform.dom.DOMSource;
 34  
 import javax.xml.transform.stream.StreamResult;
 35  
 
 36  
 /**
 37  
  * <code>XmlRequestEntity</code>...
 38  
  */
 39  
 public class XmlRequestEntity implements RequestEntity
 40  
 {
 41  
 
 42  2
     private static Logger log = LoggerFactory.getLogger( XmlRequestEntity.class );
 43  
 
 44  
     private final RequestEntity delegatee;
 45  
 
 46  
     public XmlRequestEntity( Document xmlDocument ) throws IOException
 47  
     {
 48  24
         super();
 49  24
         ByteArrayOutputStream out = new ByteArrayOutputStream();
 50  
 
 51  
         try
 52  
         {
 53  24
             TransformerFactory factory = TransformerFactory.newInstance();
 54  24
             Transformer transformer = factory.newTransformer();
 55  24
             transformer.setOutputProperty( OutputKeys.METHOD, "xml" );
 56  24
             transformer.setOutputProperty( OutputKeys.ENCODING, "UTF-8" );
 57  24
             transformer.setOutputProperty( OutputKeys.INDENT, "no" );
 58  24
             transformer.transform( new DOMSource( xmlDocument ), new StreamResult( out ) );
 59  
         }
 60  0
         catch ( TransformerException e )
 61  
         {
 62  0
             log.error( "XML serialization failed", e );
 63  0
             IOException exception = new IOException( "XML serialization failed" );
 64  0
             exception.initCause( e );
 65  0
             throw exception;
 66  24
         }
 67  
 
 68  24
         delegatee = new StringRequestEntity( out.toString(), "text/xml", "UTF-8" );
 69  24
     }
 70  
 
 71  
     public boolean isRepeatable()
 72  
     {
 73  0
         return delegatee.isRepeatable();
 74  
     }
 75  
 
 76  
     public String getContentType()
 77  
     {
 78  48
         return delegatee.getContentType();
 79  
     }
 80  
 
 81  
     public void writeRequest( OutputStream out ) throws IOException
 82  
     {
 83  24
         delegatee.writeRequest( out );
 84  24
     }
 85  
 
 86  
     public long getContentLength()
 87  
     {
 88  48
         return delegatee.getContentLength();
 89  
     }
 90  
 }