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