nss: upgrade to release 3.73
[LibreOffice.git] / forms / source / xforms / submission / submission_get.cxx
blob4939497ec7b952af7e786bc76b5efe1dd2336857
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/io/Pipe.hpp>
28 #include <com/sun/star/task/InteractionHandler.hpp>
30 #include <memory>
32 using namespace css::uno;
33 using namespace css::ucb;
34 using namespace css::task;
35 using namespace css::io;
36 using namespace osl;
37 using namespace ucbhelper;
38 using namespace std;
41 CSubmissionGet::CSubmissionGet(const OUString& aURL, const css::uno::Reference< css::xml::dom::XDocumentFragment >& aFragment)
42 : CSubmission(aURL, aFragment)
46 CSubmission::SubmissionResult CSubmissionGet::submit(const css::uno::Reference< css::task::XInteractionHandler >& aInteractionHandler)
48 // GET always uses application/x-www-formurlencoded
49 std::unique_ptr< CSerialization > apSerialization(new CSerializationURLEncoded());
50 apSerialization->setSource(m_aFragment);
51 apSerialization->serialize();
53 css::uno::Reference< XInputStream > aInStream = apSerialization->getInputStream();
55 // create a commandEnvironment and use the default interaction handler
56 CCommandEnvironmentHelper *pHelper = new CCommandEnvironmentHelper;
57 if( aInteractionHandler.is() )
58 pHelper->m_aInteractionHandler = aInteractionHandler;
59 else
60 pHelper->m_aInteractionHandler.set(
61 css::task::InteractionHandler::createWithParent(m_xContext, nullptr), UNO_QUERY_THROW);
62 CProgressHandlerHelper *pProgressHelper = new CProgressHandlerHelper;
63 pHelper->m_aProgressHandler.set(pProgressHelper);
65 // UCB has ownership of environment...
66 css::uno::Reference< XCommandEnvironment > aEnvironment(pHelper);
68 // append query string to the URL
69 try {
70 OStringBuffer aUTF8QueryURL(OUStringToOString(m_aURLObj.GetMainURL(INetURLObject::DecodeMechanism::NONE),
71 RTL_TEXTENCODING_UTF8));
72 OStringBuffer aQueryString;
74 const sal_Int32 size = 1024;
75 sal_Int32 n = 0;
76 Sequence< sal_Int8 > aByteBuffer(size);
77 while ((n = aInStream->readSomeBytes(aByteBuffer, size-1)) != 0)
78 aQueryString.append(reinterpret_cast<char const *>(aByteBuffer.getConstArray()), n);
79 if (!aQueryString.isEmpty() && m_aURLObj.GetProtocol() != INetProtocol::File)
81 aUTF8QueryURL.append('?');
82 aUTF8QueryURL.append(aQueryString.makeStringAndClear());
84 OUString aQueryURL = OStringToOUString(aUTF8QueryURL.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
85 ucbhelper::Content aContent(aQueryURL, aEnvironment, m_xContext);
86 css::uno::Reference< XOutputStream > aPipe( css::io::Pipe::create(m_xContext), UNO_QUERY_THROW );
87 if (!aContent.openStream(aPipe))
88 return UNKNOWN_ERROR;
89 // get reply
90 try {
91 m_aResultStream = aContent.openStream();
92 } catch (const Exception&) {
93 OSL_FAIL("Cannot open reply stream from content");
95 } catch (const Exception&)
97 // XXX
98 OSL_FAIL("Exception during UCB operatration.");
99 return UNKNOWN_ERROR;
102 return SUCCESS;
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */