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