android: Update app-specific/MIME type icons
[LibreOffice.git] / forms / source / xforms / submission / submission_get.cxx
blob1ddcd529ef1aa0311ad0cc52346ede525ce655ce
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_urlencoded.hxx"
24 #include <rtl/strbuf.hxx>
25 #include <osl/diagnose.h>
26 #include <ucbhelper/content.hxx>
27 #include <com/sun/star/task/InteractionHandler.hpp>
28 #include <comphelper/diagnose_ex.hxx>
30 using namespace css::uno;
31 using namespace css::ucb;
32 using namespace css::task;
33 using namespace css::io;
34 using namespace osl;
35 using namespace ucbhelper;
38 CSubmissionGet::CSubmissionGet(std::u16string_view aURL, const css::uno::Reference< css::xml::dom::XDocumentFragment >& aFragment)
39 : CSubmission(aURL, aFragment)
43 CSubmission::SubmissionResult CSubmissionGet::submit(const css::uno::Reference< css::task::XInteractionHandler >& aInteractionHandler)
45 // GET always uses application/x-www-formurlencoded
46 CSerializationURLEncoded aSerialization;
47 aSerialization.setSource(m_aFragment);
48 aSerialization.serialize();
50 css::uno::Reference< XInputStream > aInStream = aSerialization.getInputStream();
52 // create a commandEnvironment and use the default interaction handler
53 rtl::Reference<CCommandEnvironmentHelper> pHelper = new CCommandEnvironmentHelper;
54 if( aInteractionHandler.is() )
55 pHelper->m_aInteractionHandler = aInteractionHandler;
56 else
57 pHelper->m_aInteractionHandler.set(
58 css::task::InteractionHandler::createWithParent(m_xContext, nullptr), UNO_QUERY_THROW);
59 rtl::Reference<CProgressHandlerHelper> pProgressHelper = new CProgressHandlerHelper;
60 pHelper->m_aProgressHandler.set(pProgressHelper);
62 // UCB has ownership of environment...
63 css::uno::Reference< XCommandEnvironment > aEnvironment(pHelper);
65 // append query string to the URL
66 try {
67 OStringBuffer aUTF8QueryURL(OUStringToOString(m_aURLObj.GetMainURL(INetURLObject::DecodeMechanism::NONE),
68 RTL_TEXTENCODING_UTF8));
69 OStringBuffer aQueryString;
71 const sal_Int32 size = 1024;
72 sal_Int32 n = 0;
73 Sequence< sal_Int8 > aByteBuffer(size);
74 while ((n = aInStream->readSomeBytes(aByteBuffer, size-1)) != 0)
75 aQueryString.append(reinterpret_cast<char const *>(aByteBuffer.getConstArray()), n);
76 if (!aQueryString.isEmpty() && m_aURLObj.GetProtocol() != INetProtocol::File)
78 aUTF8QueryURL.append("?" + aQueryString);
80 OUString aQueryURL = OStringToOUString(aUTF8QueryURL, RTL_TEXTENCODING_UTF8);
81 ucbhelper::Content aContent(aQueryURL, aEnvironment, m_xContext);
82 // get reply
83 try {
84 m_aResultStream = aContent.openStream();
85 } catch (const Exception&) {
86 OSL_FAIL("Cannot open reply stream from content");
88 } catch (const Exception&)
90 // XXX
91 TOOLS_WARN_EXCEPTION( "forms.misc", "Exception during UCB operation.");
92 return UNKNOWN_ERROR;
95 return SUCCESS;
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */