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