LCOV - code coverage report
Current view: top level - ucb/source/ucp/hierarchy - hierarchydata.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 215 434 49.5 %
Date: 2012-08-25 Functions: 14 16 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 199 741 26.9 %

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

Generated by: LCOV version 1.10