diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-08-15 14:43:17 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-08-15 16:55:23 +0200 |
commit | da00f5e6249c1beef6e7c377398b33cc9af27d09 (patch) | |
tree | 4f4186711da8253f595b494181bb91f3cdf8755c /ucb | |
parent | 41c05c607cd52d327f51cd986d21aa0cdafa1ae1 (diff) |
Adapt to LibreOffice the previous commit
..."i121935 - UCB: new 'addProperty' and 'removeProperty' commands."
Change-Id: If0451c6d1b6471d27f5fb1551ccf0230e62dfb60
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/source/ucp/webdav-neon/DAVProperties.cxx | 32 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-neon/DAVProperties.hxx | 2 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-neon/webdavcontent.cxx | 161 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-neon/webdavcontent.hxx | 16 | ||||
-rw-r--r-- | ucb/source/ucp/webdav-neon/webdavcontentcaps.cxx | 15 |
5 files changed, 196 insertions, 30 deletions
diff --git a/ucb/source/ucp/webdav-neon/DAVProperties.cxx b/ucb/source/ucp/webdav-neon/DAVProperties.cxx index a95aea3482f4..1daf6d5f503c 100644 --- a/ucb/source/ucp/webdav-neon/DAVProperties.cxx +++ b/ucb/source/ucp/webdav-neon/DAVProperties.cxx @@ -172,4 +172,36 @@ bool DAVProperties::isUCBDeadProperty( const NeonPropName & rName ) == 0 ) ); } +bool DAVProperties::isUCBSpecialProperty( + const OUString& rFullName, OUString& rParsedName) +{ + if ( !rFullName.startsWith( "<prop:" ) || !rFullName.endsWith( "\">" ) ) + return false; + + sal_Int32 nStart = strlen( "<prop:" ); + sal_Int32 nEnd = rFullName.indexOf( sal_Unicode( ' ' ), nStart ); + if ( nEnd <= nStart ) // incl. -1 for "not found" + return false; + + OUString sPropName = rFullName.copy( nStart, nEnd - nStart ); + + // TODO skip whitespaces? + if ( !rFullName.match( "xmlns:prop=\"", ++nEnd ) ) + return false; + + nStart = nEnd + strlen( "xmlns:prop=\"" ); + nEnd = rFullName.indexOf( sal_Unicode( '"' ), nStart ); + if ( nEnd != rFullName.getLength() - sal_Int32( strlen( "\">" ) ) + || nEnd == nStart ) + { + return false; + } + + rParsedName = rFullName.copy( nStart, nEnd - nStart ); + if ( !rParsedName.endsWith( "/" ) ) + rParsedName += "/"; + + return rParsedName.getLength(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ucb/source/ucp/webdav-neon/DAVProperties.hxx b/ucb/source/ucp/webdav-neon/DAVProperties.hxx index 5e8d219b2815..f80001165245 100644 --- a/ucb/source/ucp/webdav-neon/DAVProperties.hxx +++ b/ucb/source/ucp/webdav-neon/DAVProperties.hxx @@ -57,6 +57,8 @@ struct DAVProperties OUString & rFullName ); static bool isUCBDeadProperty( const NeonPropName & rName ); + static bool isUCBSpecialProperty( const OUString & rFullName, + OUString & rParsedName ); }; } // namespace webdav_ucp diff --git a/ucb/source/ucp/webdav-neon/webdavcontent.cxx b/ucb/source/ucp/webdav-neon/webdavcontent.cxx index 49e8655e1116..81b27b65ad63 100644 --- a/ucb/source/ucp/webdav-neon/webdavcontent.cxx +++ b/ucb/source/ucp/webdav-neon/webdavcontent.cxx @@ -72,6 +72,7 @@ #include <com/sun/star/ucb/OpenCommandArgument3.hpp> #include <com/sun/star/ucb/OpenMode.hpp> #include <com/sun/star/ucb/PostCommandArgument2.hpp> +#include <com/sun/star/ucb/PropertyCommandArgument.hpp> #include <com/sun/star/ucb/TransferInfo.hpp> #include <com/sun/star/ucb/UnsupportedCommandException.hpp> #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> @@ -644,6 +645,66 @@ uno::Any SAL_CALL Content::execute( aRet = uno::makeAny( createNewContent( aArg ) ); } + else if ( aCommand.Name == "addProperty" ) + { + ucb::PropertyCommandArgument aPropArg; + if ( !( aCommand.Argument >>= aPropArg )) + { + ucbhelper::cancelCommandExecution( + uno::makeAny( lang::IllegalArgumentException( + "Wrong argument type!", + static_cast< cppu::OWeakObject * >( this ), + -1 ) ), + Environment ); + } + + // TODO when/if XPropertyContainer is removed, + // the command execution can be canceled in addProperty + try + { + addProperty( aPropArg, Environment ); + } + catch ( const beans::PropertyExistException &e ) + { + ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment ); + } + catch ( const beans::IllegalTypeException&e ) + { + ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment ); + } + catch ( const lang::IllegalArgumentException&e ) + { + ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment ); + } + } + else if ( aCommand.Name == "removeProperty" ) + { + OUString sPropName; + if ( !( aCommand.Argument >>= sPropName ) ) + { + ucbhelper::cancelCommandExecution( + uno::makeAny( lang::IllegalArgumentException( + "Wrong argument type!", + static_cast< cppu::OWeakObject * >( this ), + -1 ) ), + Environment ); + } + + // TODO when/if XPropertyContainer is removed, + // the command execution can be canceled in removeProperty + try + { + removeProperty( sPropName, Environment ); + } + catch( const beans::UnknownPropertyException &e ) + { + ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment ); + } + catch( const beans::NotRemoveableException &e ) + { + ucbhelper::cancelCommandExecution( uno::makeAny( e ), Environment ); + } + } else { ////////////////////////////////////////////////////////////////// @@ -697,10 +758,8 @@ void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ ) // //========================================================================= -// virtual -void SAL_CALL Content::addProperty( const OUString& Name, - sal_Int16 Attributes, - const uno::Any& DefaultValue ) +void Content::addProperty( const ucb::PropertyCommandArgument& aCmdArg, + const uno::Reference< ucb::XCommandEnvironment >& xEnv ) throw( beans::PropertyExistException, beans::IllegalTypeException, lang::IllegalArgumentException, @@ -709,14 +768,26 @@ void SAL_CALL Content::addProperty( const OUString& Name, // if ( m_bTransient ) // @@@ ??? - if ( Name.isEmpty() ) - throw lang::IllegalArgumentException(); + if ( aCmdArg.Property.Name.isEmpty() ) + throw lang::IllegalArgumentException( + "\"addProperty\" with empty Property.Name", + static_cast< cppu::OWeakObject * >( this ), + -1 ); // Check property type. - if ( !UCBDeadPropertyValue::supportsType( DefaultValue.getValueType() ) ) + if ( !UCBDeadPropertyValue::supportsType( aCmdArg.Property.Type ) ) + { + throw beans::IllegalTypeException( + "\"addProperty\" unsupported Property.Type", + static_cast< cppu::OWeakObject * >( this ) ); + } + + if ( aCmdArg.DefaultValue.hasValue() + && aCmdArg.DefaultValue.getValueType() != aCmdArg.Property.Type ) { - OSL_FAIL( "Content::addProperty - Unsupported property type!" ); - throw beans::IllegalTypeException(); + throw beans::IllegalTypeException( + "\"addProperty\" DefaultValue does not match Property.Type", + static_cast< ::cppu::OWeakObject * >( this ) ); } ////////////////////////////////////////////////////////////////////// @@ -724,14 +795,16 @@ void SAL_CALL Content::addProperty( const OUString& Name, // exist in dynamic and static(!) properties. ////////////////////////////////////////////////////////////////////// - // @@@ Need real command environment here, but where to get it from? - // XPropertyContainer interface should be replaced by - // XCommandProcessor commands! - uno::Reference< ucb::XCommandEnvironment > xEnv; + // Take into account special properties with custom namespace + // using <prop:the_propname xmlns:prop="the_namespace"> + OUString aSpecialName; + bool bIsSpecial = DAVProperties::isUCBSpecialProperty( + aCmdArg.Property.Name, aSpecialName ); // Note: This requires network access! if ( getPropertySetInfo( xEnv, sal_False /* don't cache data */ ) - ->hasPropertyByName( Name ) ) + ->hasPropertyByName( + bIsSpecial ? aSpecialName : aCmdArg.Property.Name ) ) { // Property does already exist. throw beans::PropertyExistException(); @@ -741,7 +814,8 @@ void SAL_CALL Content::addProperty( const OUString& Name, // Add a new dynamic property. ////////////////////////////////////////////////////////////////////// - ProppatchValue aValue( PROPSET, Name, DefaultValue ); + ProppatchValue aValue( + PROPSET, aCmdArg.Property.Name, aCmdArg.DefaultValue ); std::vector< ProppatchValue > aProppatchValues; aProppatchValues.push_back( aValue ); @@ -765,7 +839,7 @@ void SAL_CALL Content::addProperty( const OUString& Name, // Notify propertyset info change listeners. beans::PropertySetInfoChangeEvent evt( static_cast< cppu::OWeakObject * >( this ), - Name, + bIsSpecial ? aSpecialName : aCmdArg.Property.Name, -1, // No handle available beans::PropertySetInfoChange::PROPERTY_INSERTED ); notifyPropertySetInfoChange( evt ); @@ -778,7 +852,8 @@ void SAL_CALL Content::addProperty( const OUString& Name, // Store property locally. ContentImplHelper::addProperty( - Name, Attributes, DefaultValue ); + bIsSpecial ? aSpecialName : aCmdArg.Property.Name, + aCmdArg.Property.Attributes, aCmdArg.DefaultValue ); } else { @@ -796,9 +871,9 @@ void SAL_CALL Content::addProperty( const OUString& Name, case FTP: case NON_DAV: // Store property locally. - ContentImplHelper::addProperty( Name, - Attributes, - DefaultValue ); + ContentImplHelper::addProperty( + bIsSpecial ? aSpecialName : aCmdArg.Property.Name, + aCmdArg.Property.Attributes, aCmdArg.DefaultValue ); break; default: @@ -822,18 +897,12 @@ void SAL_CALL Content::addProperty( const OUString& Name, } } -//========================================================================= -// virtual -void SAL_CALL Content::removeProperty( const OUString& Name ) +void Content::removeProperty( const OUString& Name, + const uno::Reference< ucb::XCommandEnvironment >& xEnv ) throw( beans::UnknownPropertyException, beans::NotRemoveableException, uno::RuntimeException ) { - // @@@ Need real command environment here, but where to get it from? - // XPropertyContainer interface should be replaced by - // XCommandProcessor commands! - uno::Reference< ucb::XCommandEnvironment > xEnv; - ////////////////////////////////////////////////////////////////////// // Try to remove property from server. ////////////////////////////////////////////////////////////////////// @@ -916,6 +985,35 @@ void SAL_CALL Content::removeProperty( const OUString& Name ) } } +// virtual +void SAL_CALL Content::addProperty( const OUString& Name, + sal_Int16 Attributes, + const uno::Any& DefaultValue ) + throw( beans::PropertyExistException, + beans::IllegalTypeException, + lang::IllegalArgumentException, + uno::RuntimeException ) +{ + beans::Property aProperty; + aProperty.Name = Name; + aProperty.Type = DefaultValue.getValueType(); + aProperty.Attributes = Attributes; + aProperty.Handle = -1; + + addProperty( ucb::PropertyCommandArgument( aProperty, DefaultValue ), + uno::Reference< ucb::XCommandEnvironment >()); +} + +// virtual +void SAL_CALL Content::removeProperty( const OUString& Name ) + throw( beans::UnknownPropertyException, + beans::NotRemoveableException, + uno::RuntimeException ) +{ + removeProperty( Name, + uno::Reference< ucb::XCommandEnvironment >() ); +} + //========================================================================= // // XContentCreator methods. @@ -1588,11 +1686,16 @@ uno::Sequence< uno::Any > Content::setPropertyValues( // Optional props. ////////////////////////////////////////////////////////////// + OUString aSpecialName; + bool bIsSpecial = DAVProperties::isUCBSpecialProperty( + rName, aSpecialName ); + if ( !xInfo.is() ) xInfo = getPropertySetInfo( xEnv, sal_False /* don't cache data */ ); - if ( !xInfo->hasPropertyByName( rName ) ) + if ( !xInfo->hasPropertyByName( + bIsSpecial ? aSpecialName : rName ) ) { // Check, whether property exists. Skip otherwise. // PROPPATCH::set would add the property automatically, which diff --git a/ucb/source/ucp/webdav-neon/webdavcontent.hxx b/ucb/source/ucp/webdav-neon/webdavcontent.hxx index 74140fd7f179..f2d378b657ab 100644 --- a/ucb/source/ucp/webdav-neon/webdavcontent.hxx +++ b/ucb/source/ucp/webdav-neon/webdavcontent.hxx @@ -55,6 +55,7 @@ namespace com { namespace sun { namespace star { namespace sdbc { namespace com { namespace sun { namespace star { namespace ucb { struct OpenCommandArgument3; struct PostCommandArgument2; + struct PropertyCommandArgument; struct TransferInfo; } } } } @@ -204,6 +205,21 @@ private: const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& Environment ); + void addProperty( const com::sun::star::ucb::PropertyCommandArgument &aCmdArg, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& Environment ) + throw( com::sun::star::beans::PropertyExistException, + com::sun::star::beans::IllegalTypeException, + com::sun::star::lang::IllegalArgumentException, + com::sun::star::uno::RuntimeException ); + + void removeProperty( const OUString& Name, + const com::sun::star::uno::Reference< + com::sun::star::ucb::XCommandEnvironment >& Environment ) + throw( com::sun::star::beans::UnknownPropertyException, + com::sun::star::beans::NotRemoveableException, + com::sun::star::uno::RuntimeException ); + public: Content( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext, diff --git a/ucb/source/ucp/webdav-neon/webdavcontentcaps.cxx b/ucb/source/ucp/webdav-neon/webdavcontentcaps.cxx index 92a5721371ee..bae5cb6c44e0 100644 --- a/ucb/source/ucp/webdav-neon/webdavcontentcaps.cxx +++ b/ucb/source/ucp/webdav-neon/webdavcontentcaps.cxx @@ -41,6 +41,7 @@ #include <com/sun/star/ucb/OpenCommandArgument2.hpp> #include <com/sun/star/ucb/InsertCommandArgument.hpp> #include <com/sun/star/ucb/PostCommandArgument2.hpp> +#include <com/sun/star/ucb/PropertyCommandArgument.hpp> #include <com/sun/star/ucb/TransferInfo.hpp> #include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/util/DateTime.hpp> @@ -520,7 +521,7 @@ uno::Sequence< ucb::CommandInfo > Content::getCommands( { osl::Guard< osl::Mutex > aGuard( m_aMutex ); - uno::Sequence< ucb::CommandInfo > aCmdInfo( 8 ); + uno::Sequence< ucb::CommandInfo > aCmdInfo( 10 ); /////////////////////////////////////////////////////////////// // Mandatory commands @@ -581,6 +582,18 @@ uno::Sequence< ucb::CommandInfo > Content::getCommands( -1, getCppuType( static_cast< ucb::PostCommandArgument2 * >( 0 ) ) ); + aCmdInfo[ 8 ] = + ucb::CommandInfo( + OUString( "addProperty" ), + -1, + getCppuType( static_cast< + ucb::PropertyCommandArgument * >( 0 ) ) ); + aCmdInfo[ 9 ] = + ucb::CommandInfo( + OUString( "removeProperty" ), + -1, + getCppuType( static_cast< + rtl::OUString * >( 0 ) ) ); sal_Bool bFolder = sal_False; |