Kaydet (Commit) da00f5e6 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Adapt to LibreOffice the previous commit

..."i121935 - UCB: new 'addProperty' and 'removeProperty' commands."

Change-Id: If0451c6d1b6471d27f5fb1551ccf0230e62dfb60
üst 41c05c60
...@@ -487,7 +487,7 @@ published service Content ...@@ -487,7 +487,7 @@ published service Content
<type scope="com::sun::star::lang">IllegalArgumentException</type> <type scope="com::sun::star::lang">IllegalArgumentException</type>
if the Name of the property is empty.</p> if the Name of the property is empty.</p>
<blockquote> <blockquote>
Note: This command replaces the deprecated interface method Note: This command is new since Apache OpenOffice 4.0, LibreOffice 4.2 and replaces the deprecated interface method
<member scope="com::sun::star::beans">XPropertyContainer::addProperty</member>. <member scope="com::sun::star::beans">XPropertyContainer::addProperty</member>.
</blockquote> </blockquote>
</td> </td>
...@@ -502,7 +502,7 @@ published service Content ...@@ -502,7 +502,7 @@ published service Content
<type scope="com::sun::star::beans">NotRemoveableException</type> <type scope="com::sun::star::beans">NotRemoveableException</type>
if the property is not removable.</p> if the property is not removable.</p>
<blockquote> <blockquote>
Note: This command replaces the deprecated interface method Note: This command is new since Apache OpenOffice 4.0, LibreOffice 4.2 and replaces the deprecated interface method
<member scope="com::sun::star::beans">XPropertyContainer::removeProperty</member>. <member scope="com::sun::star::beans">XPropertyContainer::removeProperty</member>.
</blockquote> </blockquote>
</td> </td>
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* /*
* This file is part of the LibreOffice project. * This file is part of the LibreOffice project.
* *
...@@ -25,7 +26,7 @@ module com { module sun { module star { module ucb { ...@@ -25,7 +26,7 @@ module com { module sun { module star { module ucb {
/** The argument for the "addProperty" command. /** The argument for the "addProperty" command.
@see XCommandProcessor @see XCommandProcessor
@since Apache OpenOffice 4.0 @since Apache OpenOffice 4.0, LibreOffice 4.2
*/ */
struct PropertyCommandArgument struct PropertyCommandArgument
{ {
...@@ -41,3 +42,5 @@ struct PropertyCommandArgument ...@@ -41,3 +42,5 @@ struct PropertyCommandArgument
}; }; }; }; }; }; }; };
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -172,4 +172,36 @@ bool DAVProperties::isUCBDeadProperty( const NeonPropName & rName ) ...@@ -172,4 +172,36 @@ bool DAVProperties::isUCBDeadProperty( const NeonPropName & rName )
== 0 ) ); == 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -57,6 +57,8 @@ struct DAVProperties ...@@ -57,6 +57,8 @@ struct DAVProperties
OUString & rFullName ); OUString & rFullName );
static bool isUCBDeadProperty( const NeonPropName & rName ); static bool isUCBDeadProperty( const NeonPropName & rName );
static bool isUCBSpecialProperty( const OUString & rFullName,
OUString & rParsedName );
}; };
} // namespace webdav_ucp } // namespace webdav_ucp
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#include <com/sun/star/ucb/OpenCommandArgument3.hpp> #include <com/sun/star/ucb/OpenCommandArgument3.hpp>
#include <com/sun/star/ucb/OpenMode.hpp> #include <com/sun/star/ucb/OpenMode.hpp>
#include <com/sun/star/ucb/PostCommandArgument2.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/TransferInfo.hpp>
#include <com/sun/star/ucb/UnsupportedCommandException.hpp> #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
#include <com/sun/star/ucb/UnsupportedDataSinkException.hpp> #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
...@@ -644,6 +645,66 @@ uno::Any SAL_CALL Content::execute( ...@@ -644,6 +645,66 @@ uno::Any SAL_CALL Content::execute(
aRet = uno::makeAny( createNewContent( aArg ) ); 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 else
{ {
////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////
...@@ -697,10 +758,8 @@ void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ ) ...@@ -697,10 +758,8 @@ void SAL_CALL Content::abort( sal_Int32 /*CommandId*/ )
// //
//========================================================================= //=========================================================================
// virtual void Content::addProperty( const ucb::PropertyCommandArgument& aCmdArg,
void SAL_CALL Content::addProperty( const OUString& Name, const uno::Reference< ucb::XCommandEnvironment >& xEnv )
sal_Int16 Attributes,
const uno::Any& DefaultValue )
throw( beans::PropertyExistException, throw( beans::PropertyExistException,
beans::IllegalTypeException, beans::IllegalTypeException,
lang::IllegalArgumentException, lang::IllegalArgumentException,
...@@ -709,14 +768,26 @@ void SAL_CALL Content::addProperty( const OUString& Name, ...@@ -709,14 +768,26 @@ void SAL_CALL Content::addProperty( const OUString& Name,
// if ( m_bTransient ) // if ( m_bTransient )
// @@@ ??? // @@@ ???
if ( Name.isEmpty() ) if ( aCmdArg.Property.Name.isEmpty() )
throw lang::IllegalArgumentException(); throw lang::IllegalArgumentException(
"\"addProperty\" with empty Property.Name",
static_cast< cppu::OWeakObject * >( this ),
-1 );
// Check property type. // 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, ...@@ -724,14 +795,16 @@ void SAL_CALL Content::addProperty( const OUString& Name,
// exist in dynamic and static(!) properties. // exist in dynamic and static(!) properties.
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// @@@ Need real command environment here, but where to get it from? // Take into account special properties with custom namespace
// XPropertyContainer interface should be replaced by // using <prop:the_propname xmlns:prop="the_namespace">
// XCommandProcessor commands! OUString aSpecialName;
uno::Reference< ucb::XCommandEnvironment > xEnv; bool bIsSpecial = DAVProperties::isUCBSpecialProperty(
aCmdArg.Property.Name, aSpecialName );
// Note: This requires network access! // Note: This requires network access!
if ( getPropertySetInfo( xEnv, sal_False /* don't cache data */ ) if ( getPropertySetInfo( xEnv, sal_False /* don't cache data */ )
->hasPropertyByName( Name ) ) ->hasPropertyByName(
bIsSpecial ? aSpecialName : aCmdArg.Property.Name ) )
{ {
// Property does already exist. // Property does already exist.
throw beans::PropertyExistException(); throw beans::PropertyExistException();
...@@ -741,7 +814,8 @@ void SAL_CALL Content::addProperty( const OUString& Name, ...@@ -741,7 +814,8 @@ void SAL_CALL Content::addProperty( const OUString& Name,
// Add a new dynamic property. // Add a new dynamic property.
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
ProppatchValue aValue( PROPSET, Name, DefaultValue ); ProppatchValue aValue(
PROPSET, aCmdArg.Property.Name, aCmdArg.DefaultValue );
std::vector< ProppatchValue > aProppatchValues; std::vector< ProppatchValue > aProppatchValues;
aProppatchValues.push_back( aValue ); aProppatchValues.push_back( aValue );
...@@ -765,7 +839,7 @@ void SAL_CALL Content::addProperty( const OUString& Name, ...@@ -765,7 +839,7 @@ void SAL_CALL Content::addProperty( const OUString& Name,
// Notify propertyset info change listeners. // Notify propertyset info change listeners.
beans::PropertySetInfoChangeEvent evt( beans::PropertySetInfoChangeEvent evt(
static_cast< cppu::OWeakObject * >( this ), static_cast< cppu::OWeakObject * >( this ),
Name, bIsSpecial ? aSpecialName : aCmdArg.Property.Name,
-1, // No handle available -1, // No handle available
beans::PropertySetInfoChange::PROPERTY_INSERTED ); beans::PropertySetInfoChange::PROPERTY_INSERTED );
notifyPropertySetInfoChange( evt ); notifyPropertySetInfoChange( evt );
...@@ -778,7 +852,8 @@ void SAL_CALL Content::addProperty( const OUString& Name, ...@@ -778,7 +852,8 @@ void SAL_CALL Content::addProperty( const OUString& Name,
// Store property locally. // Store property locally.
ContentImplHelper::addProperty( ContentImplHelper::addProperty(
Name, Attributes, DefaultValue ); bIsSpecial ? aSpecialName : aCmdArg.Property.Name,
aCmdArg.Property.Attributes, aCmdArg.DefaultValue );
} }
else else
{ {
...@@ -796,9 +871,9 @@ void SAL_CALL Content::addProperty( const OUString& Name, ...@@ -796,9 +871,9 @@ void SAL_CALL Content::addProperty( const OUString& Name,
case FTP: case FTP:
case NON_DAV: case NON_DAV:
// Store property locally. // Store property locally.
ContentImplHelper::addProperty( Name, ContentImplHelper::addProperty(
Attributes, bIsSpecial ? aSpecialName : aCmdArg.Property.Name,
DefaultValue ); aCmdArg.Property.Attributes, aCmdArg.DefaultValue );
break; break;
default: default:
...@@ -822,18 +897,12 @@ void SAL_CALL Content::addProperty( const OUString& Name, ...@@ -822,18 +897,12 @@ void SAL_CALL Content::addProperty( const OUString& Name,
} }
} }
//========================================================================= void Content::removeProperty( const OUString& Name,
// virtual const uno::Reference< ucb::XCommandEnvironment >& xEnv )
void SAL_CALL Content::removeProperty( const OUString& Name )
throw( beans::UnknownPropertyException, throw( beans::UnknownPropertyException,
beans::NotRemoveableException, beans::NotRemoveableException,
uno::RuntimeException ) 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. // Try to remove property from server.
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
...@@ -916,6 +985,35 @@ void SAL_CALL Content::removeProperty( const OUString& Name ) ...@@ -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. // XContentCreator methods.
...@@ -1588,11 +1686,16 @@ uno::Sequence< uno::Any > Content::setPropertyValues( ...@@ -1588,11 +1686,16 @@ uno::Sequence< uno::Any > Content::setPropertyValues(
// Optional props. // Optional props.
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
OUString aSpecialName;
bool bIsSpecial = DAVProperties::isUCBSpecialProperty(
rName, aSpecialName );
if ( !xInfo.is() ) if ( !xInfo.is() )
xInfo = getPropertySetInfo( xEnv, xInfo = getPropertySetInfo( xEnv,
sal_False /* don't cache data */ ); sal_False /* don't cache data */ );
if ( !xInfo->hasPropertyByName( rName ) ) if ( !xInfo->hasPropertyByName(
bIsSpecial ? aSpecialName : rName ) )
{ {
// Check, whether property exists. Skip otherwise. // Check, whether property exists. Skip otherwise.
// PROPPATCH::set would add the property automatically, which // PROPPATCH::set would add the property automatically, which
......
...@@ -55,6 +55,7 @@ namespace com { namespace sun { namespace star { namespace sdbc { ...@@ -55,6 +55,7 @@ namespace com { namespace sun { namespace star { namespace sdbc {
namespace com { namespace sun { namespace star { namespace ucb { namespace com { namespace sun { namespace star { namespace ucb {
struct OpenCommandArgument3; struct OpenCommandArgument3;
struct PostCommandArgument2; struct PostCommandArgument2;
struct PropertyCommandArgument;
struct TransferInfo; struct TransferInfo;
} } } } } } } }
...@@ -204,6 +205,21 @@ private: ...@@ -204,6 +205,21 @@ private:
const com::sun::star::uno::Reference< const com::sun::star::uno::Reference<
com::sun::star::ucb::XCommandEnvironment >& Environment ); 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: public:
Content( const ::com::sun::star::uno::Reference< Content( const ::com::sun::star::uno::Reference<
::com::sun::star::uno::XComponentContext >& rxContext, ::com::sun::star::uno::XComponentContext >& rxContext,
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <com/sun/star/ucb/OpenCommandArgument2.hpp> #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
#include <com/sun/star/ucb/InsertCommandArgument.hpp> #include <com/sun/star/ucb/InsertCommandArgument.hpp>
#include <com/sun/star/ucb/PostCommandArgument2.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/TransferInfo.hpp>
#include <com/sun/star/uno/Sequence.hxx> #include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/util/DateTime.hpp> #include <com/sun/star/util/DateTime.hpp>
...@@ -520,7 +521,7 @@ uno::Sequence< ucb::CommandInfo > Content::getCommands( ...@@ -520,7 +521,7 @@ uno::Sequence< ucb::CommandInfo > Content::getCommands(
{ {
osl::Guard< osl::Mutex > aGuard( m_aMutex ); osl::Guard< osl::Mutex > aGuard( m_aMutex );
uno::Sequence< ucb::CommandInfo > aCmdInfo( 8 ); uno::Sequence< ucb::CommandInfo > aCmdInfo( 10 );
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Mandatory commands // Mandatory commands
...@@ -581,6 +582,18 @@ uno::Sequence< ucb::CommandInfo > Content::getCommands( ...@@ -581,6 +582,18 @@ uno::Sequence< ucb::CommandInfo > Content::getCommands(
-1, -1,
getCppuType( static_cast< getCppuType( static_cast<
ucb::PostCommandArgument2 * >( 0 ) ) ); 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; sal_Bool bFolder = sal_False;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment