Line data Source code
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 <memory>
22 :
23 : #include "submission_get.hxx"
24 : #include "serialization_app_xml.hxx"
25 : #include "serialization_urlencoded.hxx"
26 :
27 : #include <rtl/strbuf.hxx>
28 : #include <rtl/string.hxx>
29 : #include <osl/file.hxx>
30 : #include <comphelper/processfactory.hxx>
31 : #include <ucbhelper/content.hxx>
32 : #include <com/sun/star/io/Pipe.hpp>
33 : #include <com/sun/star/task/InteractionHandler.hpp>
34 :
35 : using namespace CSS::uno;
36 : using namespace CSS::ucb;
37 : using namespace CSS::task;
38 : using namespace CSS::io;
39 : using namespace osl;
40 : using namespace ucbhelper;
41 : using namespace std;
42 :
43 : using ::rtl::OUString;
44 : using ::rtl::OStringToOUString;
45 : using ::rtl::OStringBuffer;
46 :
47 :
48 0 : CSubmissionGet::CSubmissionGet(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment)
49 0 : : CSubmission(aURL, aFragment)
50 : {
51 0 : }
52 :
53 0 : CSubmission::SubmissionResult CSubmissionGet::submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler)
54 : {
55 : // GET always uses apllicatin/x-www-formurlencoded
56 0 : auto_ptr< CSerialization > apSerialization(new CSerializationURLEncoded());
57 0 : apSerialization->setSource(m_aFragment);
58 0 : apSerialization->serialize();
59 :
60 0 : CSS::uno::Reference< XInputStream > aInStream = apSerialization->getInputStream();
61 :
62 : // create a commandEnvironment and use the default interaction handler
63 0 : CCommandEnvironmentHelper *pHelper = new CCommandEnvironmentHelper;
64 0 : if( aInteractionHandler.is() )
65 0 : pHelper->m_aInteractionHandler = aInteractionHandler;
66 : else
67 : pHelper->m_aInteractionHandler.set(
68 0 : CSS::task::InteractionHandler::createWithParent(m_xContext, 0), UNO_QUERY_THROW);
69 0 : CProgressHandlerHelper *pProgressHelper = new CProgressHandlerHelper;
70 0 : pHelper->m_aProgressHandler = CSS::uno::Reference< XProgressHandler >(pProgressHelper);
71 :
72 : // UCB has ownership of environment...
73 0 : CSS::uno::Reference< XCommandEnvironment > aEnvironment(pHelper);
74 :
75 : // append query string to the URL
76 : try {
77 : OStringBuffer aUTF8QueryURL(OUStringToOString(m_aURLObj.GetMainURL(INetURLObject::NO_DECODE),
78 0 : RTL_TEXTENCODING_UTF8));
79 0 : OStringBuffer aQueryString;
80 :
81 0 : const sal_Int32 size = 1024;
82 0 : sal_Int32 n = 0;
83 0 : Sequence< sal_Int8 > aByteBuffer(size);
84 0 : while ((n = aInStream->readSomeBytes(aByteBuffer, size-1)) != 0)
85 0 : aQueryString.append((sal_Char*)aByteBuffer.getArray(), n);
86 0 : if (aQueryString.getLength() > 0 && m_aURLObj.GetProtocol() != INET_PROT_FILE)
87 : {
88 0 : aUTF8QueryURL.append('?');
89 0 : aUTF8QueryURL.append(aQueryString.makeStringAndClear());
90 : }
91 0 : OUString aQueryURL = OStringToOUString(aUTF8QueryURL.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
92 0 : ucbhelper::Content aContent(aQueryURL, aEnvironment, m_xContext);
93 0 : CSS::uno::Reference< XOutputStream > aPipe( CSS::io::Pipe::create(m_xContext), UNO_QUERY_THROW );
94 0 : aContent.openStream(aPipe);
95 : // get reply
96 : try {
97 0 : m_aResultStream = aContent.openStream();
98 0 : } catch (const Exception&) {
99 : OSL_FAIL("Cannot open reply stream from content");
100 0 : }
101 0 : } catch (const Exception&)
102 : {
103 : // XXX
104 : OSL_FAIL("Exception during UCB operatration.");
105 0 : return UNKNOWN_ERROR;
106 : }
107 :
108 0 : return SUCCESS;
109 : }
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|