update dev300-m58
[ooovba.git] / ucbhelper / source / client / content.cxx
blob8e2e6bada52e923e08c46fcfc799bcd4104e7a25
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: content.cxx,v $
10 * $Revision: 1.38 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucbhelper.hxx"
34 /**************************************************************************
35 TODO
36 **************************************************************************
38 *************************************************************************/
39 #include <osl/diagnose.h>
40 #include <osl/mutex.hxx>
41 #include <salhelper/simplereferenceobject.hxx>
42 #include <cppuhelper/weak.hxx>
44 #include <cppuhelper/implbase1.hxx>
45 #include <com/sun/star/ucb/ContentCreationError.hpp>
46 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
47 #include <com/sun/star/ucb/XCommandInfo.hpp>
48 #include <com/sun/star/ucb/XCommandProcessor.hpp>
49 #include <com/sun/star/ucb/Command.hpp>
50 #include <com/sun/star/ucb/CommandInfo.hpp>
51 #include <com/sun/star/ucb/ContentAction.hpp>
52 #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
53 #include <com/sun/star/ucb/InsertCommandArgument.hpp>
54 #include <com/sun/star/ucb/GlobalTransferCommandArgument.hpp>
55 #include <com/sun/star/ucb/NameClash.hpp>
56 #include <com/sun/star/ucb/OpenMode.hpp>
57 #include <com/sun/star/ucb/XContentCreator.hpp>
58 #include <com/sun/star/ucb/XContentEventListener.hpp>
59 #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
60 #include <com/sun/star/ucb/XContentProvider.hpp>
61 #include <com/sun/star/ucb/XContentProviderManager.hpp>
62 #include <com/sun/star/ucb/XDynamicResultSet.hpp>
63 #include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
64 #include <com/sun/star/beans/XPropertySetInfo.hpp>
65 #include <com/sun/star/beans/Property.hpp>
66 #include <com/sun/star/beans/PropertyValue.hpp>
67 #include <com/sun/star/sdbc/XResultSet.hpp>
68 #include <com/sun/star/sdbc/XRow.hpp>
69 #include <com/sun/star/lang/IllegalArgumentException.hpp>
70 #include <com/sun/star/beans/UnknownPropertyException.hpp>
71 #include <ucbhelper/macros.hxx>
72 #include <ucbhelper/content.hxx>
73 #include <ucbhelper/contentbroker.hxx>
74 #include <ucbhelper/activedatasink.hxx>
75 #include <ucbhelper/activedatastreamer.hxx>
76 #ifndef _UCBHELPER_INTERACTIONREQUEST_HXX
77 #include <ucbhelper/interactionrequest.hxx>
78 #endif
79 #include <ucbhelper/cancelcommandexecution.hxx>
81 using namespace com::sun::star::container;
82 using namespace com::sun::star::beans;
83 using namespace com::sun::star::io;
84 using namespace com::sun::star::lang;
85 using namespace com::sun::star::sdbc;
86 using namespace com::sun::star::task;
87 using namespace com::sun::star::ucb;
88 using namespace com::sun::star::uno;
90 namespace ucbhelper
93 class EmptyInputStream : public ::cppu::WeakImplHelper1< XInputStream >
95 public:
96 virtual sal_Int32 SAL_CALL readBytes(
97 Sequence< sal_Int8 > & data, sal_Int32 nBytesToRead )
98 throw (IOException, RuntimeException);
99 virtual sal_Int32 SAL_CALL readSomeBytes(
100 Sequence< sal_Int8 > & data, sal_Int32 nMaxBytesToRead )
101 throw (IOException, RuntimeException);
102 virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip )
103 throw (IOException, RuntimeException);
104 virtual sal_Int32 SAL_CALL available()
105 throw (IOException, RuntimeException);
106 virtual void SAL_CALL closeInput()
107 throw (IOException, RuntimeException);
110 sal_Int32 EmptyInputStream::readBytes(
111 Sequence< sal_Int8 > & data, sal_Int32 )
112 throw (IOException, RuntimeException)
114 data.realloc( 0 );
115 return 0;
118 sal_Int32 EmptyInputStream::readSomeBytes(
119 Sequence< sal_Int8 > & data, sal_Int32 )
120 throw (IOException, RuntimeException)
122 data.realloc( 0 );
123 return 0;
126 void EmptyInputStream::skipBytes( sal_Int32 )
127 throw (IOException, RuntimeException)
131 sal_Int32 EmptyInputStream::available()
132 throw (IOException, RuntimeException)
134 return 0;
137 void EmptyInputStream::closeInput()
138 throw (IOException, RuntimeException)
143 //=========================================================================
144 //=========================================================================
146 // class ContentEventListener_Impl.
148 //=========================================================================
149 //=========================================================================
151 class ContentEventListener_Impl : public cppu::OWeakObject,
152 public XContentEventListener
154 Content_Impl& m_rContent;
156 public:
157 ContentEventListener_Impl( Content_Impl& rContent )
158 : m_rContent( rContent ) {}
160 // XInterface
161 XINTERFACE_DECL()
163 // XContentEventListener
164 virtual void SAL_CALL contentEvent( const ContentEvent& evt )
165 throw( RuntimeException );
167 // XEventListener ( base of XContentEventListener )
168 virtual void SAL_CALL disposing( const EventObject& Source )
169 throw( RuntimeException );
172 //=========================================================================
173 //=========================================================================
175 // class Content_Impl.
177 //=========================================================================
178 //=========================================================================
180 class Content_Impl : public salhelper::SimpleReferenceObject
182 friend class ContentEventListener_Impl;
184 mutable rtl::OUString m_aURL;
185 Reference< XMultiServiceFactory > m_xSMgr;
186 Reference< XContent > m_xContent;
187 Reference< XCommandProcessor > m_xCommandProcessor;
188 Reference< XCommandEnvironment > m_xEnv;
189 Reference< XContentEventListener > m_xContentEventListener;
190 mutable osl::Mutex m_aMutex;
191 sal_Int32 m_nCommandId;
193 private:
194 void reinit( const Reference< XContent >& xContent );
195 void disposing(const EventObject& Source);
197 public:
198 Content_Impl() : m_nCommandId( 0 ) {};
199 Content_Impl( const Reference< XMultiServiceFactory >& rSMgr,
200 const Reference< XContent >& rContent,
201 const Reference< XCommandEnvironment >& rEnv );
203 virtual ~Content_Impl();
205 const rtl::OUString& getURL() const;
206 Reference< XContent > getContent();
207 Reference< XCommandProcessor > getCommandProcessor();
208 sal_Int32 getCommandId();
209 Reference< XMultiServiceFactory > getServiceManager() { return m_xSMgr; }
211 Any executeCommand( const Command& rCommand );
212 void abortCommand();
213 inline const Reference< XCommandEnvironment >& getEnvironment() const;
214 inline void setEnvironment(
215 const Reference< XCommandEnvironment >& xNewEnv );
217 void inserted();
220 //=========================================================================
221 // Helpers.
222 //=========================================================================
224 static void ensureContentProviderForURL( const ContentBroker & rBroker,
225 const rtl::OUString & rURL )
226 throw ( ContentCreationException, RuntimeException )
228 Reference< XContentProviderManager > xMgr
229 = rBroker.getContentProviderManagerInterface();
230 if ( !xMgr.is() )
232 throw RuntimeException(
233 rtl::OUString::createFromAscii(
234 "UCB does not implement mandatory interface "
235 "XContentProviderManager!" ),
236 Reference< XInterface >() );
238 else
240 Reference< XContentProvider > xProv
241 = xMgr->queryContentProvider( rURL );
242 if ( !xProv.is() )
244 throw ContentCreationException(
245 rtl::OUString::createFromAscii(
246 "No Content Provider available for given URL!" ),
247 Reference< XInterface >(),
248 ContentCreationError_NO_CONTENT_PROVIDER );
253 //=========================================================================
254 static ContentBroker* getContentBroker( bool bThrow )
255 throw ( ContentCreationException, RuntimeException )
257 ContentBroker* pBroker = ContentBroker::get();
259 if ( !pBroker )
261 if ( bThrow )
262 throw RuntimeException(
263 rtl::OUString::createFromAscii( "No Content Broker!" ),
264 Reference< XInterface >() );
266 else
268 #if OSL_DEBUG_LEVEL > 1
269 Reference< XContentProviderManager > xMgr
270 = pBroker->getContentProviderManagerInterface();
271 if ( !xMgr.is() )
273 if ( bThrow )
274 throw RuntimeException(
275 rtl::OUString::createFromAscii(
276 "UCB does not implement mandatory interface "
277 "XContentProviderManager!" ),
278 Reference< XInterface >() );
280 else
282 OSL_ENSURE( xMgr->queryContentProviders().getLength(),
283 "Content Broker not configured (no providers)!" );
285 #endif
288 return pBroker;
291 //=========================================================================
292 static Reference< XContentIdentifier > getContentIdentifier(
293 const ContentBroker & rBroker,
294 const rtl::OUString & rURL,
295 bool bThrow )
296 throw ( ContentCreationException, RuntimeException )
298 Reference< XContentIdentifierFactory > xIdFac
299 = rBroker.getContentIdentifierFactoryInterface();
300 if ( xIdFac.is() )
302 Reference< XContentIdentifier > xId
303 = xIdFac->createContentIdentifier( rURL );
305 if ( xId.is() )
306 return xId;
308 if ( bThrow )
310 ensureContentProviderForURL( rBroker, rURL );
312 throw ContentCreationException(
313 rtl::OUString::createFromAscii(
314 "Unable to create Content Identifier!" ),
315 Reference< XInterface >(),
316 ContentCreationError_IDENTIFIER_CREATION_FAILED );
319 else
321 if ( bThrow )
322 throw RuntimeException(
323 rtl::OUString::createFromAscii(
324 "UCB does not implement mandatory interface "
325 "XContentIdentifierFactory!" ),
326 Reference< XInterface >() );
329 return Reference< XContentIdentifier >();
332 //=========================================================================
333 static Reference< XContent > getContent(
334 const ContentBroker & rBroker,
335 const Reference< XContentIdentifier > & xId,
336 bool bThrow )
337 throw ( ContentCreationException, RuntimeException )
339 Reference< XContentProvider > xProvider
340 = rBroker.getContentProviderInterface();
341 if ( xProvider.is() )
343 Reference< XContent > xContent;
346 xContent = xProvider->queryContent( xId );
348 catch ( IllegalIdentifierException const & )
350 // handled below.
353 if ( xContent.is() )
354 return xContent;
356 if ( bThrow )
358 ensureContentProviderForURL( rBroker, xId->getContentIdentifier() );
360 throw ContentCreationException(
361 rtl::OUString::createFromAscii(
362 "Unable to create Content!" ),
363 Reference< XInterface >(),
364 ContentCreationError_CONTENT_CREATION_FAILED );
367 else
369 if ( bThrow )
370 throw RuntimeException(
371 rtl::OUString::createFromAscii(
372 "UCB does not implement mandatory interface "
373 "XContentProvider!" ),
374 Reference< XInterface >() );
377 return Reference< XContent >();
380 //=========================================================================
381 //=========================================================================
383 // Content Implementation.
385 //=========================================================================
386 //=========================================================================
388 Content::Content()
389 : m_xImpl( new Content_Impl )
393 //=========================================================================
394 Content::Content( const rtl::OUString& rURL,
395 const Reference< XCommandEnvironment >& rEnv )
396 throw ( ContentCreationException, RuntimeException )
398 ContentBroker* pBroker = getContentBroker( true );
400 Reference< XContentIdentifier > xId
401 = getContentIdentifier( *pBroker, rURL, true );
403 Reference< XContent > xContent = getContent( *pBroker, xId, true );
405 m_xImpl = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
408 //=========================================================================
409 Content::Content( const Reference< XContentIdentifier >& rId,
410 const Reference< XCommandEnvironment >& rEnv )
411 throw ( ContentCreationException, RuntimeException )
413 ContentBroker* pBroker = getContentBroker( true );
415 Reference< XContent > xContent = getContent( *pBroker, rId, true );
417 m_xImpl = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
420 //=========================================================================
421 Content::Content( const Reference< XContent >& rContent,
422 const Reference< XCommandEnvironment >& rEnv )
423 throw ( ContentCreationException, RuntimeException )
425 ContentBroker* pBroker = getContentBroker( true );
427 m_xImpl = new Content_Impl( pBroker->getServiceManager(), rContent, rEnv );
430 //=========================================================================
431 Content::Content( const Content& rOther )
433 m_xImpl = rOther.m_xImpl;
436 //=========================================================================
437 // static
438 sal_Bool Content::create( const rtl::OUString& rURL,
439 const Reference< XCommandEnvironment >& rEnv,
440 Content& rContent )
442 ContentBroker* pBroker = getContentBroker( false );
443 if ( !pBroker )
444 return sal_False;
446 Reference< XContentIdentifier > xId
447 = getContentIdentifier( *pBroker, rURL, false );
448 if ( !xId.is() )
449 return sal_False;
451 Reference< XContent > xContent = getContent( *pBroker, xId, false );
452 if ( !xContent.is() )
453 return sal_False;
455 rContent.m_xImpl
456 = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
458 return sal_True;
461 //=========================================================================
462 // static
463 sal_Bool Content::create( const Reference< XContentIdentifier >& rId,
464 const Reference< XCommandEnvironment >& rEnv,
465 Content& rContent )
467 ContentBroker* pBroker = getContentBroker( false );
468 if ( !pBroker )
469 return sal_False;
471 Reference< XContent > xContent = getContent( *pBroker, rId, false );
472 if ( !xContent.is() )
473 return sal_False;
475 rContent.m_xImpl
476 = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
478 return sal_True;
481 //=========================================================================
482 // static
483 sal_Bool Content::create( const Reference< XContent >& xContent,
484 const Reference< XCommandEnvironment >& rEnv,
485 Content& rContent )
487 ContentBroker* pBroker = getContentBroker( false );
488 if ( !pBroker )
489 return sal_False;
491 rContent.m_xImpl
492 = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv );
494 return sal_True;
497 //=========================================================================
498 Content::~Content()
502 //=========================================================================
503 Content& Content::operator=( const Content& rOther )
505 m_xImpl = rOther.m_xImpl;
506 return *this;
509 //=========================================================================
510 Reference< XContent > Content::get() const
512 return m_xImpl->getContent();
515 //=========================================================================
516 const rtl::OUString& Content::getURL() const
518 return m_xImpl->getURL();
521 //=========================================================================
522 const Reference< XCommandEnvironment >& Content::getCommandEnvironment() const
524 return m_xImpl->getEnvironment();
527 //=========================================================================
528 void Content::setCommandEnvironment(
529 const Reference< XCommandEnvironment >& xNewEnv )
531 m_xImpl->setEnvironment( xNewEnv );
534 //=========================================================================
535 Reference< XCommandInfo > Content::getCommands()
536 throw( CommandAbortedException, RuntimeException, Exception )
538 Command aCommand;
539 aCommand.Name = rtl::OUString::createFromAscii( "getCommandInfo" );
540 aCommand.Handle = -1; // n/a
541 aCommand.Argument = Any();
543 Any aResult = m_xImpl->executeCommand( aCommand );
545 Reference< XCommandInfo > xInfo;
546 aResult >>= xInfo;
547 return xInfo;
550 //=========================================================================
551 Reference< XPropertySetInfo > Content::getProperties()
552 throw( CommandAbortedException, RuntimeException, Exception )
554 Command aCommand;
555 aCommand.Name = rtl::OUString::createFromAscii( "getPropertySetInfo" );
556 aCommand.Handle = -1; // n/a
557 aCommand.Argument = Any();
559 Any aResult = m_xImpl->executeCommand( aCommand );
561 Reference< XPropertySetInfo > xInfo;
562 aResult >>= xInfo;
563 return xInfo;
566 //=========================================================================
567 Any Content::getPropertyValue( const rtl::OUString& rPropertyName )
568 throw( CommandAbortedException, RuntimeException, Exception )
570 Sequence< rtl::OUString > aNames( 1 );
571 aNames.getArray()[ 0 ] = rPropertyName;
573 Sequence< Any > aRet = getPropertyValues( aNames );
574 return aRet.getConstArray()[ 0 ];
577 //=========================================================================
578 Any Content::getPropertyValue( sal_Int32 nPropertyHandle )
579 throw( CommandAbortedException, RuntimeException, Exception )
581 Sequence< sal_Int32 > aHandles( 1 );
582 aHandles.getArray()[ 0 ] = nPropertyHandle;
584 Sequence< Any > aRet = getPropertyValues( aHandles );
585 return aRet.getConstArray()[ 0 ];
588 //=========================================================================
589 Any Content::setPropertyValue( const rtl::OUString& rName,
590 const Any& rValue )
591 throw( CommandAbortedException, RuntimeException, Exception )
593 Sequence< rtl::OUString > aNames( 1 );
594 aNames.getArray()[ 0 ] = rName;
596 Sequence< Any > aValues( 1 );
597 aValues.getArray()[ 0 ] = rValue;
599 Sequence< Any > aErrors = setPropertyValues( aNames, aValues );
600 return aErrors.getConstArray()[ 0 ];
603 //=========================================================================
604 Any Content::setPropertyValue( const sal_Int32 nPropertyHandle,
605 const Any& rValue )
606 throw( CommandAbortedException, RuntimeException, Exception )
608 Sequence< sal_Int32 > aHandles( 1 );
609 aHandles.getArray()[ 0 ] = nPropertyHandle;
611 Sequence< Any > aValues( 1 );
612 aValues.getArray()[ 0 ] = rValue;
614 Sequence< Any > aErrors = setPropertyValues( aHandles, aValues );
615 return aErrors.getConstArray()[ 0 ];
618 //=========================================================================
619 Sequence< Any > Content::getPropertyValues(
620 const Sequence< rtl::OUString >& rPropertyNames )
621 throw( CommandAbortedException, RuntimeException, Exception )
623 Reference< XRow > xRow = getPropertyValuesInterface( rPropertyNames );
625 sal_Int32 nCount = rPropertyNames.getLength();
626 Sequence< Any > aValues( nCount );
628 if ( xRow.is() )
630 Any* pValues = aValues.getArray();
632 for ( sal_Int32 n = 0; n < nCount; ++n )
633 pValues[ n ] = xRow->getObject( n + 1, Reference< XNameAccess >() );
636 return aValues;
639 //=========================================================================
640 Sequence< Any > Content::getPropertyValues(
641 const Sequence< sal_Int32 >& nPropertyHandles )
642 throw( CommandAbortedException, RuntimeException, Exception )
644 Reference< XRow > xRow = getPropertyValuesInterface( nPropertyHandles );
646 sal_Int32 nCount = nPropertyHandles.getLength();
647 Sequence< Any > aValues( nCount );
649 if ( xRow.is() )
651 Any* pValues = aValues.getArray();
653 for ( sal_Int32 n = 0; n < nCount; ++n )
654 pValues[ n ] = xRow->getObject( n + 1, Reference< XNameAccess >() );
657 return aValues;
660 //=========================================================================
661 Reference< XRow > Content::getPropertyValuesInterface(
662 const Sequence< rtl::OUString >& rPropertyNames )
663 throw( CommandAbortedException, RuntimeException, Exception )
665 sal_Int32 nCount = rPropertyNames.getLength();
666 Sequence< Property > aProps( nCount );
667 Property* pProps = aProps.getArray();
669 const rtl::OUString* pNames = rPropertyNames.getConstArray();
671 for ( sal_Int32 n = 0; n< nCount; ++n )
673 Property& rProp = pProps[ n ];
675 rProp.Name = pNames[ n ];
676 rProp.Handle = -1; // n/a
677 // rProp.Type =
678 // rProp.Attributes = ;
681 Command aCommand;
682 aCommand.Name = rtl::OUString::createFromAscii( "getPropertyValues" );
683 aCommand.Handle = -1; // n/a
684 aCommand.Argument <<= aProps;
686 Any aResult = m_xImpl->executeCommand( aCommand );
688 Reference< XRow > xRow;
689 aResult >>= xRow;
690 return xRow;
693 //=========================================================================
694 Reference< XRow > Content::getPropertyValuesInterface(
695 const Sequence< sal_Int32 >& nPropertyHandles )
696 throw( CommandAbortedException, RuntimeException, Exception )
698 sal_Int32 nCount = nPropertyHandles.getLength();
699 Sequence< Property > aProps( nCount );
700 Property* pProps = aProps.getArray();
702 const sal_Int32* pHandles = nPropertyHandles.getConstArray();
704 for ( sal_Int32 n = 0; n< nCount; ++n )
706 Property& rProp = pProps[ n ];
708 rProp.Name = rtl::OUString(); // n/a
709 rProp.Handle = pHandles[ n ];
710 // rProp.Type =
711 // rProp.Attributes = ;
714 Command aCommand;
715 aCommand.Name = rtl::OUString::createFromAscii( "getPropertyValues" );
716 aCommand.Handle = -1; // n/a
717 aCommand.Argument <<= aProps;
719 Any aResult = m_xImpl->executeCommand( aCommand );
721 Reference< XRow > xRow;
722 aResult >>= xRow;
723 return xRow;
726 //=========================================================================
727 Sequence< Any > Content::setPropertyValues(
728 const Sequence< rtl::OUString >& rPropertyNames,
729 const Sequence< Any >& rValues )
730 throw( CommandAbortedException, RuntimeException, Exception )
732 if ( rPropertyNames.getLength() != rValues.getLength() )
734 ucbhelper::cancelCommandExecution(
735 makeAny( IllegalArgumentException(
736 rtl::OUString::createFromAscii(
737 "Length of property names sequence and value "
738 "sequence are unequal!" ),
739 get(),
740 -1 ) ),
741 m_xImpl->getEnvironment() );
742 // Unreachable
745 sal_Int32 nCount = rValues.getLength();
746 Sequence< PropertyValue > aProps( nCount );
747 PropertyValue* pProps = aProps.getArray();
749 const rtl::OUString* pNames = rPropertyNames.getConstArray();
750 const Any* pValues = rValues.getConstArray();
752 for ( sal_Int32 n = 0; n< nCount; ++n )
754 PropertyValue& rProp = pProps[ n ];
756 rProp.Name = pNames[ n ];
757 rProp.Handle = -1; // n/a
758 rProp.Value = pValues[ n ];
759 // rProp.State = ;
762 Command aCommand;
763 aCommand.Name = rtl::OUString::createFromAscii( "setPropertyValues" );
764 aCommand.Handle = -1; // n/a
765 aCommand.Argument <<= aProps;
767 Any aResult = m_xImpl->executeCommand( aCommand );
769 Sequence< Any > aErrors;
770 aResult >>= aErrors;
771 return aErrors;
774 //=========================================================================
775 Sequence< Any > Content::setPropertyValues(
776 const Sequence< sal_Int32 >& nPropertyHandles,
777 const Sequence< Any >& rValues )
778 throw( CommandAbortedException, RuntimeException, Exception )
780 if ( nPropertyHandles.getLength() != rValues.getLength() )
782 ucbhelper::cancelCommandExecution(
783 makeAny( IllegalArgumentException(
784 rtl::OUString::createFromAscii(
785 "Length of property handles sequence and value "
786 "sequence are unequal!" ),
787 get(),
788 -1 ) ),
789 m_xImpl->getEnvironment() );
790 // Unreachable
793 sal_Int32 nCount = rValues.getLength();
794 Sequence< PropertyValue > aProps( nCount );
795 PropertyValue* pProps = aProps.getArray();
797 const sal_Int32* pHandles = nPropertyHandles.getConstArray();
798 const Any* pValues = rValues.getConstArray();
800 for ( sal_Int32 n = 0; n< nCount; ++n )
802 PropertyValue& rProp = pProps[ n ];
804 rProp.Name = rtl::OUString(); // n/a
805 rProp.Handle = pHandles[ n ];
806 rProp.Value = pValues[ n ];
807 // rProp.State = ;
810 Command aCommand;
811 aCommand.Name = rtl::OUString::createFromAscii( "setPropertyValues" );
812 aCommand.Handle = -1; // n/a
813 aCommand.Argument <<= aProps;
815 Any aResult = m_xImpl->executeCommand( aCommand );
817 Sequence< Any > aErrors;
818 aResult >>= aErrors;
819 return aErrors;
822 //=========================================================================
823 Any Content::executeCommand( const rtl::OUString& rCommandName,
824 const Any& rCommandArgument )
825 throw( CommandAbortedException, RuntimeException, Exception )
827 Command aCommand;
828 aCommand.Name = rCommandName;
829 aCommand.Handle = -1; // n/a
830 aCommand.Argument = rCommandArgument;
832 return m_xImpl->executeCommand( aCommand );
835 //=========================================================================
836 Any Content::executeCommand( sal_Int32 nCommandHandle,
837 const Any& rCommandArgument )
838 throw( CommandAbortedException, RuntimeException, Exception )
840 Command aCommand;
841 aCommand.Name = rtl::OUString(); // n/a
842 aCommand.Handle = nCommandHandle;
843 aCommand.Argument = rCommandArgument;
845 return m_xImpl->executeCommand( aCommand );
848 //=========================================================================
849 void Content::abortCommand()
851 m_xImpl->abortCommand();
854 //=========================================================================
855 Any Content::createCursorAny( const Sequence< rtl::OUString >& rPropertyNames,
856 ResultSetInclude eMode )
857 throw( CommandAbortedException, RuntimeException, Exception )
859 sal_Int32 nCount = rPropertyNames.getLength();
860 Sequence< Property > aProps( nCount );
861 Property* pProps = aProps.getArray();
862 const rtl::OUString* pNames = rPropertyNames.getConstArray();
863 for ( sal_Int32 n = 0; n < nCount; ++n )
865 Property& rProp = pProps[ n ];
866 rProp.Name = pNames[ n ];
867 rProp.Handle = -1; // n/a
870 OpenCommandArgument2 aArg;
871 aArg.Mode = ( eMode == INCLUDE_FOLDERS_ONLY )
872 ? OpenMode::FOLDERS
873 : ( eMode == INCLUDE_DOCUMENTS_ONLY )
874 ? OpenMode::DOCUMENTS : OpenMode::ALL;
875 aArg.Priority = 0; // unused
876 aArg.Sink = Reference< XInterface >(); // unused
877 aArg.Properties = aProps;
879 Command aCommand;
880 aCommand.Name = rtl::OUString::createFromAscii( "open" );
881 aCommand.Handle = -1; // n/a
882 aCommand.Argument <<= aArg;
884 return m_xImpl->executeCommand( aCommand );
887 //=========================================================================
888 Any Content::createCursorAny( const Sequence< sal_Int32 >& rPropertyHandles,
889 ResultSetInclude eMode )
890 throw( CommandAbortedException, RuntimeException, Exception )
892 sal_Int32 nCount = rPropertyHandles.getLength();
893 Sequence< Property > aProps( nCount );
894 Property* pProps = aProps.getArray();
895 const sal_Int32* pHandles = rPropertyHandles.getConstArray();
896 for ( sal_Int32 n = 0; n < nCount; ++n )
898 Property& rProp = pProps[ n ];
899 rProp.Name = rtl::OUString(); // n/a
900 rProp.Handle = pHandles[ n ];
903 OpenCommandArgument2 aArg;
904 aArg.Mode = ( eMode == INCLUDE_FOLDERS_ONLY )
905 ? OpenMode::FOLDERS
906 : ( eMode == INCLUDE_DOCUMENTS_ONLY )
907 ? OpenMode::DOCUMENTS : OpenMode::ALL;
908 aArg.Priority = 0; // unused
909 aArg.Sink = Reference< XInterface >(); // unused
910 aArg.Properties = aProps;
912 Command aCommand;
913 aCommand.Name = rtl::OUString::createFromAscii( "open" );
914 aCommand.Handle = -1; // n/a
915 aCommand.Argument <<= aArg;
917 return m_xImpl->executeCommand( aCommand );
920 //=========================================================================
921 Reference< XResultSet > Content::createCursor(
922 const Sequence< rtl::OUString >& rPropertyNames,
923 ResultSetInclude eMode )
924 throw( CommandAbortedException, RuntimeException, Exception )
926 Any aCursorAny = createCursorAny( rPropertyNames, eMode );
928 Reference< XDynamicResultSet > xDynSet;
929 Reference< XResultSet > aResult;
931 aCursorAny >>= xDynSet;
932 if ( xDynSet.is() )
933 aResult = xDynSet->getStaticResultSet();
935 OSL_ENSURE( aResult.is(), "Content::createCursor - no cursor!" );
937 if ( !aResult.is() )
939 // Former, the open command directly returned a XResultSet.
940 aCursorAny >>= aResult;
942 OSL_ENSURE( !aResult.is(),
943 "Content::createCursor - open-Command must "
944 "return a Reference< XDynnamicResultSet >!" );
947 return aResult;
950 //=========================================================================
951 Reference< XResultSet > Content::createCursor(
952 const Sequence< sal_Int32 >& rPropertyHandles,
953 ResultSetInclude eMode )
954 throw( CommandAbortedException, RuntimeException, Exception )
956 Any aCursorAny = createCursorAny( rPropertyHandles, eMode );
958 Reference< XDynamicResultSet > xDynSet;
959 Reference< XResultSet > aResult;
961 aCursorAny >>= xDynSet;
962 if ( xDynSet.is() )
963 aResult = xDynSet->getStaticResultSet();
965 OSL_ENSURE( aResult.is(), "Content::createCursor - no cursor!" );
967 if ( !aResult.is() )
969 // Former, the open command directly returned a XResultSet.
970 aCursorAny >>= aResult;
972 OSL_ENSURE( !aResult.is(),
973 "Content::createCursor - open-Command must "
974 "return a Reference< XDynnamicResultSet >!" );
977 return aResult;
980 //=========================================================================
981 Reference< XDynamicResultSet > Content::createDynamicCursor(
982 const Sequence< rtl::OUString >& rPropertyNames,
983 ResultSetInclude eMode )
984 throw( CommandAbortedException, RuntimeException, Exception )
986 Reference< XDynamicResultSet > aResult;
987 createCursorAny( rPropertyNames, eMode ) >>= aResult;
989 OSL_ENSURE( aResult.is(), "Content::createDynamicCursor - no cursor!" );
991 return aResult;
994 //=========================================================================
995 Reference< XDynamicResultSet > Content::createDynamicCursor(
996 const Sequence< sal_Int32 >& rPropertyHandles,
997 ResultSetInclude eMode )
998 throw( CommandAbortedException, RuntimeException, Exception )
1000 Reference< XDynamicResultSet > aResult;
1001 createCursorAny( rPropertyHandles, eMode ) >>= aResult;
1003 OSL_ENSURE( aResult.is(), "Content::createDynamicCursor - no cursor!" );
1005 return aResult;
1008 //=========================================================================
1009 Reference< XDynamicResultSet > Content::createSortedDynamicCursor(
1010 const Sequence< rtl::OUString >& rPropertyNames,
1011 const ::com::sun::star::uno::Sequence< ::com::sun::star::ucb::NumberedSortingInfo >& rSortInfo,
1012 Reference< XAnyCompareFactory > rAnyCompareFactory,
1013 ResultSetInclude eMode )
1014 throw( CommandAbortedException, RuntimeException, Exception )
1016 Reference< XDynamicResultSet > aResult;
1017 Reference< XDynamicResultSet > aOrigCursor = createDynamicCursor( rPropertyNames, eMode );
1019 if( aOrigCursor.is() )
1021 Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
1023 if( aServiceManager.is() )
1025 Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
1026 rtl::OUString::createFromAscii( "com.sun.star.ucb.SortedDynamicResultSetFactory" )),
1027 UNO_QUERY );
1029 aResult = aSortFactory->createSortedDynamicResultSet( aOrigCursor,
1030 rSortInfo,
1031 rAnyCompareFactory );
1034 OSL_ENSURE( aResult.is(), "Content::createSortedDynamicCursor - no sorted cursor!\n" );
1036 if( !aResult.is() )
1037 aResult = aOrigCursor;
1040 return aResult;
1043 //=========================================================================
1044 Reference< XDynamicResultSet > Content::createSortedDynamicCursor(
1045 const Sequence< sal_Int32 >& rPropertyHandles,
1046 const ::com::sun::star::uno::Sequence< ::com::sun::star::ucb::NumberedSortingInfo >& rSortInfo,
1047 Reference< XAnyCompareFactory > rAnyCompareFactory,
1048 ResultSetInclude eMode )
1049 throw( CommandAbortedException, RuntimeException, Exception )
1051 Reference< XDynamicResultSet > aResult;
1052 Reference< XDynamicResultSet > aOrigCursor = createDynamicCursor( rPropertyHandles, eMode );
1054 if( aOrigCursor.is() )
1056 Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
1058 if( aServiceManager.is() )
1060 Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
1061 rtl::OUString::createFromAscii( "com.sun.star.ucb.SortedDynamicResultSetFactory" )),
1062 UNO_QUERY );
1064 aResult = aSortFactory->createSortedDynamicResultSet( aOrigCursor,
1065 rSortInfo,
1066 rAnyCompareFactory );
1069 OSL_ENSURE( aResult.is(), "Content::createSortedDynamicCursor - no sorted cursor!\n" );
1071 if( !aResult.is() )
1072 aResult = aOrigCursor;
1075 return aResult;
1078 //=========================================================================
1079 Reference< XResultSet > Content::createSortedCursor(
1080 const Sequence< rtl::OUString >& rPropertyNames,
1081 const ::com::sun::star::uno::Sequence< ::com::sun::star::ucb::NumberedSortingInfo >& rSortInfo,
1082 Reference< XAnyCompareFactory > rAnyCompareFactory,
1083 ResultSetInclude eMode )
1084 throw( CommandAbortedException, RuntimeException, Exception )
1086 Reference< XResultSet > aResult;
1087 Reference< XDynamicResultSet > aDynSet;
1089 Any aCursorAny = createCursorAny( rPropertyNames, eMode );
1091 aCursorAny >>= aDynSet;
1093 if( aDynSet.is() )
1095 Reference< XDynamicResultSet > aDynResult;
1096 Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
1098 if( aServiceManager.is() )
1100 Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
1101 rtl::OUString::createFromAscii( "com.sun.star.ucb.SortedDynamicResultSetFactory" )),
1102 UNO_QUERY );
1104 aDynResult = aSortFactory->createSortedDynamicResultSet( aDynSet,
1105 rSortInfo,
1106 rAnyCompareFactory );
1109 OSL_ENSURE( aDynResult.is(), "Content::createSortedCursor - no sorted cursor!\n" );
1111 if( aDynResult.is() )
1112 aResult = aDynResult->getStaticResultSet();
1113 else
1114 aResult = aDynSet->getStaticResultSet();
1117 OSL_ENSURE( aResult.is(), "Content::createSortedCursor - no cursor!" );
1119 if ( !aResult.is() )
1121 // Former, the open command directly returned a XResultSet.
1122 aCursorAny >>= aResult;
1124 OSL_ENSURE( !aResult.is(),
1125 "Content::createCursor - open-Command must "
1126 "return a Reference< XDynnamicResultSet >!" );
1129 return aResult;
1132 //=========================================================================
1133 Reference< XResultSet > Content::createSortedCursor(
1134 const Sequence< sal_Int32 >& rPropertyHandles,
1135 const ::com::sun::star::uno::Sequence< ::com::sun::star::ucb::NumberedSortingInfo >& rSortInfo,
1136 Reference< XAnyCompareFactory > rAnyCompareFactory,
1137 ResultSetInclude eMode )
1138 throw( CommandAbortedException, RuntimeException, Exception )
1140 Reference< XResultSet > aResult;
1141 Reference< XDynamicResultSet > aDynSet;
1143 Any aCursorAny = createCursorAny( rPropertyHandles, eMode );
1145 aCursorAny >>= aDynSet;
1147 if( aDynSet.is() )
1149 Reference< XDynamicResultSet > aDynResult;
1150 Reference< XMultiServiceFactory > aServiceManager = m_xImpl->getServiceManager();
1152 if( aServiceManager.is() )
1154 Reference< XSortedDynamicResultSetFactory > aSortFactory( aServiceManager->createInstance(
1155 rtl::OUString::createFromAscii( "com.sun.star.ucb.SortedDynamicResultSetFactory" )),
1156 UNO_QUERY );
1158 aDynResult = aSortFactory->createSortedDynamicResultSet( aDynSet,
1159 rSortInfo,
1160 rAnyCompareFactory );
1163 OSL_ENSURE( aDynResult.is(), "Content::createSortedCursor - no sorted cursor!\n" );
1165 if( aDynResult.is() )
1166 aResult = aDynResult->getStaticResultSet();
1167 else
1168 aResult = aDynSet->getStaticResultSet();
1171 OSL_ENSURE( aResult.is(), "Content::createSortedCursor - no cursor!" );
1173 if ( !aResult.is() )
1175 // Former, the open command directly returned a XResultSet.
1176 aCursorAny >>= aResult;
1178 OSL_ENSURE( !aResult.is(),
1179 "Content::createCursor - open-Command must "
1180 "return a Reference< XDynnamicResultSet >!" );
1183 return aResult;
1186 //=========================================================================
1187 Reference< XInputStream > Content::openStream()
1188 throw( CommandAbortedException, RuntimeException, Exception )
1190 if ( !isDocument() )
1191 return Reference< XInputStream >();
1193 Reference< XActiveDataSink > xSink = new ActiveDataSink;
1195 OpenCommandArgument2 aArg;
1196 aArg.Mode = OpenMode::DOCUMENT;
1197 aArg.Priority = 0; // unused
1198 aArg.Sink = xSink;
1199 aArg.Properties = Sequence< Property >( 0 ); // unused
1201 Command aCommand;
1202 aCommand.Name = rtl::OUString::createFromAscii( "open" );
1203 aCommand.Handle = -1; // n/a
1204 aCommand.Argument <<= aArg;
1206 m_xImpl->executeCommand( aCommand );
1208 return xSink->getInputStream();
1211 //=========================================================================
1212 Reference< XInputStream > Content::openStreamNoLock()
1213 throw( CommandAbortedException, RuntimeException, Exception )
1215 if ( !isDocument() )
1216 return Reference< XInputStream >();
1218 Reference< XActiveDataSink > xSink = new ActiveDataSink;
1220 OpenCommandArgument2 aArg;
1221 aArg.Mode = OpenMode::DOCUMENT_SHARE_DENY_NONE;
1222 aArg.Priority = 0; // unused
1223 aArg.Sink = xSink;
1224 aArg.Properties = Sequence< Property >( 0 ); // unused
1226 Command aCommand;
1227 aCommand.Name = rtl::OUString::createFromAscii( "open" );
1228 aCommand.Handle = -1; // n/a
1229 aCommand.Argument <<= aArg;
1231 m_xImpl->executeCommand( aCommand );
1233 return xSink->getInputStream();
1236 //=========================================================================
1237 Reference< XStream > Content::openWriteableStream()
1238 throw( CommandAbortedException, RuntimeException, Exception )
1240 if ( !isDocument() )
1241 return Reference< XStream >();
1243 Reference< XActiveDataStreamer > xStreamer = new ActiveDataStreamer;
1245 OpenCommandArgument2 aArg;
1246 aArg.Mode = OpenMode::DOCUMENT;
1247 aArg.Priority = 0; // unused
1248 aArg.Sink = xStreamer;
1249 aArg.Properties = Sequence< Property >( 0 ); // unused
1251 Command aCommand;
1252 aCommand.Name = rtl::OUString::createFromAscii( "open" );
1253 aCommand.Handle = -1; // n/a
1254 aCommand.Argument <<= aArg;
1256 m_xImpl->executeCommand( aCommand );
1258 return xStreamer->getStream();
1261 //=========================================================================
1262 Reference< XStream > Content::openWriteableStreamNoLock()
1263 throw( CommandAbortedException, RuntimeException, Exception )
1265 if ( !isDocument() )
1266 return Reference< XStream >();
1268 Reference< XActiveDataStreamer > xStreamer = new ActiveDataStreamer;
1270 OpenCommandArgument2 aArg;
1271 aArg.Mode = OpenMode::DOCUMENT_SHARE_DENY_NONE;
1272 aArg.Priority = 0; // unused
1273 aArg.Sink = xStreamer;
1274 aArg.Properties = Sequence< Property >( 0 ); // unused
1276 Command aCommand;
1277 aCommand.Name = rtl::OUString::createFromAscii( "open" );
1278 aCommand.Handle = -1; // n/a
1279 aCommand.Argument <<= aArg;
1281 m_xImpl->executeCommand( aCommand );
1283 return xStreamer->getStream();
1286 //=========================================================================
1287 sal_Bool Content::openStream( const Reference< XActiveDataSink >& rSink )
1288 throw( CommandAbortedException, RuntimeException, Exception )
1290 if ( !isDocument() )
1291 return sal_False;
1293 OpenCommandArgument2 aArg;
1294 aArg.Mode = OpenMode::DOCUMENT;
1295 aArg.Priority = 0; // unused
1296 aArg.Sink = rSink;
1297 aArg.Properties = Sequence< Property >( 0 ); // unused
1299 Command aCommand;
1300 aCommand.Name = rtl::OUString::createFromAscii( "open" );
1301 aCommand.Handle = -1; // n/a
1302 aCommand.Argument <<= aArg;
1304 m_xImpl->executeCommand( aCommand );
1306 return sal_True;
1309 //=========================================================================
1310 sal_Bool Content::openStream( const Reference< XOutputStream >& rStream )
1311 throw( CommandAbortedException, RuntimeException, Exception )
1313 if ( !isDocument() )
1314 return sal_False;
1316 OpenCommandArgument2 aArg;
1317 aArg.Mode = OpenMode::DOCUMENT;
1318 aArg.Priority = 0; // unused
1319 aArg.Sink = rStream;
1320 aArg.Properties = Sequence< Property >( 0 ); // unused
1322 Command aCommand;
1323 aCommand.Name = rtl::OUString::createFromAscii( "open" );
1324 aCommand.Handle = -1; // n/a
1325 aCommand.Argument <<= aArg;
1327 m_xImpl->executeCommand( aCommand );
1329 return sal_True;
1332 //=========================================================================
1333 void Content::writeStream( const Reference< XInputStream >& rStream,
1334 sal_Bool bReplaceExisting )
1335 throw( CommandAbortedException, RuntimeException, Exception )
1337 InsertCommandArgument aArg;
1338 aArg.Data = rStream.is() ? rStream : new EmptyInputStream;
1339 aArg.ReplaceExisting = bReplaceExisting;
1341 Command aCommand;
1342 aCommand.Name = rtl::OUString::createFromAscii( "insert" );
1343 aCommand.Handle = -1; // n/a
1344 aCommand.Argument <<= aArg;
1346 m_xImpl->executeCommand( aCommand );
1348 m_xImpl->inserted();
1351 //=========================================================================
1352 sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
1353 const Sequence< rtl::OUString >&
1354 rPropertyNames,
1355 const Sequence< Any >& rPropertyValues,
1356 Content& rNewContent )
1357 throw( CommandAbortedException, RuntimeException, Exception )
1359 return insertNewContent( rContentType,
1360 rPropertyNames,
1361 rPropertyValues,
1362 new EmptyInputStream,
1363 rNewContent );
1366 //=========================================================================
1367 sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
1368 const Sequence< sal_Int32 >&
1369 nPropertyHandles,
1370 const Sequence< Any >& rPropertyValues,
1371 Content& rNewContent )
1372 throw( CommandAbortedException, RuntimeException, Exception )
1374 return insertNewContent( rContentType,
1375 nPropertyHandles,
1376 rPropertyValues,
1377 new EmptyInputStream,
1378 rNewContent );
1381 //=========================================================================
1382 sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
1383 const Sequence< rtl::OUString >&
1384 rPropertyNames,
1385 const Sequence< Any >& rPropertyValues,
1386 const Reference< XInputStream >& rData,
1387 Content& rNewContent )
1388 throw( CommandAbortedException, RuntimeException, Exception )
1390 if ( rContentType.getLength() == 0 )
1391 return sal_False;
1393 Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY );
1395 OSL_ENSURE( xCreator.is(),
1396 "Content::insertNewContent - Not a XContentCreator!" );
1398 if ( !xCreator.is() )
1399 return sal_False;
1401 ContentInfo aInfo;
1402 aInfo.Type = rContentType;
1403 aInfo.Attributes = 0;
1405 Reference< XContent > xNew = xCreator->createNewContent( aInfo );
1406 if ( !xNew.is() )
1407 return sal_False;
1409 Content aNewContent( xNew, m_xImpl->getEnvironment() );
1410 aNewContent.setPropertyValues( rPropertyNames, rPropertyValues );
1411 aNewContent.executeCommand( rtl::OUString::createFromAscii( "insert" ),
1412 makeAny(
1413 InsertCommandArgument(
1414 rData.is() ? rData : new EmptyInputStream,
1415 sal_False /* ReplaceExisting */ ) ) );
1416 aNewContent.m_xImpl->inserted();
1418 rNewContent = aNewContent;
1419 return sal_True;
1422 //=========================================================================
1423 sal_Bool Content::insertNewContent( const rtl::OUString& rContentType,
1424 const Sequence< sal_Int32 >&
1425 nPropertyHandles,
1426 const Sequence< Any >& rPropertyValues,
1427 const Reference< XInputStream >& rData,
1428 Content& rNewContent )
1429 throw( CommandAbortedException, RuntimeException, Exception )
1431 if ( rContentType.getLength() == 0 )
1432 return sal_False;
1434 Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY );
1436 OSL_ENSURE( xCreator.is(),
1437 "Content::insertNewContent - Not a XContentCreator!" );
1439 if ( !xCreator.is() )
1440 return sal_False;
1442 ContentInfo aInfo;
1443 aInfo.Type = rContentType;
1444 aInfo.Attributes = 0;
1446 Reference< XContent > xNew = xCreator->createNewContent( aInfo );
1447 if ( !xNew.is() )
1448 return sal_False;
1450 Content aNewContent( xNew, m_xImpl->getEnvironment() );
1451 aNewContent.setPropertyValues( nPropertyHandles, rPropertyValues );
1452 aNewContent.executeCommand( rtl::OUString::createFromAscii( "insert" ),
1453 makeAny(
1454 InsertCommandArgument(
1455 rData.is() ? rData : new EmptyInputStream,
1456 sal_False /* ReplaceExisting */ ) ) );
1457 aNewContent.m_xImpl->inserted();
1459 rNewContent = aNewContent;
1460 return sal_True;
1463 //=========================================================================
1464 sal_Bool Content::transferContent( const Content& rSourceContent,
1465 InsertOperation eOperation,
1466 const rtl::OUString & rTitle,
1467 const sal_Int32 nNameClashAction )
1468 throw( CommandAbortedException, RuntimeException, Exception )
1470 ContentBroker* pBroker = ContentBroker::get();
1471 if ( !pBroker )
1473 OSL_ENSURE( sal_False,
1474 "Content::transferContent - No Content Broker!" );
1475 return sal_False;
1478 Reference< XCommandProcessor > xCmdProc(
1479 pBroker->getCommandProcessorInterface() );
1480 if ( !xCmdProc.is() )
1482 OSL_ENSURE( sal_False,
1483 "Content::transferContent - No XCommandProcessor!" );
1484 return sal_False;
1487 // Execute command "globalTransfer" at UCB.
1489 TransferCommandOperation eTransOp = TransferCommandOperation();
1490 switch ( eOperation )
1492 case InsertOperation_COPY:
1493 eTransOp = TransferCommandOperation_COPY;
1494 break;
1496 case InsertOperation_MOVE:
1497 eTransOp = TransferCommandOperation_MOVE;
1498 break;
1500 case InsertOperation_LINK:
1501 eTransOp = TransferCommandOperation_LINK;
1502 break;
1504 default:
1505 ucbhelper::cancelCommandExecution(
1506 makeAny( IllegalArgumentException(
1507 rtl::OUString::createFromAscii(
1508 "Unknown transfer operation!" ),
1509 get(),
1510 -1 ) ),
1511 m_xImpl->getEnvironment() );
1512 // Unreachable
1515 GlobalTransferCommandArgument aTransferArg(
1516 eTransOp,
1517 rSourceContent.getURL(), // SourceURL
1518 getURL(), // TargetFolderURL,
1519 rTitle,
1520 nNameClashAction );
1521 Command aCommand;
1522 aCommand.Name = rtl::OUString::createFromAscii( "globalTransfer" );
1523 aCommand.Handle = -1; // n/a
1524 aCommand.Argument <<= aTransferArg;
1526 xCmdProc->execute( aCommand, 0, m_xImpl->getEnvironment() );
1527 return sal_True;
1530 //=========================================================================
1531 sal_Bool Content::isFolder()
1532 throw( CommandAbortedException, RuntimeException, Exception )
1534 sal_Bool bFolder = sal_False;
1535 if ( getPropertyValue( rtl::OUString::createFromAscii( "IsFolder" ) )
1536 >>= bFolder )
1537 return bFolder;
1539 ucbhelper::cancelCommandExecution(
1540 makeAny( UnknownPropertyException(
1541 rtl::OUString::createFromAscii(
1542 "Unable to retreive value of property 'IsFolder'!" ),
1543 get() ) ),
1544 m_xImpl->getEnvironment() );
1546 // Unreachable - cancelCommandExecution always throws an exception.
1547 // But some compilers complain...
1548 return sal_False;
1551 //=========================================================================
1552 sal_Bool Content::isDocument()
1553 throw( CommandAbortedException, RuntimeException, Exception )
1555 sal_Bool bDoc = sal_False;
1556 if ( getPropertyValue( rtl::OUString::createFromAscii( "IsDocument" ) )
1557 >>= bDoc )
1558 return bDoc;
1560 ucbhelper::cancelCommandExecution(
1561 makeAny( UnknownPropertyException(
1562 rtl::OUString::createFromAscii(
1563 "Unable to retreive value of property 'IsDocument'!" ),
1564 get() ) ),
1565 m_xImpl->getEnvironment() );
1567 // Unreachable - cancelCommandExecution always throws an exception,
1568 // But some compilers complain...
1569 return sal_False;
1572 //=========================================================================
1573 //=========================================================================
1575 // Content_Impl Implementation.
1577 //=========================================================================
1578 //=========================================================================
1580 Content_Impl::Content_Impl( const Reference< XMultiServiceFactory >& rSMgr,
1581 const Reference< XContent >& rContent,
1582 const Reference< XCommandEnvironment >& rEnv )
1583 : m_xSMgr( rSMgr ),
1584 m_xContent( rContent ),
1585 m_xEnv( rEnv ),
1586 m_nCommandId( 0 )
1588 if ( m_xContent.is() )
1590 m_xContentEventListener = new ContentEventListener_Impl( *this );
1591 m_xContent->addContentEventListener( m_xContentEventListener );
1593 #if OSL_DEBUG_LEVEL > 1
1594 // Only done on demand in product version for performance reasons,
1595 // but a nice debug helper.
1596 getURL();
1597 #endif
1601 //=========================================================================
1602 void Content_Impl::reinit( const Reference< XContent >& xContent )
1604 osl::MutexGuard aGuard( m_aMutex );
1606 m_xCommandProcessor = 0;
1607 m_nCommandId = 0;
1609 // #92581# - Don't reset m_aURL!!!
1611 if ( m_xContent.is() )
1615 m_xContent->removeContentEventListener( m_xContentEventListener );
1617 catch ( RuntimeException const & )
1622 if ( xContent.is() )
1624 m_xContent = xContent;
1625 m_xContent->addContentEventListener( m_xContentEventListener );
1627 #if OSL_DEBUG_LEVEL > 1
1628 // Only done on demand in product version for performance reasons,
1629 // but a nice debug helper.
1630 getURL();
1631 #endif
1633 else
1635 // We need m_xContent's URL in order to be able to create the
1636 // content object again if demanded ( --> Content_Impl::getContent() )
1637 getURL();
1639 m_xContent = 0;
1643 //=========================================================================
1644 // virtual
1645 Content_Impl::~Content_Impl()
1647 if ( m_xContent.is() )
1651 m_xContent->removeContentEventListener( m_xContentEventListener );
1653 catch ( RuntimeException const & )
1659 //=========================================================================
1660 void Content_Impl::disposing( const EventObject& Source )
1662 Reference<XContent> xContent;
1665 osl::MutexGuard aGuard( m_aMutex );
1666 if(Source.Source != m_xContent)
1667 return;
1669 xContent = m_xContent;
1671 m_nCommandId = 0;
1672 m_aURL = rtl::OUString();
1673 m_xCommandProcessor = 0;
1674 m_xContent = 0;
1677 if ( xContent.is() )
1679 try
1681 xContent->removeContentEventListener( m_xContentEventListener );
1683 catch ( RuntimeException const & )
1689 //=========================================================================
1690 const rtl::OUString& Content_Impl::getURL() const
1692 if ( !m_aURL.getLength() && m_xContent.is() )
1694 osl::MutexGuard aGuard( m_aMutex );
1696 if ( !m_aURL.getLength() && m_xContent.is() )
1698 Reference< XContentIdentifier > xId = m_xContent->getIdentifier();
1699 if ( xId.is() )
1700 m_aURL = xId->getContentIdentifier();
1704 return m_aURL;
1707 //=========================================================================
1708 Reference< XContent > Content_Impl::getContent()
1710 if ( !m_xContent.is() && m_aURL.getLength() )
1712 osl::MutexGuard aGuard( m_aMutex );
1714 if ( !m_xContent.is() && m_aURL.getLength() )
1716 ContentBroker* pBroker = ContentBroker::get();
1718 OSL_ENSURE( pBroker, "No Content Broker!" );
1720 if ( pBroker )
1722 OSL_ENSURE( pBroker->getContentProviderManagerInterface()
1723 ->queryContentProviders().getLength(),
1724 "Content Broker not configured (no providers)!" );
1726 Reference< XContentIdentifierFactory > xIdFac
1727 = pBroker->getContentIdentifierFactoryInterface();
1729 OSL_ENSURE( xIdFac.is(), "No Content Identifier factory!" );
1731 if ( xIdFac.is() )
1733 Reference< XContentIdentifier > xId
1734 = xIdFac->createContentIdentifier( m_aURL );
1736 OSL_ENSURE( xId.is(), "No Content Identifier!" );
1738 if ( xId.is() )
1740 Reference< XContentProvider > xProvider
1741 = pBroker->getContentProviderInterface();
1743 OSL_ENSURE( xProvider.is(), "No Content Provider!" );
1745 if ( xProvider.is() )
1749 m_xContent = xProvider->queryContent( xId );
1751 catch ( IllegalIdentifierException const & )
1755 if ( m_xContent.is() )
1756 m_xContent->addContentEventListener(
1757 m_xContentEventListener );
1765 return m_xContent;
1768 //=========================================================================
1769 Reference< XCommandProcessor > Content_Impl::getCommandProcessor()
1771 if ( !m_xCommandProcessor.is() )
1773 osl::MutexGuard aGuard( m_aMutex );
1775 if ( !m_xCommandProcessor.is() )
1776 m_xCommandProcessor
1777 = Reference< XCommandProcessor >( getContent(), UNO_QUERY );
1780 return m_xCommandProcessor;
1783 //=========================================================================
1784 sal_Int32 Content_Impl::getCommandId()
1786 if ( m_nCommandId == 0 )
1788 osl::MutexGuard aGuard( m_aMutex );
1790 if ( m_nCommandId == 0 )
1792 Reference< XCommandProcessor > xProc = getCommandProcessor();
1793 if ( xProc.is() )
1794 m_nCommandId = xProc->createCommandIdentifier();
1798 return m_nCommandId;
1801 //=========================================================================
1802 Any Content_Impl::executeCommand( const Command& rCommand )
1804 Reference< XCommandProcessor > xProc = getCommandProcessor();
1805 if ( !xProc.is() )
1806 return Any();
1808 // Execute command
1809 return xProc->execute( rCommand, getCommandId(), m_xEnv );
1812 //=========================================================================
1813 void Content_Impl::abortCommand()
1815 sal_Int32 nCommandId;
1816 Reference< XCommandProcessor > xCommandProcessor;
1818 osl::MutexGuard aGuard( m_aMutex );
1819 nCommandId = m_nCommandId;
1820 xCommandProcessor = m_xCommandProcessor;
1823 if ( ( nCommandId != 0 ) && xCommandProcessor.is() )
1824 xCommandProcessor->abort( nCommandId );
1827 //=========================================================================
1828 inline const Reference< XCommandEnvironment >&
1829 Content_Impl::getEnvironment() const
1831 return m_xEnv;
1834 //=========================================================================
1835 inline void Content_Impl::setEnvironment(
1836 const Reference< XCommandEnvironment >& xNewEnv )
1838 osl::MutexGuard aGuard( m_aMutex );
1839 m_xEnv = xNewEnv;
1842 //=========================================================================
1843 void Content_Impl::inserted()
1845 // URL might have changed during 'insert' => recalculate in next getURL()
1846 osl::MutexGuard aGuard( m_aMutex );
1847 m_aURL = ::rtl::OUString();
1850 //=========================================================================
1851 //=========================================================================
1853 // ContentEventListener_Impl Implementation.
1855 //=========================================================================
1856 //=========================================================================
1858 //=========================================================================
1860 // XInterface methods.
1862 //=========================================================================
1864 XINTERFACE_IMPL_2( ContentEventListener_Impl,
1865 XContentEventListener,
1866 XEventListener ); /* base of XContentEventListener */
1868 //=========================================================================
1870 // XContentEventListener methods.
1872 //=========================================================================
1874 // virtual
1875 void SAL_CALL ContentEventListener_Impl::contentEvent( const ContentEvent& evt )
1876 throw( RuntimeException )
1878 if ( evt.Source == m_rContent.m_xContent )
1880 switch ( evt.Action )
1882 case ContentAction::DELETED:
1883 m_rContent.reinit( Reference< XContent >() );
1884 break;
1886 case ContentAction::EXCHANGED:
1887 m_rContent.reinit( evt.Content );
1888 break;
1890 default:
1891 break;
1896 //=========================================================================
1898 // XEventListenr methods.
1900 //=========================================================================
1902 // virtual
1903 void SAL_CALL ContentEventListener_Impl::disposing( const EventObject& Source )
1904 throw( RuntimeException )
1906 m_rContent.disposing(Source);
1909 } /* namespace ucbhelper */