1dde7d3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3dde7d3faSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4dde7d3faSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5dde7d3faSAndrew Rist  * distributed with this work for additional information
6dde7d3faSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7dde7d3faSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8dde7d3faSAndrew Rist  * "License"); you may not use this file except in compliance
9dde7d3faSAndrew Rist  * with the License.  You may obtain a copy of the License at
10dde7d3faSAndrew Rist  *
11dde7d3faSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12dde7d3faSAndrew Rist  *
13dde7d3faSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14dde7d3faSAndrew Rist  * software distributed under the License is distributed on an
15dde7d3faSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16dde7d3faSAndrew Rist  * KIND, either express or implied.  See the License for the
17dde7d3faSAndrew Rist  * specific language governing permissions and limitations
18dde7d3faSAndrew Rist  * under the License.
19dde7d3faSAndrew Rist  *
20dde7d3faSAndrew Rist  *************************************************************/
21dde7d3faSAndrew Rist 
22dde7d3faSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx>
27cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
28cdf0e10cSrcweir #include <comphelper/stillreadwriteinteraction.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp>
31cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
32cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
33cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
34cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
35cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
38cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
39cdf0e10cSrcweir #include <com/sun/star/ucb/InteractiveIOException.hpp>
40cdf0e10cSrcweir #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
41cdf0e10cSrcweir #include <com/sun/star/ucb/CommandFailedException.hpp>
42cdf0e10cSrcweir #include <com/sun/star/task/XInteractionAbort.hpp>
43cdf0e10cSrcweir #include <com/sun/star/uri/XUriReferenceFactory.hpp>
44cdf0e10cSrcweir #include <com/sun/star/uri/XUriReference.hpp>
45cdf0e10cSrcweir #include <com/sun/star/ucb/PostCommandArgument2.hpp>
46cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <ucbhelper/interceptedinteraction.hxx>
49cdf0e10cSrcweir #include <ucbhelper/content.hxx>
50cdf0e10cSrcweir #include <ucbhelper/commandenvironment.hxx>
51cdf0e10cSrcweir #include <ucbhelper/activedatasink.hxx>
52cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
53cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //_______________________________________________
58cdf0e10cSrcweir // namespace
59cdf0e10cSrcweir 
60cdf0e10cSrcweir namespace comphelper{
61cdf0e10cSrcweir 
62cdf0e10cSrcweir namespace css = ::com::sun::star;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //_______________________________________________
65cdf0e10cSrcweir // definitions
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /*-----------------------------------------------
68cdf0e10cSrcweir     10.03.2004 07:35
69cdf0e10cSrcweir -----------------------------------------------*/
PROP_ABORTED()70cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_ABORTED()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Aborted"));
73cdf0e10cSrcweir     return sProp;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
PROP_ASTEMPLATE()76cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_ASTEMPLATE()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("AsTemplate"));
79cdf0e10cSrcweir     return sProp;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
PROP_CHARACTERSET()82cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_CHARACTERSET()
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("CharacterSet"));
85cdf0e10cSrcweir     return sProp;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
PROP_COMPONENTDATA()88cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_COMPONENTDATA()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ComponentData"));
91cdf0e10cSrcweir     return sProp;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
PROP_DEEPDETECTION()94cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DEEPDETECTION()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DeepDetection"));
97cdf0e10cSrcweir     return sProp;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
PROP_DETECTSERVICE()100cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DETECTSERVICE()
101cdf0e10cSrcweir {
102cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DetectService"));
103cdf0e10cSrcweir     return sProp;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
PROP_DOCUMENTSERVICE()106cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTSERVICE()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentService"));
109cdf0e10cSrcweir     return sProp;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
PROP_ENCRYPTIONDATA()112cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_ENCRYPTIONDATA()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("EncryptionData"));
115cdf0e10cSrcweir     return sProp;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
PROP_EXTENSION()118cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_EXTENSION()
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Extension"));
121cdf0e10cSrcweir     return sProp;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
PROP_FILENAME()124cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FILENAME()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FileName"));
127cdf0e10cSrcweir     return sProp;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
PROP_FILTERNAME()130cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FILTERNAME()
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FilterName"));
133cdf0e10cSrcweir     return sProp;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
PROP_FILTEROPTIONS()136cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FILTEROPTIONS()
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FilterOptions"));
139cdf0e10cSrcweir     return sProp;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
PROP_FORMAT()142cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FORMAT()
143cdf0e10cSrcweir {
144cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Format"));
145cdf0e10cSrcweir     return sProp;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
PROP_FRAME()148cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FRAME()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Frame"));
151cdf0e10cSrcweir     return sProp;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
PROP_FRAMENAME()154cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_FRAMENAME()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("FrameName"));
157cdf0e10cSrcweir     return sProp;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
PROP_HIDDEN()160cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_HIDDEN()
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Hidden"));
163cdf0e10cSrcweir     return sProp;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
PROP_INPUTSTREAM()166cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_INPUTSTREAM()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("InputStream"));
169cdf0e10cSrcweir     return sProp;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
PROP_INTERACTIONHANDLER()172cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_INTERACTIONHANDLER()
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("InteractionHandler"));
175cdf0e10cSrcweir     return sProp;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
PROP_AUTHENTICATIONHANDLER()178*3edf6992SAndrea Pescetti const ::rtl::OUString& MediaDescriptor::PROP_AUTHENTICATIONHANDLER()
179*3edf6992SAndrea Pescetti {
180*3edf6992SAndrea Pescetti     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("AuthenticationHandler"));
181*3edf6992SAndrea Pescetti     return sProp;
182*3edf6992SAndrea Pescetti }
183*3edf6992SAndrea Pescetti 
PROP_JUMPMARK()184cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_JUMPMARK()
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("JumpMark"));
187cdf0e10cSrcweir     return sProp;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
PROP_MACROEXECUTIONMODE()190cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_MACROEXECUTIONMODE()
191cdf0e10cSrcweir {
192cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode"));
193cdf0e10cSrcweir     return sProp;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
PROP_MEDIATYPE()196cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_MEDIATYPE()
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("MediaType"));
199cdf0e10cSrcweir     return sProp;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
PROP_MINIMIZED()202cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_MINIMIZED()
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Minimized"));
205cdf0e10cSrcweir     return sProp;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
PROP_NOAUTOSAVE()208cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_NOAUTOSAVE()
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("NoAutoSave"));
211cdf0e10cSrcweir     return sProp;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
PROP_OPENNEWVIEW()214cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_OPENNEWVIEW()
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("OpenNewView"));
217cdf0e10cSrcweir     return sProp;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
PROP_OUTPUTSTREAM()220cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_OUTPUTSTREAM()
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("OutputStream"));
223cdf0e10cSrcweir     return sProp;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
PROP_PATTERN()226cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_PATTERN()
227cdf0e10cSrcweir {
228cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Pattern"));
229cdf0e10cSrcweir     return sProp;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
PROP_POSSIZE()232cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_POSSIZE()
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PosSize"));
235cdf0e10cSrcweir     return sProp;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
PROP_POSTDATA()238cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_POSTDATA()
239cdf0e10cSrcweir {
240cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PostData"));
241cdf0e10cSrcweir     return sProp;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir 
PROP_POSTSTRING()244cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_POSTSTRING()
245cdf0e10cSrcweir {
246cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("PostString"));
247cdf0e10cSrcweir     return sProp;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
PROP_PREVIEW()250cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_PREVIEW()
251cdf0e10cSrcweir {
252cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Preview"));
253cdf0e10cSrcweir     return sProp;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir 
PROP_READONLY()256cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_READONLY()
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ReadOnly"));
259cdf0e10cSrcweir     return sProp;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
PROP_REFERRER()262cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_REFERRER()
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Referer"));
265cdf0e10cSrcweir     return sProp;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir 
PROP_SILENT()268cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_SILENT()
269cdf0e10cSrcweir {
270cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Silent"));
271cdf0e10cSrcweir     return sProp;
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
PROP_STATUSINDICATOR()274cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_STATUSINDICATOR()
275cdf0e10cSrcweir {
276cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("StatusIndicator"));
277cdf0e10cSrcweir     return sProp;
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
PROP_STREAM()280cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_STREAM()
281cdf0e10cSrcweir {
282cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Stream"));
283cdf0e10cSrcweir     return sProp;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
PROP_STREAMFOROUTPUT()286cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_STREAMFOROUTPUT()
287cdf0e10cSrcweir {
288cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("StreamForOutput"));
289cdf0e10cSrcweir     return sProp;
290cdf0e10cSrcweir }
291cdf0e10cSrcweir 
PROP_TEMPLATENAME()292cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_TEMPLATENAME()
293cdf0e10cSrcweir {
294cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TemplateName"));
295cdf0e10cSrcweir     return sProp;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
PROP_TEMPLATEREGIONNAME()298cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_TEMPLATEREGIONNAME()
299cdf0e10cSrcweir {
300cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TemplateRegionName"));
301cdf0e10cSrcweir     return sProp;
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
PROP_TYPENAME()304cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_TYPENAME()
305cdf0e10cSrcweir {
306cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("TypeName"));
307cdf0e10cSrcweir     return sProp;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
PROP_UCBCONTENT()310cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_UCBCONTENT()
311cdf0e10cSrcweir {
312cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("UCBContent"));
313cdf0e10cSrcweir     return sProp;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
PROP_UPDATEDOCMODE()316cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_UPDATEDOCMODE()
317cdf0e10cSrcweir {
318cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("UpdateDocMode"));
319cdf0e10cSrcweir     return sProp;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
PROP_URL()322cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_URL()
323cdf0e10cSrcweir {
324cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("URL"));
325cdf0e10cSrcweir     return sProp;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
PROP_VERSION()328cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_VERSION()
329cdf0e10cSrcweir {
330cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Version"));
331cdf0e10cSrcweir     return sProp;
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
PROP_VIEWID()334cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_VIEWID()
335cdf0e10cSrcweir {
336cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewId"));
337cdf0e10cSrcweir     return sProp;
338cdf0e10cSrcweir }
339cdf0e10cSrcweir 
PROP_REPAIRPACKAGE()340cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_REPAIRPACKAGE()
341cdf0e10cSrcweir {
342cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("RepairPackage"));
343cdf0e10cSrcweir     return sProp;
344cdf0e10cSrcweir }
345cdf0e10cSrcweir 
PROP_DOCUMENTTITLE()346cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTTITLE()
347cdf0e10cSrcweir {
348cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentTitle"));
349cdf0e10cSrcweir     return sProp;
350cdf0e10cSrcweir }
351cdf0e10cSrcweir 
PROP_MODEL()352cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_MODEL()
353cdf0e10cSrcweir {
354cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Model"));
355cdf0e10cSrcweir     return sProp;
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
PROP_PASSWORD()358cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_PASSWORD()
359cdf0e10cSrcweir {
360cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Password"));
361cdf0e10cSrcweir     return sProp;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir 
PROP_TITLE()364cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_TITLE()
365cdf0e10cSrcweir {
366cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("Title"));
367cdf0e10cSrcweir     return sProp;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
PROP_SALVAGEDFILE()370cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_SALVAGEDFILE()
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("SalvagedFile"));
373cdf0e10cSrcweir     return sProp;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
PROP_VIEWONLY()376cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_VIEWONLY()
377cdf0e10cSrcweir {
378cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewOnly"));
379cdf0e10cSrcweir     return sProp;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
PROP_DOCUMENTBASEURL()382cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_DOCUMENTBASEURL()
383cdf0e10cSrcweir {
384cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("DocumentBaseURL"));
385cdf0e10cSrcweir     return sProp;
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
PROP_VIEWCONTROLLERNAME()388cdf0e10cSrcweir const ::rtl::OUString& MediaDescriptor::PROP_VIEWCONTROLLERNAME()
389cdf0e10cSrcweir {
390cdf0e10cSrcweir     static const ::rtl::OUString sProp(RTL_CONSTASCII_USTRINGPARAM("ViewControllerName"));
391cdf0e10cSrcweir     return sProp;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir /*-----------------------------------------------
394cdf0e10cSrcweir     10.03.2004 08:09
395cdf0e10cSrcweir -----------------------------------------------*/
MediaDescriptor()396cdf0e10cSrcweir MediaDescriptor::MediaDescriptor()
397cdf0e10cSrcweir     : SequenceAsHashMap()
398cdf0e10cSrcweir {
399cdf0e10cSrcweir }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir /*-----------------------------------------------
402cdf0e10cSrcweir     10.03.2004 08:09
403cdf0e10cSrcweir -----------------------------------------------*/
MediaDescriptor(const css::uno::Any & aSource)404cdf0e10cSrcweir MediaDescriptor::MediaDescriptor(const css::uno::Any& aSource)
405cdf0e10cSrcweir     : SequenceAsHashMap(aSource)
406cdf0e10cSrcweir {
407cdf0e10cSrcweir }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir /*-----------------------------------------------
410cdf0e10cSrcweir     10.03.2004 08:09
411cdf0e10cSrcweir -----------------------------------------------*/
MediaDescriptor(const css::uno::Sequence<css::beans::PropertyValue> & lSource)412cdf0e10cSrcweir MediaDescriptor::MediaDescriptor(const css::uno::Sequence< css::beans::PropertyValue >& lSource)
413cdf0e10cSrcweir     : SequenceAsHashMap(lSource)
414cdf0e10cSrcweir {
415cdf0e10cSrcweir }
416cdf0e10cSrcweir 
417cdf0e10cSrcweir /*-----------------------------------------------
418cdf0e10cSrcweir     10.03.2004 08:09
419cdf0e10cSrcweir -----------------------------------------------*/
MediaDescriptor(const css::uno::Sequence<css::beans::NamedValue> & lSource)420cdf0e10cSrcweir MediaDescriptor::MediaDescriptor(const css::uno::Sequence< css::beans::NamedValue >& lSource)
421cdf0e10cSrcweir     : SequenceAsHashMap(lSource)
422cdf0e10cSrcweir {
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir /*-----------------------------------------------
426cdf0e10cSrcweir     18.11.2004 13:37
427cdf0e10cSrcweir -----------------------------------------------*/
isStreamReadOnly() const428cdf0e10cSrcweir sal_Bool MediaDescriptor::isStreamReadOnly() const
429cdf0e10cSrcweir {
430cdf0e10cSrcweir     static ::rtl::OUString CONTENTSCHEME_FILE     = ::rtl::OUString::createFromAscii("file");
431cdf0e10cSrcweir     static ::rtl::OUString CONTENTPROP_ISREADONLY = ::rtl::OUString::createFromAscii("IsReadOnly");
432cdf0e10cSrcweir     static sal_Bool        READONLY_FALLBACK      = sal_False;
433cdf0e10cSrcweir 
434cdf0e10cSrcweir     sal_Bool bReadOnly = READONLY_FALLBACK;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir     // check for explicit readonly state
437cdf0e10cSrcweir     const_iterator pIt = find(MediaDescriptor::PROP_READONLY());
438cdf0e10cSrcweir     if (pIt != end())
439cdf0e10cSrcweir     {
440cdf0e10cSrcweir 		pIt->second >>= bReadOnly;
441cdf0e10cSrcweir         return bReadOnly;
442cdf0e10cSrcweir     }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir     // streams based on post data are readonly by definition
445cdf0e10cSrcweir     pIt = find(MediaDescriptor::PROP_POSTDATA());
446cdf0e10cSrcweir     if (pIt != end())
447cdf0e10cSrcweir         return sal_True;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     // A XStream capsulate XInputStream and XOutputStream ...
450cdf0e10cSrcweir     // If it exists - the file must be open in read/write mode!
451cdf0e10cSrcweir     pIt = find(MediaDescriptor::PROP_STREAM());
452cdf0e10cSrcweir     if (pIt != end())
453cdf0e10cSrcweir         return sal_False;
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     // Only file system content provider is able to provide XStream
456cdf0e10cSrcweir     // so for this content impossibility to create XStream triggers
457cdf0e10cSrcweir     // switch to readonly mode.
458cdf0e10cSrcweir     try
459cdf0e10cSrcweir     {
460cdf0e10cSrcweir         css::uno::Reference< css::ucb::XContent > xContent = getUnpackedValueOrDefault(MediaDescriptor::PROP_UCBCONTENT(), css::uno::Reference< css::ucb::XContent >());
461cdf0e10cSrcweir         if (xContent.is())
462cdf0e10cSrcweir         {
463cdf0e10cSrcweir             css::uno::Reference< css::ucb::XContentIdentifier > xId(xContent->getIdentifier(), css::uno::UNO_QUERY);
464cdf0e10cSrcweir             ::rtl::OUString aScheme;
465cdf0e10cSrcweir             if (xId.is())
466cdf0e10cSrcweir                 aScheme = xId->getContentProviderScheme();
467cdf0e10cSrcweir 
468cdf0e10cSrcweir             if (aScheme.equalsIgnoreAsciiCase(CONTENTSCHEME_FILE))
469cdf0e10cSrcweir                 bReadOnly = sal_True;
470cdf0e10cSrcweir             else
471cdf0e10cSrcweir             {
472cdf0e10cSrcweir                 ::ucbhelper::Content aContent(xContent, css::uno::Reference< css::ucb::XCommandEnvironment >());
473cdf0e10cSrcweir                 aContent.getPropertyValue(CONTENTPROP_ISREADONLY) >>= bReadOnly;
474cdf0e10cSrcweir             }
475cdf0e10cSrcweir         }
476cdf0e10cSrcweir     }
477cdf0e10cSrcweir     catch(const css::uno::RuntimeException& exRun)
478cdf0e10cSrcweir         { throw exRun; }
479cdf0e10cSrcweir     catch(const css::uno::Exception&)
480cdf0e10cSrcweir         {}
481cdf0e10cSrcweir 
482cdf0e10cSrcweir     return bReadOnly;
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir // ----------------------------------------------------------------------------
486cdf0e10cSrcweir 
getComponentDataEntry(const::rtl::OUString & rName) const487cdf0e10cSrcweir css::uno::Any MediaDescriptor::getComponentDataEntry( const ::rtl::OUString& rName ) const
488cdf0e10cSrcweir {
489cdf0e10cSrcweir     css::uno::Any aEntry;
490cdf0e10cSrcweir     SequenceAsHashMap::const_iterator aPropertyIter = find( PROP_COMPONENTDATA() );
491cdf0e10cSrcweir     if( aPropertyIter != end() )
492cdf0e10cSrcweir         return NamedValueCollection( aPropertyIter->second ).get( rName );
493cdf0e10cSrcweir     return css::uno::Any();
494cdf0e10cSrcweir }
495cdf0e10cSrcweir 
setComponentDataEntry(const::rtl::OUString & rName,const css::uno::Any & rValue)496cdf0e10cSrcweir void MediaDescriptor::setComponentDataEntry( const ::rtl::OUString& rName, const css::uno::Any& rValue )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir     if( rValue.hasValue() )
499cdf0e10cSrcweir     {
500cdf0e10cSrcweir         // get or create the 'ComponentData' property entry
501cdf0e10cSrcweir         css::uno::Any& rCompDataAny = operator[]( PROP_COMPONENTDATA() );
502cdf0e10cSrcweir         // insert the value (retain sequence type, create NamedValue elements by default)
503cdf0e10cSrcweir         bool bHasNamedValues = !rCompDataAny.hasValue() || rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >();
504cdf0e10cSrcweir         bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >();
505cdf0e10cSrcweir         OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::setComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
506cdf0e10cSrcweir         if( bHasNamedValues || bHasPropValues )
507cdf0e10cSrcweir         {
508cdf0e10cSrcweir             // insert or overwrite the passed value
509cdf0e10cSrcweir             SequenceAsHashMap aCompDataMap( rCompDataAny );
510cdf0e10cSrcweir             aCompDataMap[ rName ] = rValue;
511cdf0e10cSrcweir             // write back the sequence (restore sequence with correct element type)
512cdf0e10cSrcweir             rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues );
513cdf0e10cSrcweir         }
514cdf0e10cSrcweir     }
515cdf0e10cSrcweir     else
516cdf0e10cSrcweir     {
517cdf0e10cSrcweir         // if an empty Any is passed, clear the entry
518cdf0e10cSrcweir         clearComponentDataEntry( rName );
519cdf0e10cSrcweir     }
520cdf0e10cSrcweir }
521cdf0e10cSrcweir 
clearComponentDataEntry(const::rtl::OUString & rName)522cdf0e10cSrcweir void MediaDescriptor::clearComponentDataEntry( const ::rtl::OUString& rName )
523cdf0e10cSrcweir {
524cdf0e10cSrcweir     SequenceAsHashMap::iterator aPropertyIter = find( PROP_COMPONENTDATA() );
525cdf0e10cSrcweir     if( aPropertyIter != end() )
526cdf0e10cSrcweir     {
527cdf0e10cSrcweir         css::uno::Any& rCompDataAny = aPropertyIter->second;
528cdf0e10cSrcweir         bool bHasNamedValues = rCompDataAny.has< css::uno::Sequence< css::beans::NamedValue > >();
529cdf0e10cSrcweir         bool bHasPropValues = rCompDataAny.has< css::uno::Sequence< css::beans::PropertyValue > >();
530cdf0e10cSrcweir         OSL_ENSURE( bHasNamedValues || bHasPropValues, "MediaDescriptor::clearComponentDataEntry - incompatible 'ComponentData' property in media descriptor" );
531cdf0e10cSrcweir         if( bHasNamedValues || bHasPropValues )
532cdf0e10cSrcweir         {
533cdf0e10cSrcweir             // remove the value with the passed name
534cdf0e10cSrcweir             SequenceAsHashMap aCompDataMap( rCompDataAny );
535cdf0e10cSrcweir             aCompDataMap.erase( rName );
536cdf0e10cSrcweir             // write back the sequence, or remove it completely if it is empty
537cdf0e10cSrcweir             if( aCompDataMap.empty() )
538cdf0e10cSrcweir                 erase( aPropertyIter );
539cdf0e10cSrcweir             else
540cdf0e10cSrcweir                 rCompDataAny = aCompDataMap.getAsConstAny( bHasPropValues );
541cdf0e10cSrcweir         }
542cdf0e10cSrcweir     }
543cdf0e10cSrcweir }
544cdf0e10cSrcweir 
545cdf0e10cSrcweir /*-----------------------------------------------
546cdf0e10cSrcweir     10.03.2004 09:02
547cdf0e10cSrcweir -----------------------------------------------*/
addInputStream()548cdf0e10cSrcweir sal_Bool MediaDescriptor::addInputStream()
549cdf0e10cSrcweir {
550cdf0e10cSrcweir     return impl_addInputStream( sal_True );
551cdf0e10cSrcweir }
552cdf0e10cSrcweir 
553cdf0e10cSrcweir /*-----------------------------------------------*/
addInputStreamOwnLock()554cdf0e10cSrcweir sal_Bool MediaDescriptor::addInputStreamOwnLock()
555cdf0e10cSrcweir {
556cdf0e10cSrcweir     // Own lock file implementation
557cdf0e10cSrcweir 
558cdf0e10cSrcweir     sal_Bool bUseLock = sal_True; // the system file locking is used per default
559cdf0e10cSrcweir     try
560cdf0e10cSrcweir     {
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 		css::uno::Reference< css::uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig(
563cdf0e10cSrcweir 							::comphelper::getProcessServiceFactory(),
564cdf0e10cSrcweir 							::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
565cdf0e10cSrcweir 							::comphelper::ConfigurationHelper::E_STANDARD );
566cdf0e10cSrcweir 		if ( !xCommonConfig.is() )
567cdf0e10cSrcweir 			throw css::uno::RuntimeException();
568cdf0e10cSrcweir 
569cdf0e10cSrcweir         ::comphelper::ConfigurationHelper::readRelativeKey(
570cdf0e10cSrcweir                 xCommonConfig,
571cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ),
572cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentSystemFileLocking" ) ) ) >>= bUseLock;
573cdf0e10cSrcweir     }
574cdf0e10cSrcweir     catch( const css::uno::Exception& )
575cdf0e10cSrcweir     {
576cdf0e10cSrcweir     }
577cdf0e10cSrcweir 
578cdf0e10cSrcweir     return impl_addInputStream( bUseLock );
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
581cdf0e10cSrcweir /*-----------------------------------------------*/
impl_addInputStream(sal_Bool bLockFile)582cdf0e10cSrcweir sal_Bool MediaDescriptor::impl_addInputStream( sal_Bool bLockFile )
583cdf0e10cSrcweir {
584cdf0e10cSrcweir     // check for an already existing stream item first
585cdf0e10cSrcweir     const_iterator pIt = find(MediaDescriptor::PROP_INPUTSTREAM());
586cdf0e10cSrcweir     if (pIt != end())
587cdf0e10cSrcweir         return sal_True;
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 	try
590cdf0e10cSrcweir 	{
591cdf0e10cSrcweir 		// No stream available - create a new one
592cdf0e10cSrcweir 		// a) data comes as PostData ...
593cdf0e10cSrcweir 		pIt = find(MediaDescriptor::PROP_POSTDATA());
594cdf0e10cSrcweir 		if (pIt != end())
595cdf0e10cSrcweir 		{
596cdf0e10cSrcweir 			const css::uno::Any& rPostData = pIt->second;
597cdf0e10cSrcweir 			css::uno::Reference< css::io::XInputStream > xPostData;
598cdf0e10cSrcweir 			rPostData >>= xPostData;
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 			return impl_openStreamWithPostData( xPostData );
601cdf0e10cSrcweir 		}
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 		// b) ... or we must get it from the given URL
604cdf0e10cSrcweir 		::rtl::OUString sURL = getUnpackedValueOrDefault(MediaDescriptor::PROP_URL(), ::rtl::OUString());
60549b34792SHerbert Dürr 		if ( sURL.isEmpty() )
606cdf0e10cSrcweir 			throw css::uno::Exception(
607cdf0e10cSrcweir 					::rtl::OUString::createFromAscii("Found no URL."),
608cdf0e10cSrcweir 					css::uno::Reference< css::uno::XInterface >());
609cdf0e10cSrcweir 
610cdf0e10cSrcweir         // Parse URL! Only the main part has to be used further. E.g. a jumpmark can make trouble
611cdf0e10cSrcweir         ::rtl::OUString sNormalizedURL = impl_normalizeURL( sURL );
612cdf0e10cSrcweir 		return impl_openStreamWithURL( sNormalizedURL, bLockFile );
613cdf0e10cSrcweir 	}
614cdf0e10cSrcweir #if OSL_DEBUG_LEVEL>0
615cdf0e10cSrcweir 	catch(const css::uno::Exception& ex)
616cdf0e10cSrcweir 	{
617cdf0e10cSrcweir 		::rtl::OUStringBuffer sMsg(256);
618cdf0e10cSrcweir 		sMsg.appendAscii("Invalid MediaDescriptor detected:\n");
619cdf0e10cSrcweir 		sMsg.append		(ex.Message							  );
620cdf0e10cSrcweir 		OSL_ENSURE(sal_False, ::rtl::OUStringToOString(sMsg.makeStringAndClear(), RTL_TEXTENCODING_UTF8).getStr());
621cdf0e10cSrcweir 	}
622cdf0e10cSrcweir #else
623cdf0e10cSrcweir 	catch(const css::uno::Exception&)
624cdf0e10cSrcweir 		{}
625cdf0e10cSrcweir #endif
626cdf0e10cSrcweir 
627cdf0e10cSrcweir 	return sal_False;
628cdf0e10cSrcweir }
629cdf0e10cSrcweir 
630cdf0e10cSrcweir /*-----------------------------------------------
631cdf0e10cSrcweir     25.03.2004 12:38
632cdf0e10cSrcweir -----------------------------------------------*/
impl_openStreamWithPostData(const css::uno::Reference<css::io::XInputStream> & _rxPostData)633cdf0e10cSrcweir sal_Bool MediaDescriptor::impl_openStreamWithPostData( const css::uno::Reference< css::io::XInputStream >& _rxPostData )
634cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
635cdf0e10cSrcweir {
636cdf0e10cSrcweir 	if ( !_rxPostData.is() )
637cdf0e10cSrcweir 		throw css::lang::IllegalArgumentException(
638cdf0e10cSrcweir 				::rtl::OUString::createFromAscii("Found invalid PostData."),
639cdf0e10cSrcweir 				css::uno::Reference< css::uno::XInterface >(), 1);
640cdf0e10cSrcweir 
641cdf0e10cSrcweir 	// PostData can't be used in read/write mode!
642cdf0e10cSrcweir 	(*this)[MediaDescriptor::PROP_READONLY()] <<= sal_True;
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     // prepare the environment
645cdf0e10cSrcweir 	css::uno::Reference< css::task::XInteractionHandler > xInteraction = getUnpackedValueOrDefault(
646cdf0e10cSrcweir 		MediaDescriptor::PROP_INTERACTIONHANDLER(),
647cdf0e10cSrcweir 		css::uno::Reference< css::task::XInteractionHandler >());
648cdf0e10cSrcweir 	css::uno::Reference< css::ucb::XProgressHandler > xProgress;
649cdf0e10cSrcweir     ::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress);
650cdf0e10cSrcweir 	css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY);
651cdf0e10cSrcweir 
652cdf0e10cSrcweir     // media type
653cdf0e10cSrcweir 	::rtl::OUString sMediaType = getUnpackedValueOrDefault(MediaDescriptor::PROP_MEDIATYPE(), ::rtl::OUString());
65449b34792SHerbert Dürr     if ( sMediaType.isEmpty() )
655cdf0e10cSrcweir     {
656cdf0e10cSrcweir         sMediaType = ::rtl::OUString::createFromAscii("application/x-www-form-urlencoded");
657cdf0e10cSrcweir         (*this)[MediaDescriptor::PROP_MEDIATYPE()] <<= sMediaType;
658cdf0e10cSrcweir     }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir     // url
661cdf0e10cSrcweir 	::rtl::OUString sURL( getUnpackedValueOrDefault( PROP_URL(), ::rtl::OUString() ) );
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     css::uno::Reference< css::io::XInputStream > xResultStream;
664cdf0e10cSrcweir     try
665cdf0e10cSrcweir     {
666cdf0e10cSrcweir         // seek PostData stream to the beginning
667cdf0e10cSrcweir         css::uno::Reference< css::io::XSeekable > xSeek( _rxPostData, css::uno::UNO_QUERY );
668cdf0e10cSrcweir         if ( xSeek.is() )
669cdf0e10cSrcweir             xSeek->seek( 0 );
670cdf0e10cSrcweir 
671cdf0e10cSrcweir         // a content for the URL
672cdf0e10cSrcweir         ::ucbhelper::Content aContent( sURL, xCommandEnv );
673cdf0e10cSrcweir 
674cdf0e10cSrcweir         // use post command
675cdf0e10cSrcweir         css::ucb::PostCommandArgument2 aPostArgument;
676cdf0e10cSrcweir         aPostArgument.Source = _rxPostData;
677cdf0e10cSrcweir         css::uno::Reference< css::io::XActiveDataSink > xSink( new ucbhelper::ActiveDataSink );
678cdf0e10cSrcweir         aPostArgument.Sink = xSink;
679cdf0e10cSrcweir         aPostArgument.MediaType = sMediaType;
680cdf0e10cSrcweir         aPostArgument.Referer = getUnpackedValueOrDefault( PROP_REFERRER(), ::rtl::OUString() );
681cdf0e10cSrcweir 
682cdf0e10cSrcweir         ::rtl::OUString sCommandName( RTL_CONSTASCII_USTRINGPARAM( "post" ) );
683cdf0e10cSrcweir         aContent.executeCommand( sCommandName, css::uno::makeAny( aPostArgument ) );
684cdf0e10cSrcweir 
685cdf0e10cSrcweir         // get result
686cdf0e10cSrcweir         xResultStream = xSink->getInputStream();
687cdf0e10cSrcweir     }
688cdf0e10cSrcweir     catch( const css::uno::Exception& )
689cdf0e10cSrcweir     {
690cdf0e10cSrcweir     }
691cdf0e10cSrcweir 
692cdf0e10cSrcweir     // success?
693cdf0e10cSrcweir     if ( !xResultStream.is() )
694cdf0e10cSrcweir     {
695cdf0e10cSrcweir         OSL_ENSURE( false, "no valid reply to the HTTP-Post" );
696cdf0e10cSrcweir         return sal_False;
697cdf0e10cSrcweir     }
698cdf0e10cSrcweir 
699cdf0e10cSrcweir     (*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xResultStream;
700cdf0e10cSrcweir     return sal_True;
701cdf0e10cSrcweir }
702cdf0e10cSrcweir 
703cdf0e10cSrcweir /*-----------------------------------------------*/
704cdf0e10cSrcweir 
705cdf0e10cSrcweir /*-----------------------------------------------
706cdf0e10cSrcweir     25.03.2004 12:29
707cdf0e10cSrcweir -----------------------------------------------*/
impl_openStreamWithURL(const::rtl::OUString & sURL,sal_Bool bLockFile)708cdf0e10cSrcweir sal_Bool MediaDescriptor::impl_openStreamWithURL( const ::rtl::OUString& sURL, sal_Bool bLockFile )
709cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
710cdf0e10cSrcweir {
711cdf0e10cSrcweir     // prepare the environment
712cdf0e10cSrcweir 	css::uno::Reference< css::task::XInteractionHandler > xOrgInteraction = getUnpackedValueOrDefault(
713cdf0e10cSrcweir 		MediaDescriptor::PROP_INTERACTIONHANDLER(),
714cdf0e10cSrcweir 		css::uno::Reference< css::task::XInteractionHandler >());
715*3edf6992SAndrea Pescetti 	css::uno::Reference< css::task::XInteractionHandler > xAuthenticationInteraction = getUnpackedValueOrDefault(
716*3edf6992SAndrea Pescetti 		MediaDescriptor::PROP_AUTHENTICATIONHANDLER(),
717*3edf6992SAndrea Pescetti 		css::uno::Reference< css::task::XInteractionHandler >());
718cdf0e10cSrcweir 
719*3edf6992SAndrea Pescetti     StillReadWriteInteraction* pInteraction = new StillReadWriteInteraction(xOrgInteraction, xAuthenticationInteraction);
720cdf0e10cSrcweir 	css::uno::Reference< css::task::XInteractionHandler > xInteraction(static_cast< css::task::XInteractionHandler* >(pInteraction), css::uno::UNO_QUERY);
721cdf0e10cSrcweir 
722cdf0e10cSrcweir 	css::uno::Reference< css::ucb::XProgressHandler > xProgress;
723cdf0e10cSrcweir     ::ucbhelper::CommandEnvironment* pCommandEnv = new ::ucbhelper::CommandEnvironment(xInteraction, xProgress);
724cdf0e10cSrcweir 	css::uno::Reference< css::ucb::XCommandEnvironment > xCommandEnv(static_cast< css::ucb::XCommandEnvironment* >(pCommandEnv), css::uno::UNO_QUERY);
725cdf0e10cSrcweir 
726cdf0e10cSrcweir     // try to create the content
727cdf0e10cSrcweir 	// no content -> no stream => return immediatly with FALSE
728cdf0e10cSrcweir 	::ucbhelper::Content                      aContent;
729cdf0e10cSrcweir     css::uno::Reference< css::ucb::XContent > xContent;
730cdf0e10cSrcweir     try
731cdf0e10cSrcweir     {
732cdf0e10cSrcweir 		aContent = ::ucbhelper::Content(sURL, xCommandEnv);
733cdf0e10cSrcweir         xContent = aContent.get();
734cdf0e10cSrcweir     }
735cdf0e10cSrcweir     catch(const css::uno::RuntimeException&)
736cdf0e10cSrcweir         { throw; }
737cdf0e10cSrcweir     catch(const css::ucb::ContentCreationException&)
738cdf0e10cSrcweir         { return sal_False; } // TODO error handling
739cdf0e10cSrcweir 	catch(const css::uno::Exception&)
740cdf0e10cSrcweir         { return sal_False; } // TODO error handling
741cdf0e10cSrcweir 
742cdf0e10cSrcweir     // try to open the file in read/write mode
743cdf0e10cSrcweir     // (if its allowed to do so).
744cdf0e10cSrcweir     // But handle errors in a "hidden mode". Because
745cdf0e10cSrcweir     // we try it readonly later - if read/write isnt an option.
746cdf0e10cSrcweir     css::uno::Reference< css::io::XStream >      xStream     ;
747cdf0e10cSrcweir     css::uno::Reference< css::io::XInputStream > xInputStream;
748cdf0e10cSrcweir 
749cdf0e10cSrcweir     sal_Bool bReadOnly = sal_False;
750*3edf6992SAndrea Pescetti     //bModeRequestedExplicitly means 'read/write mode requested explicitly'
751cdf0e10cSrcweir 	sal_Bool bModeRequestedExplicitly = sal_False;
752*3edf6992SAndrea Pescetti     // MediaDescriptor::PROP_READONLY is present only if the mediadescriptor was used at least one time
753*3edf6992SAndrea Pescetti     // that is, it exists if the file was changed from readonly mode to read/write using the GUI interface
754cdf0e10cSrcweir     const_iterator pIt = find(MediaDescriptor::PROP_READONLY());
755cdf0e10cSrcweir     if (pIt != end())
756cdf0e10cSrcweir 	{
757cdf0e10cSrcweir 		pIt->second >>= bReadOnly;
758*3edf6992SAndrea Pescetti         // TODO: thinking a different way: we enable the switch to r/o even though the file
759*3edf6992SAndrea Pescetti         // was requested r/w explicitly (consider the case were we want to open a file in r/w mode (e.g. switching from r/o mode to r/w mode
760*3edf6992SAndrea Pescetti         // according to GUI request) instead of returning an error
761cdf0e10cSrcweir 		bModeRequestedExplicitly = sal_True;
762cdf0e10cSrcweir 	}
763cdf0e10cSrcweir 
764cdf0e10cSrcweir     if ( !bReadOnly && bLockFile )
765cdf0e10cSrcweir     {
766cdf0e10cSrcweir         try
767cdf0e10cSrcweir         {
768cdf0e10cSrcweir             // TODO: use "special" still interaction to supress error messages
769cdf0e10cSrcweir             xStream = aContent.openWriteableStream();
770cdf0e10cSrcweir             if (xStream.is())
771cdf0e10cSrcweir                 xInputStream = xStream->getInputStream();
772cdf0e10cSrcweir         }
773cdf0e10cSrcweir         catch(const css::uno::RuntimeException&)
774cdf0e10cSrcweir             { throw; }
775cdf0e10cSrcweir         catch(const css::uno::Exception&)
776cdf0e10cSrcweir             {
777cdf0e10cSrcweir                 // ignore exception, if reason was problem reasoned on
778cdf0e10cSrcweir                 // open it in WRITEABLE mode! Then we try it READONLY
779cdf0e10cSrcweir                 // later a second time.
780*3edf6992SAndrea Pescetti                 // All other errors must be handled as real error and
781cdf0e10cSrcweir                 // break this method.
782cdf0e10cSrcweir                 if (!pInteraction->wasWriteError() || bModeRequestedExplicitly)
783*3edf6992SAndrea Pescetti                 {
784*3edf6992SAndrea Pescetti                     //-> i126305
785*3edf6992SAndrea Pescetti                     // If the protocol is webdav, then we need to treat the stream as readonly, even if the
786*3edf6992SAndrea Pescetti                     // operation was requested as read/write explicitly (the WebDAV UCB implementation is monodirectional
787*3edf6992SAndrea Pescetti                     // read or write not both at the same time).
788*3edf6992SAndrea Pescetti                     rtl::OUString aScheme;
789*3edf6992SAndrea Pescetti                     css::uno::Reference< css::ucb::XContentIdentifier > xContId(
790*3edf6992SAndrea Pescetti                         aContent.get().is() ? aContent.get()->getIdentifier() : 0 );
791*3edf6992SAndrea Pescetti                     if ( xContId.is() )
792*3edf6992SAndrea Pescetti                         aScheme = xContId->getContentProviderScheme();
793*3edf6992SAndrea Pescetti                     if(!aScheme.equalsIgnoreAsciiCaseAscii( "http" ) && !aScheme.equalsIgnoreAsciiCaseAscii( "https" ))
794*3edf6992SAndrea Pescetti                         return sal_False;
795*3edf6992SAndrea Pescetti                     //<- i126305
796*3edf6992SAndrea Pescetti                 }
797*3edf6992SAndrea Pescetti 
798cdf0e10cSrcweir                 xStream.clear();
799cdf0e10cSrcweir                 xInputStream.clear();
800cdf0e10cSrcweir             }
801cdf0e10cSrcweir     }
802cdf0e10cSrcweir 
803cdf0e10cSrcweir     // If opening of the stream in read/write mode wasnt allowed
804cdf0e10cSrcweir     // or failed by an error - we must try it in readonly mode.
805cdf0e10cSrcweir     if (!xInputStream.is())
806cdf0e10cSrcweir     {
807cdf0e10cSrcweir         rtl::OUString aScheme;
808cdf0e10cSrcweir 
809cdf0e10cSrcweir 		try
810cdf0e10cSrcweir 		{
811cdf0e10cSrcweir 			css::uno::Reference< css::ucb::XContentIdentifier > xContId(
812cdf0e10cSrcweir 				aContent.get().is() ? aContent.get()->getIdentifier() : 0 );
813cdf0e10cSrcweir 
814cdf0e10cSrcweir 			if ( xContId.is() )
815cdf0e10cSrcweir 				aScheme = xContId->getContentProviderScheme();
816cdf0e10cSrcweir 
817cdf0e10cSrcweir 			// Only file system content provider is able to provide XStream
818cdf0e10cSrcweir 			// so for this content impossibility to create XStream triggers
819cdf0e10cSrcweir 			// switch to readonly mode in case of opening with locking on
820cdf0e10cSrcweir     		if( bLockFile && aScheme.equalsIgnoreAsciiCaseAscii( "file" ) )
821cdf0e10cSrcweir         		bReadOnly = sal_True;
822cdf0e10cSrcweir 			else
823cdf0e10cSrcweir             {
824cdf0e10cSrcweir                 sal_Bool bRequestReadOnly = bReadOnly;
825cdf0e10cSrcweir 				aContent.getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsReadOnly" ) ) ) >>= bReadOnly;
826cdf0e10cSrcweir                 if ( bReadOnly && !bRequestReadOnly && bModeRequestedExplicitly )
827cdf0e10cSrcweir                         return sal_False; // the document is explicitly requested with WRITEABLE mode
828cdf0e10cSrcweir             }
829cdf0e10cSrcweir 		}
830cdf0e10cSrcweir         catch(const css::uno::RuntimeException&)
831cdf0e10cSrcweir             { throw; }
832cdf0e10cSrcweir         catch(const css::uno::Exception&)
833cdf0e10cSrcweir             { /* no error handling if IsReadOnly property does not exist for UCP */ }
834cdf0e10cSrcweir 
835cdf0e10cSrcweir 		if ( bReadOnly )
836cdf0e10cSrcweir        		(*this)[MediaDescriptor::PROP_READONLY()] <<= bReadOnly;
837cdf0e10cSrcweir 
838cdf0e10cSrcweir         pInteraction->resetInterceptions();
839cdf0e10cSrcweir         pInteraction->resetErrorStates();
840cdf0e10cSrcweir         try
841cdf0e10cSrcweir         {
842cdf0e10cSrcweir             // all the contents except file-URLs should be opened as usual
843cdf0e10cSrcweir             if ( bLockFile || !aScheme.equalsIgnoreAsciiCaseAscii( "file" ) )
844cdf0e10cSrcweir                 xInputStream = aContent.openStream();
845cdf0e10cSrcweir             else
846cdf0e10cSrcweir                 xInputStream = aContent.openStreamNoLock();
847cdf0e10cSrcweir         }
848cdf0e10cSrcweir         catch(const css::uno::RuntimeException&)
849cdf0e10cSrcweir             { throw; }
850cdf0e10cSrcweir         catch(const css::uno::Exception&)
851cdf0e10cSrcweir             { return sal_False; }
852cdf0e10cSrcweir     }
853cdf0e10cSrcweir 
854cdf0e10cSrcweir     // add streams to the descriptor
855cdf0e10cSrcweir     if (xContent.is())
856cdf0e10cSrcweir         (*this)[MediaDescriptor::PROP_UCBCONTENT()] <<= xContent;
857cdf0e10cSrcweir     if (xStream.is())
858cdf0e10cSrcweir         (*this)[MediaDescriptor::PROP_STREAM()] <<= xStream;
859cdf0e10cSrcweir     if (xInputStream.is())
860cdf0e10cSrcweir         (*this)[MediaDescriptor::PROP_INPUTSTREAM()] <<= xInputStream;
861cdf0e10cSrcweir 
862cdf0e10cSrcweir     // At least we need an input stream. The r/w stream is optional ...
863cdf0e10cSrcweir     return xInputStream.is();
864cdf0e10cSrcweir }
865cdf0e10cSrcweir 
866cdf0e10cSrcweir /*-----------------------------------------------
867cdf0e10cSrcweir     10.09.2004 10:51
868cdf0e10cSrcweir -----------------------------------------------*/
impl_normalizeURL(const::rtl::OUString & sURL)869cdf0e10cSrcweir ::rtl::OUString MediaDescriptor::impl_normalizeURL(const ::rtl::OUString& sURL)
870cdf0e10cSrcweir {
871cdf0e10cSrcweir     /* Remove Jumpmarks (fragments) of an URL only here.
872cdf0e10cSrcweir        They are not part of any URL and as a result may be
873cdf0e10cSrcweir        no ucb content can be created then.
874cdf0e10cSrcweir        On the other side arguments must exists ... because
875cdf0e10cSrcweir        they are part of an URL.
876cdf0e10cSrcweir 
877cdf0e10cSrcweir        Do not use the URLTransformer service here. Because
878cdf0e10cSrcweir        it parses the URL in another way. It's main part isnt enough
879cdf0e10cSrcweir        and it's complete part contains the jumpmark (fragment) parameter ...
880cdf0e10cSrcweir     */
881cdf0e10cSrcweir     static ::rtl::OUString SERVICENAME_URIREFERENCEFACTORY = ::rtl::OUString::createFromAscii("com.sun.star.uri.UriReferenceFactory");
882cdf0e10cSrcweir 
883cdf0e10cSrcweir     try
884cdf0e10cSrcweir     {
885cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR      = ::comphelper::getProcessServiceFactory();
886cdf0e10cSrcweir         css::uno::Reference< css::uri::XUriReferenceFactory >  xUriFactory(xSMGR->createInstance(SERVICENAME_URIREFERENCEFACTORY), css::uno::UNO_QUERY_THROW);
887cdf0e10cSrcweir         css::uno::Reference< css::uri::XUriReference >         xUriRef    = xUriFactory->parse(sURL);
888cdf0e10cSrcweir         if (xUriRef.is())
889cdf0e10cSrcweir         {
890cdf0e10cSrcweir             xUriRef->clearFragment();
891cdf0e10cSrcweir             return xUriRef->getUriReference();
892cdf0e10cSrcweir         }
893cdf0e10cSrcweir     }
894cdf0e10cSrcweir     catch(const css::uno::RuntimeException& exRun)
895cdf0e10cSrcweir         { throw exRun; }
896cdf0e10cSrcweir     catch(const css::uno::Exception&)
897cdf0e10cSrcweir         {}
898cdf0e10cSrcweir 
899cdf0e10cSrcweir     // If an error ocurred ... return the original URL.
900cdf0e10cSrcweir     // It's a try .-)
901cdf0e10cSrcweir     return sURL;
902cdf0e10cSrcweir }
903cdf0e10cSrcweir 
904cdf0e10cSrcweir } // namespace comphelper
905cdf0e10cSrcweir 
906