1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "submission_get.hxx"
22 #include "serialization_app_xml.hxx"
23 #include "serialization_urlencoded.hxx"
25 #include <rtl/strbuf.hxx>
26 #include <rtl/string.hxx>
27 #include <osl/file.hxx>
28 #include <comphelper/processfactory.hxx>
29 #include <ucbhelper/content.hxx>
30 #include <com/sun/star/io/Pipe.hpp>
31 #include <com/sun/star/task/InteractionHandler.hpp>
33 #include <boost/scoped_ptr.hpp>
35 using namespace css::uno
;
36 using namespace css::ucb
;
37 using namespace css::task
;
38 using namespace css::io
;
40 using namespace ucbhelper
;
45 CSubmissionGet::CSubmissionGet(const OUString
& aURL
, const css::uno::Reference
< css::xml::dom::XDocumentFragment
>& aFragment
)
46 : CSubmission(aURL
, aFragment
)
50 CSubmission::SubmissionResult
CSubmissionGet::submit(const css::uno::Reference
< css::task::XInteractionHandler
>& aInteractionHandler
)
52 // GET always uses apllicatin/x-www-formurlencoded
53 boost::scoped_ptr
< CSerialization
> apSerialization(new CSerializationURLEncoded());
54 apSerialization
->setSource(m_aFragment
);
55 apSerialization
->serialize();
57 css::uno::Reference
< XInputStream
> aInStream
= apSerialization
->getInputStream();
59 // create a commandEnvironment and use the default interaction handler
60 CCommandEnvironmentHelper
*pHelper
= new CCommandEnvironmentHelper
;
61 if( aInteractionHandler
.is() )
62 pHelper
->m_aInteractionHandler
= aInteractionHandler
;
64 pHelper
->m_aInteractionHandler
.set(
65 css::task::InteractionHandler::createWithParent(m_xContext
, 0), UNO_QUERY_THROW
);
66 CProgressHandlerHelper
*pProgressHelper
= new CProgressHandlerHelper
;
67 pHelper
->m_aProgressHandler
= css::uno::Reference
< XProgressHandler
>(pProgressHelper
);
69 // UCB has ownership of environment...
70 css::uno::Reference
< XCommandEnvironment
> aEnvironment(pHelper
);
72 // append query string to the URL
74 OStringBuffer
aUTF8QueryURL(OUStringToOString(m_aURLObj
.GetMainURL(INetURLObject::NO_DECODE
),
75 RTL_TEXTENCODING_UTF8
));
76 OStringBuffer aQueryString
;
78 const sal_Int32 size
= 1024;
80 Sequence
< sal_Int8
> aByteBuffer(size
);
81 while ((n
= aInStream
->readSomeBytes(aByteBuffer
, size
-1)) != 0)
82 aQueryString
.append(reinterpret_cast<char const *>(aByteBuffer
.getConstArray()), n
);
83 if (!aQueryString
.isEmpty() && m_aURLObj
.GetProtocol() != INetProtocol::File
)
85 aUTF8QueryURL
.append('?');
86 aUTF8QueryURL
.append(aQueryString
.makeStringAndClear());
88 OUString aQueryURL
= OStringToOUString(aUTF8QueryURL
.makeStringAndClear(), RTL_TEXTENCODING_UTF8
);
89 ucbhelper::Content
aContent(aQueryURL
, aEnvironment
, m_xContext
);
90 css::uno::Reference
< XOutputStream
> aPipe( css::io::Pipe::create(m_xContext
), UNO_QUERY_THROW
);
91 aContent
.openStream(aPipe
);
94 m_aResultStream
= aContent
.openStream();
95 } catch (const Exception
&) {
96 OSL_FAIL("Cannot open reply stream from content");
98 } catch (const Exception
&)
101 OSL_FAIL("Exception during UCB operatration.");
102 return UNKNOWN_ERROR
;
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */