LibreOffice Module forms (master) 1
submission_get.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "submission_get.hxx"
23
24#include <rtl/strbuf.hxx>
25#include <osl/diagnose.h>
26#include <ucbhelper/content.hxx>
27#include <com/sun/star/task/InteractionHandler.hpp>
29
30using namespace css::uno;
31using namespace css::ucb;
32using namespace css::task;
33using namespace css::io;
34using namespace osl;
35using namespace ucbhelper;
36
37
38CSubmissionGet::CSubmissionGet(std::u16string_view aURL, const css::uno::Reference< css::xml::dom::XDocumentFragment >& aFragment)
39 : CSubmission(aURL, aFragment)
40{
41}
42
43CSubmission::SubmissionResult CSubmissionGet::submit(const css::uno::Reference< css::task::XInteractionHandler >& aInteractionHandler)
44{
45 // GET always uses application/x-www-formurlencoded
46 CSerializationURLEncoded aSerialization;
47 aSerialization.setSource(m_aFragment);
48 aSerialization.serialize();
49
50 css::uno::Reference< XInputStream > aInStream = aSerialization.getInputStream();
51
52 // create a commandEnvironment and use the default interaction handler
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);
60 pHelper->m_aProgressHandler.set(pProgressHelper);
61
62 // UCB has ownership of environment...
63 css::uno::Reference< XCommandEnvironment > aEnvironment(pHelper);
64
65 // append query string to the URL
66 try {
68 RTL_TEXTENCODING_UTF8));
69 OStringBuffer aQueryString;
70
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)
77 {
78 aUTF8QueryURL.append("?" + aQueryString);
79 }
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");
87 }
88 } catch (const Exception&)
89 {
90 // XXX
91 TOOLS_WARN_EXCEPTION( "forms.misc", "Exception during UCB operation.");
92 return UNKNOWN_ERROR;
93 }
94
95 return SUCCESS;
96}
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void serialize() override
start the serialization process
virtual css::uno::Reference< css::io::XInputStream > getInputStream() override
get the serialized bytes.
void setSource(const css::uno::Reference< css::xml::dom::XDocumentFragment > &aFragment)
sets the XObject that is to serialized
virtual SubmissionResult submit(const css::uno::Reference< css::task::XInteractionHandler > &aInteractionHandler) override
CSubmissionGet(std::u16string_view aURL, const css::uno::Reference< css::xml::dom::XDocumentFragment > &aFragment)
INetURLObject m_aURLObj
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Reference< css::xml::dom::XDocumentFragment > m_aFragment
css::uno::Reference< css::io::XInputStream > m_aResultStream
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
css::uno::Reference< css::io::XInputStream > openStream()
#define TOOLS_WARN_EXCEPTION(area, stream)
URL aURL
sal_Int64 n
size
@ Exception
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)