masterfix DEV300: #i10000# build fix
[LibreOffice.git] / forms / source / xforms / submission / submission_get.cxx
blob57adeda664c74b72747632bf6b69dfd4c9f67819
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_forms.hxx"
31 #include <memory>
33 #include "submission_get.hxx"
34 #include "serialization_app_xml.hxx"
35 #include "serialization_urlencoded.hxx"
37 #include <rtl/strbuf.hxx>
38 #include <rtl/string.hxx>
39 #include <osl/file.hxx>
40 #include <unotools/processfactory.hxx>
41 #include <ucbhelper/content.hxx>
43 using namespace CSS::uno;
44 using namespace CSS::ucb;
45 using namespace CSS::task;
46 using namespace CSS::io;
47 using namespace rtl;
48 using namespace osl;
49 using namespace ucbhelper;
50 using namespace std;
53 CSubmissionGet::CSubmissionGet(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment)
54 : CSubmission(aURL, aFragment)
58 CSubmission::SubmissionResult CSubmissionGet::submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler)
60 // GET always uses apllicatin/x-www-formurlencoded
61 auto_ptr< CSerialization > apSerialization(new CSerializationURLEncoded());
62 apSerialization->setSource(m_aFragment);
63 apSerialization->serialize();
65 CSS::uno::Reference< XInputStream > aInStream = apSerialization->getInputStream();
67 // create a commandEnvironment and use the default interaction handler
68 CCommandEnvironmentHelper *pHelper = new CCommandEnvironmentHelper;
69 if( aInteractionHandler.is() )
70 pHelper->m_aInteractionHandler = aInteractionHandler;
71 else
72 pHelper->m_aInteractionHandler = CSS::uno::Reference< XInteractionHandler >(m_aFactory->createInstance(
73 OUString::createFromAscii("com.sun.star.task.InteractionHandler")), UNO_QUERY);
74 OSL_ENSURE(pHelper->m_aInteractionHandler.is(), "failed to create IntreractionHandler");
75 CProgressHandlerHelper *pProgressHelper = new CProgressHandlerHelper;
76 pHelper->m_aProgressHandler = CSS::uno::Reference< XProgressHandler >(pProgressHelper);
78 // UCB has ownership of environment...
79 CSS::uno::Reference< XCommandEnvironment > aEnvironment(pHelper);
81 // append query string to the URL
82 try {
83 OStringBuffer aUTF8QueryURL(OUStringToOString(m_aURLObj.GetMainURL(INetURLObject::NO_DECODE),
84 RTL_TEXTENCODING_UTF8));
85 OStringBuffer aQueryString;
87 const sal_Int32 size = 1024;
88 sal_Int32 n = 0;
89 Sequence< sal_Int8 > aByteBuffer(size);
90 while ((n = aInStream->readSomeBytes(aByteBuffer, size-1)) != 0)
91 aQueryString.append((sal_Char*)aByteBuffer.getArray(), n);
92 if (aQueryString.getLength() > 0 && m_aURLObj.GetProtocol() != INET_PROT_FILE)
94 aUTF8QueryURL.append('?');
95 aUTF8QueryURL.append(aQueryString.makeStringAndClear());
97 OUString aQueryURL = OStringToOUString(aUTF8QueryURL.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
98 ucbhelper::Content aContent(aQueryURL, aEnvironment);
99 CSS::uno::Reference< XOutputStream > aPipe(m_aFactory->createInstance(
100 OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY_THROW);
101 aContent.openStream(aPipe);
102 // get reply
103 try {
104 m_aResultStream = aContent.openStream();
105 } catch (Exception&) {
106 OSL_ENSURE(sal_False, "Cannot open reply stream from content");
108 } catch (Exception&)
110 // XXX
111 OSL_ENSURE(sal_False, "Exception during UCB operatration.");
112 return UNKNOWN_ERROR;
115 return SUCCESS;