1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with 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,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_forms.hxx"
26 
27 #include <memory>
28 
29 #include "submission_post.hxx"
30 #include "serialization_app_xml.hxx"
31 #include "serialization_urlencoded.hxx"
32 
33 #include <osl/file.hxx>
34 #include <unotools/processfactory.hxx>
35 #include <ucbhelper/content.hxx>
36 #include <ucbhelper/activedatasink.hxx>
37 #include <com/sun/star/ucb/PostCommandArgument2.hpp>
38 
39 using namespace CSS::uno;
40 using namespace CSS::ucb;
41 using namespace CSS::task;
42 using namespace CSS::io;
43 using namespace rtl;
44 using namespace osl;
45 using namespace ucbhelper;
46 using namespace std;
47 
48 
CSubmissionPost(const rtl::OUString & aURL,const CSS::uno::Reference<CSS::xml::dom::XDocumentFragment> & aFragment)49 CSubmissionPost::CSubmissionPost(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment)
50     : CSubmission(aURL, aFragment)
51 {
52 }
53 
submit(const CSS::uno::Reference<CSS::task::XInteractionHandler> & aInteractionHandler)54 CSubmission::SubmissionResult CSubmissionPost::submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler)
55 {
56     // PUT always uses application/xml
57     CSS::uno::Reference< XCommandEnvironment > aEnvironment;
58     auto_ptr< CSerialization > apSerialization(createSerialization(aInteractionHandler,aEnvironment));
59 
60     try {
61         ucbhelper::Content aContent(m_aURLObj.GetMainURL(INetURLObject::NO_DECODE), aEnvironment);
62 
63         // use post command
64 
65         OUString aCommandName = OUString::createFromAscii("post");
66         PostCommandArgument2 aPostArgument;
67         aPostArgument.Source = apSerialization->getInputStream();
68         //CSS::uno::Reference< XInterface > aSink( m_aFactory->createInstance(
69         //    OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY_THROW);
70         CSS::uno::Reference< XActiveDataSink > aSink(new ucbhelper::ActiveDataSink);
71         //    OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY_THROW);
72         aPostArgument.Sink = aSink;
73         aPostArgument.MediaType = OUString::createFromAscii("application/xml");
74         aPostArgument.Referer = OUString();
75         Any aCommandArgument;
76         aCommandArgument <<= aPostArgument;
77         aContent.executeCommand( aCommandName, aCommandArgument);
78 
79         // wait for command to finish
80         // pProgressHelper->m_cFinished.wait();
81 
82         // CSS::uno::Reference< XOutputStream > xOut(aSink, UNO_QUERY_THROW);
83         // xOut->closeOutput();
84 
85         try {
86             // m_aResultStream = CSS::uno::Reference< XInputStream >(aSink, UNO_QUERY_THROW);
87             m_aResultStream = aSink->getInputStream();
88         } catch (Exception&) {
89             OSL_ENSURE(sal_False, "Cannot open reply stream from content");
90         }
91     } catch (Exception&)
92     {
93         // XXX
94         OSL_ENSURE(sal_False, "Exception during UCB operatration.");
95         return UNKNOWN_ERROR;
96     }
97 
98 
99     return SUCCESS;
100 }
101 
102