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