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