diff options
author | Kai Sommerfeld <kso@openoffice.org> | 2010-01-06 16:46:36 +0100 |
---|---|---|
committer | Kai Sommerfeld <kso@openoffice.org> | 2010-01-06 16:46:36 +0100 |
commit | 31a763ce50ce977168ba7806077465130c89b26a (patch) | |
tree | eff03e6aaa1fc0c9cc82c4d643bb9d63cd38ea02 /ucbhelper | |
parent | cdb860118873e199e1f011d9a328a38d2e14d34c (diff) |
#i61429# - Adapted UCB clients to deprecated XContentCreator interface.
Diffstat (limited to 'ucbhelper')
-rw-r--r-- | ucbhelper/inc/ucbhelper/content.hxx | 67 | ||||
-rw-r--r-- | ucbhelper/source/client/content.cxx | 107 |
2 files changed, 128 insertions, 46 deletions
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 <ucbhelper/contentbroker.hxx> #include <ucbhelper/activedatasink.hxx> #include <ucbhelper/activedatastreamer.hxx> -#ifndef _UCBHELPER_INTERACTIONREQUEST_HXX #include <ucbhelper/interactionrequest.hxx> -#endif #include <ucbhelper/cancelcommandexecution.hxx> 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 ); @@ -1349,6 +1348,26 @@ void Content::writeStream( const Reference< XInputStream >& rStream, } //========================================================================= +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 >& rPropertyNames, @@ -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 ); |