Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : /**************************************************************************
22 : : TODO
23 : : **************************************************************************
24 : :
25 : : *************************************************************************/
26 : : #include <osl/diagnose.h>
27 : : #include <osl/mutex.hxx>
28 : : #include <salhelper/simplereferenceobject.hxx>
29 : : #include <cppuhelper/weak.hxx>
30 : :
31 : : #include <cppuhelper/implbase1.hxx>
32 : : #include <com/sun/star/ucb/ContentCreationError.hpp>
33 : : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
34 : : #include <com/sun/star/ucb/XCommandInfo.hpp>
35 : : #include <com/sun/star/ucb/XCommandProcessor.hpp>
36 : : #include <com/sun/star/ucb/Command.hpp>
37 : : #include <com/sun/star/ucb/CommandInfo.hpp>
38 : : #include <com/sun/star/ucb/ContentAction.hpp>
39 : : #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
40 : : #include <com/sun/star/ucb/InsertCommandArgument.hpp>
41 : : #include <com/sun/star/ucb/GlobalTransferCommandArgument.hpp>
42 : : #include <com/sun/star/ucb/NameClash.hpp>
43 : : #include <com/sun/star/ucb/OpenMode.hpp>
44 : : #include <com/sun/star/ucb/XContentCreator.hpp>
45 : : #include <com/sun/star/ucb/XContentEventListener.hpp>
46 : : #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
47 : : #include <com/sun/star/ucb/XContentProvider.hpp>
48 : : #include <com/sun/star/ucb/XContentProviderManager.hpp>
49 : : #include <com/sun/star/ucb/XDynamicResultSet.hpp>
50 : : #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
51 : : #include <com/sun/star/beans/XPropertySetInfo.hpp>
52 : : #include <com/sun/star/beans/Property.hpp>
53 : : #include <com/sun/star/beans/PropertyValue.hpp>
54 : : #include <com/sun/star/sdbc/XResultSet.hpp>
55 : : #include <com/sun/star/sdbc/XRow.hpp>
56 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
57 : : #include <com/sun/star/beans/UnknownPropertyException.hpp>
58 : : #include <ucbhelper/macros.hxx>
59 : : #include <ucbhelper/content.hxx>
60 : : #include <ucbhelper/contentbroker.hxx>
61 : : #include <ucbhelper/activedatasink.hxx>
62 : : #include <ucbhelper/activedatastreamer.hxx>
63 : : #include <ucbhelper/interactionrequest.hxx>
64 : : #include <ucbhelper/cancelcommandexecution.hxx>
65 : :
66 : : using namespace com::sun::star::container;
67 : : using namespace com::sun::star::beans;
68 : : using namespace com::sun::star::io;
69 : : using namespace com::sun::star::lang;
70 : : using namespace com::sun::star::sdbc;
71 : : using namespace com::sun::star::task;
72 : : using namespace com::sun::star::ucb;
73 : : using namespace com::sun::star::uno;
74 : :
75 : : namespace ucbhelper
76 : : {
77 : :
78 [ - + ]: 6981 : class EmptyInputStream : public ::cppu::WeakImplHelper1< XInputStream >
79 : : {
80 : : public:
81 : : virtual sal_Int32 SAL_CALL readBytes(
82 : : Sequence< sal_Int8 > & data, sal_Int32 nBytesToRead )
83 : : throw (IOException, RuntimeException);
84 : : virtual sal_Int32 SAL_CALL readSomeBytes(
85 : : Sequence< sal_Int8 > & data, sal_Int32 nMaxBytesToRead )
86 : : throw (IOException, RuntimeException);
87 : : virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
88 : : throw (IOException, RuntimeException);
89 : : virtual sal_Int32 SAL_CALL available()
90 : : throw (IOException, RuntimeException);
91 : : virtual void SAL_CALL closeInput()
92 : : throw (IOException, RuntimeException);
93 : : };
94 : :
95 : 0 : sal_Int32 EmptyInputStream::readBytes(
96 : : Sequence< sal_Int8 > & data, sal_Int32 )
97 : : throw (IOException, RuntimeException)
98 : : {
99 : 0 : data.realloc( 0 );
100 : 0 : return 0;
101 : : }
102 : :
103 : 0 : sal_Int32 EmptyInputStream::readSomeBytes(
104 : : Sequence< sal_Int8 > & data, sal_Int32 )
105 : : throw (IOException, RuntimeException)
106 : : {
107 : 0 : data.realloc( 0 );
108 : 0 : return 0;
109 : : }
110 : :
111 : 0 : void EmptyInputStream::skipBytes( sal_Int32 )
112 : : throw (IOException, RuntimeException)
113 : : {
114 : 0 : }
115 : :
116 : 0 : sal_Int32 EmptyInputStream::available()
117 : : throw (IOException, RuntimeException)
118 : : {
119 : 0 : return 0;
120 : : }
121 : :
122 : 0 : void EmptyInputStream::closeInput()
123 : : throw (IOException, RuntimeException)
124 : : {
125 : 0 : }
126 : :
127 : :
128 : : //=========================================================================
129 : : //=========================================================================
130 : : //
131 : : // class ContentEventListener_Impl.
132 : : //
133 : : //=========================================================================
134 : : //=========================================================================
135 : :
136 [ - + ]: 258110 : class ContentEventListener_Impl : public cppu::OWeakObject,
137 : : public XContentEventListener
138 : : {
139 : : Content_Impl& m_rContent;
140 : :
141 : : public:
142 : 129284 : ContentEventListener_Impl( Content_Impl& rContent )
143 : 129284 : : m_rContent( rContent ) {}
144 : :
145 : : // XInterface
146 : : XINTERFACE_DECL()
147 : :
148 : : // XContentEventListener
149 : : virtual void SAL_CALL contentEvent( const ContentEvent& evt )
150 : : throw( RuntimeException );
151 : :
152 : : // XEventListener ( base of XContentEventListener )
153 : : virtual void SAL_CALL disposing( const EventObject& Source )
154 : : throw( RuntimeException );
155 : : };
156 : :
157 : : //=========================================================================
158 : : //=========================================================================
159 : : //
160 : : // class Content_Impl.
161 : : //
162 : : //=========================================================================
163 : : //=========================================================================
164 : :
165 : : class Content_Impl : public salhelper::SimpleReferenceObject
166 : : {
167 : : friend class ContentEventListener_Impl;
168 : :
169 : : mutable rtl::OUString m_aURL;
170 : : Reference< XMultiServiceFactory > m_xSMgr;
171 : : Reference< XContent > m_xContent;
172 : : Reference< XCommandProcessor > m_xCommandProcessor;
173 : : Reference< XCommandEnvironment > m_xEnv;
174 : : Reference< XContentEventListener > m_xContentEventListener;
175 : : mutable osl::Mutex m_aMutex;
176 : : sal_Int32 m_nCommandId;
177 : :
178 : : private:
179 : : void reinit( const Reference< XContent >& xContent );
180 : : void disposing(const EventObject& Source);
181 : :
182 : : public:
183 [ + - ]: 58953 : Content_Impl() : m_nCommandId( 0 ) {};
184 : : Content_Impl( const Reference< XMultiServiceFactory >& rSMgr,
185 : : const Reference< XContent >& rContent,
186 : : const Reference< XCommandEnvironment >& rEnv );
187 : :
188 : : virtual ~Content_Impl();
189 : :
190 : : const rtl::OUString& getURL() const;
191 : : Reference< XContent > getContent();
192 : : Reference< XCommandProcessor > getCommandProcessor();
193 : : sal_Int32 getCommandId();
194 : 8 : Reference< XMultiServiceFactory > getServiceManager() { return m_xSMgr; }
195 : :
196 : : Any executeCommand( const Command& rCommand );
197 : :
198 : : inline const Reference< XCommandEnvironment >& getEnvironment() const;
199 : : inline void setEnvironment(
200 : : const Reference< XCommandEnvironment >& xNewEnv );
201 : :
202 : : void inserted();
203 : : };
204 : :
205 : : //=========================================================================
206 : : // Helpers.
207 : : //=========================================================================
208 : :
209 : 6051 : static void ensureContentProviderForURL( const ContentBroker & rBroker,
210 : : const rtl::OUString & rURL )
211 : : throw ( ContentCreationException, RuntimeException )
212 : : {
213 : : Reference< XContentProviderManager > xMgr
214 [ + - ]: 6051 : = rBroker.getContentProviderManagerInterface();
215 [ - + ]: 6051 : if ( !xMgr.is() )
216 : : {
217 : : throw RuntimeException(
218 : : rtl::OUString(
219 : : "UCB does not implement mandatory interface "
220 : : "XContentProviderManager!" ),
221 [ # # ]: 0 : Reference< XInterface >() );
222 : : }
223 : : else
224 : : {
225 : : Reference< XContentProvider > xProv
226 [ + - ][ + - ]: 6051 : = xMgr->queryContentProvider( rURL );
227 [ + + ]: 6051 : if ( !xProv.is() )
228 : : {
229 : : throw ContentCreationException(
230 : : rtl::OUString(
231 : : "No Content Provider available for URL: ") + rURL,
232 : : Reference< XInterface >(),
233 [ + - ]: 5475 : ContentCreationError_NO_CONTENT_PROVIDER );
234 : 6051 : }
235 : 6051 : }
236 : 576 : }
237 : :
238 : : //=========================================================================
239 : 135418 : static ContentBroker* getContentBroker( bool bThrow )
240 : : throw ( ContentCreationException, RuntimeException )
241 : : {
242 : 135418 : ContentBroker* pBroker = ContentBroker::get();
243 : :
244 [ + + ]: 135418 : if ( !pBroker )
245 : : {
246 [ + - ]: 3 : if ( bThrow )
247 : : throw RuntimeException(
248 : : rtl::OUString("No Content Broker!"),
249 [ + - ]: 3 : Reference< XInterface >() );
250 : : }
251 : : else
252 : : {
253 : : #if OSL_DEBUG_LEVEL > 1
254 : : Reference< XContentProviderManager > xMgr
255 : : = pBroker->getContentProviderManagerInterface();
256 : : if ( !xMgr.is() )
257 : : {
258 : : if ( bThrow )
259 : : throw RuntimeException(
260 : : rtl::OUString(
261 : : "UCB does not implement mandatory interface "
262 : : "XContentProviderManager!" ),
263 : : Reference< XInterface >() );
264 : : }
265 : : else
266 : : {
267 : : OSL_ENSURE( xMgr->queryContentProviders().getLength(),
268 : : "Content Broker not configured (no providers)!" );
269 : : }
270 : : #endif
271 : : }
272 : :
273 : 135415 : return pBroker;
274 : : }
275 : :
276 : : //=========================================================================
277 : 120142 : static Reference< XContentIdentifier > getContentIdentifier(
278 : : const ContentBroker & rBroker,
279 : : const rtl::OUString & rURL,
280 : : bool bThrow )
281 : : throw ( ContentCreationException, RuntimeException )
282 : : {
283 : : Reference< XContentIdentifierFactory > xIdFac
284 [ + - ]: 120142 : = rBroker.getContentIdentifierFactoryInterface();
285 [ + - ]: 120142 : if ( xIdFac.is() )
286 : : {
287 : : Reference< XContentIdentifier > xId
288 [ + - ][ + - ]: 120142 : = xIdFac->createContentIdentifier( rURL );
289 : :
290 [ + - ]: 120142 : if ( xId.is() )
291 : 120142 : return xId;
292 : :
293 [ # # ]: 0 : if ( bThrow )
294 : : {
295 [ # # ]: 0 : ensureContentProviderForURL( rBroker, rURL );
296 : :
297 : : throw ContentCreationException(
298 : : rtl::OUString(
299 : : "Unable to create Content Identifier!" ),
300 : : Reference< XInterface >(),
301 [ # # ]: 0 : ContentCreationError_IDENTIFIER_CREATION_FAILED );
302 [ - + ]: 120142 : }
303 : : }
304 : : else
305 : : {
306 [ # # ]: 0 : if ( bThrow )
307 : : throw RuntimeException(
308 : : rtl::OUString(
309 : : "UCB does not implement mandatory interface "
310 : : "XContentIdentifierFactory!" ),
311 [ # # ]: 0 : Reference< XInterface >() );
312 : : }
313 : :
314 : 120142 : return Reference< XContentIdentifier >();
315 : : }
316 : :
317 : : //=========================================================================
318 : 120142 : static Reference< XContent > getContent(
319 : : const ContentBroker & rBroker,
320 : : const Reference< XContentIdentifier > & xId,
321 : : bool bThrow )
322 : : throw ( ContentCreationException, RuntimeException )
323 : : {
324 : : Reference< XContentProvider > xProvider
325 [ + - ]: 120142 : = rBroker.getContentProviderInterface();
326 [ + - ]: 120142 : if ( xProvider.is() )
327 : : {
328 : 120142 : Reference< XContent > xContent;
329 : 120142 : rtl::OUString msg;
330 : : try
331 : : {
332 [ + + ][ + - ]: 120142 : xContent = xProvider->queryContent( xId );
[ - + ][ + - ]
333 : : }
334 [ + - ]: 6 : catch ( IllegalIdentifierException const & e )
335 : : {
336 : 3 : msg = e.Message;
337 : : // handled below.
338 : : }
339 : :
340 [ + + ]: 120142 : if ( xContent.is() )
341 : 114011 : return xContent;
342 : :
343 [ + + ]: 6131 : if ( bThrow )
344 : : {
345 [ + - ][ + - ]: 6051 : ensureContentProviderForURL( rBroker, xId->getContentIdentifier() );
[ + + ]
346 : :
347 : : throw ContentCreationException(
348 : : rtl::OUString(
349 : : "Unable to create Content! " ) + msg,
350 : : Reference< XInterface >(),
351 [ + - ]: 656 : ContentCreationError_CONTENT_CREATION_FAILED );
352 [ + + ][ + + ]: 120142 : }
353 : : }
354 : : else
355 : : {
356 [ # # ]: 0 : if ( bThrow )
357 : : throw RuntimeException(
358 : : rtl::OUString(
359 : : "UCB does not implement mandatory interface "
360 : : "XContentProvider!" ),
361 [ # # ]: 0 : Reference< XInterface >() );
362 : : }
363 : :
364 : 120142 : return Reference< XContent >();
365 : : }
366 : :
367 : : //=========================================================================
368 : : //=========================================================================
369 : : //
370 : : // Content Implementation.
371 : : //
372 : : //=========================================================================
373 : : //=========================================================================
374 : :
375 : 58953 : Content::Content()
376 [ + - ]: 58953 : : m_xImpl( new Content_Impl )
377 : : {
378 : 58953 : }
379 : :
380 : : //=========================================================================
381 : 93179 : Content::Content( const rtl::OUString& rURL,
382 : : const Reference< XCommandEnvironment >& rEnv )
383 : 99233 : throw ( ContentCreationException, RuntimeException )
384 : : {
385 [ + + ]: 93179 : ContentBroker* pBroker = getContentBroker( true );
386 : :
387 : : Reference< XContentIdentifier > xId
388 [ + - ]: 93176 : = getContentIdentifier( *pBroker, rURL, true );
389 : :
390 [ + + ]: 93176 : Reference< XContent > xContent = getContent( *pBroker, xId, true );
391 : :
392 [ + - ][ + - ]: 93179 : m_xImpl = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
[ + - ][ + - ]
393 : 87125 : }
394 : :
395 : : //=========================================================================
396 : 15273 : Content::Content( const Reference< XContent >& rContent,
397 : : const Reference< XCommandEnvironment >& rEnv )
398 : 15273 : throw ( ContentCreationException, RuntimeException )
399 : : {
400 [ + - ]: 15273 : ContentBroker* pBroker = getContentBroker( true );
401 : :
402 [ + - ][ + - ]: 15273 : m_xImpl = new Content_Impl( pBroker->getServiceManager(), rContent, rEnv );
[ + - ][ + - ]
403 : 15273 : }
404 : :
405 : : //=========================================================================
406 : 2385 : Content::Content( const Content& rOther )
407 : : {
408 [ + - ]: 2385 : m_xImpl = rOther.m_xImpl;
409 : 2385 : }
410 : :
411 : : //=========================================================================
412 : : // static
413 : 26966 : sal_Bool Content::create( const rtl::OUString& rURL,
414 : : const Reference< XCommandEnvironment >& rEnv,
415 : : Content& rContent )
416 : : {
417 [ + - ]: 26966 : ContentBroker* pBroker = getContentBroker( false );
418 [ - + ]: 26966 : if ( !pBroker )
419 : 0 : return sal_False;
420 : :
421 : : Reference< XContentIdentifier > xId
422 [ + - ]: 26966 : = getContentIdentifier( *pBroker, rURL, false );
423 [ - + ]: 26966 : if ( !xId.is() )
424 : 0 : return sal_False;
425 : :
426 [ + - ]: 26966 : Reference< XContent > xContent = getContent( *pBroker, xId, false );
427 [ + + ]: 26966 : if ( !xContent.is() )
428 : 80 : return sal_False;
429 : :
430 : : rContent.m_xImpl
431 [ + - ][ + - ]: 26886 : = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
[ + - ][ + - ]
432 : :
433 : 26966 : return sal_True;
434 : : }
435 : :
436 : : //=========================================================================
437 : 163425 : Content::~Content()
438 : : {
439 : 163425 : }
440 : :
441 : : //=========================================================================
442 : 26816 : Content& Content::operator=( const Content& rOther )
443 : : {
444 : 26816 : m_xImpl = rOther.m_xImpl;
445 : 26816 : return *this;
446 : : }
447 : :
448 : : //=========================================================================
449 : 57045 : Reference< XContent > Content::get() const
450 : : {
451 : 57045 : return m_xImpl->getContent();
452 : : }
453 : :
454 : : //=========================================================================
455 : 5220 : const rtl::OUString& Content::getURL() const
456 : : {
457 : 5220 : return m_xImpl->getURL();
458 : : }
459 : :
460 : : //=========================================================================
461 : 12 : const Reference< XCommandEnvironment >& Content::getCommandEnvironment() const
462 : : {
463 : 12 : return m_xImpl->getEnvironment();
464 : : }
465 : :
466 : : //=========================================================================
467 : 9412 : void Content::setCommandEnvironment(
468 : : const Reference< XCommandEnvironment >& xNewEnv )
469 : : {
470 : 9412 : m_xImpl->setEnvironment( xNewEnv );
471 : 9412 : }
472 : :
473 : : //=========================================================================
474 : 0 : Reference< XCommandInfo > Content::getCommands()
475 : : throw( CommandAbortedException, RuntimeException, Exception )
476 : : {
477 : 0 : Command aCommand;
478 : 0 : aCommand.Name = rtl::OUString("getCommandInfo");
479 : 0 : aCommand.Handle = -1; // n/a
480 : 0 : aCommand.Argument = Any();
481 : :
482 [ # # ]: 0 : Any aResult = m_xImpl->executeCommand( aCommand );
483 : :
484 : 0 : Reference< XCommandInfo > xInfo;
485 [ # # ]: 0 : aResult >>= xInfo;
486 : 0 : return xInfo;
487 : : }
488 : :
489 : : //=========================================================================
490 : 2499 : Reference< XPropertySetInfo > Content::getProperties()
491 : : throw( CommandAbortedException, RuntimeException, Exception )
492 : : {
493 : 2499 : Command aCommand;
494 : 2499 : aCommand.Name = rtl::OUString("getPropertySetInfo");
495 : 2499 : aCommand.Handle = -1; // n/a
496 : 2499 : aCommand.Argument = Any();
497 : :
498 [ + - ]: 2499 : Any aResult = m_xImpl->executeCommand( aCommand );
499 : :
500 : 2499 : Reference< XPropertySetInfo > xInfo;
501 [ + - ]: 2499 : aResult >>= xInfo;
502 : 2499 : return xInfo;
503 : : }
504 : :
505 : : //=========================================================================
506 : 66560 : Any Content::getPropertyValue( const rtl::OUString& rPropertyName )
507 : : throw( CommandAbortedException, RuntimeException, Exception )
508 : : {
509 [ + - ]: 66560 : Sequence< rtl::OUString > aNames( 1 );
510 [ + - ]: 66560 : aNames.getArray()[ 0 ] = rPropertyName;
511 : :
512 [ + + ]: 66560 : Sequence< Any > aRet = getPropertyValues( aNames );
513 [ + - ][ + - ]: 66560 : return aRet.getConstArray()[ 0 ];
514 : : }
515 : :
516 : : //=========================================================================
517 : 338 : Any Content::setPropertyValue( const rtl::OUString& rName,
518 : : const Any& rValue )
519 : : throw( CommandAbortedException, RuntimeException, Exception )
520 : : {
521 [ + - ]: 338 : Sequence< rtl::OUString > aNames( 1 );
522 [ + - ]: 338 : aNames.getArray()[ 0 ] = rName;
523 : :
524 [ + - ]: 338 : Sequence< Any > aValues( 1 );
525 [ + - ]: 338 : aValues.getArray()[ 0 ] = rValue;
526 : :
527 [ + - ]: 338 : Sequence< Any > aErrors = setPropertyValues( aNames, aValues );
528 [ + - ][ + - ]: 338 : return aErrors.getConstArray()[ 0 ];
[ + - ]
529 : : }
530 : :
531 : : //=========================================================================
532 : 66560 : Sequence< Any > Content::getPropertyValues(
533 : : const Sequence< rtl::OUString >& rPropertyNames )
534 : : throw( CommandAbortedException, RuntimeException, Exception )
535 : : {
536 [ + + ]: 66560 : Reference< XRow > xRow = getPropertyValuesInterface( rPropertyNames );
537 : :
538 : 54894 : sal_Int32 nCount = rPropertyNames.getLength();
539 [ + - ]: 54894 : Sequence< Any > aValues( nCount );
540 : :
541 [ + - ]: 54894 : if ( xRow.is() )
542 : : {
543 [ + - ]: 54894 : Any* pValues = aValues.getArray();
544 : :
545 [ + + ]: 109788 : for ( sal_Int32 n = 0; n < nCount; ++n )
546 [ + - ][ + - ]: 54894 : pValues[ n ] = xRow->getObject( n + 1, Reference< XNameAccess >() );
547 : : }
548 : :
549 : 66560 : return aValues;
550 : : }
551 : :
552 : : //=========================================================================
553 : 66560 : Reference< XRow > Content::getPropertyValuesInterface(
554 : : const Sequence< rtl::OUString >& rPropertyNames )
555 : : throw( CommandAbortedException, RuntimeException, Exception )
556 : : {
557 : 66560 : sal_Int32 nCount = rPropertyNames.getLength();
558 [ + - ]: 66560 : Sequence< Property > aProps( nCount );
559 [ + - ]: 66560 : Property* pProps = aProps.getArray();
560 : :
561 : 66560 : const rtl::OUString* pNames = rPropertyNames.getConstArray();
562 : :
563 [ + + ]: 133120 : for ( sal_Int32 n = 0; n< nCount; ++n )
564 : : {
565 : 66560 : Property& rProp = pProps[ n ];
566 : :
567 : 66560 : rProp.Name = pNames[ n ];
568 : 66560 : rProp.Handle = -1; // n/a
569 : : // rProp.Type =
570 : : // rProp.Attributes = ;
571 : : }
572 : :
573 : 66560 : Command aCommand;
574 : 66560 : aCommand.Name = rtl::OUString("getPropertyValues");
575 : 66560 : aCommand.Handle = -1; // n/a
576 [ + - ]: 66560 : aCommand.Argument <<= aProps;
577 : :
578 [ + + ]: 66560 : Any aResult = m_xImpl->executeCommand( aCommand );
579 : :
580 : 54894 : Reference< XRow > xRow;
581 [ + - ]: 54894 : aResult >>= xRow;
582 [ + - ]: 66560 : return xRow;
583 : : }
584 : :
585 : : //=========================================================================
586 : 2665 : Sequence< Any > Content::setPropertyValues(
587 : : const Sequence< rtl::OUString >& rPropertyNames,
588 : : const Sequence< Any >& rValues )
589 : : throw( CommandAbortedException, RuntimeException, Exception )
590 : : {
591 [ - + ]: 2665 : if ( rPropertyNames.getLength() != rValues.getLength() )
592 : : {
593 : : ucbhelper::cancelCommandExecution(
594 : : makeAny( IllegalArgumentException(
595 : : rtl::OUString(
596 : : "Length of property names sequence and value "
597 : : "sequence are unequal!" ),
598 : : get(),
599 [ # # ]: 0 : -1 ) ),
600 [ # # ][ # # ]: 0 : m_xImpl->getEnvironment() );
[ # # ][ # # ]
601 : : // Unreachable
602 : : }
603 : :
604 : 2665 : sal_Int32 nCount = rValues.getLength();
605 [ + - ]: 2665 : Sequence< PropertyValue > aProps( nCount );
606 [ + - ]: 2665 : PropertyValue* pProps = aProps.getArray();
607 : :
608 : 2665 : const rtl::OUString* pNames = rPropertyNames.getConstArray();
609 : 2665 : const Any* pValues = rValues.getConstArray();
610 : :
611 [ + + ]: 5380 : for ( sal_Int32 n = 0; n< nCount; ++n )
612 : : {
613 : 2715 : PropertyValue& rProp = pProps[ n ];
614 : :
615 : 2715 : rProp.Name = pNames[ n ];
616 : 2715 : rProp.Handle = -1; // n/a
617 : 2715 : rProp.Value = pValues[ n ];
618 : : // rProp.State = ;
619 : : }
620 : :
621 : 2665 : Command aCommand;
622 : 2665 : aCommand.Name = rtl::OUString("setPropertyValues");
623 : 2665 : aCommand.Handle = -1; // n/a
624 [ + - ]: 2665 : aCommand.Argument <<= aProps;
625 : :
626 [ + - ]: 2665 : Any aResult = m_xImpl->executeCommand( aCommand );
627 : :
628 [ + - ]: 2665 : Sequence< Any > aErrors;
629 [ + - ]: 2665 : aResult >>= aErrors;
630 [ + - ]: 2665 : return aErrors;
631 : : }
632 : :
633 : : //=========================================================================
634 : 18679 : Any Content::executeCommand( const rtl::OUString& rCommandName,
635 : : const Any& rCommandArgument )
636 : : throw( CommandAbortedException, RuntimeException, Exception )
637 : : {
638 : 18679 : Command aCommand;
639 : 18679 : aCommand.Name = rCommandName;
640 : 18679 : aCommand.Handle = -1; // n/a
641 : 18679 : aCommand.Argument = rCommandArgument;
642 : :
643 [ + + ]: 18679 : return m_xImpl->executeCommand( aCommand );
644 : : }
645 : :
646 : : //=========================================================================
647 : 24356 : Any Content::createCursorAny( const Sequence< rtl::OUString >& rPropertyNames,
648 : : ResultSetInclude eMode )
649 : : throw( CommandAbortedException, RuntimeException, Exception )
650 : : {
651 : 24356 : sal_Int32 nCount = rPropertyNames.getLength();
652 [ + - ]: 24356 : Sequence< Property > aProps( nCount );
653 [ + - ]: 24356 : Property* pProps = aProps.getArray();
654 : 24356 : const rtl::OUString* pNames = rPropertyNames.getConstArray();
655 [ + + ]: 48495 : for ( sal_Int32 n = 0; n < nCount; ++n )
656 : : {
657 : 24139 : Property& rProp = pProps[ n ];
658 : 24139 : rProp.Name = pNames[ n ];
659 : 24139 : rProp.Handle = -1; // n/a
660 : : }
661 : :
662 [ + - ]: 24356 : OpenCommandArgument2 aArg;
663 : : aArg.Mode = ( eMode == INCLUDE_FOLDERS_ONLY )
664 : : ? OpenMode::FOLDERS
665 : : : ( eMode == INCLUDE_DOCUMENTS_ONLY )
666 [ + + ][ + + ]: 24356 : ? OpenMode::DOCUMENTS : OpenMode::ALL;
667 : 24356 : aArg.Priority = 0; // unused
668 [ + - ]: 24356 : aArg.Sink = Reference< XInterface >(); // unused
669 [ + - ]: 24356 : aArg.Properties = aProps;
670 : :
671 : 24356 : Command aCommand;
672 : 24356 : aCommand.Name = rtl::OUString("open");
673 : 24356 : aCommand.Handle = -1; // n/a
674 [ + - ]: 24356 : aCommand.Argument <<= aArg;
675 : :
676 [ + - ][ + - ]: 24356 : return m_xImpl->executeCommand( aCommand );
[ + - ]
677 : : }
678 : :
679 : : //=========================================================================
680 : 24086 : Reference< XResultSet > Content::createCursor(
681 : : const Sequence< rtl::OUString >& rPropertyNames,
682 : : ResultSetInclude eMode )
683 : : throw( CommandAbortedException, RuntimeException, Exception )
684 : : {
685 [ + - ]: 24086 : Any aCursorAny = createCursorAny( rPropertyNames, eMode );
686 : :
687 : 24086 : Reference< XDynamicResultSet > xDynSet;
688 : 24086 : Reference< XResultSet > aResult;
689 : :
690 [ + - ]: 24086 : aCursorAny >>= xDynSet;
691 [ + - ]: 24086 : if ( xDynSet.is() )
692 [ + - ][ + - ]: 24086 : aResult = xDynSet->getStaticResultSet();
[ + - ]
693 : :
694 : : OSL_ENSURE( aResult.is(), "Content::createCursor - no cursor!" );
695 : :
696 [ - + ]: 24086 : if ( !aResult.is() )
697 : : {
698 : : // Former, the open command directly returned a XResultSet.
699 [ # # ]: 0 : aCursorAny >>= aResult;
700 : :
701 : : OSL_ENSURE( !aResult.is(),
702 : : "Content::createCursor - open-Command must "
703 : : "return a Reference< XDynnamicResultSet >!" );
704 : : }
705 : :
706 : 24086 : return aResult;
707 : : }
708 : :
709 : : //=========================================================================
710 : 262 : Reference< XDynamicResultSet > Content::createDynamicCursor(
711 : : const Sequence< rtl::OUString >& rPropertyNames,
712 : : ResultSetInclude eMode )
713 : : throw( CommandAbortedException, RuntimeException, Exception )
714 : : {
715 : 262 : Reference< XDynamicResultSet > aResult;
716 [ + - ][ + - ]: 262 : createCursorAny( rPropertyNames, eMode ) >>= aResult;
717 : :
718 : : OSL_ENSURE( aResult.is(), "Content::createDynamicCursor - no cursor!" );
719 : :
720 : 262 : return aResult;
721 : : }
722 : :
723 : : //=========================================================================
724 : 8 : Reference< XResultSet > Content::createSortedCursor(
725 : : const Sequence< rtl::OUString >& rPropertyNames,
726 : : const Sequence< NumberedSortingInfo >& rSortInfo,
727 : : Reference< XAnyCompareFactory > rAnyCompareFactory,
728 : : ResultSetInclude eMode )
729 : : throw( CommandAbortedException, RuntimeException, Exception )
730 : : {
731 : 8 : Reference< XResultSet > aResult;
732 : 8 : Reference< XDynamicResultSet > aDynSet;
733 : :
734 [ + - ]: 8 : Any aCursorAny = createCursorAny( rPropertyNames, eMode );
735 : :
736 [ + - ]: 8 : aCursorAny >>= aDynSet;
737 : :
738 [ + - ]: 8 : if( aDynSet.is() )
739 : : {
740 : 8 : Reference< XDynamicResultSet > aDynResult;
741 [ + - ]: 8 : Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
742 : :
743 [ + - ]: 8 : if( aServiceManager.is() )
744 : : {
745 [ + - ]: 8 : Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
746 : 8 : rtl::OUString("com.sun.star.ucb.SortedDynamicResultSetFactory")),
747 [ + - ][ + - ]: 8 : UNO_QUERY );
748 : :
749 [ + - ]: 8 : aDynResult = aSortFactory->createSortedDynamicResultSet( aDynSet,
750 : : rSortInfo,
751 [ + - ][ + - ]: 8 : rAnyCompareFactory );
752 : : }
753 : :
754 : : OSL_ENSURE( aDynResult.is(), "Content::createSortedCursor - no sorted cursor!\n" );
755 : :
756 [ + - ]: 8 : if( aDynResult.is() )
757 [ + - ][ + - ]: 8 : aResult = aDynResult->getStaticResultSet();
[ + - ]
758 : : else
759 [ # # ][ # # ]: 8 : aResult = aDynSet->getStaticResultSet();
[ # # ]
760 : : }
761 : :
762 : : OSL_ENSURE( aResult.is(), "Content::createSortedCursor - no cursor!" );
763 : :
764 [ - + ]: 8 : if ( !aResult.is() )
765 : : {
766 : : // Former, the open command directly returned a XResultSet.
767 [ # # ]: 0 : aCursorAny >>= aResult;
768 : :
769 : : OSL_ENSURE( !aResult.is(),
770 : : "Content::createCursor - open-Command must "
771 : : "return a Reference< XDynnamicResultSet >!" );
772 : : }
773 : :
774 : 8 : return aResult;
775 : : }
776 : :
777 : : //=========================================================================
778 : 11684 : Reference< XInputStream > Content::openStream()
779 : : throw( CommandAbortedException, RuntimeException, Exception )
780 : : {
781 [ + + ][ - + ]: 11684 : if ( !isDocument() )
782 : 0 : return Reference< XInputStream >();
783 : :
784 [ + - ][ + - ]: 11594 : Reference< XActiveDataSink > xSink = new ActiveDataSink;
[ + - ]
785 : :
786 [ + - ]: 11594 : OpenCommandArgument2 aArg;
787 : 11594 : aArg.Mode = OpenMode::DOCUMENT;
788 : 11594 : aArg.Priority = 0; // unused
789 [ + - ]: 11594 : aArg.Sink = xSink;
790 [ + - ][ + - ]: 11594 : aArg.Properties = Sequence< Property >( 0 ); // unused
[ + - ]
791 : :
792 : 11594 : Command aCommand;
793 : 11594 : aCommand.Name = rtl::OUString("open");
794 : 11594 : aCommand.Handle = -1; // n/a
795 [ + - ]: 11594 : aCommand.Argument <<= aArg;
796 : :
797 [ + - ]: 11594 : m_xImpl->executeCommand( aCommand );
798 : :
799 [ + - ][ + - ]: 11684 : return xSink->getInputStream();
[ + - ]
800 : : }
801 : :
802 : : //=========================================================================
803 : 585 : Reference< XInputStream > Content::openStreamNoLock()
804 : : throw( CommandAbortedException, RuntimeException, Exception )
805 : : {
806 [ + + ][ - + ]: 585 : if ( !isDocument() )
807 : 0 : return Reference< XInputStream >();
808 : :
809 [ + - ][ + - ]: 567 : Reference< XActiveDataSink > xSink = new ActiveDataSink;
[ + - ]
810 : :
811 [ + - ]: 567 : OpenCommandArgument2 aArg;
812 : 567 : aArg.Mode = OpenMode::DOCUMENT_SHARE_DENY_NONE;
813 : 567 : aArg.Priority = 0; // unused
814 [ + - ]: 567 : aArg.Sink = xSink;
815 [ + - ][ + - ]: 567 : aArg.Properties = Sequence< Property >( 0 ); // unused
[ + - ]
816 : :
817 : 567 : Command aCommand;
818 : 567 : aCommand.Name = rtl::OUString("open");
819 : 567 : aCommand.Handle = -1; // n/a
820 [ + - ]: 567 : aCommand.Argument <<= aArg;
821 : :
822 [ + - ]: 567 : m_xImpl->executeCommand( aCommand );
823 : :
824 [ + - ][ + - ]: 585 : return xSink->getInputStream();
[ + - ]
825 : : }
826 : :
827 : : //=========================================================================
828 : 954 : Reference< XStream > Content::openWriteableStream()
829 : : throw( CommandAbortedException, RuntimeException, Exception )
830 : : {
831 [ + + ][ - + ]: 954 : if ( !isDocument() )
832 : 0 : return Reference< XStream >();
833 : :
834 [ + - ][ + - ]: 934 : Reference< XActiveDataStreamer > xStreamer = new ActiveDataStreamer;
[ + - ]
835 : :
836 [ + - ]: 934 : OpenCommandArgument2 aArg;
837 : 934 : aArg.Mode = OpenMode::DOCUMENT;
838 : 934 : aArg.Priority = 0; // unused
839 [ + - ]: 934 : aArg.Sink = xStreamer;
840 [ + - ][ + - ]: 934 : aArg.Properties = Sequence< Property >( 0 ); // unused
[ + - ]
841 : :
842 : 934 : Command aCommand;
843 : 934 : aCommand.Name = rtl::OUString("open");
844 : 934 : aCommand.Handle = -1; // n/a
845 [ + - ]: 934 : aCommand.Argument <<= aArg;
846 : :
847 [ + - ]: 934 : m_xImpl->executeCommand( aCommand );
848 : :
849 [ + - ][ + - ]: 954 : return xStreamer->getStream();
[ + - ]
850 : : }
851 : :
852 : : //=========================================================================
853 : 3 : Reference< XStream > Content::openWriteableStreamNoLock()
854 : : throw( CommandAbortedException, RuntimeException, Exception )
855 : : {
856 [ - + ][ # # ]: 3 : if ( !isDocument() )
857 : 0 : return Reference< XStream >();
858 : :
859 [ # # ][ # # ]: 0 : Reference< XActiveDataStreamer > xStreamer = new ActiveDataStreamer;
[ # # ]
860 : :
861 [ # # ]: 0 : OpenCommandArgument2 aArg;
862 : 0 : aArg.Mode = OpenMode::DOCUMENT_SHARE_DENY_NONE;
863 : 0 : aArg.Priority = 0; // unused
864 [ # # ]: 0 : aArg.Sink = xStreamer;
865 [ # # ][ # # ]: 0 : aArg.Properties = Sequence< Property >( 0 ); // unused
[ # # ]
866 : :
867 : 0 : Command aCommand;
868 : 0 : aCommand.Name = rtl::OUString("open");
869 : 0 : aCommand.Handle = -1; // n/a
870 [ # # ]: 0 : aCommand.Argument <<= aArg;
871 : :
872 [ # # ]: 0 : m_xImpl->executeCommand( aCommand );
873 : :
874 [ # # ][ # # ]: 3 : return xStreamer->getStream();
[ # # ]
875 : : }
876 : :
877 : : //=========================================================================
878 : 3011 : sal_Bool Content::openStream( const Reference< XActiveDataSink >& rSink )
879 : : throw( CommandAbortedException, RuntimeException, Exception )
880 : : {
881 [ + + ][ - + ]: 3011 : if ( !isDocument() )
882 : 0 : return sal_False;
883 : :
884 [ + - ]: 2565 : OpenCommandArgument2 aArg;
885 : 2565 : aArg.Mode = OpenMode::DOCUMENT;
886 : 2565 : aArg.Priority = 0; // unused
887 [ + - ]: 2565 : aArg.Sink = rSink;
888 [ + - ][ + - ]: 2565 : aArg.Properties = Sequence< Property >( 0 ); // unused
[ + - ]
889 : :
890 : 2565 : Command aCommand;
891 : 2565 : aCommand.Name = rtl::OUString("open");
892 : 2565 : aCommand.Handle = -1; // n/a
893 [ + - ]: 2565 : aCommand.Argument <<= aArg;
894 : :
895 [ + - ]: 2565 : m_xImpl->executeCommand( aCommand );
896 : :
897 [ + - ]: 3011 : return sal_True;
898 : : }
899 : :
900 : : //=========================================================================
901 : 2172 : sal_Bool Content::openStream( const Reference< XOutputStream >& rStream )
902 : : throw( CommandAbortedException, RuntimeException, Exception )
903 : : {
904 [ + - ][ - + ]: 2172 : if ( !isDocument() )
905 : 0 : return sal_False;
906 : :
907 [ + - ]: 2172 : OpenCommandArgument2 aArg;
908 : 2172 : aArg.Mode = OpenMode::DOCUMENT;
909 : 2172 : aArg.Priority = 0; // unused
910 [ + - ]: 2172 : aArg.Sink = rStream;
911 [ + - ][ + - ]: 2172 : aArg.Properties = Sequence< Property >( 0 ); // unused
[ + - ]
912 : :
913 : 2172 : Command aCommand;
914 : 2172 : aCommand.Name = rtl::OUString("open");
915 : 2172 : aCommand.Handle = -1; // n/a
916 [ + - ]: 2172 : aCommand.Argument <<= aArg;
917 : :
918 [ + - ]: 2172 : m_xImpl->executeCommand( aCommand );
919 : :
920 [ + - ]: 2172 : return sal_True;
921 : : }
922 : :
923 : : //=========================================================================
924 : 6926 : void Content::writeStream( const Reference< XInputStream >& rStream,
925 : : sal_Bool bReplaceExisting )
926 : : throw( CommandAbortedException, RuntimeException, Exception )
927 : : {
928 [ + - ]: 6926 : InsertCommandArgument aArg;
929 [ + - ][ # # ]: 6926 : aArg.Data = rStream.is() ? rStream : new EmptyInputStream;
[ # # ][ # # ]
[ + - ]
930 : 6926 : aArg.ReplaceExisting = bReplaceExisting;
931 : :
932 : 6926 : Command aCommand;
933 : 6926 : aCommand.Name = rtl::OUString("insert");
934 : 6926 : aCommand.Handle = -1; // n/a
935 [ + - ]: 6926 : aCommand.Argument <<= aArg;
936 : :
937 [ + - ]: 6926 : m_xImpl->executeCommand( aCommand );
938 : :
939 [ + - ][ + - ]: 6926 : m_xImpl->inserted();
940 : 6926 : }
941 : :
942 : : //=========================================================================
943 : 2297 : Sequence< ContentInfo > Content::queryCreatableContentsInfo()
944 : : throw( CommandAbortedException, RuntimeException, Exception )
945 : : {
946 : : // First, try it using "CreatableContentsInfo" property -> the "new" way.
947 [ + - ]: 2297 : Sequence< ContentInfo > aInfo;
948 [ - + ]: 2297 : if ( getPropertyValue(
949 : : rtl::OUString("CreatableContentsInfo") )
950 [ + - ][ + - ]: 2297 : >>= aInfo )
951 : : return aInfo;
952 : :
953 : : // Second, try it using XContentCreator interface -> the "old" way (not
954 : : // providing the chance to supply an XCommandEnvironment.
955 [ # # ][ # # ]: 0 : Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY );
956 [ # # ]: 0 : if ( xCreator.is() )
957 [ # # ][ # # ]: 0 : aInfo = xCreator->queryCreatableContentsInfo();
[ # # ][ # # ]
958 : :
959 : 2297 : return aInfo;
960 : : }
961 : :
962 : : //=========================================================================
963 : 2327 : sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
964 : : const Sequence< rtl::OUString >&
965 : : rPropertyNames,
966 : : const Sequence< Any >& rPropertyValues,
967 : : Content& rNewContent )
968 : : throw( CommandAbortedException, RuntimeException, Exception )
969 : : {
970 : : return insertNewContent( rContentType,
971 : : rPropertyNames,
972 : : rPropertyValues,
973 [ + - ]: 2327 : new EmptyInputStream,
974 [ + - ][ + + ]: 4654 : rNewContent );
975 : : }
976 : :
977 : : //=========================================================================
978 : 2327 : sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
979 : : const Sequence< rtl::OUString >&
980 : : rPropertyNames,
981 : : const Sequence< Any >& rPropertyValues,
982 : : const Reference< XInputStream >& rData,
983 : : Content& rNewContent )
984 : : throw( CommandAbortedException, RuntimeException, Exception )
985 : : {
986 [ - + ]: 2327 : if ( rContentType.isEmpty() )
987 : 0 : return sal_False;
988 : :
989 : : // First, try it using "createNewContent" command -> the "new" way.
990 [ + - ]: 2327 : ContentInfo aInfo;
991 : 2327 : aInfo.Type = rContentType;
992 : 2327 : aInfo.Attributes = 0;
993 : :
994 : 2327 : Command aCommand;
995 : 2327 : aCommand.Name = rtl::OUString("createNewContent");
996 : 2327 : aCommand.Handle = -1; // n/a
997 [ + - ]: 2327 : aCommand.Argument <<= aInfo;
998 : :
999 : 2327 : Reference< XContent > xNew;
1000 : : try
1001 : : {
1002 [ + - ][ + - ]: 2327 : m_xImpl->executeCommand( aCommand ) >>= xNew;
1003 : : }
1004 [ # # # ]: 0 : catch ( RuntimeException const & )
1005 : : {
1006 : 0 : throw;
1007 : : }
1008 [ # # ]: 0 : catch ( Exception const & )
1009 : : {
1010 : : }
1011 : :
1012 [ - + ]: 2327 : if ( !xNew.is() )
1013 : : {
1014 : : // Second, try it using XContentCreator interface -> the "old"
1015 : : // way (not providing the chance to supply an XCommandEnvironment.
1016 [ # # ][ # # ]: 0 : Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY );
1017 : :
1018 [ # # ]: 0 : if ( !xCreator.is() )
1019 : 0 : return sal_False;
1020 : :
1021 [ # # ][ # # ]: 0 : xNew = xCreator->createNewContent( aInfo );
[ # # ]
1022 : :
1023 [ # # ]: 0 : if ( !xNew.is() )
1024 [ # # ]: 0 : return sal_False;
1025 : : }
1026 : :
1027 [ + - ]: 2327 : Content aNewContent( xNew, m_xImpl->getEnvironment() );
1028 [ + - ][ + - ]: 2327 : aNewContent.setPropertyValues( rPropertyNames, rPropertyValues );
1029 : : aNewContent.executeCommand( rtl::OUString("insert"),
1030 : : makeAny(
1031 : : InsertCommandArgument(
1032 [ # # ][ # # ]: 2327 : rData.is() ? rData : new EmptyInputStream,
1033 [ # # ][ + - ]: 2327 : sal_False /* ReplaceExisting */ ) ) );
[ + - ][ + + ]
[ + - ][ + - ]
1034 [ + - ]: 2252 : aNewContent.m_xImpl->inserted();
1035 : :
1036 [ + - ]: 2252 : rNewContent = aNewContent;
1037 [ + - ][ + - ]: 2327 : return sal_True;
1038 : : }
1039 : :
1040 : : //=========================================================================
1041 : 1244 : sal_Bool Content::transferContent( const Content& rSourceContent,
1042 : : InsertOperation eOperation,
1043 : : const rtl::OUString & rTitle,
1044 : : const sal_Int32 nNameClashAction )
1045 : : throw( CommandAbortedException, RuntimeException, Exception )
1046 : : {
1047 [ + - ]: 1244 : ContentBroker* pBroker = ContentBroker::get();
1048 [ - + ]: 1244 : if ( !pBroker )
1049 : : {
1050 : : OSL_FAIL( "Content::transferContent - No Content Broker!" );
1051 : 0 : return sal_False;
1052 : : }
1053 : :
1054 : : Reference< XCommandProcessor > xCmdProc(
1055 [ + - ]: 1244 : pBroker->getCommandProcessorInterface() );
1056 [ - + ]: 1244 : if ( !xCmdProc.is() )
1057 : : {
1058 : : OSL_FAIL( "Content::transferContent - No XCommandProcessor!" );
1059 : 0 : return sal_False;
1060 : : }
1061 : :
1062 : : // Execute command "globalTransfer" at UCB.
1063 : :
1064 : 1244 : TransferCommandOperation eTransOp = TransferCommandOperation();
1065 [ + - - - ]: 1244 : switch ( eOperation )
1066 : : {
1067 : : case InsertOperation_COPY:
1068 : 1244 : eTransOp = TransferCommandOperation_COPY;
1069 : 1244 : break;
1070 : :
1071 : : case InsertOperation_MOVE:
1072 : 0 : eTransOp = TransferCommandOperation_MOVE;
1073 : 0 : break;
1074 : :
1075 : : case InsertOperation_LINK:
1076 : 0 : eTransOp = TransferCommandOperation_LINK;
1077 : 0 : break;
1078 : :
1079 : : default:
1080 : : ucbhelper::cancelCommandExecution(
1081 : : makeAny( IllegalArgumentException(
1082 : : rtl::OUString(
1083 : : "Unknown transfer operation!" ),
1084 : : get(),
1085 [ # # ]: 0 : -1 ) ),
1086 [ # # ][ # # ]: 0 : m_xImpl->getEnvironment() );
[ # # ][ # # ]
1087 : : // Unreachable
1088 : : }
1089 : :
1090 : : GlobalTransferCommandArgument aTransferArg(
1091 : : eTransOp,
1092 [ + - ]: 1244 : rSourceContent.getURL(), // SourceURL
1093 [ + - ]: 1244 : getURL(), // TargetFolderURL,
1094 : : rTitle,
1095 : 1244 : nNameClashAction );
1096 : 1244 : Command aCommand;
1097 : 1244 : aCommand.Name = rtl::OUString("globalTransfer");
1098 : 1244 : aCommand.Handle = -1; // n/a
1099 [ + - ]: 1244 : aCommand.Argument <<= aTransferArg;
1100 : :
1101 [ + - ][ + + ]: 1244 : xCmdProc->execute( aCommand, 0, m_xImpl->getEnvironment() );
1102 : 1244 : return sal_True;
1103 : : }
1104 : :
1105 : : //=========================================================================
1106 : 32088 : sal_Bool Content::isFolder()
1107 : : throw( CommandAbortedException, RuntimeException, Exception )
1108 : : {
1109 : 32088 : sal_Bool bFolder = sal_False;
1110 [ + - ]: 22538 : if ( getPropertyValue( rtl::OUString("IsFolder") )
1111 [ + + ]: 32088 : >>= bFolder )
1112 : 22538 : return bFolder;
1113 : :
1114 : : ucbhelper::cancelCommandExecution(
1115 : : makeAny( UnknownPropertyException(
1116 : : rtl::OUString(
1117 : : "Unable to retreive value of property 'IsFolder'!" ),
1118 [ # # ]: 9550 : get() ) ),
1119 [ # # ][ # # ]: 0 : m_xImpl->getEnvironment() );
[ # # ][ # # ]
1120 : :
1121 : : // Unreachable - cancelCommandExecution always throws an exception.
1122 : : // But some compilers complain...
1123 : 22538 : return sal_False;
1124 : : }
1125 : :
1126 : : //=========================================================================
1127 : 21863 : sal_Bool Content::isDocument()
1128 : : throw( CommandAbortedException, RuntimeException, Exception )
1129 : : {
1130 : 21863 : sal_Bool bDoc = sal_False;
1131 [ + - ]: 19868 : if ( getPropertyValue( rtl::OUString("IsDocument") )
1132 [ + + ]: 21863 : >>= bDoc )
1133 : 19868 : return bDoc;
1134 : :
1135 : : ucbhelper::cancelCommandExecution(
1136 : : makeAny( UnknownPropertyException(
1137 : : rtl::OUString(
1138 : : "Unable to retreive value of property 'IsDocument'!" ),
1139 [ # # ]: 1995 : get() ) ),
1140 [ # # ][ # # ]: 0 : m_xImpl->getEnvironment() );
[ # # ][ # # ]
1141 : :
1142 : : // Unreachable - cancelCommandExecution always throws an exception,
1143 : : // But some compilers complain...
1144 : 19868 : return sal_False;
1145 : : }
1146 : :
1147 : : //=========================================================================
1148 : : //=========================================================================
1149 : : //
1150 : : // Content_Impl Implementation.
1151 : : //
1152 : : //=========================================================================
1153 : : //=========================================================================
1154 : :
1155 : 129284 : Content_Impl::Content_Impl( const Reference< XMultiServiceFactory >& rSMgr,
1156 : : const Reference< XContent >& rContent,
1157 : : const Reference< XCommandEnvironment >& rEnv )
1158 : : : m_xSMgr( rSMgr ),
1159 : : m_xContent( rContent ),
1160 : : m_xEnv( rEnv ),
1161 [ + - ]: 129284 : m_nCommandId( 0 )
1162 : : {
1163 [ + - ]: 129284 : if ( m_xContent.is() )
1164 : : {
1165 [ + - ][ + - ]: 129284 : m_xContentEventListener = new ContentEventListener_Impl( *this );
[ + - ]
1166 [ + - ][ + - ]: 129284 : m_xContent->addContentEventListener( m_xContentEventListener );
1167 : :
1168 : : #if OSL_DEBUG_LEVEL > 1
1169 : : // Only done on demand in product version for performance reasons,
1170 : : // but a nice debug helper.
1171 : : getURL();
1172 : : #endif
1173 : : }
1174 : 129284 : }
1175 : :
1176 : : //=========================================================================
1177 : 636 : void Content_Impl::reinit( const Reference< XContent >& xContent )
1178 : : {
1179 [ + - ]: 636 : osl::MutexGuard aGuard( m_aMutex );
1180 : :
1181 [ + - ]: 636 : m_xCommandProcessor = 0;
1182 : 636 : m_nCommandId = 0;
1183 : :
1184 : : // #92581# - Don't reset m_aURL!!!
1185 : :
1186 [ + - ]: 636 : if ( m_xContent.is() )
1187 : : {
1188 : : try
1189 : : {
1190 [ + - ][ + - ]: 636 : m_xContent->removeContentEventListener( m_xContentEventListener );
1191 : : }
1192 [ # # ]: 0 : catch ( RuntimeException const & )
1193 : : {
1194 : : }
1195 : : }
1196 : :
1197 [ - + ]: 636 : if ( xContent.is() )
1198 : : {
1199 [ # # ]: 0 : m_xContent = xContent;
1200 [ # # ][ # # ]: 0 : m_xContent->addContentEventListener( m_xContentEventListener );
1201 : :
1202 : : #if OSL_DEBUG_LEVEL > 1
1203 : : // Only done on demand in product version for performance reasons,
1204 : : // but a nice debug helper.
1205 : : getURL();
1206 : : #endif
1207 : : }
1208 : : else
1209 : : {
1210 : : // We need m_xContent's URL in order to be able to create the
1211 : : // content object again if demanded ( --> Content_Impl::getContent() )
1212 [ + - ]: 636 : getURL();
1213 : :
1214 [ + - ]: 636 : m_xContent = 0;
1215 [ + - ]: 636 : }
1216 [ # # ]: 636 : }
1217 : :
1218 : : //=========================================================================
1219 : : // virtual
1220 [ + - ]: 187926 : Content_Impl::~Content_Impl()
1221 : : {
1222 [ + + ]: 187926 : if ( m_xContent.is() )
1223 : : {
1224 : : try
1225 : : {
1226 [ + - ][ + - ]: 128423 : m_xContent->removeContentEventListener( m_xContentEventListener );
1227 : : }
1228 [ # # ]: 0 : catch ( RuntimeException const & )
1229 : : {
1230 : : }
1231 : : }
1232 [ - + ][ # # ]: 375852 : }
1233 : :
1234 : : //=========================================================================
1235 : 0 : void Content_Impl::disposing( const EventObject& Source )
1236 : : {
1237 : 0 : Reference<XContent> xContent;
1238 : :
1239 : : {
1240 [ # # ]: 0 : osl::MutexGuard aGuard( m_aMutex );
1241 [ # # ][ # # ]: 0 : if(Source.Source != m_xContent)
1242 : 0 : return;
1243 : :
1244 [ # # ]: 0 : xContent = m_xContent;
1245 : :
1246 : 0 : m_nCommandId = 0;
1247 : 0 : m_aURL = rtl::OUString();
1248 [ # # ]: 0 : m_xCommandProcessor = 0;
1249 [ # # ][ # # ]: 0 : m_xContent = 0;
[ # # # # ]
1250 : : }
1251 : :
1252 [ # # ]: 0 : if ( xContent.is() )
1253 : : {
1254 : : try
1255 : : {
1256 [ # # ][ # # ]: 0 : xContent->removeContentEventListener( m_xContentEventListener );
1257 : : }
1258 [ # # ]: 0 : catch ( RuntimeException const & )
1259 : : {
1260 : : }
1261 [ # # ]: 0 : }
1262 : : }
1263 : :
1264 : : //=========================================================================
1265 : 5856 : const rtl::OUString& Content_Impl::getURL() const
1266 : : {
1267 [ + + ][ + - ]: 5856 : if ( m_aURL.isEmpty() && m_xContent.is() )
[ + + ]
1268 : : {
1269 [ + - ]: 5628 : osl::MutexGuard aGuard( m_aMutex );
1270 : :
1271 [ + - ][ + - ]: 5628 : if ( m_aURL.isEmpty() && m_xContent.is() )
[ + - ]
1272 : : {
1273 [ + - ][ + - ]: 5628 : Reference< XContentIdentifier > xId = m_xContent->getIdentifier();
1274 [ + - ]: 5628 : if ( xId.is() )
1275 [ + - ][ + - ]: 5628 : m_aURL = xId->getContentIdentifier();
1276 [ + - ]: 5628 : }
1277 : : }
1278 : :
1279 : 5856 : return m_aURL;
1280 : : }
1281 : :
1282 : : //=========================================================================
1283 : 142277 : Reference< XContent > Content_Impl::getContent()
1284 : : {
1285 [ + + ][ + + ]: 142277 : if ( !m_xContent.is() && !m_aURL.isEmpty() )
[ + + ]
1286 : : {
1287 [ + - ]: 4 : osl::MutexGuard aGuard( m_aMutex );
1288 : :
1289 [ + - ][ + - ]: 4 : if ( !m_xContent.is() && !m_aURL.isEmpty() )
[ + - ]
1290 : : {
1291 [ + - ]: 4 : ContentBroker* pBroker = ContentBroker::get();
1292 : :
1293 : : OSL_ENSURE( pBroker, "No Content Broker!" );
1294 : :
1295 [ + - ]: 4 : if ( pBroker )
1296 : : {
1297 : : OSL_ENSURE( pBroker->getContentProviderManagerInterface()
1298 : : ->queryContentProviders().getLength(),
1299 : : "Content Broker not configured (no providers)!" );
1300 : :
1301 : : Reference< XContentIdentifierFactory > xIdFac
1302 [ + - ]: 4 : = pBroker->getContentIdentifierFactoryInterface();
1303 : :
1304 : : OSL_ENSURE( xIdFac.is(), "No Content Identifier factory!" );
1305 : :
1306 [ + - ]: 4 : if ( xIdFac.is() )
1307 : : {
1308 : : Reference< XContentIdentifier > xId
1309 [ + - ][ + - ]: 4 : = xIdFac->createContentIdentifier( m_aURL );
1310 : :
1311 : : OSL_ENSURE( xId.is(), "No Content Identifier!" );
1312 : :
1313 [ + - ]: 4 : if ( xId.is() )
1314 : : {
1315 : : Reference< XContentProvider > xProvider
1316 [ + - ]: 4 : = pBroker->getContentProviderInterface();
1317 : :
1318 : : OSL_ENSURE( xProvider.is(), "No Content Provider!" );
1319 : :
1320 [ + - ]: 4 : if ( xProvider.is() )
1321 : : {
1322 : : try
1323 : : {
1324 [ + - ][ + - ]: 4 : m_xContent = xProvider->queryContent( xId );
[ + - ][ # # ]
1325 : : }
1326 [ # # ]: 0 : catch ( IllegalIdentifierException const & )
1327 : : {
1328 : : }
1329 : :
1330 [ + - ]: 4 : if ( m_xContent.is() )
1331 [ + - ]: 4 : m_xContent->addContentEventListener(
1332 [ + - ]: 4 : m_xContentEventListener );
1333 : 4 : }
1334 : 4 : }
1335 : 4 : }
1336 : : }
1337 [ + - ]: 4 : }
1338 : : }
1339 : :
1340 : 142277 : return m_xContent;
1341 : : }
1342 : :
1343 : : //=========================================================================
1344 : 227076 : Reference< XCommandProcessor > Content_Impl::getCommandProcessor()
1345 : : {
1346 [ + + ]: 227076 : if ( !m_xCommandProcessor.is() )
1347 : : {
1348 [ + - ]: 85232 : osl::MutexGuard aGuard( m_aMutex );
1349 : :
1350 [ + - ]: 85232 : if ( !m_xCommandProcessor.is() )
1351 : : m_xCommandProcessor
1352 [ + - ][ + - ]: 85232 : = Reference< XCommandProcessor >( getContent(), UNO_QUERY );
[ + - ][ + - ]
1353 : : }
1354 : :
1355 : 227076 : return m_xCommandProcessor;
1356 : : }
1357 : :
1358 : : //=========================================================================
1359 : 141844 : sal_Int32 Content_Impl::getCommandId()
1360 : : {
1361 [ + + ]: 141844 : if ( m_nCommandId == 0 )
1362 : : {
1363 [ + - ]: 85232 : osl::MutexGuard aGuard( m_aMutex );
1364 : :
1365 [ + - ]: 85232 : if ( m_nCommandId == 0 )
1366 : : {
1367 [ + - ]: 85232 : Reference< XCommandProcessor > xProc = getCommandProcessor();
1368 [ + - ]: 85232 : if ( xProc.is() )
1369 [ + - ][ + - ]: 85232 : m_nCommandId = xProc->createCommandIdentifier();
1370 [ + - ]: 85232 : }
1371 : : }
1372 : :
1373 : 141844 : return m_nCommandId;
1374 : : }
1375 : :
1376 : : //=========================================================================
1377 : 141844 : Any Content_Impl::executeCommand( const Command& rCommand )
1378 : : {
1379 [ + - ]: 141844 : Reference< XCommandProcessor > xProc = getCommandProcessor();
1380 [ - + ]: 141844 : if ( !xProc.is() )
1381 : 0 : return Any();
1382 : :
1383 : : // Execute command
1384 [ + - ][ + - ]: 141844 : return xProc->execute( rCommand, getCommandId(), m_xEnv );
[ + + ]
1385 : : }
1386 : :
1387 : : //=========================================================================
1388 : : inline const Reference< XCommandEnvironment >&
1389 : 3583 : Content_Impl::getEnvironment() const
1390 : : {
1391 : 3583 : return m_xEnv;
1392 : : }
1393 : :
1394 : : //=========================================================================
1395 : 9412 : inline void Content_Impl::setEnvironment(
1396 : : const Reference< XCommandEnvironment >& xNewEnv )
1397 : : {
1398 [ + - ]: 9412 : osl::MutexGuard aGuard( m_aMutex );
1399 [ + - ][ + - ]: 9412 : m_xEnv = xNewEnv;
1400 : 9412 : }
1401 : :
1402 : : //=========================================================================
1403 : 9178 : void Content_Impl::inserted()
1404 : : {
1405 : : // URL might have changed during 'insert' => recalculate in next getURL()
1406 [ + - ]: 9178 : osl::MutexGuard aGuard( m_aMutex );
1407 [ + - ]: 9178 : m_aURL = ::rtl::OUString();
1408 : 9178 : }
1409 : :
1410 : : //=========================================================================
1411 : : //=========================================================================
1412 : : //
1413 : : // ContentEventListener_Impl Implementation.
1414 : : //
1415 : : //=========================================================================
1416 : : //=========================================================================
1417 : :
1418 : : //=========================================================================
1419 : : //
1420 : : // XInterface methods.
1421 : : //
1422 : : //=========================================================================
1423 : :
1424 [ + - ][ + - ]: 862514 : XINTERFACE_IMPL_2( ContentEventListener_Impl,
[ # # ]
1425 : : XContentEventListener,
1426 : : XEventListener ); /* base of XContentEventListener */
1427 : :
1428 : : //=========================================================================
1429 : : //
1430 : : // XContentEventListener methods.
1431 : : //
1432 : : //=========================================================================
1433 : :
1434 : : // virtual
1435 : 4498 : void SAL_CALL ContentEventListener_Impl::contentEvent( const ContentEvent& evt )
1436 : : throw( RuntimeException )
1437 : : {
1438 [ + - ]: 4498 : if ( evt.Source == m_rContent.m_xContent )
1439 : : {
1440 [ + - + ]: 4498 : switch ( evt.Action )
1441 : : {
1442 : : case ContentAction::DELETED:
1443 [ + - ]: 636 : m_rContent.reinit( Reference< XContent >() );
1444 : 636 : break;
1445 : :
1446 : : case ContentAction::EXCHANGED:
1447 : 0 : m_rContent.reinit( evt.Content );
1448 : 0 : break;
1449 : :
1450 : : default:
1451 : 4498 : break;
1452 : : }
1453 : : }
1454 : 4498 : }
1455 : :
1456 : : //=========================================================================
1457 : : //
1458 : : // XEventListenr methods.
1459 : : //
1460 : : //=========================================================================
1461 : :
1462 : : // virtual
1463 : 0 : void SAL_CALL ContentEventListener_Impl::disposing( const EventObject& Source )
1464 : : throw( RuntimeException )
1465 : : {
1466 : 0 : m_rContent.disposing(Source);
1467 : 0 : }
1468 : :
1469 : : } /* namespace ucbhelper */
1470 : :
1471 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|