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