diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx index e671012fc560..274f7d4a4c1a 100644 --- a/sot/source/sdstor/ucbstorage.cxx +++ b/sot/source/sdstor/ucbstorage.cxx @@ -48,7 +48,7 @@ #include #include #include -#include +#include #include #include #include @@ -2277,13 +2277,10 @@ BOOL UCBStorage_Impl::Insert( ::ucbhelper::Content *pContent ) // a new substorage is inserted into a UCBStorage ( given by the parameter pContent ) // it must be inserted with a title and a type BOOL bRet = FALSE; - Reference< XContentCreator > xCreator = Reference< XContentCreator >( pContent->get(), UNO_QUERY ); - if ( !xCreator.is() ) - return sal_False; try { - Sequence< ContentInfo > aInfo = xCreator->queryCreatableContentsInfo(); + Sequence< ContentInfo > aInfo = pContent->queryCreatableContentsInfo(); sal_Int32 nCount = aInfo.getLength(); if ( nCount == 0 ) return sal_False; diff --git a/ucbhelper/inc/ucbhelper/content.hxx b/ucbhelper/inc/ucbhelper/content.hxx index 1e8f32107241..fde86609e850 100644 --- a/ucbhelper/inc/ucbhelper/content.hxx +++ b/ucbhelper/inc/ucbhelper/content.hxx @@ -60,6 +60,7 @@ namespace com { namespace sun { namespace star { namespace ucb { class XContentIdentifier; class XDynamicResultSet; class XAnyCompareFactory; + struct ContentInfo; struct NumberedSortingInfo; } } } } @@ -70,7 +71,7 @@ namespace ucbhelper /** * These are the possible values for the parameter eMode of method - * ucb::Content::createCursor. + * ucbhelper::Content::createCursor. */ enum ResultSetInclude { @@ -81,7 +82,7 @@ enum ResultSetInclude /** * These are the possible values for the parameter eOperation of method - * ucb::Content::insertNewContent. + * ucbhelper::Content::insertNewContent. */ enum InsertOperation { @@ -821,16 +822,31 @@ public: throw( ::com::sun::star::ucb::CommandAbortedException, ::com::sun::star::uno::RuntimeException, ::com::sun::star::uno::Exception ); + + /** + * This method returns the different types of contents this content + * can create. + * + * @return the content types or an empty sequence if no contents can be + * created by this content. + */ + ::com::sun::star::uno::Sequence< ::com::sun::star::ucb::ContentInfo > + queryCreatableContentsInfo() + throw( ::com::sun::star::ucb::CommandAbortedException, + ::com::sun::star::uno::RuntimeException, + ::com::sun::star::uno::Exception ); + /** * This method creates, initializes and inserts ( commits ) a new content * (i.e. it could be used to create a new file system folder). - * Internally this method does a XContentCreator::createNewContent(...)- - * XCommandProcessor::execute( "setPropertyValues", ... )- - * XCommandProcessor::execute( "insert", ... ) calling sequence. + * Internally this method does a + * XCommandProcessor::execute( "createNewContent", ... ); + * XCommandProcessor::execute( "setPropertyValues", ... ); + * XCommandProcessor::execute( "insert", ... ); calling sequence. * * @param rContentType is the type for the new UCB content. Each content - * provider implementation may introduce own types for its contnt - * objects. + * provider implementation may introduce own types for its content + * objects (See queryCreatableContentsInfo()). * @param rPropertyNames is a sequence of names of properties for that * values are to set at the new content before it will be inserted * ( commited ). @@ -856,13 +872,14 @@ public: /** * This method creates, initializes and inserts ( commits ) a new content * (i.e. it could be used to create a new file system folder). - * Internally this method does a XContentCreator::createNewContent(...)- - * XCommandProcessor::execute( "setPropertyValues", ... )- - * XCommandProcessor::execute( "insert", ... ) calling sequence. + * Internally this method does a + * XCommandProcessor::execute( "createNewContent", ... ); + * XCommandProcessor::execute( "setPropertyValues", ... ); + * XCommandProcessor::execute( "insert", ... ); calling sequence. * * @param rContentType is the type for the new UCB content. Each content - * provider implementation may introduce own types for its contnt - * objects. + * provider implementation may introduce own types for its content + * objects (See queryCreatableContentsInfo()). * @param nPropertyHandes is a sequence of handles of properties for that * values are to set at the new content before it will be inserted * ( commited ). @@ -888,14 +905,15 @@ public: /** * This method creates, initializes and inserts (commits) a new content * inside this (the target folder) content. For example, it can be used to - * create a new file system folder. - * Internally this method does a XContentCreator::createNewContent(...)- - * XCommandProcessor::execute( "setPropertyValues", ... )- - * XCommandProcessor::execute( "insert", ... ) calling sequence. + * create a new file system file. + * Internally this method does a + * XCommandProcessor::execute( "createNewContent", ... ); + * XCommandProcessor::execute( "setPropertyValues", ... ); + * XCommandProcessor::execute( "insert", ... ); calling sequence. * * @param rContentType is the type for the new UCB content. Each content - * provider implementation may introduce own types for its contnt - * objects. + * provider implementation may introduce own types for its content + * objects (See queryCreatableContentsInfo()). * @param rPropertyNames is a sequence of names of properties for that * values are to set at the new content before it will be inserted * ( commited ). @@ -925,14 +943,15 @@ public: /** * This method creates, initializes and inserts (commits) a new content * inside this (the target folder) content. For example, it can be used to - * create a new file system folder. - * Internally this method does a XContentCreator::createNewContent(...)- - * XCommandProcessor::execute( "setPropertyValues", ... )- - * XCommandProcessor::execute( "insert", ... ) calling sequence. + * create a new file system file. + * Internally this method does a + * XCommandProcessor::execute( "createNewContent", ... ); + * XCommandProcessor::execute( "setPropertyValues", ... ); + * XCommandProcessor::execute( "insert", ... ); calling sequence. * * @param rContentType is the type for the new UCB content. Each content - * provider implementation may introduce own types for its contnt - * objects. + * provider implementation may introduce own types for its content + * objects (See queryCreatableContentsInfo()). * @param nPropertyHandes is a sequence of handles of properties for that * values are to set at the new content before it will be inserted * ( commited ). diff --git a/ucbhelper/source/client/content.cxx b/ucbhelper/source/client/content.cxx index e3b98ed24d81..28eef297e85f 100644 --- a/ucbhelper/source/client/content.cxx +++ b/ucbhelper/source/client/content.cxx @@ -73,9 +73,7 @@ #include #include #include -#ifndef _UCBHELPER_INTERACTIONREQUEST_HXX #include -#endif #include using namespace com::sun::star::container; @@ -210,6 +208,7 @@ public: Any executeCommand( const Command& rCommand ); void abortCommand(); + inline const Reference< XCommandEnvironment >& getEnvironment() const; inline void setEnvironment( const Reference< XCommandEnvironment >& xNewEnv ); @@ -1348,6 +1347,26 @@ void Content::writeStream( const Reference< XInputStream >& rStream, m_xImpl->inserted(); } +//========================================================================= +Sequence< ContentInfo > Content::queryCreatableContentsInfo() + throw( CommandAbortedException, RuntimeException, Exception ) +{ + // First, try it using "CreatableContentsInfo" property -> the "new" way. + Sequence< ContentInfo > aInfo; + if ( getPropertyValue( + rtl::OUString::createFromAscii( "CreatableContentsInfo" ) ) + >>= aInfo ) + return aInfo; + + // Second, try it using XContentCreator interface -> the "old" way (not + // providing the chance to supply an XCommandEnvironment. + Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY ); + if ( xCreator.is() ) + aInfo = xCreator->queryCreatableContentsInfo(); + + return aInfo; +} + //========================================================================= sal_Bool Content::insertNewContent( const rtl::OUString& rContentType, const Sequence< rtl::OUString >& @@ -1390,21 +1409,43 @@ sal_Bool Content::insertNewContent( const rtl::OUString& rContentType, if ( rContentType.getLength() == 0 ) return sal_False; - Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY ); - - OSL_ENSURE( xCreator.is(), - "Content::insertNewContent - Not a XContentCreator!" ); - - if ( !xCreator.is() ) - return sal_False; - + // First, try it using "createNewContent" command -> the "new" way. ContentInfo aInfo; aInfo.Type = rContentType; aInfo.Attributes = 0; - Reference< XContent > xNew = xCreator->createNewContent( aInfo ); + Command aCommand; + aCommand.Name = rtl::OUString::createFromAscii( "createNewContent" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aInfo; + + Reference< XContent > xNew; + try + { + m_xImpl->executeCommand( aCommand ) >>= xNew; + } + catch ( RuntimeException const & ) + { + throw; + } + catch ( Exception const & ) + { + } + if ( !xNew.is() ) - return sal_False; + { + // Second, try it using XContentCreator interface -> the "old" + // way (not providing the chance to supply an XCommandEnvironment. + Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY ); + + if ( !xCreator.is() ) + return sal_False; + + xNew = xCreator->createNewContent( aInfo ); + + if ( !xNew.is() ) + return sal_False; + } Content aNewContent( xNew, m_xImpl->getEnvironment() ); aNewContent.setPropertyValues( rPropertyNames, rPropertyValues ); @@ -1431,21 +1472,43 @@ sal_Bool Content::insertNewContent( const rtl::OUString& rContentType, if ( rContentType.getLength() == 0 ) return sal_False; - Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY ); - - OSL_ENSURE( xCreator.is(), - "Content::insertNewContent - Not a XContentCreator!" ); - - if ( !xCreator.is() ) - return sal_False; - + // First, try it using "createNewContent" command -> the "new" way. ContentInfo aInfo; aInfo.Type = rContentType; aInfo.Attributes = 0; - Reference< XContent > xNew = xCreator->createNewContent( aInfo ); + Command aCommand; + aCommand.Name = rtl::OUString::createFromAscii( "createNewContent" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aInfo; + + Reference< XContent > xNew; + try + { + m_xImpl->executeCommand( aCommand ) >>= xNew; + } + catch ( RuntimeException const & ) + { + throw; + } + catch ( Exception const & ) + { + } + if ( !xNew.is() ) - return sal_False; + { + // Second, try it using XContentCreator interface -> the "old" + // way (not providing the chance to supply an XCommandEnvironment. + Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY ); + + if ( !xCreator.is() ) + return sal_False; + + xNew = xCreator->createNewContent( aInfo ); + + if ( !xNew.is() ) + return sal_False; + } Content aNewContent( xNew, m_xImpl->getEnvironment() ); aNewContent.setPropertyValues( nPropertyHandles, rPropertyValues ); diff --git a/unotools/source/ucbhelper/ucbhelper.cxx b/unotools/source/ucbhelper/ucbhelper.cxx index 2b301efc4e52..a798f485516a 100644 --- a/unotools/source/ucbhelper/ucbhelper.cxx +++ b/unotools/source/ucbhelper/ucbhelper.cxx @@ -46,15 +46,13 @@ #include #include #include +#include #include -#include #include #include #include #include -#ifndef _COM_SUN_STAR_UCB_INTERACTIVEIODEXCEPTION_HPP_ #include -#endif #include #include #include @@ -489,11 +487,7 @@ sal_Bool UCBContentHelper::CanMakeFolder( const String& rFolder ) try { Content aCnt( rFolder, uno::Reference< XCommandEnvironment > () ); - uno::Reference< XContentCreator > xCreator = uno::Reference< XContentCreator >( aCnt.get(), UNO_QUERY ); - if ( !xCreator.is() ) - return sal_False; - - Sequence< ContentInfo > aInfo = xCreator->queryCreatableContentsInfo(); + Sequence< ContentInfo > aInfo = aCnt.queryCreatableContentsInfo(); sal_Int32 nCount = aInfo.getLength(); if ( nCount == 0 ) return sal_False; @@ -538,11 +532,7 @@ sal_Bool UCBContentHelper::MakeFolder( Content& aCnt, const String& aTitle, Cont try { - uno::Reference< XContentCreator > xCreator( aCnt.get(), UNO_QUERY ); - if ( !xCreator.is() ) - return sal_False; - - Sequence< ContentInfo > aInfo = xCreator->queryCreatableContentsInfo(); + Sequence< ContentInfo > aInfo = aCnt.queryCreatableContentsInfo(); sal_Int32 nCount = aInfo.getLength(); if ( nCount == 0 ) return sal_False;