Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <sfx2/docfile.hxx>
31 : : #include <sfx2/docfilt.hxx>
32 : : #include <sfx2/fcontnr.hxx>
33 : : #include "osl/file.hxx"
34 : : #include "sfx2/app.hxx"
35 : : #include <svl/fstathelper.hxx>
36 : :
37 : : #include "dispatchwatcher.hxx"
38 : : #include <rtl/ustring.hxx>
39 : : #include <tools/string.hxx>
40 : : #include <comphelper/processfactory.hxx>
41 : : #include <comphelper/synchronousdispatch.hxx>
42 : : #include <com/sun/star/util/XCloseable.hpp>
43 : : #include <com/sun/star/util/CloseVetoException.hpp>
44 : : #include <com/sun/star/task/XInteractionHandler.hpp>
45 : : #include <com/sun/star/util/URL.hpp>
46 : : #include <com/sun/star/frame/XDesktop.hpp>
47 : : #include <com/sun/star/container/XEnumeration.hpp>
48 : : #include <com/sun/star/frame/XFramesSupplier.hpp>
49 : : #include <com/sun/star/frame/XDispatch.hpp>
50 : : #include <com/sun/star/frame/XComponentLoader.hpp>
51 : : #include <com/sun/star/beans/PropertyValue.hpp>
52 : : #include <com/sun/star/view/XPrintable.hpp>
53 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
54 : : #include <com/sun/star/util/URLTransformer.hpp>
55 : : #include <com/sun/star/util/XURLTransformer.hpp>
56 : : #include <com/sun/star/document/MacroExecMode.hpp>
57 : : #include <com/sun/star/document/UpdateDocMode.hpp>
58 : : #include <com/sun/star/frame/XStorable.hpp>
59 : :
60 : : #include <tools/urlobj.hxx>
61 : : #include <comphelper/mediadescriptor.hxx>
62 : :
63 : : #include <vector>
64 : : #include <osl/thread.hxx>
65 : : #include <rtl/instance.hxx>
66 : :
67 : : using ::rtl::OUString;
68 : : using namespace ::osl;
69 : : using namespace ::com::sun::star::uno;
70 : : using namespace ::com::sun::star::util;
71 : : using namespace ::com::sun::star::lang;
72 : : using namespace ::com::sun::star::frame;
73 : : using namespace ::com::sun::star::container;
74 : : using namespace ::com::sun::star::beans;
75 : : using namespace ::com::sun::star::view;
76 : :
77 : : namespace desktop
78 : : {
79 : :
80 : : String GetURL_Impl(
81 : : const String& rName, boost::optional< rtl::OUString > const & cwdUrl );
82 : :
83 : 0 : struct DispatchHolder
84 : : {
85 : 0 : DispatchHolder( const URL& rURL, Reference< XDispatch >& rDispatch ) :
86 : 0 : aURL( rURL ), xDispatch( rDispatch ) {}
87 : :
88 : : URL aURL;
89 : : rtl::OUString cwdUrl;
90 : : Reference< XDispatch > xDispatch;
91 : : };
92 : :
93 : 0 : static String impl_GetFilterFromExt( OUString aUrl, SfxFilterFlags nFlags,
94 : : String aAppl )
95 : : {
96 [ # # ]: 0 : String aFilter;
97 : : SfxMedium* pMedium = new SfxMedium( aUrl,
98 [ # # ][ # # ]: 0 : STREAM_STD_READ );
[ # # ][ # # ]
99 : :
100 : 0 : const SfxFilter *pSfxFilter = NULL;
101 [ # # ]: 0 : if( nFlags == SFX_FILTER_EXPORT )
102 : : {
103 [ # # ][ # # ]: 0 : SfxFilterMatcher( aAppl ).GuessFilterIgnoringContent( *pMedium, &pSfxFilter, nFlags, 0 );
[ # # ]
104 : : }
105 : : else
106 : : {
107 [ # # ][ # # ]: 0 : SFX_APP()->GetFilterMatcher().GuessFilter( *pMedium, &pSfxFilter, nFlags, 0 );
[ # # ]
108 : : }
109 : :
110 [ # # ]: 0 : if( pSfxFilter )
111 : : {
112 [ # # ]: 0 : if (nFlags == SFX_FILTER_EXPORT)
113 [ # # ]: 0 : aFilter = pSfxFilter->GetFilterName();
114 : : else
115 [ # # ]: 0 : aFilter = pSfxFilter->GetServiceName();
116 : : }
117 : :
118 [ # # ][ # # ]: 0 : delete pMedium;
119 : 0 : return aFilter;
120 : : }
121 : 0 : static OUString impl_GuessFilter( OUString aUrlIn, OUString aUrlOut )
122 : : {
123 : : /* aAppl can also be set to Factory like scalc, swriter... */
124 [ # # ]: 0 : String aAppl;
125 [ # # ][ # # ]: 0 : aAppl = impl_GetFilterFromExt( aUrlIn, SFX_FILTER_IMPORT, aAppl );
[ # # ][ # # ]
[ # # ]
126 [ # # ][ # # ]: 0 : return impl_GetFilterFromExt( aUrlOut, SFX_FILTER_EXPORT, aAppl );
[ # # ][ # # ]
[ # # ][ # # ]
127 : : }
128 : :
129 : : namespace
130 : : {
131 : : class theWatcherMutex : public rtl::Static<Mutex, theWatcherMutex> {};
132 : : }
133 : :
134 : 192 : Mutex& DispatchWatcher::GetMutex()
135 : : {
136 : 192 : return theWatcherMutex::get();
137 : : }
138 : :
139 : : // Create or get the dispatch watcher implementation. This implementation must be
140 : : // a singleton to prevent access to the framework after it wants to terminate.
141 : 96 : DispatchWatcher* DispatchWatcher::GetDispatchWatcher()
142 : : {
143 [ + - ][ + - ]: 96 : static Reference< XInterface > xDispatchWatcher;
144 : : static DispatchWatcher* pDispatchWatcher = NULL;
145 : :
146 [ + - ]: 96 : if ( !xDispatchWatcher.is() )
147 : : {
148 [ + - ][ + - ]: 96 : ::osl::MutexGuard aGuard( GetMutex() );
149 : :
150 [ + - ]: 96 : if ( !xDispatchWatcher.is() )
151 : : {
152 [ + - ]: 96 : pDispatchWatcher = new DispatchWatcher();
153 : :
154 : : // We have to hold a reference to ourself forever to prevent our own destruction.
155 [ + - ]: 96 : xDispatchWatcher = static_cast< cppu::OWeakObject *>( pDispatchWatcher );
156 [ + - ]: 96 : }
157 : : }
158 : :
159 : 96 : return pDispatchWatcher;
160 : : }
161 : :
162 : :
163 : 96 : DispatchWatcher::DispatchWatcher()
164 [ + - ]: 96 : : m_nRequestCount(0)
165 : : {
166 : 96 : }
167 : :
168 : :
169 [ + - ]: 96 : DispatchWatcher::~DispatchWatcher()
170 : : {
171 [ - + ]: 192 : }
172 : :
173 : :
174 : 96 : sal_Bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequestsList, bool bNoTerminate )
175 : : {
176 [ + - ][ + - ]: 192 : Reference< XComponentLoader > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
177 : 96 : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ),
178 [ + - ][ + - ]: 96 : UNO_QUERY );
[ + - ]
179 : :
180 : 96 : DispatchList::const_iterator p;
181 [ + - ]: 96 : std::vector< DispatchHolder > aDispatches;
182 [ + - ]: 96 : ::rtl::OUString aAsTemplateArg( RTL_CONSTASCII_USTRINGPARAM( "AsTemplate"));
183 : 96 : sal_Bool bSetInputFilter = sal_False;
184 : 96 : ::rtl::OUString aForcedInputFilter;
185 : :
186 [ + - ][ - + ]: 96 : for ( p = aDispatchRequestsList.begin(); p != aDispatchRequestsList.end(); ++p )
187 : : {
188 : 0 : const DispatchRequest& aDispatchRequest = *p;
189 : :
190 : : // create parameter array
191 : 0 : sal_Int32 nCount = 4;
192 [ # # ]: 0 : if ( !aDispatchRequest.aPreselectedFactory.isEmpty() )
193 : 0 : nCount++;
194 : :
195 : : // Set Input Filter
196 [ # # ]: 0 : if ( aDispatchRequest.aRequestType == REQUEST_INFILTER )
197 : : {
198 : 0 : bSetInputFilter = sal_True;
199 : 0 : aForcedInputFilter = aDispatchRequest.aURL;
200 [ # # ]: 0 : OfficeIPCThread::RequestsCompleted( 1 );
201 : 0 : continue;
202 : : }
203 : :
204 : : // we need more properties for a print/print to request
205 [ # # ][ # # ]: 0 : if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
[ # # ][ # # ]
206 : : aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
207 : : aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
208 : : aDispatchRequest.aRequestType == REQUEST_CONVERSION)
209 : 0 : nCount++;
210 : :
211 [ # # ]: 0 : Sequence < PropertyValue > aArgs( nCount );
212 : :
213 : : // mark request as user interaction from outside
214 [ # # ][ # # ]: 0 : aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Referer"));
215 [ # # ][ # # ]: 0 : aArgs[0].Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:OpenEvent"));
[ # # ]
216 : :
217 [ # # ][ # # ]: 0 : if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
[ # # ][ # # ]
218 : : aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
219 : : aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
220 : : aDispatchRequest.aRequestType == REQUEST_CONVERSION)
221 : : {
222 [ # # ][ # # ]: 0 : aArgs[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly"));
223 [ # # ][ # # ]: 0 : aArgs[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OpenNewView"));
224 [ # # ][ # # ]: 0 : aArgs[3].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hidden"));
225 [ # # ][ # # ]: 0 : aArgs[4].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Silent"));
226 : : }
227 : : else
228 : : {
229 : : Reference < com::sun::star::task::XInteractionHandler > xInteraction(
230 [ # # ][ # # ]: 0 : ::comphelper::getProcessServiceFactory()->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.InteractionHandler")) ),
231 [ # # ][ # # ]: 0 : com::sun::star::uno::UNO_QUERY );
[ # # ]
232 : :
233 [ # # ][ # # ]: 0 : aArgs[1].Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ));
234 [ # # ][ # # ]: 0 : aArgs[1].Value <<= xInteraction;
235 : :
236 : 0 : sal_Int16 nMacroExecMode = ::com::sun::star::document::MacroExecMode::USE_CONFIG;
237 [ # # ][ # # ]: 0 : aArgs[2].Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "MacroExecutionMode" ));
238 [ # # ][ # # ]: 0 : aArgs[2].Value <<= nMacroExecMode;
239 : :
240 : 0 : sal_Int16 nUpdateDoc = ::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG;
241 [ # # ][ # # ]: 0 : aArgs[3].Name = OUString(RTL_CONSTASCII_USTRINGPARAM( "UpdateDocMode" ));
242 [ # # ][ # # ]: 0 : aArgs[3].Value <<= nUpdateDoc;
243 : : }
244 : :
245 [ # # ]: 0 : if ( !aDispatchRequest.aPreselectedFactory.isEmpty() )
246 : : {
247 [ # # ][ # # ]: 0 : aArgs[nCount-1].Name = ::comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE();
248 [ # # ][ # # ]: 0 : aArgs[nCount-1].Value <<= aDispatchRequest.aPreselectedFactory;
249 : : }
250 : :
251 [ # # ][ # # ]: 0 : String aName( GetURL_Impl( aDispatchRequest.aURL, aDispatchRequest.aCwdUrl ) );
[ # # ]
252 [ # # ]: 0 : ::rtl::OUString aTarget( RTL_CONSTASCII_USTRINGPARAM("_default") );
253 : :
254 [ # # ][ # # ]: 0 : if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
[ # # ][ # # ]
255 : : aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
256 : : aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
257 : : aDispatchRequest.aRequestType == REQUEST_CONVERSION)
258 : : {
259 : : // documents opened for printing are opened readonly because they must be opened as a new document and this
260 : : // document could be open already
261 [ # # ][ # # ]: 0 : aArgs[1].Value <<= sal_True;
262 : :
263 : : // always open a new document for printing, because it must be disposed afterwards
264 [ # # ][ # # ]: 0 : aArgs[2].Value <<= sal_True;
265 : :
266 : : // printing is done in a hidden view
267 [ # # ][ # # ]: 0 : aArgs[3].Value <<= sal_True;
268 : :
269 : : // load document for printing without user interaction
270 [ # # ][ # # ]: 0 : aArgs[4].Value <<= sal_True;
271 : :
272 : : // hidden documents should never be put into open tasks
273 [ # # ]: 0 : aTarget = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_blank") );
274 : : }
275 : : // load the document ... if they are loadable!
276 : : // Otherwise try to dispatch it ...
277 : 0 : Reference < XPrintable > xDoc;
278 [ # # ][ # # ]: 0 : if(
[ # # ][ # # ]
[ # # ]
279 [ # # ]: 0 : ( aName.CompareToAscii( ".uno" , 4 ) == COMPARE_EQUAL ) ||
280 [ # # ]: 0 : ( aName.CompareToAscii( "slot:" , 5 ) == COMPARE_EQUAL ) ||
281 [ # # ]: 0 : ( aName.CompareToAscii( "macro:", 6 ) == COMPARE_EQUAL ) ||
282 [ # # ]: 0 : ( aName.CompareToAscii("vnd.sun.star.script", 19) == COMPARE_EQUAL)
283 : : )
284 : : {
285 : : // Attention: URL must be parsed full. Otherwise some detections on it will fail!
286 : : // It doesnt matter, if parser isn't available. Because; We try loading of URL then ...
287 : 0 : URL aURL ;
288 [ # # ]: 0 : aURL.Complete = aName;
289 : :
290 : 0 : Reference < XDispatch > xDispatcher ;
291 [ # # ]: 0 : Reference < XDispatchProvider > xProvider ( xDesktop, UNO_QUERY );
292 [ # # ][ # # ]: 0 : Reference < XURLTransformer > xParser ( URLTransformer::create(::comphelper::getProcessComponentContext()) );
293 : :
294 [ # # ]: 0 : if( xParser.is() == sal_True )
295 [ # # ][ # # ]: 0 : xParser->parseStrict( aURL );
296 : :
297 [ # # ]: 0 : if( xProvider.is() == sal_True )
298 [ # # ][ # # ]: 0 : xDispatcher = xProvider->queryDispatch( aURL, ::rtl::OUString(), 0 );
[ # # ]
299 : :
300 [ # # ]: 0 : if( xDispatcher.is() == sal_True )
301 : : {
302 : : {
303 [ # # ][ # # ]: 0 : ::osl::ClearableMutexGuard aGuard( GetMutex() );
304 : : // Remember request so we can find it in statusChanged!
305 [ # # ]: 0 : m_aRequestContainer.insert( DispatchWatcherHashMap::value_type( aURL.Complete, (sal_Int32)1 ) );
306 [ # # ]: 0 : m_nRequestCount++;
307 : : }
308 : :
309 : : // Use local vector to store dispatcher because we have to fill our request container before
310 : : // we can dispatch. Otherwise it would be possible that statusChanged is called before we dispatched all requests!!
311 [ # # ][ # # ]: 0 : aDispatches.push_back( DispatchHolder( aURL, xDispatcher ));
[ # # ]
312 : 0 : }
313 : : }
314 [ # # ][ # # ]: 0 : else if ( ( aName.CompareToAscii( "service:" , 8 ) == COMPARE_EQUAL ) )
315 : : {
316 : : // TODO: the dispatch has to be done for loadComponentFromURL as well. Please ask AS for more details.
317 : 0 : URL aURL ;
318 [ # # ]: 0 : aURL.Complete = aName;
319 : :
320 : 0 : Reference < XDispatch > xDispatcher ;
321 [ # # ]: 0 : Reference < XDispatchProvider > xProvider ( xDesktop, UNO_QUERY );
322 [ # # ][ # # ]: 0 : Reference < XURLTransformer > xParser ( URLTransformer::create(::comphelper::getProcessComponentContext()) );
323 : :
324 [ # # ]: 0 : if( xParser.is() == sal_True )
325 [ # # ][ # # ]: 0 : xParser->parseStrict( aURL );
326 : :
327 [ # # ]: 0 : if( xProvider.is() == sal_True )
328 [ # # ][ # # ]: 0 : xDispatcher = xProvider->queryDispatch( aURL, ::rtl::OUString(), 0 );
[ # # ]
329 : :
330 [ # # ]: 0 : if( xDispatcher.is() == sal_True )
331 : : {
332 : : try
333 : : {
334 : : // We have to be listener to catch errors during dispatching URLs.
335 : : // Otherwise it would be possible to have an office running without an open
336 : : // window!!
337 [ # # ]: 0 : Sequence < PropertyValue > aArgs2(1);
338 [ # # ][ # # ]: 0 : aArgs2[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SynchronMode"));
339 [ # # ][ # # ]: 0 : aArgs2[0].Value <<= sal_True;
340 [ # # ]: 0 : Reference < XNotifyingDispatch > xDisp( xDispatcher, UNO_QUERY );
341 [ # # ]: 0 : if ( xDisp.is() )
342 [ # # ][ # # ]: 0 : xDisp->dispatchWithNotification( aURL, aArgs2, DispatchWatcher::GetDispatchWatcher() );
[ # # ][ # # ]
[ # # ]
343 : : else
344 [ # # ][ # # ]: 0 : xDispatcher->dispatch( aURL, aArgs2 );
[ # # ]
345 : : }
346 [ # # # # ]: 0 : catch (const ::com::sun::star::uno::Exception&)
347 : : {
348 : : OUString aMsg = OUString(RTL_CONSTASCII_USTRINGPARAM(
349 [ # # ]: 0 : "Desktop::OpenDefault() IllegalArgumentException while calling XNotifyingDispatch: "));
350 : 0 : OSL_FAIL( OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
351 : : }
352 : 0 : }
353 : : }
354 : : else
355 : : {
356 [ # # ][ # # ]: 0 : INetURLObject aObj( aName );
357 [ # # ]: 0 : if ( aObj.GetProtocol() == INET_PROT_PRIVATE )
358 [ # # ]: 0 : aTarget = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_default") );
359 : :
360 : : // Set "AsTemplate" argument according to request type
361 [ # # ][ # # ]: 0 : if ( aDispatchRequest.aRequestType == REQUEST_FORCENEW ||
362 : : aDispatchRequest.aRequestType == REQUEST_FORCEOPEN )
363 : : {
364 : 0 : sal_Int32 nIndex = aArgs.getLength();
365 [ # # ]: 0 : aArgs.realloc( nIndex+1 );
366 [ # # ]: 0 : aArgs[nIndex].Name = aAsTemplateArg;
367 [ # # ]: 0 : if ( aDispatchRequest.aRequestType == REQUEST_FORCENEW )
368 [ # # ][ # # ]: 0 : aArgs[nIndex].Value <<= sal_True;
369 : : else
370 [ # # ][ # # ]: 0 : aArgs[nIndex].Value <<= sal_False;
371 : : }
372 : :
373 : : // if we are called in viewmode, open document read-only
374 [ # # ]: 0 : if(aDispatchRequest.aRequestType == REQUEST_VIEW) {
375 : 0 : sal_Int32 nIndex = aArgs.getLength();
376 [ # # ]: 0 : aArgs.realloc(nIndex+1);
377 [ # # ][ # # ]: 0 : aArgs[nIndex].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("ReadOnly"));
378 [ # # ][ # # ]: 0 : aArgs[nIndex].Value <<= sal_True;
379 : : }
380 : :
381 : : // if we are called with -start set Start in mediadescriptor
382 [ # # ]: 0 : if(aDispatchRequest.aRequestType == REQUEST_START) {
383 : 0 : sal_Int32 nIndex = aArgs.getLength();
384 [ # # ]: 0 : aArgs.realloc(nIndex+1);
385 [ # # ][ # # ]: 0 : aArgs[nIndex].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("StartPresentation"));
386 [ # # ][ # # ]: 0 : aArgs[nIndex].Value <<= sal_True;
387 : : }
388 : :
389 : : // Force input filter, if possible
390 [ # # ]: 0 : if( bSetInputFilter )
391 : : {
392 : 0 : sal_Int32 nIndex = aArgs.getLength();
393 [ # # ]: 0 : aArgs.realloc(nIndex+1);
394 [ # # ][ # # ]: 0 : aArgs[nIndex].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("FilterName"));
395 [ # # ][ # # ]: 0 : aArgs[nIndex].Value <<= aForcedInputFilter;
396 : : }
397 : :
398 : : // This is a synchron loading of a component so we don't have to deal with our statusChanged listener mechanism.
399 : : try
400 : : {
401 [ # # ][ # # ]: 0 : xDoc = Reference < XPrintable >( ::comphelper::SynchronousDispatch::dispatch( xDesktop, aName, aTarget, 0, aArgs ), UNO_QUERY );
[ # # ][ # # ]
402 : : }
403 [ # # ]: 0 : catch (const ::com::sun::star::lang::IllegalArgumentException& iae)
404 : : {
405 : : OUString aMsg = OUString(RTL_CONSTASCII_USTRINGPARAM(
406 : : "Dispatchwatcher IllegalArgumentException while calling loadComponentFromURL: "))
407 [ # # ]: 0 : + iae.Message;
408 : 0 : OSL_FAIL( OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
409 : : }
410 [ # # # # : 0 : catch (const com::sun::star::io::IOException& ioe)
# ]
411 : : {
412 : : OUString aMsg = OUString(RTL_CONSTASCII_USTRINGPARAM(
413 : : "Dispatchwatcher IOException while calling loadComponentFromURL: "))
414 [ # # ]: 0 : + ioe.Message;
415 : 0 : OSL_FAIL( OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
416 : : }
417 [ # # ][ # # ]: 0 : if ( aDispatchRequest.aRequestType == REQUEST_OPEN ||
[ # # ][ # # ]
[ # # ]
418 : : aDispatchRequest.aRequestType == REQUEST_VIEW ||
419 : : aDispatchRequest.aRequestType == REQUEST_START ||
420 : : aDispatchRequest.aRequestType == REQUEST_FORCEOPEN ||
421 : : aDispatchRequest.aRequestType == REQUEST_FORCENEW )
422 : : {
423 : : // request is completed
424 [ # # ]: 0 : OfficeIPCThread::RequestsCompleted( 1 );
425 : : }
426 [ # # ][ # # ]: 0 : else if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
[ # # ][ # # ]
427 : : aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
428 : : aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
429 : : aDispatchRequest.aRequestType == REQUEST_CONVERSION )
430 : : {
431 [ # # ]: 0 : if ( xDoc.is() )
432 : : {
433 [ # # ]: 0 : if ( aDispatchRequest.aRequestType == REQUEST_CONVERSION ) {
434 [ # # ]: 0 : Reference< XStorable > xStorable( xDoc, UNO_QUERY );
435 [ # # ]: 0 : if ( xStorable.is() ) {
436 : 0 : rtl::OUString aParam = aDispatchRequest.aPrinterName;
437 : 0 : sal_Int32 nPathIndex = aParam.lastIndexOf( ';' );
438 : 0 : sal_Int32 nFilterIndex = aParam.indexOf( ':' );
439 [ # # ]: 0 : if( nPathIndex < nFilterIndex )
440 : 0 : nFilterIndex = -1;
441 : 0 : rtl::OUString aFilterOut=aParam.copy( nPathIndex+1 );
442 : 0 : rtl::OUString aFilter;
443 : 0 : rtl::OUString aFilterExt;
444 : 0 : sal_Bool bGuess = sal_False;
445 : :
446 [ # # ]: 0 : if( nFilterIndex >= 0 )
447 : : {
448 : 0 : aFilter = aParam.copy( nFilterIndex+1, nPathIndex-nFilterIndex-1 );
449 : 0 : aFilterExt = aParam.copy( 0, nFilterIndex );
450 : : }
451 : : else
452 : : {
453 : : // Guess
454 : 0 : bGuess = sal_True;
455 : 0 : aFilterExt = aParam.copy( 0, nPathIndex );
456 : : }
457 [ # # ]: 0 : INetURLObject aOutFilename( aObj );
458 [ # # ]: 0 : aOutFilename.SetExtension( aFilterExt );
459 [ # # ]: 0 : FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut );
460 : : rtl::OUString aOutFile = aFilterOut+
461 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/" ))+
462 [ # # ][ # # ]: 0 : aOutFilename.getName();
463 : :
464 [ # # ]: 0 : if ( bGuess )
465 : : {
466 [ # # ][ # # ]: 0 : aFilter = impl_GuessFilter( aName, aOutFile );
467 : : }
468 : :
469 [ # # ]: 0 : Sequence<PropertyValue> conversionProperties( 2 );
470 [ # # ][ # # ]: 0 : conversionProperties[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Overwrite" ));
471 [ # # ][ # # ]: 0 : conversionProperties[0].Value <<= sal_True;
472 : :
473 [ # # ][ # # ]: 0 : conversionProperties[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "FilterName" ));
474 [ # # ][ # # ]: 0 : conversionProperties[1].Value <<= aFilter;
475 : :
476 : 0 : rtl::OUString aTempName;
477 [ # # ][ # # ]: 0 : FileBase::getSystemPathFromFileURL( aName, aTempName );
478 [ # # ]: 0 : rtl::OString aSource8 = ::rtl::OUStringToOString ( aTempName, RTL_TEXTENCODING_UTF8 );
479 [ # # ]: 0 : FileBase::getSystemPathFromFileURL( aOutFile, aTempName );
480 [ # # ]: 0 : rtl::OString aTargetURL8 = ::rtl::OUStringToOString(aTempName, RTL_TEXTENCODING_UTF8 );
481 : : printf("convert %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
482 [ # # ][ # # ]: 0 : ::rtl::OUStringToOString( aFilter, RTL_TEXTENCODING_UTF8 ).getStr());
483 [ # # ][ # # ]: 0 : if( FStatHelper::IsDocument(aOutFile) )
484 [ # # ][ # # ]: 0 : printf("Overwriting: %s\n",::rtl::OUStringToOString( aTempName, RTL_TEXTENCODING_UTF8 ).getStr() );
485 : : try
486 : : {
487 [ # # ][ # # ]: 0 : xStorable->storeToURL( aOutFile, conversionProperties );
488 : : }
489 [ # # # # ]: 0 : catch (const Exception&)
490 : : {
491 [ # # ]: 0 : fprintf( stderr, "Error: Please reverify input parameters...\n" );
492 [ # # ][ # # ]: 0 : }
493 : 0 : }
494 [ # # ]: 0 : } else if ( aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ) {
495 : 0 : rtl::OUString aParam = aDispatchRequest.aPrinterName;
496 : 0 : sal_Int32 nPathIndex = aParam.lastIndexOf( ';' );
497 : :
498 : 0 : rtl::OUString aFilterOut;
499 : 0 : rtl::OUString aPrinterName;
500 [ # # ]: 0 : if( nPathIndex != -1 )
501 : 0 : aFilterOut=aParam.copy( nPathIndex+1 );
502 [ # # ]: 0 : if( nPathIndex != 0 )
503 : 0 : aPrinterName=aParam.copy( 0, nPathIndex );
504 : :
505 [ # # ]: 0 : INetURLObject aOutFilename( aObj );
506 [ # # ][ # # ]: 0 : aOutFilename.SetExtension( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ps")) );
507 [ # # ]: 0 : FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut );
508 : : rtl::OUString aOutFile = aFilterOut+
509 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "/" ))+
510 [ # # ][ # # ]: 0 : aOutFilename.getName();
511 : :
512 : 0 : rtl::OUString aTempName;
513 [ # # ][ # # ]: 0 : FileBase::getSystemPathFromFileURL( aName, aTempName );
514 [ # # ]: 0 : rtl::OString aSource8 = ::rtl::OUStringToOString ( aTempName, RTL_TEXTENCODING_UTF8 );
515 [ # # ]: 0 : FileBase::getSystemPathFromFileURL( aOutFile, aTempName );
516 [ # # ]: 0 : rtl::OString aTargetURL8 = ::rtl::OUStringToOString(aTempName, RTL_TEXTENCODING_UTF8 );
517 : : printf("print %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
518 : 0 : aPrinterName.isEmpty() ?
519 [ # # ][ # # ]: 0 : "<default_printer>" : ::rtl::OUStringToOString( aPrinterName, RTL_TEXTENCODING_UTF8 ).getStr() );
[ # # ][ # # ]
[ # # ]
520 : :
521 : : // create the custom printer, if given
522 [ # # ]: 0 : Sequence < PropertyValue > aPrinterArgs( 1 );
523 [ # # ]: 0 : if( !aPrinterName.isEmpty() )
524 : : {
525 [ # # ][ # # ]: 0 : aPrinterArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
526 [ # # ][ # # ]: 0 : aPrinterArgs[0].Value <<= aPrinterName;
527 [ # # ][ # # ]: 0 : xDoc->setPrinter( aPrinterArgs );
528 : : }
529 : :
530 : : // print ( also without user interaction )
531 [ # # ]: 0 : aPrinterArgs.realloc(2);
532 [ # # ][ # # ]: 0 : aPrinterArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FileName"));
533 [ # # ][ # # ]: 0 : aPrinterArgs[0].Value <<= aOutFile;
534 [ # # ][ # # ]: 0 : aPrinterArgs[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Wait"));
535 [ # # ][ # # ]: 0 : aPrinterArgs[1].Value <<= ( sal_Bool ) sal_True;
536 [ # # ][ # # ]: 0 : xDoc->print( aPrinterArgs );
[ # # ][ # # ]
537 : : } else {
538 [ # # ]: 0 : if ( aDispatchRequest.aRequestType == REQUEST_PRINTTO )
539 : : {
540 : : // create the printer
541 [ # # ]: 0 : Sequence < PropertyValue > aPrinterArgs( 1 );
542 [ # # ][ # # ]: 0 : aPrinterArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
543 [ # # ][ # # ]: 0 : aPrinterArgs[0].Value <<= ::rtl::OUString( aDispatchRequest.aPrinterName );
544 [ # # ][ # # ]: 0 : xDoc->setPrinter( aPrinterArgs );
[ # # ]
545 : : }
546 : :
547 : : // print ( also without user interaction )
548 [ # # ]: 0 : Sequence < PropertyValue > aPrinterArgs( 1 );
549 [ # # ][ # # ]: 0 : aPrinterArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Wait"));
550 [ # # ][ # # ]: 0 : aPrinterArgs[0].Value <<= ( sal_Bool ) sal_True;
551 [ # # ][ # # ]: 0 : xDoc->print( aPrinterArgs );
[ # # ]
552 : : }
553 : : }
554 : : else
555 : : {
556 : : // place error message here ...
557 : : }
558 : :
559 : : // remove the document
560 : : try
561 : : {
562 [ # # ]: 0 : Reference < XCloseable > xClose( xDoc, UNO_QUERY );
563 [ # # ]: 0 : if ( xClose.is() )
564 [ # # ][ # # ]: 0 : xClose->close( sal_True );
565 : : else
566 : : {
567 [ # # ]: 0 : Reference < XComponent > xComp( xDoc, UNO_QUERY );
568 [ # # ]: 0 : if ( xComp.is() )
569 [ # # ][ # # ]: 0 : xComp->dispose();
570 [ # # ]: 0 : }
571 : : }
572 [ # # ]: 0 : catch (const com::sun::star::util::CloseVetoException&)
573 : : {
574 : : }
575 : :
576 : : // request is completed
577 [ # # ]: 0 : OfficeIPCThread::RequestsCompleted( 1 );
578 [ # # ]: 0 : }
579 : : }
580 [ # # ][ # # ]: 0 : }
581 : :
582 [ - + ]: 96 : if ( !aDispatches.empty() )
583 : : {
584 : : // Execute all asynchronous dispatches now after we placed them into our request container!
585 [ # # ]: 0 : Sequence < PropertyValue > aArgs( 2 );
586 [ # # ][ # # ]: 0 : aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Referer"));
587 [ # # ][ # # ]: 0 : aArgs[0].Value <<= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:OpenEvent"));
[ # # ]
588 [ # # ][ # # ]: 0 : aArgs[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SynchronMode"));
589 [ # # ][ # # ]: 0 : aArgs[1].Value <<= sal_True;
590 : :
591 [ # # ]: 0 : for ( sal_uInt32 n = 0; n < aDispatches.size(); n++ )
592 : : {
593 : 0 : Reference< XDispatch > xDispatch = aDispatches[n].xDispatch;
594 [ # # ]: 0 : Reference < XNotifyingDispatch > xDisp( xDispatch, UNO_QUERY );
595 [ # # ]: 0 : if ( xDisp.is() )
596 [ # # ][ # # ]: 0 : xDisp->dispatchWithNotification( aDispatches[n].aURL, aArgs, this );
[ # # ]
597 : : else
598 : : {
599 [ # # ][ # # ]: 0 : ::osl::ClearableMutexGuard aGuard( GetMutex() );
600 : 0 : m_nRequestCount--;
601 [ # # ]: 0 : aGuard.clear();
602 [ # # ][ # # ]: 0 : xDispatch->dispatch( aDispatches[n].aURL, aArgs );
[ # # ]
603 : : }
604 [ # # ]: 0 : }
605 : : }
606 : :
607 [ + - ][ + - ]: 96 : ::osl::ClearableMutexGuard aGuard( GetMutex() );
608 : 96 : bool bEmpty = (m_nRequestCount == 0);
609 [ + - ]: 96 : aGuard.clear();
610 : :
611 : : // No more asynchronous requests?
612 : : // The requests are removed from the request container after they called back to this
613 : : // implementation via statusChanged!!
614 [ + - ][ - + ]: 96 : if ( bEmpty && !bNoTerminate /*m_aRequestContainer.empty()*/ )
615 : : {
616 : : // We have to check if we have an open task otherwise we have to shutdown the office.
617 [ # # ]: 0 : Reference< XFramesSupplier > xTasksSupplier( xDesktop, UNO_QUERY );
618 [ # # ]: 0 : aGuard.clear();
619 [ # # ][ # # ]: 0 : Reference< XElementAccess > xList( xTasksSupplier->getFrames(), UNO_QUERY );
[ # # ]
620 : :
621 [ # # ][ # # ]: 0 : if ( !xList->hasElements() )
[ # # ]
622 : : {
623 : : // We don't have any task open so we have to shutdown ourself!!
624 [ # # ]: 0 : Reference< XDesktop > xDesktop2( xTasksSupplier, UNO_QUERY );
625 [ # # ]: 0 : if ( xDesktop2.is() )
626 [ # # ][ # # ]: 0 : return xDesktop2->terminate();
[ # # ]
627 [ # # ][ # # ]: 0 : }
628 : : }
629 : :
630 [ + - ]: 96 : return sal_False;
631 : : }
632 : :
633 : :
634 : 0 : void SAL_CALL DispatchWatcher::disposing( const ::com::sun::star::lang::EventObject& )
635 : : throw(::com::sun::star::uno::RuntimeException)
636 : : {
637 : 0 : }
638 : :
639 : :
640 : 0 : void SAL_CALL DispatchWatcher::dispatchFinished( const DispatchResultEvent& ) throw( RuntimeException )
641 : : {
642 [ # # ][ # # ]: 0 : osl::ClearableMutexGuard aGuard( GetMutex() );
643 : 0 : sal_Int16 nCount = --m_nRequestCount;
644 [ # # ]: 0 : aGuard.clear();
645 [ # # ]: 0 : OfficeIPCThread::RequestsCompleted( 1 );
646 [ # # ][ # # ]: 0 : if ( !nCount && !OfficeIPCThread::AreRequestsPending() )
[ # # ][ # # ]
647 : : {
648 : : // We have to check if we have an open task otherwise we have to shutdown the office.
649 [ # # ][ # # ]: 0 : Reference< XFramesSupplier > xTasksSupplier( ::comphelper::getProcessServiceFactory()->createInstance(
650 : 0 : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ),
651 [ # # ][ # # ]: 0 : UNO_QUERY );
[ # # ]
652 [ # # ][ # # ]: 0 : Reference< XElementAccess > xList( xTasksSupplier->getFrames(), UNO_QUERY );
[ # # ]
653 : :
654 [ # # ][ # # ]: 0 : if ( !xList->hasElements() )
[ # # ]
655 : : {
656 : : // We don't have any task open so we have to shutdown ourself!!
657 [ # # ]: 0 : Reference< XDesktop > xDesktop( xTasksSupplier, UNO_QUERY );
658 [ # # ]: 0 : if ( xDesktop.is() )
659 [ # # ][ # # ]: 0 : xDesktop->terminate();
660 : 0 : }
661 [ # # ]: 0 : }
662 : 0 : }
663 : :
664 : : }
665 : :
666 : :
667 : :
668 : :
669 : :
670 : :
671 : :
672 : :
673 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|