1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_ucb.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir /************************************************************************** 32*cdf0e10cSrcweir TODO 33*cdf0e10cSrcweir ************************************************************************** 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir - HierarchyEntry::move 36*cdf0e10cSrcweir --> Rewrite to use XNamed ( once this is supported by config db api ). 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir *************************************************************************/ 39*cdf0e10cSrcweir #include "hierarchydata.hxx" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <vector> 42*cdf0e10cSrcweir #include <osl/diagnose.h> 43*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 44*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp> 49*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XOFFICEINSTALLTIONDIRECTORIES_HPP_ 50*cdf0e10cSrcweir #include <com/sun/star/util/XOfficeInstallationDirectories.hpp> 51*cdf0e10cSrcweir #endif 52*cdf0e10cSrcweir #include "hierarchyprovider.hxx" 53*cdf0e10cSrcweir #include "hierarchyuri.hxx" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir using namespace com::sun::star; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir namespace hierarchy_ucp 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //========================================================================= 61*cdf0e10cSrcweir struct HierarchyEntry::iterator_Impl 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir HierarchyEntryData entry; 64*cdf0e10cSrcweir uno::Reference< container::XHierarchicalNameAccess > dir; 65*cdf0e10cSrcweir uno::Reference< util::XOfficeInstallationDirectories > officeDirs; 66*cdf0e10cSrcweir uno::Sequence< rtl::OUString> names; 67*cdf0e10cSrcweir sal_Int32 pos; 68*cdf0e10cSrcweir iterator_Impl() 69*cdf0e10cSrcweir : officeDirs( 0 ), pos( -1 /* before first */ ) {}; 70*cdf0e10cSrcweir }; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir //========================================================================= 73*cdf0e10cSrcweir void makeXMLName( const rtl::OUString & rIn, rtl::OUStringBuffer & rBuffer ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir sal_Int32 nCount = rIn.getLength(); 76*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nCount; ++n ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir const sal_Unicode c = rIn.getStr()[ n ]; 79*cdf0e10cSrcweir switch ( c ) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir case '&': 82*cdf0e10cSrcweir rBuffer.appendAscii( "&" ); 83*cdf0e10cSrcweir break; 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir case '"': 86*cdf0e10cSrcweir rBuffer.appendAscii( """ ); 87*cdf0e10cSrcweir break; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir case '\'': 90*cdf0e10cSrcweir rBuffer.appendAscii( "'" ); 91*cdf0e10cSrcweir break; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir case '<': 94*cdf0e10cSrcweir rBuffer.appendAscii( "<" ); 95*cdf0e10cSrcweir break; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir case '>': 98*cdf0e10cSrcweir rBuffer.appendAscii( ">" ); 99*cdf0e10cSrcweir break; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir default: 102*cdf0e10cSrcweir rBuffer.append( c ); 103*cdf0e10cSrcweir break; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir //========================================================================= 109*cdf0e10cSrcweir //========================================================================= 110*cdf0e10cSrcweir // 111*cdf0e10cSrcweir // HierarchyEntry Implementation. 112*cdf0e10cSrcweir // 113*cdf0e10cSrcweir //========================================================================= 114*cdf0e10cSrcweir //========================================================================= 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir #define READ_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadAccess" 117*cdf0e10cSrcweir #define READWRITE_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadWriteAccess" 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir // describe path of cfg entry 120*cdf0e10cSrcweir #define CFGPROPERTY_NODEPATH "nodepath" 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //========================================================================= 123*cdf0e10cSrcweir HierarchyEntry::HierarchyEntry( 124*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& rSMgr, 125*cdf0e10cSrcweir HierarchyContentProvider* pProvider, 126*cdf0e10cSrcweir const rtl::OUString& rURL ) 127*cdf0e10cSrcweir : m_xSMgr( rSMgr ), 128*cdf0e10cSrcweir m_xOfficeInstDirs( pProvider->getOfficeInstallationDirectories() ), 129*cdf0e10cSrcweir m_bTriedToGetRootReadAccess( sal_False ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir HierarchyUri aUri( rURL ); 132*cdf0e10cSrcweir m_aServiceSpecifier = aUri.getService(); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir if ( pProvider ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir m_xConfigProvider 137*cdf0e10cSrcweir = pProvider->getConfigProvider( m_aServiceSpecifier ); 138*cdf0e10cSrcweir m_xRootReadAccess 139*cdf0e10cSrcweir = pProvider->getRootConfigReadNameAccess( m_aServiceSpecifier ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // Note: do not init m_aPath in init list. createPathFromHierarchyURL 143*cdf0e10cSrcweir // needs m_xSMgr and m_aMutex. 144*cdf0e10cSrcweir m_aPath = createPathFromHierarchyURL( aUri ); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // Extract language independent name from URL. 147*cdf0e10cSrcweir sal_Int32 nPos = rURL.lastIndexOf( '/' ); 148*cdf0e10cSrcweir if ( nPos > HIERARCHY_URL_SCHEME_LENGTH ) 149*cdf0e10cSrcweir m_aName = rURL.copy( nPos + 1 ); 150*cdf0e10cSrcweir else 151*cdf0e10cSrcweir OSL_ENSURE( sal_False, "HierarchyEntry - Invalid URL!" ); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir //========================================================================= 155*cdf0e10cSrcweir sal_Bool HierarchyEntry::hasData() 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 158*cdf0e10cSrcweir uno::Reference< container::XHierarchicalNameAccess > xRootReadAccess 159*cdf0e10cSrcweir = getRootReadAccess(); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir OSL_ENSURE( xRootReadAccess.is(), "HierarchyEntry::hasData - No root!" ); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir if ( xRootReadAccess.is() ) 164*cdf0e10cSrcweir return xRootReadAccess->hasByHierarchicalName( m_aPath ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir return sal_False; 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir //========================================================================= 170*cdf0e10cSrcweir sal_Bool HierarchyEntry::getData( HierarchyEntryData& rData ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir try 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir uno::Reference< container::XHierarchicalNameAccess > xRootReadAccess 177*cdf0e10cSrcweir = getRootReadAccess(); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir OSL_ENSURE( xRootReadAccess.is(), 180*cdf0e10cSrcweir "HierarchyEntry::getData - No root!" ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir if ( xRootReadAccess.is() ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir rtl::OUString aTitlePath = m_aPath; 185*cdf0e10cSrcweir aTitlePath += rtl::OUString::createFromAscii( "/Title" ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // Note: Avoid NoSuchElementExceptions, because exceptions are 188*cdf0e10cSrcweir // relatively 'expensive'. Checking for availability of 189*cdf0e10cSrcweir // title value is sufficient here, because if it is 190*cdf0e10cSrcweir // there, the other values will be available too. 191*cdf0e10cSrcweir if ( !xRootReadAccess->hasByHierarchicalName( aTitlePath ) ) 192*cdf0e10cSrcweir return sal_False; 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir rtl::OUString aValue; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // Get Title value. 197*cdf0e10cSrcweir if ( !( xRootReadAccess->getByHierarchicalName( aTitlePath ) 198*cdf0e10cSrcweir >>= aValue ) ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir OSL_ENSURE( sal_False, 201*cdf0e10cSrcweir "HierarchyEntry::getData - " 202*cdf0e10cSrcweir "Got no Title value!" ); 203*cdf0e10cSrcweir return sal_False; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir rData.setTitle( aValue ); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir // Get TargetURL value. 209*cdf0e10cSrcweir rtl::OUString aTargetURLPath = m_aPath; 210*cdf0e10cSrcweir aTargetURLPath += rtl::OUString::createFromAscii( "/TargetURL" ); 211*cdf0e10cSrcweir if ( !( xRootReadAccess->getByHierarchicalName( aTargetURLPath ) 212*cdf0e10cSrcweir >>= aValue ) ) 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir OSL_ENSURE( sal_False, 215*cdf0e10cSrcweir "HierarchyEntry::getData - " 216*cdf0e10cSrcweir "Got no TargetURL value!" ); 217*cdf0e10cSrcweir return sal_False; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir // TargetURL property may contain a reference to the Office 221*cdf0e10cSrcweir // installation directory. To ensure a reloctable office 222*cdf0e10cSrcweir // installation, the path to the office installtion directory must 223*cdf0e10cSrcweir // never be stored directly. A placeholder is used instead. Replace 224*cdf0e10cSrcweir // it by actual installation directory. 225*cdf0e10cSrcweir if ( m_xOfficeInstDirs.is() && ( aValue.getLength() > 0 ) ) 226*cdf0e10cSrcweir aValue = m_xOfficeInstDirs->makeAbsoluteURL( aValue ); 227*cdf0e10cSrcweir rData.setTargetURL( aValue ); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir rtl::OUString aTypePath = m_aPath; 230*cdf0e10cSrcweir aTypePath += rtl::OUString::createFromAscii( "/Type" ); 231*cdf0e10cSrcweir if ( xRootReadAccess->hasByHierarchicalName( aTypePath ) ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir // Might not be present since it was introduced long after 234*cdf0e10cSrcweir // Title and TargetURL (#82433#)... So not getting it is 235*cdf0e10cSrcweir // not an error. 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir // Get Type value. 238*cdf0e10cSrcweir sal_Int32 nType = 0; 239*cdf0e10cSrcweir if ( xRootReadAccess->getByHierarchicalName( aTypePath ) 240*cdf0e10cSrcweir >>= nType ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir if ( nType == 0 ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir rData.setType( HierarchyEntryData::LINK ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir else if ( nType == 1 ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir rData.setType( HierarchyEntryData::FOLDER ); 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir else 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir OSL_ENSURE( sal_False, 253*cdf0e10cSrcweir "HierarchyEntry::getData - " 254*cdf0e10cSrcweir "Unknown Type value!" ); 255*cdf0e10cSrcweir return sal_False; 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir rData.setName( m_aName ); 261*cdf0e10cSrcweir return sal_True; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir throw; 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir // getByHierarchicalName 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir OSL_ENSURE( sal_False, 273*cdf0e10cSrcweir "HierarchyEntry::getData - caught NoSuchElementException!" ); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir return sal_False; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir //========================================================================= 279*cdf0e10cSrcweir sal_Bool HierarchyEntry::setData( 280*cdf0e10cSrcweir const HierarchyEntryData& rData, sal_Bool bCreate ) 281*cdf0e10cSrcweir { 282*cdf0e10cSrcweir try 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir if ( !m_xConfigProvider.is() ) 287*cdf0e10cSrcweir m_xConfigProvider = uno::Reference< lang::XMultiServiceFactory >( 288*cdf0e10cSrcweir m_xSMgr->createInstance( m_aServiceSpecifier ), 289*cdf0e10cSrcweir uno::UNO_QUERY ); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir if ( m_xConfigProvider.is() ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir // Create parent's key. It must exist! 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir rtl::OUString aParentPath; 296*cdf0e10cSrcweir sal_Bool bRoot = sal_True; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir sal_Int32 nPos = m_aPath.lastIndexOf( '/' ); 299*cdf0e10cSrcweir if ( nPos != -1 ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir // Skip "/Children" segment of the path, too. 302*cdf0e10cSrcweir nPos = m_aPath.lastIndexOf( '/', nPos - 1 ); 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir OSL_ENSURE( nPos != -1, 305*cdf0e10cSrcweir "HierarchyEntry::setData - Wrong path!" ); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir aParentPath += m_aPath.copy( 0, nPos ); 308*cdf0e10cSrcweir bRoot = sal_False; 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir uno::Sequence< uno::Any > aArguments( 1 ); 312*cdf0e10cSrcweir beans::PropertyValue aProperty; 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir aProperty.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 315*cdf0e10cSrcweir CFGPROPERTY_NODEPATH ) ); 316*cdf0e10cSrcweir aProperty.Value <<= aParentPath; 317*cdf0e10cSrcweir aArguments[ 0 ] <<= aProperty; 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir uno::Reference< util::XChangesBatch > xBatch( 320*cdf0e10cSrcweir m_xConfigProvider->createInstanceWithArguments( 321*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 322*cdf0e10cSrcweir READWRITE_SERVICE_NAME ) ), 323*cdf0e10cSrcweir aArguments ), 324*cdf0e10cSrcweir uno::UNO_QUERY ); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir OSL_ENSURE( xBatch.is(), 327*cdf0e10cSrcweir "HierarchyEntry::setData - No batch!" ); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xParentNameAccess( 330*cdf0e10cSrcweir xBatch, uno::UNO_QUERY ); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir OSL_ENSURE( xParentNameAccess.is(), 333*cdf0e10cSrcweir "HierarchyEntry::setData - No name access!" ); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir if ( xBatch.is() && xParentNameAccess.is() ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir // Try to create own key. It must not exist! 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir sal_Bool bExists = sal_True; 340*cdf0e10cSrcweir uno::Any aMyKey; 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir try 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess; 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir if ( bRoot ) 347*cdf0e10cSrcweir { 348*cdf0e10cSrcweir xNameAccess = xParentNameAccess; 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir else 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir xParentNameAccess->getByName( 353*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Children" ) ) 354*cdf0e10cSrcweir >>= xNameAccess; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir if ( xNameAccess->hasByName( m_aName ) ) 358*cdf0e10cSrcweir aMyKey = xNameAccess->getByName( m_aName ); 359*cdf0e10cSrcweir else 360*cdf0e10cSrcweir bExists = sal_False; 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir bExists = sal_False; 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir uno::Reference< container::XNameReplace > xNameReplace; 368*cdf0e10cSrcweir uno::Reference< container::XNameContainer > xContainer; 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir if ( bExists ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir // Key exists. Replace values. 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir aMyKey >>= xNameReplace; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir OSL_ENSURE( xNameReplace.is(), 377*cdf0e10cSrcweir "HierarchyEntry::setData - No name replace!" ); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir else 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir if ( !bCreate ) 382*cdf0e10cSrcweir return sal_True; 383*cdf0e10cSrcweir 384*cdf0e10cSrcweir // Key does not exist. Create / fill / insert it. 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFac; 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir if ( bRoot ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir // Special handling for children of root, 391*cdf0e10cSrcweir // which is not an entry. It's only a set 392*cdf0e10cSrcweir // of entries. 393*cdf0e10cSrcweir xFac = uno::Reference< lang::XSingleServiceFactory >( 394*cdf0e10cSrcweir xParentNameAccess, uno::UNO_QUERY ); 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir else 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir // Append new entry to parents child list, 399*cdf0e10cSrcweir // which is a set of entries. 400*cdf0e10cSrcweir xParentNameAccess->getByName( 401*cdf0e10cSrcweir rtl::OUString::createFromAscii( 402*cdf0e10cSrcweir "Children" ) ) >>= xFac; 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir OSL_ENSURE( xFac.is(), 406*cdf0e10cSrcweir "HierarchyEntry::setData - No factory!" ); 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir if ( xFac.is() ) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir xNameReplace 411*cdf0e10cSrcweir = uno::Reference< container::XNameReplace >( 412*cdf0e10cSrcweir xFac->createInstance(), uno::UNO_QUERY ); 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir OSL_ENSURE( xNameReplace.is(), 415*cdf0e10cSrcweir "HierarchyEntry::setData - No name replace!" ); 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir if ( xNameReplace.is() ) 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir xContainer 420*cdf0e10cSrcweir = uno::Reference< container::XNameContainer >( 421*cdf0e10cSrcweir xFac, uno::UNO_QUERY ); 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir OSL_ENSURE( xContainer.is(), 424*cdf0e10cSrcweir "HierarchyEntry::setData - No container!" ); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir if ( xNameReplace.is() ) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir // Set Title value. 432*cdf0e10cSrcweir xNameReplace->replaceByName( 433*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Title" ), 434*cdf0e10cSrcweir uno::makeAny( rData.getTitle() ) ); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir // Set TargetURL value. 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir // TargetURL property may contain a reference to the Office 439*cdf0e10cSrcweir // installation directory. To ensure a reloctable office 440*cdf0e10cSrcweir // installation, the path to the office installtion 441*cdf0e10cSrcweir // directory must never be stored directly. Use a 442*cdf0e10cSrcweir // placeholder instead. 443*cdf0e10cSrcweir rtl::OUString aValue( rData.getTargetURL() ); 444*cdf0e10cSrcweir if ( m_xOfficeInstDirs.is() && ( aValue.getLength() > 0 ) ) 445*cdf0e10cSrcweir aValue 446*cdf0e10cSrcweir = m_xOfficeInstDirs->makeRelocatableURL( aValue ); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir xNameReplace->replaceByName( 449*cdf0e10cSrcweir rtl::OUString::createFromAscii( "TargetURL" ), 450*cdf0e10cSrcweir uno::makeAny( aValue ) ); 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir // Set Type value. 453*cdf0e10cSrcweir sal_Int32 nType 454*cdf0e10cSrcweir = rData.getType() == HierarchyEntryData::LINK ? 0 : 1; 455*cdf0e10cSrcweir xNameReplace->replaceByName( 456*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Type" ), 457*cdf0e10cSrcweir uno::makeAny( nType ) ); 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir if ( xContainer.is() ) 460*cdf0e10cSrcweir xContainer->insertByName( 461*cdf0e10cSrcweir m_aName, uno::makeAny( xNameReplace ) ); 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir // Commit changes. 464*cdf0e10cSrcweir xBatch->commitChanges(); 465*cdf0e10cSrcweir return sal_True; 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir throw; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir // replaceByName, insertByName 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir OSL_ENSURE( 479*cdf0e10cSrcweir sal_False, 480*cdf0e10cSrcweir "HierarchyEntry::setData - caught IllegalArgumentException!" ); 481*cdf0e10cSrcweir } 482*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir // replaceByName, getByName 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir OSL_ENSURE( 487*cdf0e10cSrcweir sal_False, 488*cdf0e10cSrcweir "HierarchyEntry::setData - caught NoSuchElementException!" ); 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir catch ( container::ElementExistException const & ) 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir // insertByName 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir OSL_ENSURE( 495*cdf0e10cSrcweir sal_False, 496*cdf0e10cSrcweir "HierarchyEntry::setData - caught ElementExistException!" ); 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir catch ( lang::WrappedTargetException const & ) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir // replaceByName, insertByName, getByName, commitChanges 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir OSL_ENSURE( 503*cdf0e10cSrcweir sal_False, 504*cdf0e10cSrcweir "HierarchyEntry::setData - caught WrappedTargetException!" ); 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir catch ( uno::Exception const & ) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir // createInstance, createInstanceWithArguments 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir OSL_ENSURE( 511*cdf0e10cSrcweir sal_False, 512*cdf0e10cSrcweir "HierarchyEntry::setData - caught Exception!" ); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir return sal_False; 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir //========================================================================= 519*cdf0e10cSrcweir sal_Bool HierarchyEntry::move( 520*cdf0e10cSrcweir const rtl::OUString& rNewURL, const HierarchyEntryData& rData ) 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir rtl::OUString aNewPath = createPathFromHierarchyURL( rNewURL ); 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir if ( aNewPath == m_aPath ) 527*cdf0e10cSrcweir return sal_True; 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir #if 0 530*cdf0e10cSrcweir // In the "near future"... ( not yet implemented in config db ) 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir - get update access for m_aPath 533*cdf0e10cSrcweir - update access -> XNamed 534*cdf0e10cSrcweir - xNamed::setName( newName ) 535*cdf0e10cSrcweir - updateaccess commit 536*cdf0e10cSrcweir #else 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir sal_Bool bOldRoot = sal_True; 539*cdf0e10cSrcweir uno::Reference< util::XChangesBatch > xOldParentBatch; 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir rtl::OUString aNewKey; 542*cdf0e10cSrcweir sal_Int32 nURLPos = rNewURL.lastIndexOf( '/' ); 543*cdf0e10cSrcweir if ( nURLPos > HIERARCHY_URL_SCHEME_LENGTH ) 544*cdf0e10cSrcweir aNewKey = rNewURL.copy( nURLPos + 1 ); 545*cdf0e10cSrcweir else 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir OSL_ENSURE( sal_False, "HierarchyEntry::move - Invalid URL!" ); 548*cdf0e10cSrcweir return sal_False; 549*cdf0e10cSrcweir } 550*cdf0e10cSrcweir 551*cdf0e10cSrcweir sal_Bool bNewRoot = sal_True; 552*cdf0e10cSrcweir uno::Reference< util::XChangesBatch > xNewParentBatch; 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir sal_Bool bDifferentParents = sal_True; 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir try 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir if ( !m_xConfigProvider.is() ) 559*cdf0e10cSrcweir m_xConfigProvider = uno::Reference< lang::XMultiServiceFactory >( 560*cdf0e10cSrcweir m_xSMgr->createInstance( m_aServiceSpecifier ), 561*cdf0e10cSrcweir uno::UNO_QUERY ); 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir if ( !m_xConfigProvider.is() ) 564*cdf0e10cSrcweir return sal_False; 565*cdf0e10cSrcweir 566*cdf0e10cSrcweir rtl::OUString aOldParentPath; 567*cdf0e10cSrcweir sal_Int32 nPos = m_aPath.lastIndexOf( '/' ); 568*cdf0e10cSrcweir if ( nPos != -1 ) 569*cdf0e10cSrcweir { 570*cdf0e10cSrcweir // Skip "/Children" segment of the path, too. 571*cdf0e10cSrcweir nPos = m_aPath.lastIndexOf( '/', nPos - 1 ); 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir OSL_ENSURE( nPos != -1, "HierarchyEntry::move - Wrong path!" ); 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir aOldParentPath += m_aPath.copy( 0, nPos ); 576*cdf0e10cSrcweir bOldRoot = sal_False; 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir rtl::OUString aNewParentPath; 580*cdf0e10cSrcweir nPos = aNewPath.lastIndexOf( '/' ); 581*cdf0e10cSrcweir if ( nPos != -1 ) 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir // Skip "/Children" segment of the path, too. 584*cdf0e10cSrcweir nPos = aNewPath.lastIndexOf( '/', nPos - 1 ); 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir OSL_ENSURE( nPos != -1, "HierarchyEntry::move - Wrong path!" ); 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir aNewParentPath += aNewPath.copy( 0, nPos ); 589*cdf0e10cSrcweir bNewRoot = sal_False; 590*cdf0e10cSrcweir } 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir uno::Sequence< uno::Any > aArguments( 1 ); 593*cdf0e10cSrcweir beans::PropertyValue aProperty; 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir aProperty.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 596*cdf0e10cSrcweir CFGPROPERTY_NODEPATH ) ); 597*cdf0e10cSrcweir aProperty.Value <<= aOldParentPath; 598*cdf0e10cSrcweir aArguments[ 0 ] <<= aProperty; 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir xOldParentBatch = uno::Reference< util::XChangesBatch >( 601*cdf0e10cSrcweir m_xConfigProvider->createInstanceWithArguments( 602*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 603*cdf0e10cSrcweir READWRITE_SERVICE_NAME ) ), 604*cdf0e10cSrcweir aArguments ), 605*cdf0e10cSrcweir uno::UNO_QUERY ); 606*cdf0e10cSrcweir 607*cdf0e10cSrcweir OSL_ENSURE( xOldParentBatch.is(), "HierarchyEntry::move - No batch!" ); 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir if ( !xOldParentBatch.is() ) 610*cdf0e10cSrcweir return sal_False; 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir if ( aOldParentPath == aNewParentPath ) 613*cdf0e10cSrcweir { 614*cdf0e10cSrcweir bDifferentParents = sal_False; 615*cdf0e10cSrcweir xNewParentBatch = xOldParentBatch; 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir else 618*cdf0e10cSrcweir { 619*cdf0e10cSrcweir bDifferentParents = sal_True; 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir aProperty.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 622*cdf0e10cSrcweir CFGPROPERTY_NODEPATH ) ); 623*cdf0e10cSrcweir aProperty.Value <<= aNewParentPath; 624*cdf0e10cSrcweir aArguments[ 0 ] <<= aProperty; 625*cdf0e10cSrcweir 626*cdf0e10cSrcweir xNewParentBatch = uno::Reference< util::XChangesBatch >( 627*cdf0e10cSrcweir m_xConfigProvider->createInstanceWithArguments( 628*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 629*cdf0e10cSrcweir READWRITE_SERVICE_NAME ) ), 630*cdf0e10cSrcweir aArguments ), 631*cdf0e10cSrcweir uno::UNO_QUERY ); 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir OSL_ENSURE( 634*cdf0e10cSrcweir xNewParentBatch.is(), "HierarchyEntry::move - No batch!" ); 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir if ( !xNewParentBatch.is() ) 637*cdf0e10cSrcweir return sal_False; 638*cdf0e10cSrcweir } 639*cdf0e10cSrcweir } 640*cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir throw; 643*cdf0e10cSrcweir } 644*cdf0e10cSrcweir catch ( uno::Exception const & ) 645*cdf0e10cSrcweir { 646*cdf0e10cSrcweir // createInstance, createInstanceWithArguments 647*cdf0e10cSrcweir 648*cdf0e10cSrcweir OSL_ENSURE( sal_False, "HierarchyEntry::move - caught Exception!" ); 649*cdf0e10cSrcweir return sal_False; 650*cdf0e10cSrcweir } 651*cdf0e10cSrcweir 652*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 653*cdf0e10cSrcweir // (1) Get entry... 654*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 655*cdf0e10cSrcweir 656*cdf0e10cSrcweir uno::Any aEntry; 657*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xOldParentNameAccess; 658*cdf0e10cSrcweir uno::Reference< container::XNameContainer > xOldNameContainer; 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir try 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir xOldParentNameAccess 663*cdf0e10cSrcweir = uno::Reference< container::XNameAccess >( 664*cdf0e10cSrcweir xOldParentBatch, uno::UNO_QUERY ); 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir OSL_ENSURE( xOldParentNameAccess.is(), 667*cdf0e10cSrcweir "HierarchyEntry::move - No name access!" ); 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir if ( !xOldParentNameAccess.is() ) 670*cdf0e10cSrcweir return sal_False; 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir if ( bOldRoot ) 673*cdf0e10cSrcweir { 674*cdf0e10cSrcweir xOldNameContainer = uno::Reference< container::XNameContainer >( 675*cdf0e10cSrcweir xOldParentNameAccess, uno::UNO_QUERY ); 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir else 678*cdf0e10cSrcweir { 679*cdf0e10cSrcweir xOldParentNameAccess->getByName( 680*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Children" ) ) 681*cdf0e10cSrcweir >>= xOldNameContainer; 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir aEntry = xOldNameContainer->getByName( m_aName ); 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 687*cdf0e10cSrcweir { 688*cdf0e10cSrcweir // getByName 689*cdf0e10cSrcweir 690*cdf0e10cSrcweir OSL_ENSURE( sal_False, 691*cdf0e10cSrcweir "HierarchyEntry::move - caught NoSuchElementException!" ); 692*cdf0e10cSrcweir return sal_False; 693*cdf0e10cSrcweir } 694*cdf0e10cSrcweir catch ( lang::WrappedTargetException const & ) 695*cdf0e10cSrcweir { 696*cdf0e10cSrcweir // getByName 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir OSL_ENSURE( sal_False, 699*cdf0e10cSrcweir "HierarchyEntry::move - caught WrappedTargetException!" ); 700*cdf0e10cSrcweir return sal_False; 701*cdf0e10cSrcweir } 702*cdf0e10cSrcweir 703*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 704*cdf0e10cSrcweir // (2) Remove entry... Note: Insert BEFORE remove does not work! 705*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir try 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir xOldNameContainer->removeByName( m_aName ); 710*cdf0e10cSrcweir xOldParentBatch->commitChanges(); 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 713*cdf0e10cSrcweir { 714*cdf0e10cSrcweir // getByName, removeByName 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir OSL_ENSURE( sal_False, 717*cdf0e10cSrcweir "HierarchyEntry::move - caught NoSuchElementException!" ); 718*cdf0e10cSrcweir return sal_False; 719*cdf0e10cSrcweir } 720*cdf0e10cSrcweir 721*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 722*cdf0e10cSrcweir // (3) Insert entry at new parent... 723*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 724*cdf0e10cSrcweir 725*cdf0e10cSrcweir try 726*cdf0e10cSrcweir { 727*cdf0e10cSrcweir uno::Reference< container::XNameReplace > xNewNameReplace; 728*cdf0e10cSrcweir aEntry >>= xNewNameReplace; 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir OSL_ENSURE( xNewNameReplace.is(), 731*cdf0e10cSrcweir "HierarchyEntry::move - No name replace!" ); 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir if ( !xNewNameReplace.is() ) 734*cdf0e10cSrcweir return sal_False; 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNewParentNameAccess; 737*cdf0e10cSrcweir if ( bDifferentParents ) 738*cdf0e10cSrcweir xNewParentNameAccess 739*cdf0e10cSrcweir = uno::Reference< container::XNameAccess >( 740*cdf0e10cSrcweir xNewParentBatch, uno::UNO_QUERY ); 741*cdf0e10cSrcweir else 742*cdf0e10cSrcweir xNewParentNameAccess = xOldParentNameAccess; 743*cdf0e10cSrcweir 744*cdf0e10cSrcweir OSL_ENSURE( xNewParentNameAccess.is(), 745*cdf0e10cSrcweir "HierarchyEntry::move - No name access!" ); 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir if ( !xNewParentNameAccess.is() ) 748*cdf0e10cSrcweir return sal_False; 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir uno::Reference< container::XNameContainer > xNewNameContainer; 751*cdf0e10cSrcweir if ( bDifferentParents ) 752*cdf0e10cSrcweir { 753*cdf0e10cSrcweir if ( bNewRoot ) 754*cdf0e10cSrcweir { 755*cdf0e10cSrcweir xNewNameContainer 756*cdf0e10cSrcweir = uno::Reference< container::XNameContainer >( 757*cdf0e10cSrcweir xNewParentNameAccess, uno::UNO_QUERY ); 758*cdf0e10cSrcweir } 759*cdf0e10cSrcweir else 760*cdf0e10cSrcweir { 761*cdf0e10cSrcweir xNewParentNameAccess->getByName( 762*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Children" ) ) 763*cdf0e10cSrcweir >>= xNewNameContainer; 764*cdf0e10cSrcweir } 765*cdf0e10cSrcweir } 766*cdf0e10cSrcweir else 767*cdf0e10cSrcweir xNewNameContainer = xOldNameContainer; 768*cdf0e10cSrcweir 769*cdf0e10cSrcweir if ( !xNewNameContainer.is() ) 770*cdf0e10cSrcweir return sal_False; 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir xNewNameReplace->replaceByName( 773*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Title" ), 774*cdf0e10cSrcweir uno::makeAny( rData.getTitle() ) ); 775*cdf0e10cSrcweir 776*cdf0e10cSrcweir // TargetURL property may contain a reference to the Office 777*cdf0e10cSrcweir // installation directory. To ensure a reloctable office 778*cdf0e10cSrcweir // installation, the path to the office installtion 779*cdf0e10cSrcweir // directory must never be stored directly. Use a placeholder 780*cdf0e10cSrcweir // instead. 781*cdf0e10cSrcweir rtl::OUString aValue( rData.getTargetURL() ); 782*cdf0e10cSrcweir if ( m_xOfficeInstDirs.is() && ( aValue.getLength() > 0 ) ) 783*cdf0e10cSrcweir aValue = m_xOfficeInstDirs->makeRelocatableURL( aValue ); 784*cdf0e10cSrcweir xNewNameReplace->replaceByName( 785*cdf0e10cSrcweir rtl::OUString::createFromAscii( "TargetURL" ), 786*cdf0e10cSrcweir uno::makeAny( aValue ) ); 787*cdf0e10cSrcweir sal_Int32 nType = rData.getType() == HierarchyEntryData::LINK ? 0 : 1; 788*cdf0e10cSrcweir xNewNameReplace->replaceByName( 789*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Type" ), 790*cdf0e10cSrcweir uno::makeAny( nType ) ); 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir xNewNameContainer->insertByName( aNewKey, aEntry ); 793*cdf0e10cSrcweir xNewParentBatch->commitChanges(); 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 796*cdf0e10cSrcweir { 797*cdf0e10cSrcweir // replaceByName, insertByName, getByName 798*cdf0e10cSrcweir 799*cdf0e10cSrcweir OSL_ENSURE( sal_False, 800*cdf0e10cSrcweir "HierarchyEntry::move - caught NoSuchElementException!" ); 801*cdf0e10cSrcweir return sal_False; 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir catch ( lang::IllegalArgumentException const & ) 804*cdf0e10cSrcweir { 805*cdf0e10cSrcweir // replaceByName, insertByName 806*cdf0e10cSrcweir 807*cdf0e10cSrcweir OSL_ENSURE( 808*cdf0e10cSrcweir sal_False, 809*cdf0e10cSrcweir "HierarchyEntry::move - caught IllegalArgumentException!" ); 810*cdf0e10cSrcweir return sal_False; 811*cdf0e10cSrcweir } 812*cdf0e10cSrcweir catch ( container::ElementExistException const & ) 813*cdf0e10cSrcweir { 814*cdf0e10cSrcweir // insertByName 815*cdf0e10cSrcweir 816*cdf0e10cSrcweir OSL_ENSURE( sal_False, 817*cdf0e10cSrcweir "HierarchyEntry::move - caught ElementExistException!" ); 818*cdf0e10cSrcweir return sal_False; 819*cdf0e10cSrcweir } 820*cdf0e10cSrcweir catch ( lang::WrappedTargetException const & ) 821*cdf0e10cSrcweir { 822*cdf0e10cSrcweir // replaceByName, insertByName, getByName 823*cdf0e10cSrcweir 824*cdf0e10cSrcweir OSL_ENSURE( sal_False, 825*cdf0e10cSrcweir "HierarchyEntry::move - caught WrappedTargetException!" ); 826*cdf0e10cSrcweir return sal_False; 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir #if 0 830*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 831*cdf0e10cSrcweir // (4) Commit changes... 832*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir try 835*cdf0e10cSrcweir { 836*cdf0e10cSrcweir xNewParentBatch->commitChanges(); 837*cdf0e10cSrcweir 838*cdf0e10cSrcweir if ( bDifferentParents ) 839*cdf0e10cSrcweir xOldParentBatch->commitChanges(); 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir catch ( lang::WrappedTargetException const & ) 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir // commitChanges 844*cdf0e10cSrcweir 845*cdf0e10cSrcweir OSL_ENSURE( sal_False, 846*cdf0e10cSrcweir "HierarchyEntry::move - caught WrappedTargetException!" ); 847*cdf0e10cSrcweir return sal_False; 848*cdf0e10cSrcweir } 849*cdf0e10cSrcweir #endif 850*cdf0e10cSrcweir 851*cdf0e10cSrcweir return sal_True; 852*cdf0e10cSrcweir #endif 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir 855*cdf0e10cSrcweir //========================================================================= 856*cdf0e10cSrcweir sal_Bool HierarchyEntry::remove() 857*cdf0e10cSrcweir { 858*cdf0e10cSrcweir try 859*cdf0e10cSrcweir { 860*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 861*cdf0e10cSrcweir 862*cdf0e10cSrcweir if ( !m_xConfigProvider.is() ) 863*cdf0e10cSrcweir m_xConfigProvider = uno::Reference< lang::XMultiServiceFactory >( 864*cdf0e10cSrcweir m_xSMgr->createInstance( m_aServiceSpecifier ), 865*cdf0e10cSrcweir uno::UNO_QUERY ); 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir if ( m_xConfigProvider.is() ) 868*cdf0e10cSrcweir { 869*cdf0e10cSrcweir // Create parent's key. It must exist! 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir rtl::OUString aParentPath; 872*cdf0e10cSrcweir sal_Bool bRoot = sal_True; 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir sal_Int32 nPos = m_aPath.lastIndexOf( '/' ); 875*cdf0e10cSrcweir if ( nPos != -1 ) 876*cdf0e10cSrcweir { 877*cdf0e10cSrcweir // Skip "/Children" segment of the path, too. 878*cdf0e10cSrcweir nPos = m_aPath.lastIndexOf( '/', nPos - 1 ); 879*cdf0e10cSrcweir 880*cdf0e10cSrcweir OSL_ENSURE( nPos != -1, 881*cdf0e10cSrcweir "HierarchyEntry::remove - Wrong path!" ); 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir aParentPath += m_aPath.copy( 0, nPos ); 884*cdf0e10cSrcweir bRoot = sal_False; 885*cdf0e10cSrcweir } 886*cdf0e10cSrcweir 887*cdf0e10cSrcweir uno::Sequence< uno::Any > aArguments( 1 ); 888*cdf0e10cSrcweir beans::PropertyValue aProperty; 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir aProperty.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 891*cdf0e10cSrcweir CFGPROPERTY_NODEPATH ) ); 892*cdf0e10cSrcweir aProperty.Value <<= aParentPath; 893*cdf0e10cSrcweir aArguments[ 0 ] <<= aProperty; 894*cdf0e10cSrcweir 895*cdf0e10cSrcweir uno::Reference< util::XChangesBatch > xBatch( 896*cdf0e10cSrcweir m_xConfigProvider->createInstanceWithArguments( 897*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 898*cdf0e10cSrcweir READWRITE_SERVICE_NAME ) ), 899*cdf0e10cSrcweir aArguments ), 900*cdf0e10cSrcweir uno::UNO_QUERY ); 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir OSL_ENSURE( xBatch.is(), 903*cdf0e10cSrcweir "HierarchyEntry::remove - No batch!" ); 904*cdf0e10cSrcweir 905*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xParentNameAccess( 906*cdf0e10cSrcweir xBatch, uno::UNO_QUERY ); 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir OSL_ENSURE( xParentNameAccess.is(), 909*cdf0e10cSrcweir "HierarchyEntry::remove - No name access!" ); 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir if ( xBatch.is() && xParentNameAccess.is() ) 912*cdf0e10cSrcweir { 913*cdf0e10cSrcweir uno::Reference< container::XNameContainer > xContainer; 914*cdf0e10cSrcweir 915*cdf0e10cSrcweir if ( bRoot ) 916*cdf0e10cSrcweir { 917*cdf0e10cSrcweir // Special handling for children of root, 918*cdf0e10cSrcweir // which is not an entry. It's only a set 919*cdf0e10cSrcweir // of entries. 920*cdf0e10cSrcweir xContainer = uno::Reference< container::XNameContainer >( 921*cdf0e10cSrcweir xParentNameAccess, uno::UNO_QUERY ); 922*cdf0e10cSrcweir } 923*cdf0e10cSrcweir else 924*cdf0e10cSrcweir { 925*cdf0e10cSrcweir // Append new entry to parents child list, 926*cdf0e10cSrcweir // which is a set of entries. 927*cdf0e10cSrcweir xParentNameAccess->getByName( 928*cdf0e10cSrcweir rtl::OUString::createFromAscii( "Children" ) ) 929*cdf0e10cSrcweir >>= xContainer; 930*cdf0e10cSrcweir } 931*cdf0e10cSrcweir 932*cdf0e10cSrcweir OSL_ENSURE( xContainer.is(), 933*cdf0e10cSrcweir "HierarchyEntry::remove - No container!" ); 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir if ( xContainer.is() ) 936*cdf0e10cSrcweir { 937*cdf0e10cSrcweir xContainer->removeByName( m_aName ); 938*cdf0e10cSrcweir xBatch->commitChanges(); 939*cdf0e10cSrcweir return sal_True; 940*cdf0e10cSrcweir } 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir } 943*cdf0e10cSrcweir } 944*cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 945*cdf0e10cSrcweir { 946*cdf0e10cSrcweir throw; 947*cdf0e10cSrcweir } 948*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 949*cdf0e10cSrcweir { 950*cdf0e10cSrcweir // getByName, removeByName 951*cdf0e10cSrcweir 952*cdf0e10cSrcweir OSL_ENSURE( 953*cdf0e10cSrcweir sal_False, 954*cdf0e10cSrcweir "HierarchyEntry::remove - caught NoSuchElementException!" ); 955*cdf0e10cSrcweir } 956*cdf0e10cSrcweir catch ( lang::WrappedTargetException const & ) 957*cdf0e10cSrcweir { 958*cdf0e10cSrcweir // getByName, commitChanges 959*cdf0e10cSrcweir 960*cdf0e10cSrcweir OSL_ENSURE( 961*cdf0e10cSrcweir sal_False, 962*cdf0e10cSrcweir "HierarchyEntry::remove - caught WrappedTargetException!" ); 963*cdf0e10cSrcweir } 964*cdf0e10cSrcweir catch ( uno::Exception const & ) 965*cdf0e10cSrcweir { 966*cdf0e10cSrcweir // createInstance, createInstanceWithArguments 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir OSL_ENSURE( sal_False, 969*cdf0e10cSrcweir "HierarchyEntry::remove - caught Exception!" ); 970*cdf0e10cSrcweir } 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir return sal_False; 973*cdf0e10cSrcweir } 974*cdf0e10cSrcweir 975*cdf0e10cSrcweir //========================================================================= 976*cdf0e10cSrcweir sal_Bool HierarchyEntry::first( iterator& it ) 977*cdf0e10cSrcweir { 978*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 979*cdf0e10cSrcweir 980*cdf0e10cSrcweir if ( it.m_pImpl->pos == -1 ) 981*cdf0e10cSrcweir { 982*cdf0e10cSrcweir // Init... 983*cdf0e10cSrcweir 984*cdf0e10cSrcweir try 985*cdf0e10cSrcweir { 986*cdf0e10cSrcweir uno::Reference< container::XHierarchicalNameAccess > 987*cdf0e10cSrcweir xRootHierNameAccess = getRootReadAccess(); 988*cdf0e10cSrcweir 989*cdf0e10cSrcweir if ( xRootHierNameAccess.is() ) 990*cdf0e10cSrcweir { 991*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess; 992*cdf0e10cSrcweir 993*cdf0e10cSrcweir if ( m_aPath.getLength() > 0 ) 994*cdf0e10cSrcweir { 995*cdf0e10cSrcweir rtl::OUString aPath = m_aPath; 996*cdf0e10cSrcweir aPath += rtl::OUString::createFromAscii( "/Children" ); 997*cdf0e10cSrcweir 998*cdf0e10cSrcweir xRootHierNameAccess->getByHierarchicalName( aPath ) 999*cdf0e10cSrcweir >>= xNameAccess; 1000*cdf0e10cSrcweir } 1001*cdf0e10cSrcweir else 1002*cdf0e10cSrcweir xNameAccess 1003*cdf0e10cSrcweir = uno::Reference< container::XNameAccess >( 1004*cdf0e10cSrcweir xRootHierNameAccess, uno::UNO_QUERY ); 1005*cdf0e10cSrcweir 1006*cdf0e10cSrcweir OSL_ENSURE( xNameAccess.is(), 1007*cdf0e10cSrcweir "HierarchyEntry::first - No name access!" ); 1008*cdf0e10cSrcweir 1009*cdf0e10cSrcweir if ( xNameAccess.is() ) 1010*cdf0e10cSrcweir it.m_pImpl->names = xNameAccess->getElementNames(); 1011*cdf0e10cSrcweir 1012*cdf0e10cSrcweir uno::Reference< container::XHierarchicalNameAccess > 1013*cdf0e10cSrcweir xHierNameAccess( xNameAccess, uno::UNO_QUERY ); 1014*cdf0e10cSrcweir 1015*cdf0e10cSrcweir OSL_ENSURE( xHierNameAccess.is(), 1016*cdf0e10cSrcweir "HierarchyEntry::first - No hier. name access!" ); 1017*cdf0e10cSrcweir 1018*cdf0e10cSrcweir it.m_pImpl->dir = xHierNameAccess; 1019*cdf0e10cSrcweir 1020*cdf0e10cSrcweir it.m_pImpl->officeDirs = m_xOfficeInstDirs; 1021*cdf0e10cSrcweir } 1022*cdf0e10cSrcweir } 1023*cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 1024*cdf0e10cSrcweir { 1025*cdf0e10cSrcweir throw; 1026*cdf0e10cSrcweir } 1027*cdf0e10cSrcweir catch ( container::NoSuchElementException const& ) 1028*cdf0e10cSrcweir { 1029*cdf0e10cSrcweir // getByHierarchicalName 1030*cdf0e10cSrcweir 1031*cdf0e10cSrcweir OSL_ENSURE( 1032*cdf0e10cSrcweir sal_False, 1033*cdf0e10cSrcweir "HierarchyEntry::first - caught NoSuchElementException!" ); 1034*cdf0e10cSrcweir } 1035*cdf0e10cSrcweir catch ( uno::Exception const & ) 1036*cdf0e10cSrcweir { 1037*cdf0e10cSrcweir OSL_ENSURE( sal_False, 1038*cdf0e10cSrcweir "HierarchyEntry::first - caught Exception!" ); 1039*cdf0e10cSrcweir } 1040*cdf0e10cSrcweir } 1041*cdf0e10cSrcweir 1042*cdf0e10cSrcweir if ( it.m_pImpl->names.getLength() == 0 ) 1043*cdf0e10cSrcweir return sal_False; 1044*cdf0e10cSrcweir 1045*cdf0e10cSrcweir it.m_pImpl->pos = 0; 1046*cdf0e10cSrcweir return sal_True; 1047*cdf0e10cSrcweir } 1048*cdf0e10cSrcweir 1049*cdf0e10cSrcweir //========================================================================= 1050*cdf0e10cSrcweir sal_Bool HierarchyEntry::next( iterator& it ) 1051*cdf0e10cSrcweir { 1052*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1053*cdf0e10cSrcweir 1054*cdf0e10cSrcweir if ( it.m_pImpl->pos == -1 ) 1055*cdf0e10cSrcweir return first( it ); 1056*cdf0e10cSrcweir 1057*cdf0e10cSrcweir ++(it.m_pImpl->pos); 1058*cdf0e10cSrcweir 1059*cdf0e10cSrcweir return ( it.m_pImpl->pos < it.m_pImpl->names.getLength() ); 1060*cdf0e10cSrcweir } 1061*cdf0e10cSrcweir 1062*cdf0e10cSrcweir //========================================================================= 1063*cdf0e10cSrcweir rtl::OUString HierarchyEntry::createPathFromHierarchyURL( 1064*cdf0e10cSrcweir const HierarchyUri& rURI ) 1065*cdf0e10cSrcweir { 1066*cdf0e10cSrcweir // Transform path.... 1067*cdf0e10cSrcweir // folder/subfolder/subsubfolder 1068*cdf0e10cSrcweir // --> ['folder']/Children/['subfolder']/Children/['subsubfolder'] 1069*cdf0e10cSrcweir 1070*cdf0e10cSrcweir const rtl::OUString aPath = rURI.getPath().copy( 1 ); // skip leading slash. 1071*cdf0e10cSrcweir sal_Int32 nLen = aPath.getLength(); 1072*cdf0e10cSrcweir 1073*cdf0e10cSrcweir if ( nLen ) 1074*cdf0e10cSrcweir { 1075*cdf0e10cSrcweir rtl::OUStringBuffer aNewPath; 1076*cdf0e10cSrcweir aNewPath.appendAscii( "['" ); 1077*cdf0e10cSrcweir 1078*cdf0e10cSrcweir sal_Int32 nStart = 0; 1079*cdf0e10cSrcweir sal_Int32 nEnd = aPath.indexOf( '/' ); 1080*cdf0e10cSrcweir 1081*cdf0e10cSrcweir do 1082*cdf0e10cSrcweir { 1083*cdf0e10cSrcweir if ( nEnd == -1 ) 1084*cdf0e10cSrcweir nEnd = nLen; 1085*cdf0e10cSrcweir 1086*cdf0e10cSrcweir rtl::OUString aToken = aPath.copy( nStart, nEnd - nStart ); 1087*cdf0e10cSrcweir makeXMLName( aToken, aNewPath ); 1088*cdf0e10cSrcweir 1089*cdf0e10cSrcweir if ( nEnd != nLen ) 1090*cdf0e10cSrcweir { 1091*cdf0e10cSrcweir aNewPath.appendAscii( "']/Children/['" ); 1092*cdf0e10cSrcweir nStart = nEnd + 1; 1093*cdf0e10cSrcweir nEnd = aPath.indexOf( '/', nStart ); 1094*cdf0e10cSrcweir } 1095*cdf0e10cSrcweir else 1096*cdf0e10cSrcweir aNewPath.appendAscii( "']" ); 1097*cdf0e10cSrcweir } 1098*cdf0e10cSrcweir while ( nEnd != nLen ); 1099*cdf0e10cSrcweir 1100*cdf0e10cSrcweir return aNewPath.makeStringAndClear(); 1101*cdf0e10cSrcweir } 1102*cdf0e10cSrcweir 1103*cdf0e10cSrcweir return aPath; 1104*cdf0e10cSrcweir } 1105*cdf0e10cSrcweir 1106*cdf0e10cSrcweir //========================================================================= 1107*cdf0e10cSrcweir uno::Reference< container::XHierarchicalNameAccess > 1108*cdf0e10cSrcweir HierarchyEntry::getRootReadAccess() 1109*cdf0e10cSrcweir { 1110*cdf0e10cSrcweir if ( !m_xRootReadAccess.is() ) 1111*cdf0e10cSrcweir { 1112*cdf0e10cSrcweir osl::Guard< osl::Mutex > aGuard( m_aMutex ); 1113*cdf0e10cSrcweir if ( !m_xRootReadAccess.is() ) 1114*cdf0e10cSrcweir { 1115*cdf0e10cSrcweir if ( m_bTriedToGetRootReadAccess ) // #82494# 1116*cdf0e10cSrcweir { 1117*cdf0e10cSrcweir OSL_ENSURE( sal_False, 1118*cdf0e10cSrcweir "HierarchyEntry::getRootReadAccess - " 1119*cdf0e10cSrcweir "Unable to read any config data! -> #82494#" ); 1120*cdf0e10cSrcweir return uno::Reference< container::XHierarchicalNameAccess >(); 1121*cdf0e10cSrcweir } 1122*cdf0e10cSrcweir 1123*cdf0e10cSrcweir try 1124*cdf0e10cSrcweir { 1125*cdf0e10cSrcweir if ( !m_xConfigProvider.is() ) 1126*cdf0e10cSrcweir m_xConfigProvider 1127*cdf0e10cSrcweir = uno::Reference< lang::XMultiServiceFactory >( 1128*cdf0e10cSrcweir m_xSMgr->createInstance( m_aServiceSpecifier ), 1129*cdf0e10cSrcweir uno::UNO_QUERY ); 1130*cdf0e10cSrcweir 1131*cdf0e10cSrcweir if ( m_xConfigProvider.is() ) 1132*cdf0e10cSrcweir { 1133*cdf0e10cSrcweir // Create Root object. 1134*cdf0e10cSrcweir 1135*cdf0e10cSrcweir uno::Sequence< uno::Any > aArguments( 1 ); 1136*cdf0e10cSrcweir beans::PropertyValue aProperty; 1137*cdf0e10cSrcweir aProperty.Name = rtl::OUString( 1138*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( CFGPROPERTY_NODEPATH ) ); 1139*cdf0e10cSrcweir aProperty.Value <<= rtl::OUString(); // root path 1140*cdf0e10cSrcweir aArguments[ 0 ] <<= aProperty; 1141*cdf0e10cSrcweir 1142*cdf0e10cSrcweir m_bTriedToGetRootReadAccess = sal_True; 1143*cdf0e10cSrcweir 1144*cdf0e10cSrcweir m_xRootReadAccess 1145*cdf0e10cSrcweir = uno::Reference< container::XHierarchicalNameAccess >( 1146*cdf0e10cSrcweir m_xConfigProvider->createInstanceWithArguments( 1147*cdf0e10cSrcweir rtl::OUString( 1148*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 1149*cdf0e10cSrcweir READ_SERVICE_NAME ) ), 1150*cdf0e10cSrcweir aArguments ), 1151*cdf0e10cSrcweir uno::UNO_QUERY ); 1152*cdf0e10cSrcweir } 1153*cdf0e10cSrcweir } 1154*cdf0e10cSrcweir catch ( uno::RuntimeException const & ) 1155*cdf0e10cSrcweir { 1156*cdf0e10cSrcweir throw; 1157*cdf0e10cSrcweir } 1158*cdf0e10cSrcweir catch ( uno::Exception const & ) 1159*cdf0e10cSrcweir { 1160*cdf0e10cSrcweir // createInstance, createInstanceWithArguments 1161*cdf0e10cSrcweir 1162*cdf0e10cSrcweir OSL_ENSURE( sal_False, 1163*cdf0e10cSrcweir "HierarchyEntry::getRootReadAccess - " 1164*cdf0e10cSrcweir "caught Exception!" ); 1165*cdf0e10cSrcweir } 1166*cdf0e10cSrcweir } 1167*cdf0e10cSrcweir } 1168*cdf0e10cSrcweir return m_xRootReadAccess; 1169*cdf0e10cSrcweir } 1170*cdf0e10cSrcweir 1171*cdf0e10cSrcweir //========================================================================= 1172*cdf0e10cSrcweir //========================================================================= 1173*cdf0e10cSrcweir // 1174*cdf0e10cSrcweir // HierarchyEntry::iterator Implementation. 1175*cdf0e10cSrcweir // 1176*cdf0e10cSrcweir //========================================================================= 1177*cdf0e10cSrcweir //========================================================================= 1178*cdf0e10cSrcweir 1179*cdf0e10cSrcweir HierarchyEntry::iterator::iterator() 1180*cdf0e10cSrcweir { 1181*cdf0e10cSrcweir m_pImpl = new iterator_Impl; 1182*cdf0e10cSrcweir } 1183*cdf0e10cSrcweir 1184*cdf0e10cSrcweir //========================================================================= 1185*cdf0e10cSrcweir HierarchyEntry::iterator::~iterator() 1186*cdf0e10cSrcweir { 1187*cdf0e10cSrcweir delete m_pImpl; 1188*cdf0e10cSrcweir } 1189*cdf0e10cSrcweir 1190*cdf0e10cSrcweir //========================================================================= 1191*cdf0e10cSrcweir const HierarchyEntryData& HierarchyEntry::iterator::operator*() const 1192*cdf0e10cSrcweir { 1193*cdf0e10cSrcweir if ( ( m_pImpl->pos != -1 ) 1194*cdf0e10cSrcweir && ( m_pImpl->dir.is() ) 1195*cdf0e10cSrcweir && ( m_pImpl->pos < m_pImpl->names.getLength() ) ) 1196*cdf0e10cSrcweir { 1197*cdf0e10cSrcweir try 1198*cdf0e10cSrcweir { 1199*cdf0e10cSrcweir rtl::OUStringBuffer aKey; 1200*cdf0e10cSrcweir aKey.appendAscii( "['" ); 1201*cdf0e10cSrcweir makeXMLName( m_pImpl->names.getConstArray()[ m_pImpl->pos ], aKey ); 1202*cdf0e10cSrcweir aKey.appendAscii( "']" ); 1203*cdf0e10cSrcweir 1204*cdf0e10cSrcweir rtl::OUString aTitle = aKey.makeStringAndClear(); 1205*cdf0e10cSrcweir rtl::OUString aTargetURL = aTitle; 1206*cdf0e10cSrcweir rtl::OUString aType = aTitle; 1207*cdf0e10cSrcweir 1208*cdf0e10cSrcweir aTitle += rtl::OUString::createFromAscii( "/Title" ); 1209*cdf0e10cSrcweir aTargetURL += rtl::OUString::createFromAscii( "/TargetURL" ); 1210*cdf0e10cSrcweir aType += rtl::OUString::createFromAscii( "/Type" ); 1211*cdf0e10cSrcweir 1212*cdf0e10cSrcweir rtl::OUString aValue; 1213*cdf0e10cSrcweir m_pImpl->dir->getByHierarchicalName( aTitle ) >>= aValue; 1214*cdf0e10cSrcweir m_pImpl->entry.setTitle( aValue ); 1215*cdf0e10cSrcweir 1216*cdf0e10cSrcweir m_pImpl->dir->getByHierarchicalName( aTargetURL ) >>= aValue; 1217*cdf0e10cSrcweir 1218*cdf0e10cSrcweir // TargetURL property may contain a reference to the Office 1219*cdf0e10cSrcweir // installation directory. To ensure a reloctable office 1220*cdf0e10cSrcweir // installation, the path to the office installtion directory must 1221*cdf0e10cSrcweir // never be stored directly. A placeholder is used instead. Replace 1222*cdf0e10cSrcweir // it by actual installation directory. 1223*cdf0e10cSrcweir if ( m_pImpl->officeDirs.is() && ( aValue.getLength() > 0 ) ) 1224*cdf0e10cSrcweir aValue = m_pImpl->officeDirs->makeAbsoluteURL( aValue ); 1225*cdf0e10cSrcweir m_pImpl->entry.setTargetURL( aValue ); 1226*cdf0e10cSrcweir 1227*cdf0e10cSrcweir if ( m_pImpl->dir->hasByHierarchicalName( aType ) ) 1228*cdf0e10cSrcweir { 1229*cdf0e10cSrcweir // Might not be present since it was introduced long 1230*cdf0e10cSrcweir // after Title and TargetURL (#82433#)... So not getting 1231*cdf0e10cSrcweir // it is not an error. 1232*cdf0e10cSrcweir 1233*cdf0e10cSrcweir // Get Type value. 1234*cdf0e10cSrcweir sal_Int32 nType = 0; 1235*cdf0e10cSrcweir if ( m_pImpl->dir->getByHierarchicalName( aType ) >>= nType ) 1236*cdf0e10cSrcweir { 1237*cdf0e10cSrcweir if ( nType == 0 ) 1238*cdf0e10cSrcweir { 1239*cdf0e10cSrcweir m_pImpl->entry.setType( HierarchyEntryData::LINK ); 1240*cdf0e10cSrcweir } 1241*cdf0e10cSrcweir else if ( nType == 1 ) 1242*cdf0e10cSrcweir { 1243*cdf0e10cSrcweir m_pImpl->entry.setType( HierarchyEntryData::FOLDER ); 1244*cdf0e10cSrcweir } 1245*cdf0e10cSrcweir else 1246*cdf0e10cSrcweir { 1247*cdf0e10cSrcweir OSL_ENSURE( sal_False, 1248*cdf0e10cSrcweir "HierarchyEntry::getData - " 1249*cdf0e10cSrcweir "Unknown Type value!" ); 1250*cdf0e10cSrcweir } 1251*cdf0e10cSrcweir } 1252*cdf0e10cSrcweir } 1253*cdf0e10cSrcweir 1254*cdf0e10cSrcweir m_pImpl->entry.setName( 1255*cdf0e10cSrcweir m_pImpl->names.getConstArray()[ m_pImpl->pos ] ); 1256*cdf0e10cSrcweir } 1257*cdf0e10cSrcweir catch ( container::NoSuchElementException const & ) 1258*cdf0e10cSrcweir { 1259*cdf0e10cSrcweir m_pImpl->entry = HierarchyEntryData(); 1260*cdf0e10cSrcweir } 1261*cdf0e10cSrcweir } 1262*cdf0e10cSrcweir 1263*cdf0e10cSrcweir return m_pImpl->entry; 1264*cdf0e10cSrcweir } 1265*cdf0e10cSrcweir 1266*cdf0e10cSrcweir } // namespace hierarchy_ucp 1267