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