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