diff options
author | Ariel Constenla-Haile <arielch@apache.org> | 2013-03-24 12:21:56 +0000 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-08-15 16:55:23 +0200 |
commit | 41c05c607cd52d327f51cd986d21aa0cdafa1ae1 (patch) | |
tree | cd4e46179724845921dcf8aa03ef845cab1813ed /ucb | |
parent | 6e0d836ff120ba292ba52f3623a3dd9be04aefc2 (diff) |
i121935 - UCB: new "addProperty" and "removeProperty" commands
(cherry picked from commit 3d5d60176c01f9d3504559b816281fca11aea403)
Conflicts:
offapi/com/sun/star/ucb/Content.idl
offapi/com/sun/star/ucb/makefile.mk
ucb/source/ucp/webdav/DAVProperties.cxx
ucb/source/ucp/webdav/webdavcontent.cxx
plus headerize.pl
Change-Id: I59b270ef5a72271671ae0857d11f557eec829387
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/source/ucp/webdav/DAVProperties.cxx | 40 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/DAVProperties.hxx | 2 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/webdavcontent.cxx | 216 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/webdavcontent.hxx | 16 | ||||
-rw-r--r-- | ucb/source/ucp/webdav/webdavcontentcaps.cxx | 15 |
5 files changed, 231 insertions, 58 deletions
diff --git a/ucb/source/ucp/webdav/DAVProperties.cxx b/ucb/source/ucp/webdav/DAVProperties.cxx index 7340dbe6a35c..bbc894d728fe 100644 --- a/ucb/source/ucp/webdav/DAVProperties.cxx +++ b/ucb/source/ucp/webdav/DAVProperties.cxx @@ -19,6 +19,7 @@ #include <string.h> #include "DAVProperties.hxx" +#include <rtl/ustrbuf.hxx> using namespace http_dav_ucp; @@ -180,4 +181,43 @@ bool DAVProperties::isUCBDeadProperty( const SerfPropName & rName ) == 0 ) ); } +bool DAVProperties::isUCBSpecialProperty(const rtl::OUString& rFullName, rtl::OUString& rParsedName) +{ + sal_Int32 nLen = rFullName.getLength(); + if ( nLen <= 0 || + !rFullName.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "<prop:" ) ) || + !rFullName.endsWithAsciiL( RTL_CONSTASCII_STRINGPARAM( "\">" ) ) ) + return false; + + sal_Int32 nStart = RTL_CONSTASCII_LENGTH( "<prop:" ); + sal_Int32 nEnd = rFullName.indexOf( sal_Unicode( ' ' ), nStart ); + if ( nEnd == -1 ) + return false; + + rtl::OUString sPropName = rFullName.copy( nStart, nEnd - nStart ); + if ( !sPropName.getLength() ) + return false; + + // TODO skip whitespaces? + if ( !rFullName.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "xmlns:prop=\"" ), ++nEnd ) ) + return false; + + nStart = nEnd + RTL_CONSTASCII_LENGTH( "xmlns:prop=\"" ); + nEnd = rFullName.indexOf( sal_Unicode( '"' ), nStart ); + if ( nEnd != nLen - RTL_CONSTASCII_LENGTH( "\">" ) ) + return false; + + rtl::OUString sNamesp = rFullName.copy( nStart, nEnd - nStart ); + if ( !( nLen = sNamesp.getLength() ) ) + return false; + + rtl::OUStringBuffer aBuff( sNamesp ); + if ( sNamesp[nLen - 1] != '/' ) + aBuff.append( sal_Unicode( '/' ) ); + aBuff.append( sPropName ); + rParsedName = aBuff.makeStringAndClear(); + + return rParsedName.getLength(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/ucb/source/ucp/webdav/DAVProperties.hxx b/ucb/source/ucp/webdav/DAVProperties.hxx index 1906c7fb264d..8bf3ca37614e 100644 --- a/ucb/source/ucp/webdav/DAVProperties.hxx +++ b/ucb/source/ucp/webdav/DAVProperties.hxx @@ -48,6 +48,8 @@ struct DAVProperties OUString & rFullName ); static bool isUCBDeadProperty( const SerfPropName & rName ); + static bool isUCBSpecialProperty( const rtl::OUString & rFullName, + rtl::OUString & rParsedName ); }; } // namespace http_dav_ucp diff --git a/ucb/source/ucp/webdav/webdavcontent.cxx b/ucb/source/ucp/webdav/webdavcontent.cxx index 7ff158b4c483..f995bd098d5f 100644 --- a/ucb/source/ucp/webdav/webdavcontent.cxx +++ b/ucb/source/ucp/webdav/webdavcontent.cxx @@ -56,6 +56,7 @@ #include <com/sun/star/ucb/OpenCommandArgument2.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> @@ -743,6 +744,68 @@ uno::Any SAL_CALL Content::execute( aRet = uno::makeAny( createNewContent( aArg ) ); } + else if ( aCommand.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "addProperty" ))) + { + ucb::PropertyCommandArgument aPropArg; + if ( !( aCommand.Argument >>= aPropArg )) + { + ucbhelper::cancelCommandExecution( + uno::makeAny( lang::IllegalArgumentException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "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.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "removeProperty" ))) + { + rtl::OUString sPropName; + if ( !( aCommand.Argument >>= sPropName ) ) + { + ucbhelper::cancelCommandExecution( + uno::makeAny( lang::IllegalArgumentException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "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 { ////////////////////////////////////////////////////////////////// @@ -794,42 +857,53 @@ void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ ) // //========================================================================= -// 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 ) +void Content::addProperty( const com::sun::star::ucb::PropertyCommandArgument &aCmdArg, + const uno::Reference< ucb::XCommandEnvironment >& xEnv ) +throw( beans::PropertyExistException, + beans::IllegalTypeException, + lang::IllegalArgumentException, + uno::RuntimeException ) { // if ( m_bTransient ) // @@@ ??? + const beans::Property aProperty = aCmdArg.Property; + const uno::Any aDefaultValue = aCmdArg.DefaultValue; - if ( Name.isEmpty() ) - throw lang::IllegalArgumentException(); + // check property Name + if ( !aProperty.Name.getLength() ) + throw lang::IllegalArgumentException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "\"addProperty\" with empty Property.Name")), + static_cast< ::cppu::OWeakObject * >( this ), + -1 ); // Check property type. - if ( !UCBDeadPropertyValue::supportsType( DefaultValue.getValueType() ) ) - { - OSL_ENSURE( sal_False, - "Content::addProperty - Unsupported property type!" ); - throw beans::IllegalTypeException(); - } + if ( !UCBDeadPropertyValue::supportsType( aProperty.Type ) ) + throw beans::IllegalTypeException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "\"addProperty\" unsupported Property.Type")), + static_cast< ::cppu::OWeakObject * >( this ) ); + + // check default value + if ( aDefaultValue.hasValue() && aDefaultValue.getValueType() != aProperty.Type ) + throw beans::IllegalTypeException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "\"addProperty\" DefaultValue does not match Property.Type")), + static_cast< ::cppu::OWeakObject * >( this ) ); ////////////////////////////////////////////////////////////////////// // Make sure a property with the requested name does not already // 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"> + rtl::OUString aSpecialName; + bool bIsSpecial = DAVProperties::isUCBSpecialProperty( aProperty.Name, aSpecialName ); // Note: This requires network access! if ( getPropertySetInfo( xEnv, sal_False /* don't cache data */ ) - ->hasPropertyByName( Name ) ) + ->hasPropertyByName( bIsSpecial ? aSpecialName : aProperty.Name ) ) { // Property does already exist. throw beans::PropertyExistException(); @@ -839,7 +913,7 @@ void SAL_CALL Content::addProperty( const OUString& Name, // Add a new dynamic property. ////////////////////////////////////////////////////////////////////// - ProppatchValue aValue( PROPSET, Name, DefaultValue ); + ProppatchValue aValue( PROPSET, aProperty.Name, aDefaultValue ); std::vector< ProppatchValue > aProppatchValues; aProppatchValues.push_back( aValue ); @@ -861,7 +935,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 : aProperty.Name, -1, // No handle available beans::PropertySetInfoChange::PROPERTY_INSERTED ); notifyPropertySetInfoChange( evt ); @@ -873,8 +947,9 @@ void SAL_CALL Content::addProperty( const OUString& Name, // Support for setting arbitrary dead properties is optional! // Store property locally. - ContentImplHelper::addProperty( - Name, Attributes, DefaultValue ); + ContentImplHelper::addProperty( bIsSpecial ? aSpecialName : aProperty.Name, + aProperty.Attributes, + aDefaultValue ); } else { @@ -891,9 +966,9 @@ void SAL_CALL Content::addProperty( const OUString& Name, case NON_DAV: // Store property locally. - ContentImplHelper::addProperty( Name, - Attributes, - DefaultValue ); + ContentImplHelper::addProperty( bIsSpecial ? aSpecialName : aProperty.Name, + aProperty.Attributes, + aDefaultValue ); break; default: @@ -920,25 +995,19 @@ void SAL_CALL Content::addProperty( const OUString& Name, } } -//========================================================================= -// virtual -void SAL_CALL Content::removeProperty( const OUString& Name ) - throw( beans::UnknownPropertyException, - beans::NotRemoveableException, - uno::RuntimeException ) +void Content::removeProperty( const rtl::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; - #if 0 // @@@ REMOVABLE z.Z. nicht richtig an der PropSetInfo gesetzt!!! try { beans::Property aProp - = getPropertySetInfo( xEnv, sal_False /* don't cache data */ ) - ->getPropertyByName( Name ); + = getPropertySetInfo( xEnv, sal_False /* don't cache data */ ) + ->getPropertyByName( Name ); if ( !( aProp.Attributes & beans::PropertyAttribute::REMOVABLE ) ) { @@ -1001,20 +1070,20 @@ void SAL_CALL Content::removeProperty( const OUString& Name ) const ResourceType & rType = getResourceType( xEnv ); switch ( rType ) { - case UNKNOWN: - case DAV: - throw beans::UnknownPropertyException(); - - case NON_DAV: - // Try to remove property from local store. - ContentImplHelper::removeProperty( Name ); - break; - - default: - OSL_ENSURE( sal_False, - "Content::removeProperty - " - "Unsupported resource type!" ); - break; + case UNKNOWN: + case DAV: + throw beans::UnknownPropertyException(); + + case NON_DAV: + // Try to remove property from local store. + ContentImplHelper::removeProperty( Name ); + break; + + default: + OSL_ENSURE( sal_False, + "Content::removeProperty - " + "Unsupported resource type!" ); + break; } } catch ( uno::Exception const & ) @@ -1035,6 +1104,35 @@ void SAL_CALL Content::removeProperty( const OUString& Name ) } } +// virtual +void SAL_CALL Content::addProperty( const rtl::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 rtl::OUString& Name ) + throw( beans::UnknownPropertyException, + beans::NotRemoveableException, + uno::RuntimeException ) +{ + removeProperty( Name, + uno::Reference< ucb::XCommandEnvironment >() ); +} + //========================================================================= // // XContentCreator methods. @@ -1749,11 +1847,14 @@ uno::Sequence< uno::Any > Content::setPropertyValues( // Optional props. ////////////////////////////////////////////////////////////// + rtl::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 @@ -1798,7 +1899,8 @@ uno::Sequence< uno::Any > Content::setPropertyValues( "Property is read-only!" ), static_cast< cppu::OWeakObject * >( this ) ); } - if ( rName == "CreatableContentsInfo" ) + if ( rName.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM( "CreatableContentsInfo" ) ) ) { // Read-only property! aRet[ n ] <<= lang::IllegalAccessException( diff --git a/ucb/source/ucp/webdav/webdavcontent.hxx b/ucb/source/ucp/webdav/webdavcontent.hxx index 6ffbd222b072..10c3022dba8e 100644 --- a/ucb/source/ucp/webdav/webdavcontent.hxx +++ b/ucb/source/ucp/webdav/webdavcontent.hxx @@ -46,6 +46,7 @@ namespace com { namespace sun { namespace star { namespace sdbc { namespace com { namespace sun { namespace star { namespace ucb { struct OpenCommandArgument2; + struct PropertyCommandArgument; struct PostCommandArgument2; struct TransferInfo; } } } } @@ -190,6 +191,21 @@ private: const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& Environment ); + // XPropertyContainer replacement + 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 rtl::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::lang::XMultiServiceFactory >& rxSMgr, diff --git a/ucb/source/ucp/webdav/webdavcontentcaps.cxx b/ucb/source/ucp/webdav/webdavcontentcaps.cxx index f075ba0d6665..89331674f011 100644 --- a/ucb/source/ucp/webdav/webdavcontentcaps.cxx +++ b/ucb/source/ucp/webdav/webdavcontentcaps.cxx @@ -26,6 +26,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> @@ -492,7 +493,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 @@ -553,6 +554,18 @@ uno::Sequence< ucb::CommandInfo > Content::getCommands( -1, getCppuType( static_cast< ucb::PostCommandArgument2 * >( 0 ) ) ); + aCmdInfo[ 8 ] = + ucb::CommandInfo( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "addProperty" ) ), + -1, + getCppuType( static_cast< + ucb::PropertyCommandArgument * >( 0 ) ) ); + aCmdInfo[ 9 ] = + ucb::CommandInfo( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "removeProperty" ) ), + -1, + getCppuType( static_cast< + rtl::OUString * >( 0 ) ) ); sal_Bool bFolder = sal_False; |