| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
/************************************************************************** |
| 22 |
TODO |
| 23 |
************************************************************************** |
| 24 |
|
| 25 |
- optimize transfer command. "Move" should be implementable much more |
| 26 |
efficient! |
| 27 |
|
| 28 |
************************************************************************** |
| 29 |
|
| 30 |
- Root Folder vs. 'normal' Folder |
| 31 |
- root doesn't support command 'delete' |
| 32 |
- root doesn't support command 'insert' |
| 33 |
- root needs not created via XContentCreator - queryContent with root |
| 34 |
folder id ( HIERARCHY_ROOT_FOLDER_URL ) always returns a value != 0 |
| 35 |
- root has no parent. |
| 36 |
|
| 37 |
*************************************************************************/ |
| 38 |
#include <osl/diagnose.h> |
| 39 |
|
| 40 |
#include <rtl/ustring.hxx> |
| 41 |
#include <com/sun/star/beans/IllegalTypeException.hpp> |
| 42 |
#include <com/sun/star/beans/PropertyAttribute.hpp> |
| 43 |
#include <com/sun/star/beans/PropertyExistException.hpp> |
| 44 |
#include <com/sun/star/beans/PropertyState.hpp> |
| 45 |
#include <com/sun/star/lang/IllegalAccessException.hpp> |
| 46 |
#include <com/sun/star/ucb/ContentInfoAttribute.hpp> |
| 47 |
#include <com/sun/star/ucb/IllegalIdentifierException.hpp> |
| 48 |
#include <com/sun/star/ucb/InsertCommandArgument.hpp> |
| 49 |
#include <com/sun/star/ucb/InteractiveBadTransferURLException.hpp> |
| 50 |
#include <com/sun/star/ucb/MissingPropertiesException.hpp> |
| 51 |
#include <com/sun/star/ucb/NameClash.hpp> |
| 52 |
#include <com/sun/star/ucb/NameClashException.hpp> |
| 53 |
#include <com/sun/star/ucb/OpenCommandArgument2.hpp> |
| 54 |
#include <com/sun/star/ucb/TransferInfo.hpp> |
| 55 |
#include <com/sun/star/ucb/UnsupportedCommandException.hpp> |
| 56 |
#include <com/sun/star/ucb/UnsupportedNameClashException.hpp> |
| 57 |
#include <com/sun/star/ucb/XCommandInfo.hpp> |
| 58 |
#include <com/sun/star/ucb/XPersistentPropertySet.hpp> |
| 59 |
#include <com/sun/star/uno/Any.hxx> |
| 60 |
#include <com/sun/star/uno/Sequence.hxx> |
| 61 |
#include <comphelper/propertysequence.hxx> |
| 62 |
#include <comphelper/sequence.hxx> |
| 63 |
#include <cppuhelper/queryinterface.hxx> |
| 64 |
#include <ucbhelper/contentidentifier.hxx> |
| 65 |
#include <ucbhelper/propertyvalueset.hxx> |
| 66 |
#include <ucbhelper/cancelcommandexecution.hxx> |
| 67 |
#include <ucbhelper/macros.hxx> |
| 68 |
#include <utility> |
| 69 |
#include "hierarchycontent.hxx" |
| 70 |
#include "hierarchyprovider.hxx" |
| 71 |
#include "dynamicresultset.hxx" |
| 72 |
#include "hierarchyuri.hxx" |
| 73 |
|
| 74 |
#include "../inc/urihelper.hxx" |
| 75 |
|
| 76 |
using namespace com::sun::star; |
| 77 |
using namespace hierarchy_ucp; |
| 78 |
|
| 79 |
|
| 80 |
// HierarchyContent Implementation. |
| 81 |
|
| 82 |
|
| 83 |
// static ( "virtual" ctor ) |
| 84 |
rtl::Reference<HierarchyContent> HierarchyContent::create( |
| 85 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 86 |
HierarchyContentProvider* pProvider, |
| 87 |
const uno::Reference< ucb::XContentIdentifier >& Identifier ) |
| 88 |
{ |
| 89 |
// Fail, if content does not exist. |
| 90 |
HierarchyContentProperties aProps; |
| 91 |
if ( !loadData( rxContext, pProvider, Identifier, aProps ) ) |
| 92 |
return nullptr; |
| 93 |
|
| 94 |
return new HierarchyContent( rxContext, pProvider, Identifier, std::move(aProps) ); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
// static ( "virtual" ctor ) |
| 99 |
rtl::Reference<HierarchyContent> HierarchyContent::create( |
| 100 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 101 |
HierarchyContentProvider* pProvider, |
| 102 |
const uno::Reference< ucb::XContentIdentifier >& Identifier, |
| 103 |
const ucb::ContentInfo& Info ) |
| 104 |
{ |
| 105 |
if ( Info.Type.isEmpty() ) |
| 106 |
return nullptr; |
| 107 |
|
| 108 |
if ( Info.Type != HIERARCHY_FOLDER_CONTENT_TYPE && Info.Type != HIERARCHY_LINK_CONTENT_TYPE ) |
| 109 |
return nullptr; |
| 110 |
|
| 111 |
return new HierarchyContent( rxContext, pProvider, Identifier, Info ); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
HierarchyContent::HierarchyContent( |
| 116 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 117 |
HierarchyContentProvider* pProvider, |
| 118 |
const uno::Reference< ucb::XContentIdentifier >& Identifier, |
| 119 |
HierarchyContentProperties aProps ) |
| 120 |
: ContentImplHelper( rxContext, pProvider, Identifier ), |
| 121 |
m_aProps(std::move( aProps )), |
| 122 |
m_eState( PERSISTENT ), |
| 123 |
m_pProvider( pProvider ), |
| 124 |
m_bCheckedReadOnly( false ), |
| 125 |
m_bIsReadOnly( true ) |
| 126 |
{ |
| 127 |
setKind( Identifier ); |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
HierarchyContent::HierarchyContent( |
| 132 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 133 |
HierarchyContentProvider* pProvider, |
| 134 |
const uno::Reference< ucb::XContentIdentifier >& Identifier, |
| 135 |
const ucb::ContentInfo& Info ) |
| 136 |
: ContentImplHelper( rxContext, pProvider, Identifier ), |
| 137 |
m_aProps( Info.Type == HIERARCHY_FOLDER_CONTENT_TYPE ? HierarchyEntryData::FOLDER : HierarchyEntryData::LINK ), |
| 138 |
m_eState( TRANSIENT ), |
| 139 |
m_pProvider( pProvider ), |
| 140 |
m_bCheckedReadOnly( false ), |
| 141 |
m_bIsReadOnly( true ) |
| 142 |
{ |
| 143 |
setKind( Identifier ); |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
// virtual |
| 148 |
HierarchyContent::~HierarchyContent() |
| 149 |
{ |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
// XInterface methods. |
| 154 |
|
| 155 |
|
| 156 |
// virtual |
| 157 |
void SAL_CALL HierarchyContent::acquire() |
| 158 |
noexcept |
| 159 |
{ |
| 160 |
ContentImplHelper::acquire(); |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
// virtual |
| 165 |
void SAL_CALL HierarchyContent::release() |
| 166 |
noexcept |
| 167 |
{ |
| 168 |
ContentImplHelper::release(); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
// virtual |
| 173 |
uno::Any SAL_CALL HierarchyContent::queryInterface( const uno::Type & rType ) |
| 174 |
{ |
| 175 |
uno::Any aRet = ContentImplHelper::queryInterface( rType ); |
| 176 |
|
| 177 |
if ( !aRet.hasValue() ) |
| 178 |
{ |
| 179 |
// Note: isReadOnly may be relative expensive. So avoid calling it |
| 180 |
// unless it is really necessary. |
| 181 |
aRet = cppu::queryInterface( |
| 182 |
rType, static_cast< ucb::XContentCreator * >( this ) ); |
| 183 |
if ( aRet.hasValue() ) |
| 184 |
{ |
| 185 |
if ( !isFolder() || isReadOnly() ) |
| 186 |
return uno::Any(); |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
return aRet; |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
// XTypeProvider methods. |
| 195 |
|
| 196 |
|
| 197 |
XTYPEPROVIDER_COMMON_IMPL( HierarchyContent ); |
| 198 |
|
| 199 |
|
| 200 |
// virtual |
| 201 |
uno::Sequence< uno::Type > SAL_CALL HierarchyContent::getTypes() |
| 202 |
{ |
| 203 |
if ( isFolder() && !isReadOnly() ) |
| 204 |
{ |
| 205 |
static cppu::OTypeCollection s_aFolderTypes( |
| 206 |
CPPU_TYPE_REF( lang::XTypeProvider ), |
| 207 |
CPPU_TYPE_REF( lang::XServiceInfo ), |
| 208 |
CPPU_TYPE_REF( lang::XComponent ), |
| 209 |
CPPU_TYPE_REF( ucb::XContent ), |
| 210 |
CPPU_TYPE_REF( ucb::XCommandProcessor ), |
| 211 |
CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), |
| 212 |
CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), |
| 213 |
CPPU_TYPE_REF( beans::XPropertyContainer ), |
| 214 |
CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), |
| 215 |
CPPU_TYPE_REF( container::XChild ), |
| 216 |
CPPU_TYPE_REF( ucb::XContentCreator ) ); |
| 217 |
|
| 218 |
|
| 219 |
return s_aFolderTypes.getTypes(); |
| 220 |
} |
| 221 |
else |
| 222 |
{ |
| 223 |
static cppu::OTypeCollection s_aDocumentTypes( |
| 224 |
CPPU_TYPE_REF( lang::XTypeProvider ), |
| 225 |
CPPU_TYPE_REF( lang::XServiceInfo ), |
| 226 |
CPPU_TYPE_REF( lang::XComponent ), |
| 227 |
CPPU_TYPE_REF( ucb::XContent ), |
| 228 |
CPPU_TYPE_REF( ucb::XCommandProcessor ), |
| 229 |
CPPU_TYPE_REF( beans::XPropertiesChangeNotifier ), |
| 230 |
CPPU_TYPE_REF( ucb::XCommandInfoChangeNotifier ), |
| 231 |
CPPU_TYPE_REF( beans::XPropertyContainer ), |
| 232 |
CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), |
| 233 |
CPPU_TYPE_REF( container::XChild ) ); |
| 234 |
|
| 235 |
return s_aDocumentTypes.getTypes(); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
// XServiceInfo methods. |
| 241 |
|
| 242 |
|
| 243 |
// virtual |
| 244 |
OUString SAL_CALL HierarchyContent::getImplementationName() |
| 245 |
{ |
| 246 |
return u"com.sun.star.comp.ucb.HierarchyContent"_ustr; |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
// virtual |
| 251 |
uno::Sequence< OUString > SAL_CALL |
| 252 |
HierarchyContent::getSupportedServiceNames() |
| 253 |
{ |
| 254 |
uno::Sequence< OUString > aSNS( 1 ); |
| 255 |
|
| 256 |
if ( m_eKind == LINK ) |
| 257 |
aSNS.getArray()[ 0 ] = "com.sun.star.ucb.HierarchyLinkContent"; |
| 258 |
else if ( m_eKind == FOLDER ) |
| 259 |
aSNS.getArray()[ 0 ] = "com.sun.star.ucb.HierarchyFolderContent"; |
| 260 |
else |
| 261 |
aSNS.getArray()[ 0 ] = "com.sun.star.ucb.HierarchyRootFolderContent"; |
| 262 |
|
| 263 |
return aSNS; |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
// XContent methods. |
| 268 |
|
| 269 |
|
| 270 |
// virtual |
| 271 |
OUString SAL_CALL HierarchyContent::getContentType() |
| 272 |
{ |
| 273 |
return m_aProps.getContentType(); |
| 274 |
} |
| 275 |
|
| 276 |
|
| 277 |
// virtual |
| 278 |
uno::Reference< ucb::XContentIdentifier > SAL_CALL |
| 279 |
HierarchyContent::getIdentifier() |
| 280 |
{ |
| 281 |
// Transient? |
| 282 |
if ( m_eState == TRANSIENT ) |
| 283 |
{ |
| 284 |
// Transient contents have no identifier. |
| 285 |
return uno::Reference< ucb::XContentIdentifier >(); |
| 286 |
} |
| 287 |
|
| 288 |
return ContentImplHelper::getIdentifier(); |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
// XCommandProcessor methods. |
| 293 |
|
| 294 |
|
| 295 |
// virtual |
| 296 |
uno::Any SAL_CALL HierarchyContent::execute( |
| 297 |
const ucb::Command& aCommand, |
| 298 |
sal_Int32 /*CommandId*/, |
| 299 |
const uno::Reference< ucb::XCommandEnvironment >& Environment ) |
| 300 |
{ |
| 301 |
uno::Any aRet; |
| 302 |
|
| 303 |
if ( aCommand.Name == "getPropertyValues" ) |
| 304 |
{ |
| 305 |
|
| 306 |
// getPropertyValues |
| 307 |
|
| 308 |
|
| 309 |
uno::Sequence< beans::Property > Properties; |
| 310 |
if ( !( aCommand.Argument >>= Properties ) ) |
| 311 |
{ |
| 312 |
ucbhelper::cancelCommandExecution( |
| 313 |
uno::Any( lang::IllegalArgumentException( |
| 314 |
u"Wrong argument type!"_ustr, |
| 315 |
getXWeak(), |
| 316 |
-1 ) ), |
| 317 |
Environment ); |
| 318 |
// Unreachable |
| 319 |
} |
| 320 |
|
| 321 |
aRet <<= getPropertyValues( Properties ); |
| 322 |
} |
| 323 |
else if ( aCommand.Name == "setPropertyValues" ) |
| 324 |
{ |
| 325 |
|
| 326 |
// setPropertyValues |
| 327 |
|
| 328 |
|
| 329 |
uno::Sequence< beans::PropertyValue > aProperties; |
| 330 |
if ( !( aCommand.Argument >>= aProperties ) ) |
| 331 |
{ |
| 332 |
ucbhelper::cancelCommandExecution( |
| 333 |
uno::Any( lang::IllegalArgumentException( |
| 334 |
u"Wrong argument type!"_ustr, |
| 335 |
getXWeak(), |
| 336 |
-1 ) ), |
| 337 |
Environment ); |
| 338 |
// Unreachable |
| 339 |
} |
| 340 |
|
| 341 |
if ( !aProperties.hasElements() ) |
| 342 |
{ |
| 343 |
ucbhelper::cancelCommandExecution( |
| 344 |
uno::Any( lang::IllegalArgumentException( |
| 345 |
u"No properties!"_ustr, |
| 346 |
getXWeak(), |
| 347 |
-1 ) ), |
| 348 |
Environment ); |
| 349 |
// Unreachable |
| 350 |
} |
| 351 |
|
| 352 |
aRet <<= setPropertyValues( aProperties, Environment ); |
| 353 |
} |
| 354 |
else if ( aCommand.Name == "getPropertySetInfo" ) |
| 355 |
{ |
| 356 |
|
| 357 |
// getPropertySetInfo |
| 358 |
|
| 359 |
|
| 360 |
aRet <<= getPropertySetInfo( Environment ); |
| 361 |
} |
| 362 |
else if ( aCommand.Name == "getCommandInfo" ) |
| 363 |
{ |
| 364 |
|
| 365 |
// getCommandInfo |
| 366 |
|
| 367 |
|
| 368 |
aRet <<= getCommandInfo( Environment ); |
| 369 |
} |
| 370 |
else if ( aCommand.Name == "open" && isFolder() ) |
| 371 |
{ |
| 372 |
|
| 373 |
// open command for a folder content |
| 374 |
|
| 375 |
|
| 376 |
ucb::OpenCommandArgument2 aOpenCommand; |
| 377 |
if ( !( aCommand.Argument >>= aOpenCommand ) ) |
| 378 |
{ |
| 379 |
ucbhelper::cancelCommandExecution( |
| 380 |
uno::Any( lang::IllegalArgumentException( |
| 381 |
u"Wrong argument type!"_ustr, |
| 382 |
getXWeak(), |
| 383 |
-1 ) ), |
| 384 |
Environment ); |
| 385 |
// Unreachable |
| 386 |
} |
| 387 |
|
| 388 |
uno::Reference< ucb::XDynamicResultSet > xSet |
| 389 |
= new DynamicResultSet( m_xContext, this, aOpenCommand ); |
| 390 |
aRet <<= xSet; |
| 391 |
} |
| 392 |
else if ( aCommand.Name == "insert" && ( m_eKind != ROOT ) && !isReadOnly() ) |
| 393 |
{ |
| 394 |
|
| 395 |
// insert |
| 396 |
// ( Not available at root folder ) |
| 397 |
|
| 398 |
|
| 399 |
ucb::InsertCommandArgument aArg; |
| 400 |
if ( !( aCommand.Argument >>= aArg ) ) |
| 401 |
{ |
| 402 |
ucbhelper::cancelCommandExecution( |
| 403 |
uno::Any( lang::IllegalArgumentException( |
| 404 |
u"Wrong argument type!"_ustr, |
| 405 |
getXWeak(), |
| 406 |
-1 ) ), |
| 407 |
Environment ); |
| 408 |
// Unreachable |
| 409 |
} |
| 410 |
|
| 411 |
sal_Int32 nNameClash = aArg.ReplaceExisting |
| 412 |
? ucb::NameClash::OVERWRITE |
| 413 |
: ucb::NameClash::ERROR; |
| 414 |
insert( nNameClash, Environment ); |
| 415 |
} |
| 416 |
else if ( aCommand.Name == "delete" && ( m_eKind != ROOT ) && !isReadOnly() ) |
| 417 |
{ |
| 418 |
|
| 419 |
// delete |
| 420 |
// ( Not available at root folder ) |
| 421 |
|
| 422 |
|
| 423 |
bool bDeletePhysical = false; |
| 424 |
aCommand.Argument >>= bDeletePhysical; |
| 425 |
destroy( bDeletePhysical, Environment ); |
| 426 |
|
| 427 |
// Remove own and all children's persistent data. |
| 428 |
if ( !removeData() ) |
| 429 |
{ |
| 430 |
uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence( |
| 431 |
{ |
| 432 |
{"Uri", uno::Any(m_xIdentifier->getContentIdentifier())} |
| 433 |
})); |
| 434 |
ucbhelper::cancelCommandExecution( |
| 435 |
ucb::IOErrorCode_CANT_WRITE, |
| 436 |
aArgs, |
| 437 |
Environment, |
| 438 |
u"Cannot remove persistent data!"_ustr, |
| 439 |
this ); |
| 440 |
// Unreachable |
| 441 |
} |
| 442 |
|
| 443 |
// Remove own and all children's Additional Core Properties. |
| 444 |
removeAdditionalPropertySet(); |
| 445 |
} |
| 446 |
else if ( aCommand.Name == "transfer" && isFolder() && !isReadOnly() ) |
| 447 |
{ |
| 448 |
|
| 449 |
// transfer |
| 450 |
// ( Not available at link objects ) |
| 451 |
|
| 452 |
|
| 453 |
ucb::TransferInfo aInfo; |
| 454 |
if ( !( aCommand.Argument >>= aInfo ) ) |
| 455 |
{ |
| 456 |
OSL_FAIL( "Wrong argument type!" ); |
| 457 |
ucbhelper::cancelCommandExecution( |
| 458 |
uno::Any( lang::IllegalArgumentException( |
| 459 |
u"Wrong argument type!"_ustr, |
| 460 |
getXWeak(), |
| 461 |
-1 ) ), |
| 462 |
Environment ); |
| 463 |
// Unreachable |
| 464 |
} |
| 465 |
|
| 466 |
transfer( aInfo, Environment ); |
| 467 |
} |
| 468 |
else if ( aCommand.Name == "createNewContent" && isFolder() && !isReadOnly() ) |
| 469 |
{ |
| 470 |
|
| 471 |
// createNewContent |
| 472 |
// ( Not available at link objects ) |
| 473 |
|
| 474 |
|
| 475 |
ucb::ContentInfo aInfo; |
| 476 |
if ( !( aCommand.Argument >>= aInfo ) ) |
| 477 |
{ |
| 478 |
OSL_FAIL( "Wrong argument type!" ); |
| 479 |
ucbhelper::cancelCommandExecution( |
| 480 |
uno::Any( lang::IllegalArgumentException( |
| 481 |
u"Wrong argument type!"_ustr, |
| 482 |
getXWeak(), |
| 483 |
-1 ) ), |
| 484 |
Environment ); |
| 485 |
// Unreachable |
| 486 |
} |
| 487 |
|
| 488 |
aRet <<= createNewContent( aInfo ); |
| 489 |
} |
| 490 |
else |
| 491 |
{ |
| 492 |
|
| 493 |
// Unsupported command |
| 494 |
|
| 495 |
|
| 496 |
ucbhelper::cancelCommandExecution( |
| 497 |
uno::Any( ucb::UnsupportedCommandException( |
| 498 |
OUString(), |
| 499 |
getXWeak() ) ), |
| 500 |
Environment ); |
| 501 |
// Unreachable |
| 502 |
} |
| 503 |
|
| 504 |
return aRet; |
| 505 |
} |
| 506 |
|
| 507 |
|
| 508 |
// virtual |
| 509 |
void SAL_CALL HierarchyContent::abort( sal_Int32 /*CommandId*/ ) |
| 510 |
{ |
| 511 |
// @@@ Generally, no action takes much time... |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
// XContentCreator methods. |
| 516 |
|
| 517 |
|
| 518 |
// virtual |
| 519 |
uno::Sequence< ucb::ContentInfo > SAL_CALL |
| 520 |
HierarchyContent::queryCreatableContentsInfo() |
| 521 |
{ |
| 522 |
return m_aProps.getCreatableContentsInfo(); |
| 523 |
} |
| 524 |
|
| 525 |
|
| 526 |
// virtual |
| 527 |
uno::Reference< ucb::XContent > SAL_CALL |
| 528 |
HierarchyContent::createNewContent( const ucb::ContentInfo& Info ) |
| 529 |
{ |
| 530 |
if ( isFolder() ) |
| 531 |
{ |
| 532 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 533 |
|
| 534 |
if ( Info.Type.isEmpty() ) |
| 535 |
return uno::Reference< ucb::XContent >(); |
| 536 |
|
| 537 |
bool bCreateFolder = Info.Type == HIERARCHY_FOLDER_CONTENT_TYPE; |
| 538 |
|
| 539 |
if ( !bCreateFolder && Info.Type != HIERARCHY_LINK_CONTENT_TYPE ) |
| 540 |
return uno::Reference< ucb::XContent >(); |
| 541 |
|
| 542 |
OUString aURL = m_xIdentifier->getContentIdentifier(); |
| 543 |
|
| 544 |
OSL_ENSURE( !aURL.isEmpty(), |
| 545 |
"HierarchyContent::createNewContent - empty identifier!" ); |
| 546 |
|
| 547 |
if ( ( aURL.lastIndexOf( '/' ) + 1 ) != aURL.getLength() ) |
| 548 |
aURL += "/"; |
| 549 |
|
| 550 |
if ( bCreateFolder ) |
| 551 |
aURL += "New_Folder"; |
| 552 |
else |
| 553 |
aURL += "New_Link"; |
| 554 |
|
| 555 |
uno::Reference< ucb::XContentIdentifier > xId |
| 556 |
= new ::ucbhelper::ContentIdentifier( aURL ); |
| 557 |
|
| 558 |
return create( m_xContext, m_pProvider, xId, Info ); |
| 559 |
} |
| 560 |
else |
| 561 |
{ |
| 562 |
OSL_FAIL( "createNewContent called on non-folder object!" ); |
| 563 |
return uno::Reference< ucb::XContent >(); |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
// virtual |
| 569 |
OUString HierarchyContent::getParentURL() |
| 570 |
{ |
| 571 |
HierarchyUri aUri( m_xIdentifier->getContentIdentifier() ); |
| 572 |
return aUri.getParentUri(); |
| 573 |
} |
| 574 |
|
| 575 |
|
| 576 |
//static |
| 577 |
bool HierarchyContent::hasData( |
| 578 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 579 |
HierarchyContentProvider* pProvider, |
| 580 |
const uno::Reference< ucb::XContentIdentifier >& Identifier ) |
| 581 |
{ |
| 582 |
OUString aURL = Identifier->getContentIdentifier(); |
| 583 |
|
| 584 |
// Am I a root folder? |
| 585 |
HierarchyUri aUri( aURL ); |
| 586 |
if ( aUri.isRootFolder() ) |
| 587 |
{ |
| 588 |
// hasData must always return 'true' for root folder |
| 589 |
// even if no persistent data exist!!! |
| 590 |
return true; |
| 591 |
} |
| 592 |
|
| 593 |
return HierarchyEntry( rxContext, pProvider, aURL ).hasData(); |
| 594 |
} |
| 595 |
|
| 596 |
|
| 597 |
//static |
| 598 |
bool HierarchyContent::loadData( |
| 599 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 600 |
HierarchyContentProvider* pProvider, |
| 601 |
const uno::Reference< ucb::XContentIdentifier >& Identifier, |
| 602 |
HierarchyContentProperties& rProps ) |
| 603 |
{ |
| 604 |
OUString aURL = Identifier->getContentIdentifier(); |
| 605 |
|
| 606 |
// Am I a root folder? |
| 607 |
HierarchyUri aUri( aURL ); |
| 608 |
if ( aUri.isRootFolder() ) |
| 609 |
{ |
| 610 |
rProps = HierarchyContentProperties( HierarchyEntryData::FOLDER ); |
| 611 |
} |
| 612 |
else |
| 613 |
{ |
| 614 |
HierarchyEntry aEntry( rxContext, pProvider, aURL ); |
| 615 |
HierarchyEntryData aData; |
| 616 |
if ( !aEntry.getData( aData ) ) |
| 617 |
return false; |
| 618 |
|
| 619 |
rProps = HierarchyContentProperties( aData ); |
| 620 |
} |
| 621 |
return true; |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
bool HierarchyContent::storeData() |
| 626 |
{ |
| 627 |
HierarchyEntry aEntry( |
| 628 |
m_xContext, m_pProvider, m_xIdentifier->getContentIdentifier() ); |
| 629 |
return aEntry.setData( m_aProps.getHierarchyEntryData() ); |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
void HierarchyContent::renameData( |
| 634 |
const uno::Reference< ucb::XContentIdentifier >& xOldId, |
| 635 |
const uno::Reference< ucb::XContentIdentifier >& xNewId ) |
| 636 |
{ |
| 637 |
HierarchyEntry aEntry( |
| 638 |
m_xContext, m_pProvider, xOldId->getContentIdentifier() ); |
| 639 |
aEntry.move( xNewId->getContentIdentifier(), |
| 640 |
m_aProps.getHierarchyEntryData() ); |
| 641 |
} |
| 642 |
|
| 643 |
|
| 644 |
bool HierarchyContent::removeData() |
| 645 |
{ |
| 646 |
HierarchyEntry aEntry( |
| 647 |
m_xContext, m_pProvider, m_xIdentifier->getContentIdentifier() ); |
| 648 |
return aEntry.remove(); |
| 649 |
} |
| 650 |
|
| 651 |
|
| 652 |
void HierarchyContent::setKind( |
| 653 |
const uno::Reference< ucb::XContentIdentifier >& Identifier ) |
| 654 |
{ |
| 655 |
if ( m_aProps.getIsFolder() ) |
| 656 |
{ |
| 657 |
// Am I a root folder? |
| 658 |
HierarchyUri aUri( Identifier->getContentIdentifier() ); |
| 659 |
if ( aUri.isRootFolder() ) |
| 660 |
m_eKind = ROOT; |
| 661 |
else |
| 662 |
m_eKind = FOLDER; |
| 663 |
} |
| 664 |
else |
| 665 |
m_eKind = LINK; |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
bool HierarchyContent::isReadOnly() |
| 670 |
{ |
| 671 |
if ( !m_bCheckedReadOnly ) |
| 672 |
{ |
| 673 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 674 |
if ( !m_bCheckedReadOnly ) |
| 675 |
{ |
| 676 |
m_bCheckedReadOnly = true; |
| 677 |
m_bIsReadOnly = true; |
| 678 |
|
| 679 |
HierarchyUri aUri( m_xIdentifier->getContentIdentifier() ); |
| 680 |
uno::Reference< lang::XMultiServiceFactory > xConfigProv |
| 681 |
= m_pProvider->getConfigProvider( aUri.getService() ); |
| 682 |
if ( xConfigProv.is() ) |
| 683 |
{ |
| 684 |
uno::Sequence< OUString > aNames |
| 685 |
= xConfigProv->getAvailableServiceNames(); |
| 686 |
m_bIsReadOnly = comphelper::findValue(aNames, "com.sun.star.ucb.HierarchyDataReadWriteAccess") == -1; |
| 687 |
} |
| 688 |
} |
| 689 |
} |
| 690 |
|
| 691 |
return m_bIsReadOnly; |
| 692 |
} |
| 693 |
|
| 694 |
|
| 695 |
uno::Reference< ucb::XContentIdentifier > |
| 696 |
HierarchyContent::makeNewIdentifier( const OUString& rTitle ) |
| 697 |
{ |
| 698 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 699 |
|
| 700 |
// Assemble new content identifier... |
| 701 |
HierarchyUri aUri( m_xIdentifier->getContentIdentifier() ); |
| 702 |
OUString aNewURL = aUri.getParentUri() + "/" + |
| 703 |
::ucb_impl::urihelper::encodeSegment( rTitle ); |
| 704 |
|
| 705 |
return uno::Reference< ucb::XContentIdentifier >( |
| 706 |
new ::ucbhelper::ContentIdentifier( aNewURL ) ); |
| 707 |
} |
| 708 |
|
| 709 |
|
| 710 |
void HierarchyContent::queryChildren( HierarchyContentRefVector& rChildren ) |
| 711 |
{ |
| 712 |
if ( ( m_eKind != FOLDER ) && ( m_eKind != ROOT ) ) |
| 713 |
return; |
| 714 |
|
| 715 |
// Obtain a list with a snapshot of all currently instantiated contents |
| 716 |
// from provider and extract the contents which are direct children |
| 717 |
// of this content. |
| 718 |
|
| 719 |
::ucbhelper::ContentRefList aAllContents; |
| 720 |
m_xProvider->queryExistingContents( aAllContents ); |
| 721 |
|
| 722 |
OUString aURL = m_xIdentifier->getContentIdentifier(); |
| 723 |
sal_Int32 nURLPos = aURL.lastIndexOf( '/' ); |
| 724 |
|
| 725 |
if ( nURLPos != ( aURL.getLength() - 1 ) ) |
| 726 |
{ |
| 727 |
// No trailing slash found. Append. |
| 728 |
aURL += "/"; |
| 729 |
} |
| 730 |
|
| 731 |
sal_Int32 nLen = aURL.getLength(); |
| 732 |
|
| 733 |
for ( const auto& rContent : aAllContents ) |
| 734 |
{ |
| 735 |
::ucbhelper::ContentImplHelperRef xChild = rContent; |
| 736 |
OUString aChildURL |
| 737 |
= xChild->getIdentifier()->getContentIdentifier(); |
| 738 |
|
| 739 |
// Is aURL a prefix of aChildURL? |
| 740 |
if ( ( aChildURL.getLength() > nLen ) && |
| 741 |
( aChildURL.startsWith( aURL ) ) ) |
| 742 |
{ |
| 743 |
sal_Int32 nPos = aChildURL.indexOf( '/', nLen ); |
| 744 |
|
| 745 |
if ( ( nPos == -1 ) || |
| 746 |
( nPos == ( aChildURL.getLength() - 1 ) ) ) |
| 747 |
{ |
| 748 |
// No further slashes/ only a final slash. It's a child! |
| 749 |
rChildren.emplace_back( |
| 750 |
static_cast< HierarchyContent * >( xChild.get() ) ); |
| 751 |
} |
| 752 |
} |
| 753 |
} |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
bool HierarchyContent::exchangeIdentity( |
| 758 |
const uno::Reference< ucb::XContentIdentifier >& xNewId ) |
| 759 |
{ |
| 760 |
if ( !xNewId.is() ) |
| 761 |
return false; |
| 762 |
|
| 763 |
osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); |
| 764 |
|
| 765 |
uno::Reference< ucb::XContent > xThis = this; |
| 766 |
|
| 767 |
// Already persistent? |
| 768 |
if ( m_eState != PERSISTENT ) |
| 769 |
{ |
| 770 |
OSL_FAIL( "HierarchyContent::exchangeIdentity - Not persistent!" ); |
| 771 |
return false; |
| 772 |
} |
| 773 |
|
| 774 |
// Am I the root folder? |
| 775 |
if ( m_eKind == ROOT ) |
| 776 |
{ |
| 777 |
OSL_FAIL( "HierarchyContent::exchangeIdentity - " |
| 778 |
"Not supported by root folder!" ); |
| 779 |
return false; |
| 780 |
} |
| 781 |
|
| 782 |
// Exchange own identity. |
| 783 |
|
| 784 |
// Fail, if a content with given id already exists. |
| 785 |
if ( !hasData( xNewId ) ) |
| 786 |
{ |
| 787 |
OUString aOldURL = m_xIdentifier->getContentIdentifier(); |
| 788 |
|
| 789 |
aGuard.clear(); |
| 790 |
if ( exchange( xNewId ) ) |
| 791 |
{ |
| 792 |
if ( m_eKind == FOLDER ) |
| 793 |
{ |
| 794 |
// Process instantiated children... |
| 795 |
|
| 796 |
HierarchyContentRefVector aChildren; |
| 797 |
queryChildren( aChildren ); |
| 798 |
|
| 799 |
for ( const auto& rChild : aChildren ) |
| 800 |
{ |
| 801 |
HierarchyContentRef xChild = rChild; |
| 802 |
|
| 803 |
// Create new content identifier for the child... |
| 804 |
uno::Reference< ucb::XContentIdentifier > xOldChildId |
| 805 |
= xChild->getIdentifier(); |
| 806 |
OUString aOldChildURL |
| 807 |
= xOldChildId->getContentIdentifier(); |
| 808 |
OUString aNewChildURL |
| 809 |
= aOldChildURL.replaceAt( |
| 810 |
0, |
| 811 |
aOldURL.getLength(), |
| 812 |
xNewId->getContentIdentifier() ); |
| 813 |
uno::Reference< ucb::XContentIdentifier > xNewChildId |
| 814 |
= new ::ucbhelper::ContentIdentifier( aNewChildURL ); |
| 815 |
|
| 816 |
if ( !xChild->exchangeIdentity( xNewChildId ) ) |
| 817 |
return false; |
| 818 |
} |
| 819 |
} |
| 820 |
return true; |
| 821 |
} |
| 822 |
} |
| 823 |
|
| 824 |
OSL_FAIL( "HierarchyContent::exchangeIdentity - " |
| 825 |
"Panic! Cannot exchange identity!" ); |
| 826 |
return false; |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
// static |
| 831 |
uno::Reference< sdbc::XRow > HierarchyContent::getPropertyValues( |
| 832 |
const uno::Reference< uno::XComponentContext >& rxContext, |
| 833 |
const uno::Sequence< beans::Property >& rProperties, |
| 834 |
const HierarchyContentProperties& rData, |
| 835 |
HierarchyContentProvider* pProvider, |
| 836 |
const OUString& rContentId ) |
| 837 |
{ |
| 838 |
// Note: Empty sequence means "get values of all supported properties". |
| 839 |
|
| 840 |
rtl::Reference< ::ucbhelper::PropertyValueSet > xRow |
| 841 |
= new ::ucbhelper::PropertyValueSet( rxContext ); |
| 842 |
|
| 843 |
if ( rProperties.hasElements() ) |
| 844 |
{ |
| 845 |
uno::Reference< beans::XPropertySet > xAdditionalPropSet; |
| 846 |
bool bTriedToGetAdditionalPropSet = false; |
| 847 |
|
| 848 |
for ( const beans::Property& rProp : rProperties ) |
| 849 |
{ |
| 850 |
// Process Core properties. |
| 851 |
|
| 852 |
if ( rProp.Name == "ContentType" ) |
| 853 |
{ |
| 854 |
xRow->appendString ( rProp, rData.getContentType() ); |
| 855 |
} |
| 856 |
else if ( rProp.Name == "Title" ) |
| 857 |
{ |
| 858 |
xRow->appendString ( rProp, rData.getTitle() ); |
| 859 |
} |
| 860 |
else if ( rProp.Name == "IsDocument" ) |
| 861 |
{ |
| 862 |
xRow->appendBoolean( rProp, rData.getIsDocument() ); |
| 863 |
} |
| 864 |
else if ( rProp.Name == "IsFolder" ) |
| 865 |
{ |
| 866 |
xRow->appendBoolean( rProp, rData.getIsFolder() ); |
| 867 |
} |
| 868 |
else if ( rProp.Name == "CreatableContentsInfo" ) |
| 869 |
{ |
| 870 |
xRow->appendObject( |
| 871 |
rProp, uno::Any( rData.getCreatableContentsInfo() ) ); |
| 872 |
} |
| 873 |
else if ( rProp.Name == "TargetURL" ) |
| 874 |
{ |
| 875 |
// TargetURL is only supported by links. |
| 876 |
|
| 877 |
if ( rData.getIsDocument() ) |
| 878 |
xRow->appendString( rProp, rData.getTargetURL() ); |
| 879 |
else |
| 880 |
xRow->appendVoid( rProp ); |
| 881 |
} |
| 882 |
else |
| 883 |
{ |
| 884 |
// Not a Core Property! Maybe it's an Additional Core Property?! |
| 885 |
|
| 886 |
if ( !bTriedToGetAdditionalPropSet && !xAdditionalPropSet.is() ) |
| 887 |
{ |
| 888 |
xAdditionalPropSet = |
| 889 |
pProvider->getAdditionalPropertySet( rContentId, |
| 890 |
false ); |
| 891 |
bTriedToGetAdditionalPropSet = true; |
| 892 |
} |
| 893 |
|
| 894 |
if ( xAdditionalPropSet.is() ) |
| 895 |
{ |
| 896 |
if ( !xRow->appendPropertySetValue( |
| 897 |
xAdditionalPropSet, |
| 898 |
rProp ) ) |
| 899 |
{ |
| 900 |
// Append empty entry. |
| 901 |
xRow->appendVoid( rProp ); |
| 902 |
} |
| 903 |
} |
| 904 |
else |
| 905 |
{ |
| 906 |
// Append empty entry. |
| 907 |
xRow->appendVoid( rProp ); |
| 908 |
} |
| 909 |
} |
| 910 |
} |
| 911 |
} |
| 912 |
else |
| 913 |
{ |
| 914 |
// Append all Core Properties. |
| 915 |
xRow->appendString ( |
| 916 |
beans::Property( u"ContentType"_ustr, |
| 917 |
-1, |
| 918 |
cppu::UnoType<OUString>::get(), |
| 919 |
beans::PropertyAttribute::BOUND |
| 920 |
| beans::PropertyAttribute::READONLY ), |
| 921 |
rData.getContentType() ); |
| 922 |
xRow->appendString ( |
| 923 |
beans::Property( u"Title"_ustr, |
| 924 |
-1, |
| 925 |
cppu::UnoType<OUString>::get(), |
| 926 |
// @@@ Might actually be read-only! |
| 927 |
beans::PropertyAttribute::BOUND ), |
| 928 |
rData.getTitle() ); |
| 929 |
xRow->appendBoolean( |
| 930 |
beans::Property( u"IsDocument"_ustr, |
| 931 |
-1, |
| 932 |
cppu::UnoType<bool>::get(), |
| 933 |
beans::PropertyAttribute::BOUND |
| 934 |
| beans::PropertyAttribute::READONLY ), |
| 935 |
rData.getIsDocument() ); |
| 936 |
xRow->appendBoolean( |
| 937 |
beans::Property( u"IsFolder"_ustr, |
| 938 |
-1, |
| 939 |
cppu::UnoType<bool>::get(), |
| 940 |
beans::PropertyAttribute::BOUND |
| 941 |
| beans::PropertyAttribute::READONLY ), |
| 942 |
rData.getIsFolder() ); |
| 943 |
|
| 944 |
if ( rData.getIsDocument() ) |
| 945 |
xRow->appendString( |
| 946 |
beans::Property( u"TargetURL"_ustr, |
| 947 |
-1, |
| 948 |
cppu::UnoType<OUString>::get(), |
| 949 |
// @@@ Might actually be read-only! |
| 950 |
beans::PropertyAttribute::BOUND ), |
| 951 |
rData.getTargetURL() ); |
| 952 |
xRow->appendObject( |
| 953 |
beans::Property( |
| 954 |
u"CreatableContentsInfo"_ustr, |
| 955 |
-1, |
| 956 |
cppu::UnoType<uno::Sequence< ucb::ContentInfo >>::get(), |
| 957 |
beans::PropertyAttribute::BOUND |
| 958 |
| beans::PropertyAttribute::READONLY ), |
| 959 |
uno::Any( rData.getCreatableContentsInfo() ) ); |
| 960 |
|
| 961 |
// Append all Additional Core Properties. |
| 962 |
|
| 963 |
uno::Reference< beans::XPropertySet > xSet = |
| 964 |
pProvider->getAdditionalPropertySet( rContentId, false ); |
| 965 |
xRow->appendPropertySet( xSet ); |
| 966 |
} |
| 967 |
|
| 968 |
return xRow; |
| 969 |
} |
| 970 |
|
| 971 |
|
| 972 |
uno::Reference< sdbc::XRow > HierarchyContent::getPropertyValues( |
| 973 |
const uno::Sequence< beans::Property >& rProperties ) |
| 974 |
{ |
| 975 |
osl::Guard< osl::Mutex > aGuard( m_aMutex ); |
| 976 |
return getPropertyValues( m_xContext, |
| 977 |
rProperties, |
| 978 |
m_aProps, |
| 979 |
m_pProvider, |
| 980 |
m_xIdentifier->getContentIdentifier() ); |
| 981 |
} |
| 982 |
|
| 983 |
|
| 984 |
uno::Sequence< uno::Any > HierarchyContent::setPropertyValues( |
| 985 |
const uno::Sequence< beans::PropertyValue >& rValues, |
| 986 |
const uno::Reference< ucb::XCommandEnvironment > & xEnv ) |
| 987 |
{ |
| 988 |
osl::ResettableGuard< osl::Mutex > aGuard( m_aMutex ); |
| 989 |
|
| 990 |
uno::Sequence< uno::Any > aRet( rValues.getLength() ); |
| 991 |
auto aRetRange = asNonConstRange(aRet); |
| 992 |
uno::Sequence< beans::PropertyChangeEvent > aChanges( rValues.getLength() ); |
| 993 |
sal_Int32 nChanged = 0; |
| 994 |
|
| 995 |
beans::PropertyChangeEvent aEvent; |
| 996 |
aEvent.Source = getXWeak(); |
| 997 |
aEvent.Further = false; |
| 998 |
// aEvent.PropertyName = |
| 999 |
aEvent.PropertyHandle = -1; |
| 1000 |
// aEvent.OldValue = |
| 1001 |
// aEvent.NewValue = |
| 1002 |
|
| 1003 |
const beans::PropertyValue* pValues = rValues.getConstArray(); |
| 1004 |
sal_Int32 nCount = rValues.getLength(); |
| 1005 |
|
| 1006 |
uno::Reference< ucb::XPersistentPropertySet > xAdditionalPropSet; |
| 1007 |
bool bTriedToGetAdditionalPropSet = false; |
| 1008 |
|
| 1009 |
bool bExchange = false; |
| 1010 |
OUString aOldTitle; |
| 1011 |
OUString aOldName; |
| 1012 |
sal_Int32 nTitlePos = -1; |
| 1013 |
|
| 1014 |
for ( sal_Int32 n = 0; n < nCount; ++n ) |
| 1015 |
{ |
| 1016 |
const beans::PropertyValue& rValue = pValues[ n ]; |
| 1017 |
|
| 1018 |
if ( rValue.Name == "ContentType" ) |
| 1019 |
{ |
| 1020 |
// Read-only property! |
| 1021 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1022 |
u"Property is read-only!"_ustr, |
| 1023 |
getXWeak() ); |
| 1024 |
} |
| 1025 |
else if ( rValue.Name == "IsDocument" ) |
| 1026 |
{ |
| 1027 |
// Read-only property! |
| 1028 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1029 |
u"Property is read-only!"_ustr, |
| 1030 |
getXWeak() ); |
| 1031 |
} |
| 1032 |
else if ( rValue.Name == "IsFolder" ) |
| 1033 |
{ |
| 1034 |
// Read-only property! |
| 1035 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1036 |
u"Property is read-only!"_ustr, |
| 1037 |
getXWeak() ); |
| 1038 |
} |
| 1039 |
else if ( rValue.Name == "CreatableContentsInfo" ) |
| 1040 |
{ |
| 1041 |
// Read-only property! |
| 1042 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1043 |
u"Property is read-only!"_ustr, |
| 1044 |
getXWeak() ); |
| 1045 |
} |
| 1046 |
else if ( rValue.Name == "Title" ) |
| 1047 |
{ |
| 1048 |
if ( isReadOnly() ) |
| 1049 |
{ |
| 1050 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1051 |
u"Property is read-only!"_ustr, |
| 1052 |
getXWeak() ); |
| 1053 |
} |
| 1054 |
else |
| 1055 |
{ |
| 1056 |
OUString aNewValue; |
| 1057 |
if ( rValue.Value >>= aNewValue ) |
| 1058 |
{ |
| 1059 |
// No empty titles! |
| 1060 |
if ( !aNewValue.isEmpty() ) |
| 1061 |
{ |
| 1062 |
if ( aNewValue != m_aProps.getTitle() ) |
| 1063 |
{ |
| 1064 |
// modified title -> modified URL -> exchange ! |
| 1065 |
if ( m_eState == PERSISTENT ) |
| 1066 |
bExchange = true; |
| 1067 |
|
| 1068 |
aOldTitle = m_aProps.getTitle(); |
| 1069 |
aOldName = m_aProps.getName(); |
| 1070 |
|
| 1071 |
m_aProps.setTitle( aNewValue ); |
| 1072 |
m_aProps.setName( |
| 1073 |
::ucb_impl::urihelper::encodeSegment( |
| 1074 |
aNewValue ) ); |
| 1075 |
|
| 1076 |
// property change event will be set later... |
| 1077 |
|
| 1078 |
// remember position within sequence of values |
| 1079 |
// (for error handling). |
| 1080 |
nTitlePos = n; |
| 1081 |
} |
| 1082 |
} |
| 1083 |
else |
| 1084 |
{ |
| 1085 |
aRetRange[ n ] <<= lang::IllegalArgumentException( |
| 1086 |
u"Empty title not allowed!"_ustr, |
| 1087 |
getXWeak(), |
| 1088 |
-1 ); |
| 1089 |
} |
| 1090 |
} |
| 1091 |
else |
| 1092 |
{ |
| 1093 |
aRetRange[ n ] <<= beans::IllegalTypeException( |
| 1094 |
u"Property value has wrong type!"_ustr, |
| 1095 |
getXWeak() ); |
| 1096 |
} |
| 1097 |
} |
| 1098 |
} |
| 1099 |
else if ( rValue.Name == "TargetURL" ) |
| 1100 |
{ |
| 1101 |
if ( isReadOnly() ) |
| 1102 |
{ |
| 1103 |
aRetRange[ n ] <<= lang::IllegalAccessException( |
| 1104 |
u"Property is read-only!"_ustr, |
| 1105 |
getXWeak() ); |
| 1106 |
} |
| 1107 |
else |
| 1108 |
{ |
| 1109 |
// TargetURL is only supported by links. |
| 1110 |
|
| 1111 |
if ( m_eKind == LINK ) |
| 1112 |
{ |
| 1113 |
OUString aNewValue; |
| 1114 |
if ( rValue.Value >>= aNewValue ) |
| 1115 |
{ |
| 1116 |
// No empty target URL's! |
| 1117 |
if ( !aNewValue.isEmpty() ) |
| 1118 |
{ |
| 1119 |
if ( aNewValue != m_aProps.getTargetURL() ) |
| 1120 |
{ |
| 1121 |
aEvent.PropertyName = rValue.Name; |
| 1122 |
aEvent.OldValue <<= m_aProps.getTargetURL(); |
| 1123 |
aEvent.NewValue <<= aNewValue; |
| 1124 |
|
| 1125 |
aChanges.getArray()[ nChanged ] = aEvent; |
| 1126 |
|
| 1127 |
m_aProps.setTargetURL( aNewValue ); |
| 1128 |
nChanged++; |
| 1129 |
} |
| 1130 |
} |
| 1131 |
else |
| 1132 |
{ |
| 1133 |
aRetRange[ n ] <<= lang::IllegalArgumentException( |
| 1134 |
u"Empty target URL not allowed!"_ustr, |
| 1135 |
getXWeak(), |
| 1136 |
-1 ); |
| 1137 |
} |
| 1138 |
} |
| 1139 |
else |
| 1140 |
{ |
| 1141 |
aRetRange[ n ] <<= beans::IllegalTypeException( |
| 1142 |
u"Property value has wrong type!"_ustr, |
| 1143 |
getXWeak() ); |
| 1144 |
} |
| 1145 |
} |
| 1146 |
else |
| 1147 |
{ |
| 1148 |
aRetRange[ n ] <<= beans::UnknownPropertyException( |
| 1149 |
u"TargetURL only supported by links!"_ustr, |
| 1150 |
getXWeak() ); |
| 1151 |
} |
| 1152 |
} |
| 1153 |
} |
| 1154 |
else |
| 1155 |
{ |
| 1156 |
// Not a Core Property! Maybe it's an Additional Core Property?! |
| 1157 |
|
| 1158 |
if ( !bTriedToGetAdditionalPropSet && !xAdditionalPropSet.is() ) |
| 1159 |
{ |
| 1160 |
xAdditionalPropSet = getAdditionalPropertySet( false ); |
| 1161 |
bTriedToGetAdditionalPropSet = true; |
| 1162 |
} |
| 1163 |
|
| 1164 |
if ( xAdditionalPropSet.is() ) |
| 1165 |
{ |
| 1166 |
try |
| 1167 |
{ |
| 1168 |
uno::Any aOldValue = xAdditionalPropSet->getPropertyValue( |
| 1169 |
rValue.Name ); |
| 1170 |
if ( aOldValue != rValue.Value ) |
| 1171 |
{ |
| 1172 |
xAdditionalPropSet->setPropertyValue( |
| 1173 |
rValue.Name, rValue.Value ); |
| 1174 |
|
| 1175 |
aEvent.PropertyName = rValue.Name; |
| 1176 |
aEvent.OldValue = std::move(aOldValue); |
| 1177 |
aEvent.NewValue = rValue.Value; |
| 1178 |
|
| 1179 |
aChanges.getArray()[ nChanged ] = aEvent; |
| 1180 |
nChanged++; |
| 1181 |
} |
| 1182 |
} |
| 1183 |
catch ( beans::UnknownPropertyException const & e ) |
| 1184 |
{ |
| 1185 |
aRetRange[ n ] <<= e; |
| 1186 |
} |
| 1187 |
catch ( lang::WrappedTargetException const & e ) |
| 1188 |
{ |
| 1189 |
aRetRange[ n ] <<= e; |
| 1190 |
} |
| 1191 |
catch ( beans::PropertyVetoException const & e ) |
| 1192 |
{ |
| 1193 |
aRetRange[ n ] <<= e; |
| 1194 |
} |
| 1195 |
catch ( lang::IllegalArgumentException const & e ) |
| 1196 |
{ |
| 1197 |
aRetRange[ n ] <<= e; |
| 1198 |
} |
| 1199 |
} |
| 1200 |
else |
| 1201 |
{ |
| 1202 |
aRetRange[ n ] <<= uno::Exception( |
| 1203 |
u"No property set for storing the value!"_ustr, |
| 1204 |
getXWeak() ); |
| 1205 |
} |
| 1206 |
} |
| 1207 |
} |
| 1208 |
|
| 1209 |
if ( bExchange ) |
| 1210 |
{ |
| 1211 |
uno::Reference< ucb::XContentIdentifier > xOldId |
| 1212 |
= m_xIdentifier; |
| 1213 |
uno::Reference< ucb::XContentIdentifier > xNewId |
| 1214 |
= makeNewIdentifier( m_aProps.getTitle() ); |
| 1215 |
|
| 1216 |
aGuard.clear(); |
| 1217 |
if ( exchangeIdentity( xNewId ) ) |
| 1218 |
{ |
| 1219 |
// Adapt persistent data. |
| 1220 |
renameData( xOldId, xNewId ); |
| 1221 |
|
| 1222 |
// Adapt Additional Core Properties. |
| 1223 |
renameAdditionalPropertySet( xOldId->getContentIdentifier(), |
| 1224 |
xNewId->getContentIdentifier() ); |
| 1225 |
} |
| 1226 |
else |
| 1227 |
{ |
| 1228 |
// Roll-back. |
| 1229 |
m_aProps.setTitle( aOldTitle ); |
| 1230 |
m_aProps.setName ( aOldName ); |
| 1231 |
|
| 1232 |
aOldTitle.clear(); |
| 1233 |
aOldName.clear(); |
| 1234 |
|
| 1235 |
// Set error . |
| 1236 |
aRetRange[ nTitlePos ] <<= uno::Exception( |
| 1237 |
u"Exchange failed!"_ustr, |
| 1238 |
getXWeak() ); |
| 1239 |
} |
| 1240 |
aGuard.reset(); |
| 1241 |
} |
| 1242 |
|
| 1243 |
if ( !aOldTitle.isEmpty() ) |
| 1244 |
{ |
| 1245 |
aEvent.PropertyName = "Title"; |
| 1246 |
aEvent.OldValue <<= aOldTitle; |
| 1247 |
aEvent.NewValue <<= m_aProps.getTitle(); |
| 1248 |
|
| 1249 |
aChanges.getArray()[ nChanged ] = std::move(aEvent); |
| 1250 |
nChanged++; |
| 1251 |
} |
| 1252 |
|
| 1253 |
if ( nChanged > 0 ) |
| 1254 |
{ |
| 1255 |
// Save changes, if content was already made persistent. |
| 1256 |
if ( !bExchange && ( m_eState == PERSISTENT ) ) |
| 1257 |
{ |
| 1258 |
if ( !storeData() ) |
| 1259 |
{ |
| 1260 |
uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence( |
| 1261 |
{ |
| 1262 |
{"Uri", uno::Any(m_xIdentifier->getContentIdentifier())} |
| 1263 |
})); |
| 1264 |
ucbhelper::cancelCommandExecution( |
| 1265 |
ucb::IOErrorCode_CANT_WRITE, |
| 1266 |
aArgs, |
| 1267 |
xEnv, |
| 1268 |
u"Cannot store persistent data!"_ustr, |
| 1269 |
this ); |
| 1270 |
// Unreachable |
| 1271 |
} |
| 1272 |
} |
| 1273 |
|
| 1274 |
aChanges.realloc( nChanged ); |
| 1275 |
|
| 1276 |
aGuard.clear(); |
| 1277 |
notifyPropertiesChange( aChanges ); |
| 1278 |
} |
| 1279 |
|
| 1280 |
return aRet; |
| 1281 |
} |
| 1282 |
|
| 1283 |
|
| 1284 |
void HierarchyContent::insert( sal_Int32 nNameClashResolve, |
| 1285 |
const uno::Reference< |
| 1286 |
ucb::XCommandEnvironment > & xEnv ) |
| 1287 |
{ |
| 1288 |
osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); |
| 1289 |
|
| 1290 |
// Am I the root folder? |
| 1291 |
if ( m_eKind == ROOT ) |
| 1292 |
{ |
| 1293 |
ucbhelper::cancelCommandExecution( |
| 1294 |
uno::Any( ucb::UnsupportedCommandException( |
| 1295 |
u"Not supported by root folder!"_ustr, |
| 1296 |
getXWeak() ) ), |
| 1297 |
xEnv ); |
| 1298 |
// Unreachable |
| 1299 |
} |
| 1300 |
|
| 1301 |
// Check, if all required properties were set. |
| 1302 |
if ( m_aProps.getTitle().isEmpty() ) |
| 1303 |
{ |
| 1304 |
uno::Sequence<OUString> aProps { u"Title"_ustr }; |
| 1305 |
ucbhelper::cancelCommandExecution( |
| 1306 |
uno::Any( ucb::MissingPropertiesException( |
| 1307 |
OUString(), |
| 1308 |
getXWeak(), |
| 1309 |
aProps ) ), |
| 1310 |
xEnv ); |
| 1311 |
// Unreachable |
| 1312 |
} |
| 1313 |
|
| 1314 |
// Assemble new content identifier... |
| 1315 |
|
| 1316 |
uno::Reference< ucb::XContentIdentifier > xId |
| 1317 |
= makeNewIdentifier( m_aProps.getTitle() ); |
| 1318 |
|
| 1319 |
// Handle possible name clash... |
| 1320 |
|
| 1321 |
switch ( nNameClashResolve ) |
| 1322 |
{ |
| 1323 |
// fail. |
| 1324 |
case ucb::NameClash::ERROR: |
| 1325 |
if ( hasData( xId ) ) |
| 1326 |
{ |
| 1327 |
ucbhelper::cancelCommandExecution( |
| 1328 |
uno::Any( |
| 1329 |
ucb::NameClashException( |
| 1330 |
OUString(), |
| 1331 |
getXWeak(), |
| 1332 |
task::InteractionClassification_ERROR, |
| 1333 |
m_aProps.getTitle() ) ), |
| 1334 |
xEnv ); |
| 1335 |
// Unreachable |
| 1336 |
} |
| 1337 |
break; |
| 1338 |
|
| 1339 |
// replace existing object. |
| 1340 |
case ucb::NameClash::OVERWRITE: |
| 1341 |
break; |
| 1342 |
|
| 1343 |
// "invent" a new valid title. |
| 1344 |
case ucb::NameClash::RENAME: |
| 1345 |
if ( hasData( xId ) ) |
| 1346 |
{ |
| 1347 |
sal_Int32 nTry = 0; |
| 1348 |
|
| 1349 |
do |
| 1350 |
{ |
| 1351 |
OUString aNewId = xId->getContentIdentifier() + "_" + OUString::number( ++nTry ); |
| 1352 |
xId = new ::ucbhelper::ContentIdentifier( aNewId ); |
| 1353 |
} |
| 1354 |
while ( hasData( xId ) && ( nTry < 1000 ) ); |
| 1355 |
|
| 1356 |
if ( nTry == 1000 ) |
| 1357 |
{ |
| 1358 |
ucbhelper::cancelCommandExecution( |
| 1359 |
uno::Any( |
| 1360 |
ucb::UnsupportedNameClashException( |
| 1361 |
u"Unable to resolve name clash!"_ustr, |
| 1362 |
getXWeak(), |
| 1363 |
nNameClashResolve ) ), |
| 1364 |
xEnv ); |
| 1365 |
// Unreachable |
| 1366 |
} |
| 1367 |
else |
| 1368 |
{ |
| 1369 |
OUString aNewTitle( m_aProps.getTitle() + "_" + OUString::number( nTry ) ); |
| 1370 |
m_aProps.setTitle( aNewTitle ); |
| 1371 |
} |
| 1372 |
} |
| 1373 |
break; |
| 1374 |
|
| 1375 |
case ucb::NameClash::KEEP: // deprecated |
| 1376 |
case ucb::NameClash::ASK: |
| 1377 |
default: |
| 1378 |
if ( hasData( xId ) ) |
| 1379 |
{ |
| 1380 |
ucbhelper::cancelCommandExecution( |
| 1381 |
uno::Any( |
| 1382 |
ucb::UnsupportedNameClashException( |
| 1383 |
OUString(), |
| 1384 |
getXWeak(), |
| 1385 |
nNameClashResolve ) ), |
| 1386 |
xEnv ); |
| 1387 |
// Unreachable |
| 1388 |
} |
| 1389 |
break; |
| 1390 |
} |
| 1391 |
|
| 1392 |
// Identifier changed? |
| 1393 |
bool bNewId = ( xId->getContentIdentifier() |
| 1394 |
!= m_xIdentifier->getContentIdentifier() ); |
| 1395 |
m_xIdentifier = std::move(xId); |
| 1396 |
|
| 1397 |
if ( !storeData() ) |
| 1398 |
{ |
| 1399 |
uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence( |
| 1400 |
{ |
| 1401 |
{"Uri", uno::Any(m_xIdentifier->getContentIdentifier())} |
| 1402 |
})); |
| 1403 |
ucbhelper::cancelCommandExecution( |
| 1404 |
ucb::IOErrorCode_CANT_WRITE, |
| 1405 |
aArgs, |
| 1406 |
xEnv, |
| 1407 |
u"Cannot store persistent data!"_ustr, |
| 1408 |
this ); |
| 1409 |
// Unreachable |
| 1410 |
} |
| 1411 |
|
| 1412 |
m_eState = PERSISTENT; |
| 1413 |
|
| 1414 |
if ( bNewId ) |
| 1415 |
{ |
| 1416 |
aGuard.clear(); |
| 1417 |
inserted(); |
| 1418 |
} |
| 1419 |
} |
| 1420 |
|
| 1421 |
|
| 1422 |
void HierarchyContent::destroy( bool bDeletePhysical, |
| 1423 |
const uno::Reference< |
| 1424 |
ucb::XCommandEnvironment > & xEnv ) |
| 1425 |
{ |
| 1426 |
// @@@ take care about bDeletePhysical -> trashcan support |
| 1427 |
|
| 1428 |
osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); |
| 1429 |
|
| 1430 |
uno::Reference< ucb::XContent > xThis = this; |
| 1431 |
|
| 1432 |
// Persistent? |
| 1433 |
if ( m_eState != PERSISTENT ) |
| 1434 |
{ |
| 1435 |
ucbhelper::cancelCommandExecution( |
| 1436 |
uno::Any( ucb::UnsupportedCommandException( |
| 1437 |
u"Not persistent!"_ustr, |
| 1438 |
getXWeak() ) ), |
| 1439 |
xEnv ); |
| 1440 |
// Unreachable |
| 1441 |
} |
| 1442 |
|
| 1443 |
// Am I the root folder? |
| 1444 |
if ( m_eKind == ROOT ) |
| 1445 |
{ |
| 1446 |
ucbhelper::cancelCommandExecution( |
| 1447 |
uno::Any( ucb::UnsupportedCommandException( |
| 1448 |
u"Not supported by root folder!"_ustr, |
| 1449 |
getXWeak() ) ), |
| 1450 |
xEnv ); |
| 1451 |
// Unreachable |
| 1452 |
} |
| 1453 |
|
| 1454 |
m_eState = DEAD; |
| 1455 |
|
| 1456 |
aGuard.clear(); |
| 1457 |
deleted(); |
| 1458 |
|
| 1459 |
if ( m_eKind == FOLDER ) |
| 1460 |
{ |
| 1461 |
// Process instantiated children... |
| 1462 |
|
| 1463 |
HierarchyContentRefVector aChildren; |
| 1464 |
queryChildren( aChildren ); |
| 1465 |
|
| 1466 |
for ( auto & child : aChildren) |
| 1467 |
{ |
| 1468 |
child->destroy( bDeletePhysical, xEnv ); |
| 1469 |
} |
| 1470 |
} |
| 1471 |
} |
| 1472 |
|
| 1473 |
|
| 1474 |
void HierarchyContent::transfer( |
| 1475 |
const ucb::TransferInfo& rInfo, |
| 1476 |
const uno::Reference< ucb::XCommandEnvironment > & xEnv ) |
| 1477 |
{ |
| 1478 |
osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); |
| 1479 |
|
| 1480 |
// Persistent? |
| 1481 |
if ( m_eState != PERSISTENT ) |
| 1482 |
{ |
| 1483 |
ucbhelper::cancelCommandExecution( |
| 1484 |
uno::Any( ucb::UnsupportedCommandException( |
| 1485 |
u"Not persistent!"_ustr, |
| 1486 |
getXWeak() ) ), |
| 1487 |
xEnv ); |
| 1488 |
// Unreachable |
| 1489 |
} |
| 1490 |
|
| 1491 |
// Is source a hierarchy content? |
| 1492 |
if ( !rInfo.SourceURL.startsWith( HIERARCHY_URL_SCHEME ":/" ) ) |
| 1493 |
{ |
| 1494 |
ucbhelper::cancelCommandExecution( |
| 1495 |
uno::Any( ucb::InteractiveBadTransferURLException( |
| 1496 |
OUString(), |
| 1497 |
getXWeak() ) ), |
| 1498 |
xEnv ); |
| 1499 |
// Unreachable |
| 1500 |
} |
| 1501 |
|
| 1502 |
// Is source not a parent of me / not me? |
| 1503 |
OUString aId = m_xIdentifier->getContentIdentifier(); |
| 1504 |
sal_Int32 nPos = aId.lastIndexOf( '/' ); |
| 1505 |
if ( nPos != ( aId.getLength() - 1 ) ) |
| 1506 |
{ |
| 1507 |
// No trailing slash found. Append. |
| 1508 |
aId += "/"; |
| 1509 |
} |
| 1510 |
|
| 1511 |
if ( rInfo.SourceURL.getLength() <= aId.getLength() ) |
| 1512 |
{ |
| 1513 |
if ( aId.startsWith( rInfo.SourceURL ) ) |
| 1514 |
{ |
| 1515 |
uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence( |
| 1516 |
{ |
| 1517 |
{"Uri", uno::Any(rInfo.SourceURL)} |
| 1518 |
})); |
| 1519 |
ucbhelper::cancelCommandExecution( |
| 1520 |
ucb::IOErrorCode_RECURSIVE, |
| 1521 |
aArgs, |
| 1522 |
xEnv, |
| 1523 |
u"Target is equal to or is a child of source!"_ustr, |
| 1524 |
this ); |
| 1525 |
// Unreachable |
| 1526 |
} |
| 1527 |
} |
| 1528 |
|
| 1529 |
|
| 1530 |
// 0) Obtain content object for source. |
| 1531 |
|
| 1532 |
|
| 1533 |
uno::Reference< ucb::XContentIdentifier > xId |
| 1534 |
= new ::ucbhelper::ContentIdentifier( rInfo.SourceURL ); |
| 1535 |
|
| 1536 |
// Note: The static cast is okay here, because its sure that |
| 1537 |
// m_xProvider is always the HierarchyContentProvider. |
| 1538 |
rtl::Reference< HierarchyContent > xSource; |
| 1539 |
|
| 1540 |
try |
| 1541 |
{ |
| 1542 |
xSource = static_cast< HierarchyContent * >( |
| 1543 |
m_xProvider->queryContent( xId ).get() ); |
| 1544 |
} |
| 1545 |
catch ( ucb::IllegalIdentifierException const & ) |
| 1546 |
{ |
| 1547 |
// queryContent |
| 1548 |
} |
| 1549 |
|
| 1550 |
if ( !xSource.is() ) |
| 1551 |
{ |
| 1552 |
uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence( |
| 1553 |
{ |
| 1554 |
{"Uri", uno::Any(xId->getContentIdentifier())} |
| 1555 |
})); |
| 1556 |
ucbhelper::cancelCommandExecution( |
| 1557 |
ucb::IOErrorCode_CANT_READ, |
| 1558 |
aArgs, |
| 1559 |
xEnv, |
| 1560 |
u"Cannot instantiate source object!"_ustr, |
| 1561 |
this ); |
| 1562 |
// Unreachable |
| 1563 |
} |
| 1564 |
|
| 1565 |
|
| 1566 |
// 1) Create new child content. |
| 1567 |
|
| 1568 |
|
| 1569 |
ucb::ContentInfo aContentInfo; |
| 1570 |
aContentInfo.Type = xSource->isFolder() |
| 1571 |
? HIERARCHY_FOLDER_CONTENT_TYPE |
| 1572 |
: HIERARCHY_LINK_CONTENT_TYPE; |
| 1573 |
aContentInfo.Attributes = 0; |
| 1574 |
|
| 1575 |
// Note: The static cast is okay here, because its sure that |
| 1576 |
// createNewContent always creates a HierarchyContent. |
| 1577 |
rtl::Reference< HierarchyContent > xTarget |
| 1578 |
= static_cast< HierarchyContent * >( |
| 1579 |
createNewContent( aContentInfo ).get() ); |
| 1580 |
if ( !xTarget.is() ) |
| 1581 |
{ |
| 1582 |
uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence( |
| 1583 |
{ |
| 1584 |
{"Folder", uno::Any(aId)} |
| 1585 |
})); |
| 1586 |
ucbhelper::cancelCommandExecution( |
| 1587 |
ucb::IOErrorCode_CANT_CREATE, |
| 1588 |
aArgs, |
| 1589 |
xEnv, |
| 1590 |
u"XContentCreator::createNewContent failed!"_ustr, |
| 1591 |
this ); |
| 1592 |
// Unreachable |
| 1593 |
} |
| 1594 |
|
| 1595 |
|
| 1596 |
// 2) Copy data from source content to child content. |
| 1597 |
|
| 1598 |
|
| 1599 |
uno::Sequence< beans::Property > aSourceProps |
| 1600 |
= xSource->getPropertySetInfo( xEnv )->getProperties(); |
| 1601 |
sal_Int32 nCount = aSourceProps.getLength(); |
| 1602 |
|
| 1603 |
if ( nCount ) |
| 1604 |
{ |
| 1605 |
bool bHadTitle = rInfo.NewTitle.isEmpty(); |
| 1606 |
|
| 1607 |
// Get all source values. |
| 1608 |
uno::Reference< sdbc::XRow > xRow |
| 1609 |
= xSource->getPropertyValues( aSourceProps ); |
| 1610 |
|
| 1611 |
uno::Sequence< beans::PropertyValue > aValues( nCount ); |
| 1612 |
beans::PropertyValue* pValues = aValues.getArray(); |
| 1613 |
|
| 1614 |
const beans::Property* pProps = aSourceProps.getConstArray(); |
| 1615 |
for ( sal_Int32 n = 0; n < nCount; ++n ) |
| 1616 |
{ |
| 1617 |
const beans::Property& rProp = pProps[ n ]; |
| 1618 |
beans::PropertyValue& rValue = pValues[ n ]; |
| 1619 |
|
| 1620 |
rValue.Name = rProp.Name; |
| 1621 |
rValue.Handle = rProp.Handle; |
| 1622 |
|
| 1623 |
if ( !bHadTitle && rProp.Name == "Title" ) |
| 1624 |
{ |
| 1625 |
// Set new title instead of original. |
| 1626 |
bHadTitle = true; |
| 1627 |
rValue.Value <<= rInfo.NewTitle; |
| 1628 |
} |
| 1629 |
else |
| 1630 |
rValue.Value = xRow->getObject( |
| 1631 |
n + 1, |
| 1632 |
uno::Reference< container::XNameAccess >() ); |
| 1633 |
|
| 1634 |
rValue.State = beans::PropertyState_DIRECT_VALUE; |
| 1635 |
|
| 1636 |
if ( rProp.Attributes & beans::PropertyAttribute::REMOVABLE ) |
| 1637 |
{ |
| 1638 |
// Add Additional Core Property. |
| 1639 |
try |
| 1640 |
{ |
| 1641 |
xTarget->addProperty( rProp.Name, |
| 1642 |
rProp.Attributes, |
| 1643 |
rValue.Value ); |
| 1644 |
} |
| 1645 |
catch ( beans::PropertyExistException const & ) |
| 1646 |
{ |
| 1647 |
} |
| 1648 |
catch ( beans::IllegalTypeException const & ) |
| 1649 |
{ |
| 1650 |
} |
| 1651 |
catch ( lang::IllegalArgumentException const & ) |
| 1652 |
{ |
| 1653 |
} |
| 1654 |
} |
| 1655 |
} |
| 1656 |
|
| 1657 |
// Set target values. |
| 1658 |
xTarget->setPropertyValues( aValues, xEnv ); |
| 1659 |
} |
| 1660 |
|
| 1661 |
|
| 1662 |
// 3) Commit (insert) child. |
| 1663 |
|
| 1664 |
|
| 1665 |
xTarget->insert( rInfo.NameClash, xEnv ); |
| 1666 |
|
| 1667 |
|
| 1668 |
// 4) Transfer (copy) children of source. |
| 1669 |
|
| 1670 |
|
| 1671 |
if ( xSource->isFolder() ) |
| 1672 |
{ |
| 1673 |
HierarchyEntry aFolder( |
| 1674 |
m_xContext, m_pProvider, xId->getContentIdentifier() ); |
| 1675 |
HierarchyEntry::iterator it; |
| 1676 |
|
| 1677 |
while ( aFolder.next( it ) ) |
| 1678 |
{ |
| 1679 |
const HierarchyEntryData& rResult = *it; |
| 1680 |
|
| 1681 |
OUString aChildId = xId->getContentIdentifier(); |
| 1682 |
if ( ( aChildId.lastIndexOf( '/' ) + 1 ) != aChildId.getLength() ) |
| 1683 |
aChildId += "/"; |
| 1684 |
|
| 1685 |
aChildId += rResult.getName(); |
| 1686 |
|
| 1687 |
ucb::TransferInfo aInfo; |
| 1688 |
aInfo.MoveData = false; |
| 1689 |
aInfo.NewTitle.clear(); |
| 1690 |
aInfo.SourceURL = aChildId; |
| 1691 |
aInfo.NameClash = rInfo.NameClash; |
| 1692 |
|
| 1693 |
// Transfer child to target. |
| 1694 |
xTarget->transfer( aInfo, xEnv ); |
| 1695 |
} |
| 1696 |
} |
| 1697 |
|
| 1698 |
|
| 1699 |
// 5) Destroy source ( when moving only ) . |
| 1700 |
|
| 1701 |
|
| 1702 |
if ( !rInfo.MoveData ) |
| 1703 |
return; |
| 1704 |
|
| 1705 |
xSource->destroy( true, xEnv ); |
| 1706 |
|
| 1707 |
// Remove all persistent data of source and its children. |
| 1708 |
if ( !xSource->removeData() ) |
| 1709 |
{ |
| 1710 |
uno::Sequence<uno::Any> aArgs(comphelper::InitAnyPropertySequence( |
| 1711 |
{ |
| 1712 |
{"Uri", uno::Any(xSource->m_xIdentifier->getContentIdentifier())} |
| 1713 |
})); |
| 1714 |
ucbhelper::cancelCommandExecution( |
| 1715 |
ucb::IOErrorCode_CANT_WRITE, |
| 1716 |
aArgs, |
| 1717 |
xEnv, |
| 1718 |
u"Cannot remove persistent data of source object!"_ustr, |
| 1719 |
this ); |
| 1720 |
// Unreachable |
| 1721 |
} |
| 1722 |
|
| 1723 |
// Remove own and all children's Additional Core Properties. |
| 1724 |
xSource->removeAdditionalPropertySet(); |
| 1725 |
} |
| 1726 |
|
| 1727 |
|
| 1728 |
// HierarchyContentProperties Implementation. |
| 1729 |
|
| 1730 |
|
| 1731 |
uno::Sequence< ucb::ContentInfo > |
| 1732 |
HierarchyContentProperties::getCreatableContentsInfo() const |
| 1733 |
{ |
| 1734 |
if ( getIsFolder() ) |
| 1735 |
{ |
| 1736 |
uno::Sequence< ucb::ContentInfo > aSeq( 2 ); |
| 1737 |
|
| 1738 |
// Folder. |
| 1739 |
aSeq.getArray()[ 0 ].Type = HIERARCHY_FOLDER_CONTENT_TYPE; |
| 1740 |
aSeq.getArray()[ 0 ].Attributes = ucb::ContentInfoAttribute::KIND_FOLDER; |
| 1741 |
|
| 1742 |
uno::Sequence< beans::Property > aFolderProps( 1 ); |
| 1743 |
aFolderProps.getArray()[ 0 ] = beans::Property( |
| 1744 |
u"Title"_ustr, |
| 1745 |
-1, |
| 1746 |
cppu::UnoType<OUString>::get(), |
| 1747 |
beans::PropertyAttribute::BOUND ); |
| 1748 |
aSeq.getArray()[ 0 ].Properties = std::move(aFolderProps); |
| 1749 |
|
| 1750 |
// Link. |
| 1751 |
aSeq.getArray()[ 1 ].Type = HIERARCHY_LINK_CONTENT_TYPE; |
| 1752 |
aSeq.getArray()[ 1 ].Attributes = ucb::ContentInfoAttribute::KIND_LINK; |
| 1753 |
|
| 1754 |
uno::Sequence< beans::Property > aLinkProps( 2 ); |
| 1755 |
aLinkProps.getArray()[ 0 ] = beans::Property( |
| 1756 |
u"Title"_ustr, |
| 1757 |
-1, |
| 1758 |
cppu::UnoType<OUString>::get(), |
| 1759 |
beans::PropertyAttribute::BOUND ); |
| 1760 |
aLinkProps.getArray()[ 1 ] = beans::Property( |
| 1761 |
u"TargetURL"_ustr, |
| 1762 |
-1, |
| 1763 |
cppu::UnoType<OUString>::get(), |
| 1764 |
beans::PropertyAttribute::BOUND ); |
| 1765 |
aSeq.getArray()[ 1 ].Properties = std::move(aLinkProps); |
| 1766 |
|
| 1767 |
return aSeq; |
| 1768 |
} |
| 1769 |
else |
| 1770 |
{ |
| 1771 |
return uno::Sequence< ucb::ContentInfo >( 0 ); |
| 1772 |
} |
| 1773 |
} |
| 1774 |
|
| 1775 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |