1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 /**************************************************************************
23 **************************************************************************
25 - HierarchyEntry::move
26 --> Rewrite to use XNamed ( once this is supported by config db api ).
28 *************************************************************************/
29 #include "hierarchydata.hxx"
31 #include <tools/diagnose_ex.h>
32 #include <rtl/ustrbuf.hxx>
33 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
34 #include <com/sun/star/container/XNameContainer.hpp>
35 #include <com/sun/star/container/XNameReplace.hpp>
36 #include <com/sun/star/util/XChangesBatch.hpp>
37 #include <com/sun/star/util/XOfficeInstallationDirectories.hpp>
38 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
39 #include <comphelper/propertysequence.hxx>
40 #include "hierarchyprovider.hxx"
41 #include "hierarchyuri.hxx"
43 using namespace com::sun::star
;
45 namespace hierarchy_ucp
49 struct HierarchyEntry::iterator_Impl
51 HierarchyEntryData entry
;
52 uno::Reference
< container::XHierarchicalNameAccess
> dir
;
53 uno::Reference
< util::XOfficeInstallationDirectories
> officeDirs
;
54 uno::Sequence
< OUString
> names
;
57 : pos( -1 /* before first */ ) {};
61 static void makeXMLName( const OUString
& rIn
, OUStringBuffer
& rBuffer
)
63 sal_Int32 nCount
= rIn
.getLength();
64 for ( sal_Int32 n
= 0; n
< nCount
; ++n
)
66 const sal_Unicode c
= rIn
[ n
];
70 rBuffer
.append( "&" );
74 rBuffer
.append( """ );
78 rBuffer
.append( "'" );
82 rBuffer
.append( "<" );
86 rBuffer
.append( ">" );
97 // HierarchyEntry Implementation.
100 #define READ_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadAccess"
101 #define READWRITE_SERVICE_NAME "com.sun.star.ucb.HierarchyDataReadWriteAccess"
103 // describe path of cfg entry
104 #define CFGPROPERTY_NODEPATH "nodepath"
107 HierarchyEntry::HierarchyEntry(
108 const uno::Reference
< uno::XComponentContext
>& rxContext
,
109 HierarchyContentProvider
* pProvider
,
110 const OUString
& rURL
)
111 : m_xContext( rxContext
),
112 m_xOfficeInstDirs( pProvider
->getOfficeInstallationDirectories() ),
113 m_bTriedToGetRootReadAccess( false )
115 HierarchyUri
aUri( rURL
);
116 m_aServiceSpecifier
= aUri
.getService();
119 = pProvider
->getConfigProvider( m_aServiceSpecifier
);
121 = pProvider
->getRootConfigReadNameAccess( m_aServiceSpecifier
);
123 // Note: do not init m_aPath in init list. createPathFromHierarchyURL
124 // needs m_xContext and m_aMutex.
125 m_aPath
= createPathFromHierarchyURL( aUri
);
127 // Extract language independent name from URL.
128 sal_Int32 nPos
= rURL
.lastIndexOf( '/' );
129 if ( nPos
> HIERARCHY_URL_SCHEME_LENGTH
)
130 m_aName
= rURL
.copy( nPos
+ 1 );
132 OSL_FAIL( "HierarchyEntry - Invalid URL!" );
136 bool HierarchyEntry::hasData()
138 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
139 uno::Reference
< container::XHierarchicalNameAccess
> xRootReadAccess
140 = getRootReadAccess();
142 OSL_ENSURE( xRootReadAccess
.is(), "HierarchyEntry::hasData - No root!" );
144 if ( xRootReadAccess
.is() )
145 return xRootReadAccess
->hasByHierarchicalName( m_aPath
);
151 bool HierarchyEntry::getData( HierarchyEntryData
& rData
)
155 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
157 uno::Reference
< container::XHierarchicalNameAccess
> xRootReadAccess
158 = getRootReadAccess();
160 OSL_ENSURE( xRootReadAccess
.is(),
161 "HierarchyEntry::getData - No root!" );
163 if ( xRootReadAccess
.is() )
165 OUString aTitlePath
= m_aPath
+ "/Title";
167 // Note: Avoid NoSuchElementExceptions, because exceptions are
168 // relatively 'expensive'. Checking for availability of
169 // title value is sufficient here, because if it is
170 // there, the other values will be available too.
171 if ( !xRootReadAccess
->hasByHierarchicalName( aTitlePath
) )
177 if ( !( xRootReadAccess
->getByHierarchicalName( aTitlePath
)
180 OSL_FAIL( "HierarchyEntry::getData - "
181 "Got no Title value!" );
185 rData
.setTitle( aValue
);
187 // Get TargetURL value.
188 OUString aTargetURLPath
= m_aPath
+ "/TargetURL";
189 if ( !( xRootReadAccess
->getByHierarchicalName( aTargetURLPath
)
192 OSL_FAIL( "HierarchyEntry::getData - "
193 "Got no TargetURL value!" );
197 // TargetURL property may contain a reference to the Office
198 // installation directory. To ensure a reloctable office
199 // installation, the path to the office installation directory must
200 // never be stored directly. A placeholder is used instead. Replace
201 // it by actual installation directory.
202 if ( m_xOfficeInstDirs
.is() && !aValue
.isEmpty() )
203 aValue
= m_xOfficeInstDirs
->makeAbsoluteURL( aValue
);
204 rData
.setTargetURL( aValue
);
206 OUString aTypePath
= m_aPath
+ "/Type";
207 if ( xRootReadAccess
->hasByHierarchicalName( aTypePath
) )
209 // Might not be present since it was introduced long after
210 // Title and TargetURL (#82433#)... So not getting it is
215 if ( xRootReadAccess
->getByHierarchicalName( aTypePath
)
220 rData
.setType( HierarchyEntryData::LINK
);
222 else if ( nType
== 1 )
224 rData
.setType( HierarchyEntryData::FOLDER
);
228 OSL_FAIL( "HierarchyEntry::getData - "
229 "Unknown Type value!" );
235 rData
.setName( m_aName
);
239 catch ( uno::RuntimeException
const & )
243 catch ( container::NoSuchElementException
const & )
245 // getByHierarchicalName
247 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
253 bool HierarchyEntry::setData( const HierarchyEntryData
& rData
)
257 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
259 if ( !m_xConfigProvider
.is() )
260 m_xConfigProvider
.set(
261 m_xContext
->getServiceManager()->createInstanceWithContext(m_aServiceSpecifier
, m_xContext
),
264 if ( m_xConfigProvider
.is() )
266 // Create parent's key. It must exist!
268 OUString aParentPath
;
271 sal_Int32 nPos
= m_aPath
.lastIndexOf( '/' );
274 // Skip "/Children" segment of the path, too.
275 nPos
= m_aPath
.lastIndexOf( '/', nPos
- 1 );
277 OSL_ENSURE( nPos
!= -1,
278 "HierarchyEntry::setData - Wrong path!" );
280 aParentPath
+= m_aPath
.subView( 0, nPos
);
284 uno::Sequence
<uno::Any
> aArguments(comphelper::InitAnyPropertySequence(
286 {CFGPROPERTY_NODEPATH
, uno::Any(aParentPath
)}
289 uno::Reference
< util::XChangesBatch
> xBatch(
290 m_xConfigProvider
->createInstanceWithArguments(
291 READWRITE_SERVICE_NAME
,
295 OSL_ENSURE( xBatch
.is(),
296 "HierarchyEntry::setData - No batch!" );
298 uno::Reference
< container::XNameAccess
> xParentNameAccess(
299 xBatch
, uno::UNO_QUERY
);
301 OSL_ENSURE( xParentNameAccess
.is(),
302 "HierarchyEntry::setData - No name access!" );
304 if ( xBatch
.is() && xParentNameAccess
.is() )
306 // Try to create own key. It must not exist!
313 uno::Reference
< container::XNameAccess
> xNameAccess
;
317 xNameAccess
= xParentNameAccess
;
321 xParentNameAccess
->getByName("Children") >>= xNameAccess
;
324 if ( xNameAccess
->hasByName( m_aName
) )
325 aMyKey
= xNameAccess
->getByName( m_aName
);
329 catch ( container::NoSuchElementException
const & )
334 uno::Reference
< container::XNameReplace
> xNameReplace
;
335 uno::Reference
< container::XNameContainer
> xContainer
;
339 // Key exists. Replace values.
341 aMyKey
>>= xNameReplace
;
343 OSL_ENSURE( xNameReplace
.is(),
344 "HierarchyEntry::setData - No name replace!" );
348 // Key does not exist. Create / fill / insert it.
350 uno::Reference
< lang::XSingleServiceFactory
> xFac
;
354 // Special handling for children of root,
355 // which is not an entry. It's only a set
357 xFac
.set( xParentNameAccess
, uno::UNO_QUERY
);
361 // Append new entry to parents child list,
362 // which is a set of entries.
363 xParentNameAccess
->getByName("Children") >>= xFac
;
366 OSL_ENSURE( xFac
.is(),
367 "HierarchyEntry::setData - No factory!" );
371 xNameReplace
.set( xFac
->createInstance(), uno::UNO_QUERY
);
373 OSL_ENSURE( xNameReplace
.is(),
374 "HierarchyEntry::setData - No name replace!" );
376 if ( xNameReplace
.is() )
378 xContainer
.set( xFac
, uno::UNO_QUERY
);
380 OSL_ENSURE( xContainer
.is(),
381 "HierarchyEntry::setData - No container!" );
386 if ( xNameReplace
.is() )
389 xNameReplace
->replaceByName(
391 uno::makeAny( rData
.getTitle() ) );
393 // Set TargetURL value.
395 // TargetURL property may contain a reference to the Office
396 // installation directory. To ensure a reloctable office
397 // installation, the path to the office installation
398 // directory must never be stored directly. Use a
399 // placeholder instead.
400 OUString
aValue( rData
.getTargetURL() );
401 if ( m_xOfficeInstDirs
.is() && !aValue
.isEmpty() )
403 = m_xOfficeInstDirs
->makeRelocatableURL( aValue
);
405 xNameReplace
->replaceByName(
407 uno::makeAny( aValue
) );
411 = rData
.getType() == HierarchyEntryData::LINK
? 0 : 1;
412 xNameReplace
->replaceByName(
414 uno::makeAny( nType
) );
416 if ( xContainer
.is() )
417 xContainer
->insertByName(
418 m_aName
, uno::makeAny( xNameReplace
) );
421 xBatch
->commitChanges();
427 catch ( lang::IllegalArgumentException
const & )
429 // replaceByName, insertByName
431 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
433 catch ( uno::RuntimeException
const & )
437 catch ( container::NoSuchElementException
const & )
439 // replaceByName, getByName
441 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
443 catch ( container::ElementExistException
const & )
447 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
449 catch ( lang::WrappedTargetException
const & )
451 // replaceByName, insertByName, getByName, commitChanges
453 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
455 catch ( uno::Exception
const & )
457 // createInstance, createInstanceWithArguments
459 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
466 bool HierarchyEntry::move(
467 const OUString
& rNewURL
, const HierarchyEntryData
& rData
)
469 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
471 OUString aNewPath
= createPathFromHierarchyURL( HierarchyUri(rNewURL
) );
473 if ( aNewPath
== m_aPath
)
476 bool bOldRoot
= true;
477 uno::Reference
< util::XChangesBatch
> xOldParentBatch
;
480 sal_Int32 nURLPos
= rNewURL
.lastIndexOf( '/' );
481 if ( nURLPos
> HIERARCHY_URL_SCHEME_LENGTH
)
482 aNewKey
= rNewURL
.copy( nURLPos
+ 1 );
485 OSL_FAIL( "HierarchyEntry::move - Invalid URL!" );
489 bool bNewRoot
= true;
490 uno::Reference
< util::XChangesBatch
> xNewParentBatch
;
492 bool bDifferentParents
= true;
496 if ( !m_xConfigProvider
.is() )
497 m_xConfigProvider
.set(
498 m_xContext
->getServiceManager()->createInstanceWithContext(m_aServiceSpecifier
, m_xContext
),
501 if ( !m_xConfigProvider
.is() )
504 OUString aOldParentPath
;
505 sal_Int32 nPos
= m_aPath
.lastIndexOf( '/' );
508 // Skip "/Children" segment of the path, too.
509 nPos
= m_aPath
.lastIndexOf( '/', nPos
- 1 );
511 OSL_ENSURE( nPos
!= -1, "HierarchyEntry::move - Wrong path!" );
513 aOldParentPath
+= m_aPath
.subView( 0, nPos
);
517 OUString aNewParentPath
;
518 nPos
= aNewPath
.lastIndexOf( '/' );
521 // Skip "/Children" segment of the path, too.
522 nPos
= aNewPath
.lastIndexOf( '/', nPos
- 1 );
524 OSL_ENSURE( nPos
!= -1, "HierarchyEntry::move - Wrong path!" );
526 aNewParentPath
+= aNewPath
.subView( 0, nPos
);
530 uno::Sequence
<uno::Any
> aArguments(comphelper::InitAnyPropertySequence(
532 {CFGPROPERTY_NODEPATH
, uno::Any(aOldParentPath
)}
536 m_xConfigProvider
->createInstanceWithArguments(
537 READWRITE_SERVICE_NAME
,
541 OSL_ENSURE( xOldParentBatch
.is(), "HierarchyEntry::move - No batch!" );
543 if ( !xOldParentBatch
.is() )
546 if ( aOldParentPath
== aNewParentPath
)
548 bDifferentParents
= false;
549 xNewParentBatch
= xOldParentBatch
;
553 bDifferentParents
= true;
555 uno::Sequence
<uno::Any
> aArguments2(comphelper::InitAnyPropertySequence(
557 {CFGPROPERTY_NODEPATH
, uno::Any(aNewParentPath
)}
561 m_xConfigProvider
->createInstanceWithArguments(
562 READWRITE_SERVICE_NAME
,
567 xNewParentBatch
.is(), "HierarchyEntry::move - No batch!" );
569 if ( !xNewParentBatch
.is() )
573 catch ( uno::RuntimeException
const & )
577 catch ( uno::Exception
const & )
579 // createInstance, createInstanceWithArguments
581 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
590 uno::Reference
< container::XNameAccess
> xOldParentNameAccess
;
591 uno::Reference
< container::XNameContainer
> xOldNameContainer
;
595 xOldParentNameAccess
.set( xOldParentBatch
, uno::UNO_QUERY
);
597 OSL_ENSURE( xOldParentNameAccess
.is(),
598 "HierarchyEntry::move - No name access!" );
600 if ( !xOldParentNameAccess
.is() )
605 xOldNameContainer
.set( xOldParentNameAccess
, uno::UNO_QUERY
);
609 xOldParentNameAccess
->getByName("Children") >>= xOldNameContainer
;
612 aEntry
= xOldNameContainer
->getByName( m_aName
);
614 catch ( container::NoSuchElementException
const & )
618 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
621 catch ( lang::WrappedTargetException
const & )
625 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
630 // (2) Remove entry... Note: Insert BEFORE remove does not work!
635 xOldNameContainer
->removeByName( m_aName
);
636 xOldParentBatch
->commitChanges();
638 catch ( container::NoSuchElementException
const & )
640 // getByName, removeByName
642 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
647 // (3) Insert entry at new parent...
652 uno::Reference
< container::XNameReplace
> xNewNameReplace
;
653 aEntry
>>= xNewNameReplace
;
655 OSL_ENSURE( xNewNameReplace
.is(),
656 "HierarchyEntry::move - No name replace!" );
658 if ( !xNewNameReplace
.is() )
661 uno::Reference
< container::XNameAccess
> xNewParentNameAccess
;
662 if ( bDifferentParents
)
663 xNewParentNameAccess
.set( xNewParentBatch
, uno::UNO_QUERY
);
665 xNewParentNameAccess
= xOldParentNameAccess
;
667 OSL_ENSURE( xNewParentNameAccess
.is(),
668 "HierarchyEntry::move - No name access!" );
670 if ( !xNewParentNameAccess
.is() )
673 uno::Reference
< container::XNameContainer
> xNewNameContainer
;
674 if ( bDifferentParents
)
678 xNewNameContainer
.set( xNewParentNameAccess
, uno::UNO_QUERY
);
682 xNewParentNameAccess
->getByName("Children") >>= xNewNameContainer
;
686 xNewNameContainer
= xOldNameContainer
;
688 if ( !xNewNameContainer
.is() )
691 xNewNameReplace
->replaceByName(
693 uno::makeAny( rData
.getTitle() ) );
695 // TargetURL property may contain a reference to the Office
696 // installation directory. To ensure a reloctable office
697 // installation, the path to the office installation
698 // directory must never be stored directly. Use a placeholder
700 OUString
aValue( rData
.getTargetURL() );
701 if ( m_xOfficeInstDirs
.is() && !aValue
.isEmpty() )
702 aValue
= m_xOfficeInstDirs
->makeRelocatableURL( aValue
);
703 xNewNameReplace
->replaceByName(
705 uno::makeAny( aValue
) );
706 sal_Int32 nType
= rData
.getType() == HierarchyEntryData::LINK
? 0 : 1;
707 xNewNameReplace
->replaceByName(
709 uno::makeAny( nType
) );
711 xNewNameContainer
->insertByName( aNewKey
, aEntry
);
712 xNewParentBatch
->commitChanges();
714 catch ( container::NoSuchElementException
const & )
716 // replaceByName, insertByName, getByName
718 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
721 catch ( lang::IllegalArgumentException
const & )
723 // replaceByName, insertByName
725 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
728 catch ( container::ElementExistException
const & )
732 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
735 catch ( lang::WrappedTargetException
const & )
737 // replaceByName, insertByName, getByName
739 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
747 bool HierarchyEntry::remove()
751 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
753 if ( !m_xConfigProvider
.is() )
754 m_xConfigProvider
.set(
755 m_xContext
->getServiceManager()->createInstanceWithContext(m_aServiceSpecifier
, m_xContext
),
758 if ( m_xConfigProvider
.is() )
760 // Create parent's key. It must exist!
762 OUString aParentPath
;
765 sal_Int32 nPos
= m_aPath
.lastIndexOf( '/' );
768 // Skip "/Children" segment of the path, too.
769 nPos
= m_aPath
.lastIndexOf( '/', nPos
- 1 );
771 OSL_ENSURE( nPos
!= -1,
772 "HierarchyEntry::remove - Wrong path!" );
774 aParentPath
+= m_aPath
.subView( 0, nPos
);
778 uno::Sequence
<uno::Any
> aArguments(comphelper::InitAnyPropertySequence(
780 {CFGPROPERTY_NODEPATH
, uno::Any(aParentPath
)}
783 uno::Reference
< util::XChangesBatch
> xBatch(
784 m_xConfigProvider
->createInstanceWithArguments(
785 READWRITE_SERVICE_NAME
,
789 OSL_ENSURE( xBatch
.is(),
790 "HierarchyEntry::remove - No batch!" );
792 uno::Reference
< container::XNameAccess
> xParentNameAccess(
793 xBatch
, uno::UNO_QUERY
);
795 OSL_ENSURE( xParentNameAccess
.is(),
796 "HierarchyEntry::remove - No name access!" );
798 if ( xBatch
.is() && xParentNameAccess
.is() )
800 uno::Reference
< container::XNameContainer
> xContainer
;
804 // Special handling for children of root,
805 // which is not an entry. It's only a set
807 xContainer
.set( xParentNameAccess
, uno::UNO_QUERY
);
811 // Append new entry to parents child list,
812 // which is a set of entries.
813 xParentNameAccess
->getByName("Children") >>= xContainer
;
816 OSL_ENSURE( xContainer
.is(),
817 "HierarchyEntry::remove - No container!" );
819 if ( xContainer
.is() )
821 xContainer
->removeByName( m_aName
);
822 xBatch
->commitChanges();
828 catch ( uno::RuntimeException
const & )
832 catch ( container::NoSuchElementException
const & )
834 // getByName, removeByName
837 "HierarchyEntry::remove - caught NoSuchElementException!" );
839 catch ( lang::WrappedTargetException
const & )
841 // getByName, commitChanges
844 "HierarchyEntry::remove - caught WrappedTargetException!" );
846 catch ( uno::Exception
const & )
848 // createInstance, createInstanceWithArguments
850 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
857 bool HierarchyEntry::first( iterator
const & it
)
859 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
861 if ( it
.m_pImpl
->pos
== -1 )
867 uno::Reference
< container::XHierarchicalNameAccess
>
868 xRootHierNameAccess
= getRootReadAccess();
870 if ( xRootHierNameAccess
.is() )
872 uno::Reference
< container::XNameAccess
> xNameAccess
;
874 if ( !m_aPath
.isEmpty() )
876 OUString aPath
= m_aPath
+ "/Children";
878 xRootHierNameAccess
->getByHierarchicalName( aPath
)
882 xNameAccess
.set( xRootHierNameAccess
, uno::UNO_QUERY
);
884 OSL_ENSURE( xNameAccess
.is(),
885 "HierarchyEntry::first - No name access!" );
887 if ( xNameAccess
.is() )
888 it
.m_pImpl
->names
= xNameAccess
->getElementNames();
890 uno::Reference
< container::XHierarchicalNameAccess
>
891 xHierNameAccess( xNameAccess
, uno::UNO_QUERY
);
893 OSL_ENSURE( xHierNameAccess
.is(),
894 "HierarchyEntry::first - No hier. name access!" );
896 it
.m_pImpl
->dir
= xHierNameAccess
;
898 it
.m_pImpl
->officeDirs
= m_xOfficeInstDirs
;
901 catch ( uno::RuntimeException
const & )
905 catch ( container::NoSuchElementException
const& )
907 // getByHierarchicalName
909 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
911 catch ( uno::Exception
const & )
913 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
917 if ( !it
.m_pImpl
->names
.hasElements() )
925 bool HierarchyEntry::next( iterator
const & it
)
927 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
929 if ( it
.m_pImpl
->pos
== -1 )
934 return ( it
.m_pImpl
->pos
< it
.m_pImpl
->names
.getLength() );
938 OUString
HierarchyEntry::createPathFromHierarchyURL(
939 const HierarchyUri
& rURI
)
942 // folder/subfolder/subsubfolder
943 // --> ['folder']/Children/['subfolder']/Children/['subsubfolder']
945 const OUString aPath
= rURI
.getPath().copy( 1 ); // skip leading slash.
946 sal_Int32 nLen
= aPath
.getLength();
950 OUStringBuffer aNewPath
;
951 aNewPath
.append( "['" );
953 sal_Int32 nStart
= 0;
954 sal_Int32 nEnd
= aPath
.indexOf( '/' );
961 OUString aToken
= aPath
.copy( nStart
, nEnd
- nStart
);
962 makeXMLName( aToken
, aNewPath
);
966 aNewPath
.append( "']/Children/['" );
968 nEnd
= aPath
.indexOf( '/', nStart
);
971 aNewPath
.append( "']" );
973 while ( nEnd
!= nLen
);
975 return aNewPath
.makeStringAndClear();
982 uno::Reference
< container::XHierarchicalNameAccess
>
983 HierarchyEntry::getRootReadAccess()
985 if ( !m_xRootReadAccess
.is() )
987 osl::Guard
< osl::Mutex
> aGuard( m_aMutex
);
988 if ( !m_xRootReadAccess
.is() )
990 if ( m_bTriedToGetRootReadAccess
)
992 OSL_FAIL( "HierarchyEntry::getRootReadAccess - "
993 "Unable to read any config data! -> #82494#" );
994 return uno::Reference
< container::XHierarchicalNameAccess
>();
999 if ( !m_xConfigProvider
.is() )
1000 m_xConfigProvider
.set(
1001 m_xContext
->getServiceManager()->createInstanceWithContext(m_aServiceSpecifier
, m_xContext
),
1004 if ( m_xConfigProvider
.is() )
1006 // Create Root object.
1008 uno::Sequence
<uno::Any
> aArguments(comphelper::InitAnyPropertySequence(
1010 {CFGPROPERTY_NODEPATH
, uno::Any(OUString())} // root path
1013 m_bTriedToGetRootReadAccess
= true;
1015 m_xRootReadAccess
.set(
1016 m_xConfigProvider
->createInstanceWithArguments(
1022 catch ( uno::RuntimeException
const & )
1026 catch ( uno::Exception
const & )
1028 // createInstance, createInstanceWithArguments
1030 TOOLS_WARN_EXCEPTION("ucb.ucp", "");
1034 return m_xRootReadAccess
;
1038 // HierarchyEntry::iterator Implementation.
1041 HierarchyEntry::iterator::iterator()
1042 : m_pImpl( new iterator_Impl
)
1047 HierarchyEntry::iterator::~iterator()
1052 const HierarchyEntryData
& HierarchyEntry::iterator::operator*() const
1054 if ( ( m_pImpl
->pos
!= -1 )
1055 && ( m_pImpl
->dir
.is() )
1056 && ( m_pImpl
->pos
< m_pImpl
->names
.getLength() ) )
1060 OUStringBuffer aKey
;
1061 aKey
.append( "['" );
1062 makeXMLName( m_pImpl
->names
.getConstArray()[ m_pImpl
->pos
], aKey
);
1063 aKey
.append( "']" );
1065 OUString aTitle
= aKey
.makeStringAndClear();
1066 OUString aTargetURL
= aTitle
;
1067 OUString aType
= aTitle
;
1070 aTargetURL
+= "/TargetURL";
1074 m_pImpl
->dir
->getByHierarchicalName( aTitle
) >>= aValue
;
1075 m_pImpl
->entry
.setTitle( aValue
);
1077 m_pImpl
->dir
->getByHierarchicalName( aTargetURL
) >>= aValue
;
1079 // TargetURL property may contain a reference to the Office
1080 // installation directory. To ensure a reloctable office
1081 // installation, the path to the office installation directory must
1082 // never be stored directly. A placeholder is used instead. Replace
1083 // it by actual installation directory.
1084 if ( m_pImpl
->officeDirs
.is() && !aValue
.isEmpty() )
1085 aValue
= m_pImpl
->officeDirs
->makeAbsoluteURL( aValue
);
1086 m_pImpl
->entry
.setTargetURL( aValue
);
1088 if ( m_pImpl
->dir
->hasByHierarchicalName( aType
) )
1090 // Might not be present since it was introduced long
1091 // after Title and TargetURL (#82433#)... So not getting
1092 // it is not an error.
1095 sal_Int32 nType
= 0;
1096 if ( m_pImpl
->dir
->getByHierarchicalName( aType
) >>= nType
)
1100 m_pImpl
->entry
.setType( HierarchyEntryData::LINK
);
1102 else if ( nType
== 1 )
1104 m_pImpl
->entry
.setType( HierarchyEntryData::FOLDER
);
1108 OSL_FAIL( "HierarchyEntry::getData - "
1109 "Unknown Type value!" );
1114 m_pImpl
->entry
.setName(
1115 m_pImpl
->names
.getConstArray()[ m_pImpl
->pos
] );
1117 catch ( container::NoSuchElementException
const & )
1119 m_pImpl
->entry
= HierarchyEntryData();
1123 return m_pImpl
->entry
;
1126 } // namespace hierarchy_ucp
1128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */