1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*24acc546SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*24acc546SAndrew Rist * distributed with this work for additional information
6*24acc546SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*24acc546SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist * with the License. You may obtain a copy of the License at
10*24acc546SAndrew Rist *
11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist *
13*24acc546SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist * software distributed under the License is distributed on an
15*24acc546SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist * KIND, either express or implied. See the License for the
17*24acc546SAndrew Rist * specific language governing permissions and limitations
18*24acc546SAndrew Rist * under the License.
19*24acc546SAndrew Rist *
20*24acc546SAndrew Rist *************************************************************/
21*24acc546SAndrew Rist
22*24acc546SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <memory>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "submission_get.hxx"
30cdf0e10cSrcweir #include "serialization_app_xml.hxx"
31cdf0e10cSrcweir #include "serialization_urlencoded.hxx"
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <rtl/strbuf.hxx>
34cdf0e10cSrcweir #include <rtl/string.hxx>
35cdf0e10cSrcweir #include <osl/file.hxx>
36cdf0e10cSrcweir #include <unotools/processfactory.hxx>
37cdf0e10cSrcweir #include <ucbhelper/content.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir using namespace CSS::uno;
40cdf0e10cSrcweir using namespace CSS::ucb;
41cdf0e10cSrcweir using namespace CSS::task;
42cdf0e10cSrcweir using namespace CSS::io;
43cdf0e10cSrcweir using namespace rtl;
44cdf0e10cSrcweir using namespace osl;
45cdf0e10cSrcweir using namespace ucbhelper;
46cdf0e10cSrcweir using namespace std;
47cdf0e10cSrcweir
48cdf0e10cSrcweir
CSubmissionGet(const rtl::OUString & aURL,const CSS::uno::Reference<CSS::xml::dom::XDocumentFragment> & aFragment)49cdf0e10cSrcweir CSubmissionGet::CSubmissionGet(const rtl::OUString& aURL, const CSS::uno::Reference< CSS::xml::dom::XDocumentFragment >& aFragment)
50cdf0e10cSrcweir : CSubmission(aURL, aFragment)
51cdf0e10cSrcweir {
52cdf0e10cSrcweir }
53cdf0e10cSrcweir
submit(const CSS::uno::Reference<CSS::task::XInteractionHandler> & aInteractionHandler)54cdf0e10cSrcweir CSubmission::SubmissionResult CSubmissionGet::submit(const CSS::uno::Reference< CSS::task::XInteractionHandler >& aInteractionHandler)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir // GET always uses apllicatin/x-www-formurlencoded
57cdf0e10cSrcweir auto_ptr< CSerialization > apSerialization(new CSerializationURLEncoded());
58cdf0e10cSrcweir apSerialization->setSource(m_aFragment);
59cdf0e10cSrcweir apSerialization->serialize();
60cdf0e10cSrcweir
61cdf0e10cSrcweir CSS::uno::Reference< XInputStream > aInStream = apSerialization->getInputStream();
62cdf0e10cSrcweir
63cdf0e10cSrcweir // create a commandEnvironment and use the default interaction handler
64cdf0e10cSrcweir CCommandEnvironmentHelper *pHelper = new CCommandEnvironmentHelper;
65cdf0e10cSrcweir if( aInteractionHandler.is() )
66cdf0e10cSrcweir pHelper->m_aInteractionHandler = aInteractionHandler;
67cdf0e10cSrcweir else
68cdf0e10cSrcweir pHelper->m_aInteractionHandler = CSS::uno::Reference< XInteractionHandler >(m_aFactory->createInstance(
69cdf0e10cSrcweir OUString::createFromAscii("com.sun.star.task.InteractionHandler")), UNO_QUERY);
70cdf0e10cSrcweir OSL_ENSURE(pHelper->m_aInteractionHandler.is(), "failed to create IntreractionHandler");
71cdf0e10cSrcweir CProgressHandlerHelper *pProgressHelper = new CProgressHandlerHelper;
72cdf0e10cSrcweir pHelper->m_aProgressHandler = CSS::uno::Reference< XProgressHandler >(pProgressHelper);
73cdf0e10cSrcweir
74cdf0e10cSrcweir // UCB has ownership of environment...
75cdf0e10cSrcweir CSS::uno::Reference< XCommandEnvironment > aEnvironment(pHelper);
76cdf0e10cSrcweir
77cdf0e10cSrcweir // append query string to the URL
78cdf0e10cSrcweir try {
79cdf0e10cSrcweir OStringBuffer aUTF8QueryURL(OUStringToOString(m_aURLObj.GetMainURL(INetURLObject::NO_DECODE),
80cdf0e10cSrcweir RTL_TEXTENCODING_UTF8));
81cdf0e10cSrcweir OStringBuffer aQueryString;
82cdf0e10cSrcweir
83cdf0e10cSrcweir const sal_Int32 size = 1024;
84cdf0e10cSrcweir sal_Int32 n = 0;
85cdf0e10cSrcweir Sequence< sal_Int8 > aByteBuffer(size);
86cdf0e10cSrcweir while ((n = aInStream->readSomeBytes(aByteBuffer, size-1)) != 0)
87cdf0e10cSrcweir aQueryString.append((sal_Char*)aByteBuffer.getArray(), n);
88cdf0e10cSrcweir if (aQueryString.getLength() > 0 && m_aURLObj.GetProtocol() != INET_PROT_FILE)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir aUTF8QueryURL.append('?');
91cdf0e10cSrcweir aUTF8QueryURL.append(aQueryString.makeStringAndClear());
92cdf0e10cSrcweir }
93cdf0e10cSrcweir OUString aQueryURL = OStringToOUString(aUTF8QueryURL.makeStringAndClear(), RTL_TEXTENCODING_UTF8);
94cdf0e10cSrcweir ucbhelper::Content aContent(aQueryURL, aEnvironment);
95cdf0e10cSrcweir CSS::uno::Reference< XOutputStream > aPipe(m_aFactory->createInstance(
96cdf0e10cSrcweir OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY_THROW);
97cdf0e10cSrcweir aContent.openStream(aPipe);
98cdf0e10cSrcweir // get reply
99cdf0e10cSrcweir try {
100cdf0e10cSrcweir m_aResultStream = aContent.openStream();
101cdf0e10cSrcweir } catch (Exception&) {
102cdf0e10cSrcweir OSL_ENSURE(sal_False, "Cannot open reply stream from content");
103cdf0e10cSrcweir }
104cdf0e10cSrcweir } catch (Exception&)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir // XXX
107cdf0e10cSrcweir OSL_ENSURE(sal_False, "Exception during UCB operatration.");
108cdf0e10cSrcweir return UNKNOWN_ERROR;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
111cdf0e10cSrcweir return SUCCESS;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
114