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
<type scope="com::sun::star::lang">IllegalArgumentException</type>
if the Name of the property is empty.</p>
<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>.
</blockquote>
</td>
......@@ -502,7 +502,7 @@ published service Content
<type scope="com::sun::star::beans">NotRemoveableException</type>
if the property is not removable.</p>
<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>.
</blockquote>
</td>
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
......@@ -25,7 +26,7 @@ module com { module sun { module star { module ucb {
/** The argument for the "addProperty" command.
@see XCommandProcessor
@since Apache OpenOffice 4.0
@since Apache OpenOffice 4.0, LibreOffice 4.2
*/
struct PropertyCommandArgument
{
......@@ -41,3 +42,5 @@ struct PropertyCommandArgument
}; }; }; };
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -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: */
......@@ -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
......
......@@ -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
......
......@@ -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,
......
......@@ -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;
......
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