xref: /AOO41X/main/xmlhelp/source/treeview/tvread.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
30*cdf0e10cSrcweir #include "precompiled_xmlhelp.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <string.h>
33*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
34*cdf0e10cSrcweir #ifndef _VOS_DIAGNOSE_HXX_
35*cdf0e10cSrcweir #include <vos/diagnose.hxx>
36*cdf0e10cSrcweir #endif
37*cdf0e10cSrcweir #include "tvread.hxx"
38*cdf0e10cSrcweir #include <expat.h>
39*cdf0e10cSrcweir #include <osl/file.hxx>
40*cdf0e10cSrcweir #include <com/sun/star/frame/XConfigManager.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
44*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
45*cdf0e10cSrcweir #include "com/sun/star/deployment/thePackageManagerFactory.hpp"
46*cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/uri/XUriReferenceFactory.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/uri/XVndSunStarExpandUrl.hpp>
49*cdf0e10cSrcweir #include <comphelper/locale.hxx>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir namespace treeview {
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 	class TVDom
55*cdf0e10cSrcweir 	{
56*cdf0e10cSrcweir 		friend class TVChildTarget;
57*cdf0e10cSrcweir 		friend class TVRead;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 	public:
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 		TVDom( TVDom* arent = 0 )
62*cdf0e10cSrcweir 			: kind( other ),
63*cdf0e10cSrcweir               parent( arent ),
64*cdf0e10cSrcweir 			  childs( 0 )
65*cdf0e10cSrcweir 		{
66*cdf0e10cSrcweir 		}
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir 		~TVDom()
69*cdf0e10cSrcweir 		{
70*cdf0e10cSrcweir 			for( unsigned i = 0; i < childs.size(); ++i )
71*cdf0e10cSrcweir 				delete childs[i];
72*cdf0e10cSrcweir 		}
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 		TVDom* newChild()
76*cdf0e10cSrcweir 		{
77*cdf0e10cSrcweir 			childs.push_back( new TVDom( this ) );
78*cdf0e10cSrcweir 			return childs.back();
79*cdf0e10cSrcweir 		}
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 		TVDom* getParent() const
83*cdf0e10cSrcweir 		{
84*cdf0e10cSrcweir 			if( parent )
85*cdf0e10cSrcweir 				return parent;
86*cdf0e10cSrcweir 			else
87*cdf0e10cSrcweir 				return const_cast<TVDom*>(this);    // I am my own parent, if I am the root
88*cdf0e10cSrcweir 		}
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 		enum Kind {
91*cdf0e10cSrcweir 			tree_view,
92*cdf0e10cSrcweir 			tree_node,
93*cdf0e10cSrcweir 			tree_leaf,
94*cdf0e10cSrcweir 			other
95*cdf0e10cSrcweir 		};
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 		bool isLeaf() const { return kind == TVDom::tree_leaf; }
98*cdf0e10cSrcweir 		void setKind( Kind ind ) { kind = ind; }
99*cdf0e10cSrcweir 		Kind getKind( ) const { return kind; }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 		void setApplication( const char* appl )
103*cdf0e10cSrcweir 		{
104*cdf0e10cSrcweir 			application = rtl::OUString( (sal_Char*)(appl),
105*cdf0e10cSrcweir 										 strlen( appl ),
106*cdf0e10cSrcweir 										 RTL_TEXTENCODING_UTF8 );
107*cdf0e10cSrcweir 		}
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 		void setTitle( const char* itle )
110*cdf0e10cSrcweir 		{
111*cdf0e10cSrcweir 			title += rtl::OUString( (sal_Char*)(itle),
112*cdf0e10cSrcweir                                     strlen( itle ),
113*cdf0e10cSrcweir                                     RTL_TEXTENCODING_UTF8 );
114*cdf0e10cSrcweir 		}
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 		void setTitle( const XML_Char* itle,int len )
117*cdf0e10cSrcweir 		{
118*cdf0e10cSrcweir 			title += rtl::OUString( (sal_Char*)(itle),
119*cdf0e10cSrcweir                                     len,
120*cdf0e10cSrcweir                                     RTL_TEXTENCODING_UTF8 );
121*cdf0e10cSrcweir 		}
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 		void setId( const char* d )
124*cdf0e10cSrcweir 		{
125*cdf0e10cSrcweir 			id = rtl::OUString( (sal_Char*)(d),
126*cdf0e10cSrcweir 								strlen( d ),
127*cdf0e10cSrcweir 								RTL_TEXTENCODING_UTF8 );
128*cdf0e10cSrcweir 		}
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 		void setAnchor( const char* nchor )
131*cdf0e10cSrcweir 		{
132*cdf0e10cSrcweir 			anchor = rtl::OUString( (sal_Char*)(nchor),
133*cdf0e10cSrcweir 									strlen( nchor ),
134*cdf0e10cSrcweir 									RTL_TEXTENCODING_UTF8 );
135*cdf0e10cSrcweir 		}
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 		rtl::OUString getTargetURL()
138*cdf0e10cSrcweir 		{
139*cdf0e10cSrcweir 			if( ! targetURL.getLength() )
140*cdf0e10cSrcweir 			{
141*cdf0e10cSrcweir 				sal_Int32 len;
142*cdf0e10cSrcweir                 for ( const TVDom* p = this;; p = p->parent )
143*cdf0e10cSrcweir                 {
144*cdf0e10cSrcweir                     len = p->application.getLength();
145*cdf0e10cSrcweir                     if ( len != 0 )
146*cdf0e10cSrcweir                         break;
147*cdf0e10cSrcweir                 }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 				rtl::OUStringBuffer strBuff( 22 + len + id.getLength() );
150*cdf0e10cSrcweir 				strBuff.appendAscii(
151*cdf0e10cSrcweir 									"vnd.sun.star.help://"
152*cdf0e10cSrcweir 									).append(id);
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 				targetURL = strBuff.makeStringAndClear();
155*cdf0e10cSrcweir 			}
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 			return targetURL;
158*cdf0e10cSrcweir 		}
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	private:
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 		Kind   kind;
163*cdf0e10cSrcweir 		rtl::OUString  application;
164*cdf0e10cSrcweir 		rtl::OUString  title;
165*cdf0e10cSrcweir 		rtl::OUString  id;
166*cdf0e10cSrcweir 		rtl::OUString  anchor;
167*cdf0e10cSrcweir 		rtl::OUString  targetURL;
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 		TVDom *parent;
170*cdf0e10cSrcweir 		std::vector< TVDom* > childs;
171*cdf0e10cSrcweir 	};
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir using namespace treeview;
178*cdf0e10cSrcweir using namespace com::sun::star;
179*cdf0e10cSrcweir using namespace com::sun::star::uno;
180*cdf0e10cSrcweir using namespace com::sun::star::beans;
181*cdf0e10cSrcweir using namespace com::sun::star::lang;
182*cdf0e10cSrcweir using namespace com::sun::star::util;
183*cdf0e10cSrcweir using namespace com::sun::star::frame;
184*cdf0e10cSrcweir using namespace com::sun::star::container;
185*cdf0e10cSrcweir using namespace com::sun::star::deployment;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir ConfigData::ConfigData()
189*cdf0e10cSrcweir 	: prodName( rtl::OUString::createFromAscii( "%PRODUCTNAME" ) ),
190*cdf0e10cSrcweir 	  prodVersion( rtl::OUString::createFromAscii( "%PRODUCTVERSION" ) ),
191*cdf0e10cSrcweir 	  vendName( rtl::OUString::createFromAscii( "%VENDORNAME" ) ),
192*cdf0e10cSrcweir 	  vendVersion( rtl::OUString::createFromAscii( "%VENDORVERSION" ) ),
193*cdf0e10cSrcweir 	  vendShort( rtl::OUString::createFromAscii( "%VENDORSHORT" ) )
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir void SAL_CALL ConfigData::replaceName( rtl::OUString& oustring ) const
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	sal_Int32 idx = -1,k = 0,off;
200*cdf0e10cSrcweir 	bool cap = false;
201*cdf0e10cSrcweir 	rtl::OUStringBuffer aStrBuf( 0 );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	while( ( idx = oustring.indexOf( sal_Unicode('%'),++idx ) ) != -1 )
204*cdf0e10cSrcweir 	{
205*cdf0e10cSrcweir 		if( oustring.indexOf( prodName,idx ) == idx )
206*cdf0e10cSrcweir 			off = PRODUCTNAME;
207*cdf0e10cSrcweir 		else if( oustring.indexOf( prodVersion,idx ) == idx )
208*cdf0e10cSrcweir 			off = PRODUCTVERSION;
209*cdf0e10cSrcweir 		else if( oustring.indexOf( vendName,idx ) == idx )
210*cdf0e10cSrcweir 			off = VENDORNAME;
211*cdf0e10cSrcweir 		else if( oustring.indexOf( vendVersion,idx ) == idx )
212*cdf0e10cSrcweir 			off = VENDORVERSION;
213*cdf0e10cSrcweir 		else if( oustring.indexOf( vendShort,idx ) == idx )
214*cdf0e10cSrcweir 			off = VENDORSHORT;
215*cdf0e10cSrcweir 		else
216*cdf0e10cSrcweir 			off = -1;
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 		if( off != -1 )
219*cdf0e10cSrcweir 		{
220*cdf0e10cSrcweir 			if( ! cap )
221*cdf0e10cSrcweir 			{
222*cdf0e10cSrcweir 				cap = true;
223*cdf0e10cSrcweir 				aStrBuf.ensureCapacity( 256 );
224*cdf0e10cSrcweir 			}
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 			aStrBuf.append( &oustring.getStr()[k],idx - k );
227*cdf0e10cSrcweir 			aStrBuf.append( m_vReplacement[off] );
228*cdf0e10cSrcweir 			k = idx + m_vAdd[off];
229*cdf0e10cSrcweir 		}
230*cdf0e10cSrcweir 	}
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	if( cap )
233*cdf0e10cSrcweir 	{
234*cdf0e10cSrcweir 		if( k < oustring.getLength() )
235*cdf0e10cSrcweir 			aStrBuf.append( &oustring.getStr()[k],oustring.getLength()-k );
236*cdf0e10cSrcweir 		oustring = aStrBuf.makeStringAndClear();
237*cdf0e10cSrcweir 	}
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
244*cdf0e10cSrcweir // XInterface
245*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir void SAL_CALL
249*cdf0e10cSrcweir TVBase::acquire(
250*cdf0e10cSrcweir 	void )
251*cdf0e10cSrcweir 	throw()
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir   OWeakObject::acquire();
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir void SAL_CALL
258*cdf0e10cSrcweir TVBase::release(
259*cdf0e10cSrcweir 		      void )
260*cdf0e10cSrcweir   throw()
261*cdf0e10cSrcweir {
262*cdf0e10cSrcweir   OWeakObject::release();
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir Any SAL_CALL
267*cdf0e10cSrcweir TVBase::queryInterface(
268*cdf0e10cSrcweir 	const Type& rType )
269*cdf0e10cSrcweir 	throw( RuntimeException )
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir 	Any aRet = cppu::queryInterface( rType,
272*cdf0e10cSrcweir 									 SAL_STATIC_CAST( XTypeProvider*, this ),
273*cdf0e10cSrcweir 									 SAL_STATIC_CAST( XNameAccess*, this ),
274*cdf0e10cSrcweir 									 SAL_STATIC_CAST( XHierarchicalNameAccess*, this ),
275*cdf0e10cSrcweir 									 SAL_STATIC_CAST( XChangesNotifier*, this ),
276*cdf0e10cSrcweir 									 SAL_STATIC_CAST( XComponent*, this ) );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 	return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////
283*cdf0e10cSrcweir //
284*cdf0e10cSrcweir // XTypeProvider methods.
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir XTYPEPROVIDER_IMPL_5( TVBase,
287*cdf0e10cSrcweir 				   	  XTypeProvider,
288*cdf0e10cSrcweir 					  XNameAccess,
289*cdf0e10cSrcweir 					  XHierarchicalNameAccess,
290*cdf0e10cSrcweir 					  XChangesNotifier,
291*cdf0e10cSrcweir 					  XComponent );
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir // TVRead
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir TVRead::TVRead( const ConfigData& configData,TVDom* tvDom )
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir 	if( ! tvDom )
304*cdf0e10cSrcweir 		return;
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 	Title = tvDom->title;
307*cdf0e10cSrcweir 	configData.replaceName( Title );
308*cdf0e10cSrcweir 	if( tvDom->isLeaf() )
309*cdf0e10cSrcweir 	{
310*cdf0e10cSrcweir 		TargetURL = ( tvDom->getTargetURL() + configData.appendix );
311*cdf0e10cSrcweir 		if( tvDom->anchor.getLength() )
312*cdf0e10cSrcweir 			TargetURL += ( rtl::OUString::createFromAscii( "#" ) +
313*cdf0e10cSrcweir 						   tvDom->anchor );
314*cdf0e10cSrcweir 	}
315*cdf0e10cSrcweir 	else
316*cdf0e10cSrcweir 		Children = new TVChildTarget( configData,tvDom );
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir TVRead::~TVRead()
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir // XNameAccess
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir Any SAL_CALL
333*cdf0e10cSrcweir TVRead::getByName( const rtl::OUString& aName )
334*cdf0e10cSrcweir 	throw( NoSuchElementException,
335*cdf0e10cSrcweir 		   WrappedTargetException,
336*cdf0e10cSrcweir 		   RuntimeException )
337*cdf0e10cSrcweir {
338*cdf0e10cSrcweir 	bool found( true );
339*cdf0e10cSrcweir 	Any aAny;
340*cdf0e10cSrcweir 	if( aName.compareToAscii( "Title" ) == 0 )
341*cdf0e10cSrcweir 		aAny <<= Title;
342*cdf0e10cSrcweir 	else if( aName.compareToAscii( "TargetURL" ) == 0 )
343*cdf0e10cSrcweir 		aAny <<= TargetURL;
344*cdf0e10cSrcweir 	else if( aName.compareToAscii( "Children" ) == 0 )
345*cdf0e10cSrcweir 	{
346*cdf0e10cSrcweir 		cppu::OWeakObject* p = Children.get();
347*cdf0e10cSrcweir 		aAny <<= Reference< XInterface >( p );
348*cdf0e10cSrcweir 	}
349*cdf0e10cSrcweir 	else
350*cdf0e10cSrcweir 		found = false;
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir 	if( found )
353*cdf0e10cSrcweir 		return aAny;
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 	throw NoSuchElementException();
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL
362*cdf0e10cSrcweir TVRead::getElementNames( )
363*cdf0e10cSrcweir 	throw( RuntimeException )
364*cdf0e10cSrcweir {
365*cdf0e10cSrcweir 	Sequence< rtl::OUString > seq( 3 );
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	seq[0] = rtl::OUString::createFromAscii( "Title" );
368*cdf0e10cSrcweir 	seq[1] = rtl::OUString::createFromAscii( "TargetURL" );
369*cdf0e10cSrcweir 	seq[2] = rtl::OUString::createFromAscii( "Children" );
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 	return seq;
372*cdf0e10cSrcweir }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir sal_Bool SAL_CALL
377*cdf0e10cSrcweir TVRead::hasByName( const rtl::OUString& aName )
378*cdf0e10cSrcweir 	throw( RuntimeException )
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir 	if( aName.compareToAscii( "Title" ) == 0        ||
381*cdf0e10cSrcweir 		aName.compareToAscii( "TargetURL" ) == 0    ||
382*cdf0e10cSrcweir 		aName.compareToAscii( "Children" ) == 0 )
383*cdf0e10cSrcweir 		return true;
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir 	return false;
386*cdf0e10cSrcweir }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir // XHierarchicalNameAccess
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir Any SAL_CALL
392*cdf0e10cSrcweir TVRead::getByHierarchicalName( const rtl::OUString& aName )
393*cdf0e10cSrcweir 	throw( NoSuchElementException,
394*cdf0e10cSrcweir 		   RuntimeException )
395*cdf0e10cSrcweir {
396*cdf0e10cSrcweir 	sal_Int32 idx;
397*cdf0e10cSrcweir 	rtl::OUString name( aName );
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir 	if( ( idx = name.indexOf( sal_Unicode( '/' ) ) ) != -1  &&
400*cdf0e10cSrcweir 		name.copy( 0,idx ).compareToAscii( "Children" ) == 0 )
401*cdf0e10cSrcweir 		return Children->getByHierarchicalName( name.copy( 1 + idx ) );
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 	return getByName( name );
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir sal_Bool SAL_CALL
410*cdf0e10cSrcweir TVRead::hasByHierarchicalName( const rtl::OUString& aName )
411*cdf0e10cSrcweir 	throw( RuntimeException )
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir 	sal_Int32 idx;
414*cdf0e10cSrcweir 	rtl::OUString name( aName );
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir    	if( ( idx = name.indexOf( sal_Unicode( '/' ) ) ) != -1  &&
417*cdf0e10cSrcweir 		name.copy( 0,idx ).compareToAscii( "Children" ) == 0 )
418*cdf0e10cSrcweir 		return Children->hasByHierarchicalName( name.copy( 1 + idx ) );
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 	return hasByName( name );
421*cdf0e10cSrcweir }
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir /**************************************************************************/
426*cdf0e10cSrcweir /*                                                                        */
427*cdf0e10cSrcweir /*                      TVChildTarget                                     */
428*cdf0e10cSrcweir /*                                                                        */
429*cdf0e10cSrcweir /**************************************************************************/
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir extern "C" void start_handler(void *userData,
435*cdf0e10cSrcweir 				   const XML_Char *name,
436*cdf0e10cSrcweir 				   const XML_Char **atts)
437*cdf0e10cSrcweir {
438*cdf0e10cSrcweir 	TVDom::Kind kind;
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 	if( strcmp( name,"help_section" ) == 0  ||
441*cdf0e10cSrcweir 		strcmp( name,"node" ) == 0 )
442*cdf0e10cSrcweir 		kind = TVDom::tree_node;
443*cdf0e10cSrcweir 	else if( strcmp( name,"topic" ) == 0 )
444*cdf0e10cSrcweir 		kind = TVDom::tree_leaf;
445*cdf0e10cSrcweir 	else
446*cdf0e10cSrcweir 		return;
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 	TVDom **tvDom = static_cast< TVDom** >( userData );
449*cdf0e10cSrcweir 	TVDom  *p;
450*cdf0e10cSrcweir 	p = *tvDom;
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir 	*tvDom = p->newChild();
453*cdf0e10cSrcweir 	p = *tvDom;
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir 	p->setKind( kind );
456*cdf0e10cSrcweir 	while( *atts )
457*cdf0e10cSrcweir 	{
458*cdf0e10cSrcweir 		if( strcmp( *atts,"application" ) == 0 )
459*cdf0e10cSrcweir 			p->setApplication( *(atts+1) );
460*cdf0e10cSrcweir 		else if( strcmp( *atts,"title" ) == 0 )
461*cdf0e10cSrcweir 			p->setTitle( *(atts+1) );
462*cdf0e10cSrcweir 		else if( strcmp( *atts,"id" ) == 0 )
463*cdf0e10cSrcweir 			p->setId( *(atts+1) );
464*cdf0e10cSrcweir 		else if( strcmp( *atts,"anchor" ) == 0 )
465*cdf0e10cSrcweir 			p->setAnchor( *(atts+1) );
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 		atts+=2;
468*cdf0e10cSrcweir 	}
469*cdf0e10cSrcweir }
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir extern "C" void end_handler(void *userData,
473*cdf0e10cSrcweir 				 const XML_Char *name )
474*cdf0e10cSrcweir {
475*cdf0e10cSrcweir 	(void)name;
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir 	TVDom **tvDom = static_cast< TVDom** >( userData );
478*cdf0e10cSrcweir 	*tvDom = (*tvDom)->getParent();
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir extern "C" void data_handler( void *userData,
483*cdf0e10cSrcweir 				   const XML_Char *s,
484*cdf0e10cSrcweir 				   int len)
485*cdf0e10cSrcweir {
486*cdf0e10cSrcweir 	TVDom **tvDom = static_cast< TVDom** >( userData );
487*cdf0e10cSrcweir 	if( (*tvDom)->isLeaf() )
488*cdf0e10cSrcweir 		(*tvDom)->setTitle( s,len );
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir TVChildTarget::TVChildTarget( const ConfigData& configData,TVDom* tvDom )
494*cdf0e10cSrcweir {
495*cdf0e10cSrcweir 	Elements.resize( tvDom->childs.size() );
496*cdf0e10cSrcweir 	for( unsigned i = 0; i < Elements.size(); ++i )
497*cdf0e10cSrcweir 		Elements[i] = new TVRead( configData,tvDom->childs[i] );
498*cdf0e10cSrcweir }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir TVChildTarget::TVChildTarget( const Reference< XMultiServiceFactory >& xMSF )
505*cdf0e10cSrcweir {
506*cdf0e10cSrcweir 	ConfigData configData = init( xMSF );
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir 	if( ! configData.locale.getLength()  ||
509*cdf0e10cSrcweir 		! configData.system.getLength() )
510*cdf0e10cSrcweir 		return;
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 	sal_uInt64 	ret,len = 0;
513*cdf0e10cSrcweir 	int j = configData.vFileURL.size();
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 	TVDom tvDom;
516*cdf0e10cSrcweir 	TVDom* pTVDom = &tvDom;
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir 	while( j )
519*cdf0e10cSrcweir 	{
520*cdf0e10cSrcweir 		len = configData.vFileLen[--j];
521*cdf0e10cSrcweir 		char* s = new char[ int(len) ];  // the buffer to hold the installed files
522*cdf0e10cSrcweir 		osl::File aFile( configData.vFileURL[j] );
523*cdf0e10cSrcweir 		aFile.open( OpenFlag_Read );
524*cdf0e10cSrcweir 		aFile.read( s,len,ret );
525*cdf0e10cSrcweir 		aFile.close();
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir 		XML_Parser parser = XML_ParserCreate( 0 );
528*cdf0e10cSrcweir 		XML_SetElementHandler( parser,
529*cdf0e10cSrcweir 							   start_handler,
530*cdf0e10cSrcweir 							   end_handler );
531*cdf0e10cSrcweir 		XML_SetCharacterDataHandler( parser,
532*cdf0e10cSrcweir 									 data_handler);
533*cdf0e10cSrcweir 		XML_SetUserData( parser,&pTVDom ); // does not return this
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 		int parsed = XML_Parse( parser,s,int( len ),j==0 );
536*cdf0e10cSrcweir         (void)parsed;
537*cdf0e10cSrcweir 		OSL_ENSURE( parsed, "TVChildTarget::TVChildTarget(): Tree file parsing failed" );
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 		XML_ParserFree( parser );
540*cdf0e10cSrcweir 		delete[] s;
541*cdf0e10cSrcweir 	}
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir 	// now TVDom holds the relevant information
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir 	Elements.resize( tvDom.childs.size() );
546*cdf0e10cSrcweir 	for( unsigned i = 0; i < Elements.size(); ++i )
547*cdf0e10cSrcweir 		Elements[i] = new TVRead( configData,tvDom.childs[i] );
548*cdf0e10cSrcweir }
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir TVChildTarget::~TVChildTarget()
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir Any SAL_CALL
558*cdf0e10cSrcweir TVChildTarget::getByName( const rtl::OUString& aName )
559*cdf0e10cSrcweir 	throw( NoSuchElementException,
560*cdf0e10cSrcweir 		   WrappedTargetException,
561*cdf0e10cSrcweir 		   RuntimeException )
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir 	rtl::OUString num( aName.getStr()+2,aName.getLength()-4 );
564*cdf0e10cSrcweir 	sal_Int32 idx = num.toInt32() - 1;
565*cdf0e10cSrcweir 	if( idx < 0 || Elements.size() <= sal_uInt32( idx ) )
566*cdf0e10cSrcweir 		throw NoSuchElementException();
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 	Any aAny;
569*cdf0e10cSrcweir 	cppu::OWeakObject* p = Elements[idx].get();
570*cdf0e10cSrcweir 	aAny <<= Reference< XInterface >( p );
571*cdf0e10cSrcweir 	return aAny;
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir Sequence< rtl::OUString > SAL_CALL
578*cdf0e10cSrcweir TVChildTarget::getElementNames( )
579*cdf0e10cSrcweir 	throw( RuntimeException )
580*cdf0e10cSrcweir {
581*cdf0e10cSrcweir 	Sequence< rtl::OUString > seq( Elements.size() );
582*cdf0e10cSrcweir 	for( unsigned i = 0; i < Elements.size(); ++i )
583*cdf0e10cSrcweir 		seq[i] = rtl::OUString::valueOf( sal_Int32( 1+i ) );
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir 	return seq;
586*cdf0e10cSrcweir }
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir sal_Bool SAL_CALL
591*cdf0e10cSrcweir TVChildTarget::hasByName( const rtl::OUString& aName )
592*cdf0e10cSrcweir 	throw( RuntimeException )
593*cdf0e10cSrcweir {
594*cdf0e10cSrcweir 	rtl::OUString num( aName.getStr()+2,aName.getLength()-4 );
595*cdf0e10cSrcweir 	sal_Int32 idx = num.toInt32() - 1;
596*cdf0e10cSrcweir 	if( idx < 0 || Elements.size() <= sal_uInt32( idx ) )
597*cdf0e10cSrcweir 		return false;
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir 	return true;
600*cdf0e10cSrcweir }
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir // XHierarchicalNameAccess
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir Any SAL_CALL
607*cdf0e10cSrcweir TVChildTarget::getByHierarchicalName( const rtl::OUString& aName )
608*cdf0e10cSrcweir 	throw( NoSuchElementException,
609*cdf0e10cSrcweir 		   RuntimeException )
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir 	sal_Int32 idx;
612*cdf0e10cSrcweir 	rtl::OUString name( aName );
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir 	if( ( idx = name.indexOf( sal_Unicode( '/' ) ) ) != -1 )
615*cdf0e10cSrcweir 	{
616*cdf0e10cSrcweir 		rtl::OUString num( name.getStr()+2,idx-4 );
617*cdf0e10cSrcweir 		sal_Int32 pref = num.toInt32() - 1;
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir 		if( pref < 0 || Elements.size() <= sal_uInt32( pref ) )
620*cdf0e10cSrcweir 			throw NoSuchElementException();
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir 		return Elements[pref]->getByHierarchicalName( name.copy( 1 + idx ) );
623*cdf0e10cSrcweir 	}
624*cdf0e10cSrcweir 	else
625*cdf0e10cSrcweir 		return getByName( name );
626*cdf0e10cSrcweir }
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir sal_Bool SAL_CALL
631*cdf0e10cSrcweir TVChildTarget::hasByHierarchicalName( const rtl::OUString& aName )
632*cdf0e10cSrcweir 	throw( RuntimeException )
633*cdf0e10cSrcweir {
634*cdf0e10cSrcweir 	sal_Int32 idx;
635*cdf0e10cSrcweir 	rtl::OUString name( aName );
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir    	if( ( idx = name.indexOf( sal_Unicode( '/' ) ) ) != -1 )
638*cdf0e10cSrcweir 	{
639*cdf0e10cSrcweir 		rtl::OUString num( name.getStr()+2,idx-4 );
640*cdf0e10cSrcweir 		sal_Int32 pref = num.toInt32() - 1;
641*cdf0e10cSrcweir 		if( pref < 0 || Elements.size() <= sal_uInt32( pref ) )
642*cdf0e10cSrcweir 			return false;
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir 		return Elements[pref]->hasByHierarchicalName( name.copy( 1 + idx ) );
645*cdf0e10cSrcweir 	}
646*cdf0e10cSrcweir 	else
647*cdf0e10cSrcweir 		return hasByName( name );
648*cdf0e10cSrcweir }
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir ConfigData TVChildTarget::init( const Reference< XMultiServiceFactory >& xSMgr )
656*cdf0e10cSrcweir {
657*cdf0e10cSrcweir 	ConfigData configData;
658*cdf0e10cSrcweir 	Reference< XMultiServiceFactory >  sProvider( getConfiguration(xSMgr) );
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir 	/**********************************************************************/
661*cdf0e10cSrcweir 	/*                       reading Office.Common                        */
662*cdf0e10cSrcweir 	/**********************************************************************/
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xHierAccess( getHierAccess( sProvider,
665*cdf0e10cSrcweir 																	 "org.openoffice.Office.Common" ) );
666*cdf0e10cSrcweir 	rtl::OUString system( getKey( xHierAccess,"Help/System" ) );
667*cdf0e10cSrcweir 	sal_Bool showBasic( getBooleanKey(xHierAccess,"Help/ShowBasic") );
668*cdf0e10cSrcweir 	rtl::OUString instPath( getKey( xHierAccess,"Path/Current/Help" ) );
669*cdf0e10cSrcweir 	if( ! instPath.getLength() )
670*cdf0e10cSrcweir 	  // try to determine path from default
671*cdf0e10cSrcweir 	  instPath = rtl::OUString::createFromAscii( "$(instpath)/help" );
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir 	// replace anything like $(instpath);
674*cdf0e10cSrcweir 	subst( xSMgr,instPath );
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir 	/**********************************************************************/
677*cdf0e10cSrcweir 	/*                       reading setup                                */
678*cdf0e10cSrcweir 	/**********************************************************************/
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir 	xHierAccess = getHierAccess( sProvider,
681*cdf0e10cSrcweir 								 "org.openoffice.Setup" );
682*cdf0e10cSrcweir 
683*cdf0e10cSrcweir 	rtl::OUString productName( getKey(  xHierAccess,"Product/ooName" ) );
684*cdf0e10cSrcweir     rtl::OUString setupversion( getKey( xHierAccess,"Product/ooSetupVersion" ) );
685*cdf0e10cSrcweir     rtl::OUString setupextension;
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir     try
688*cdf0e10cSrcweir     {
689*cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
690*cdf0e10cSrcweir 	          xSMgr ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider")), uno::UNO_QUERY_THROW);
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir         uno::Sequence < uno::Any > lParams(1);
693*cdf0e10cSrcweir         beans::PropertyValue                       aParam ;
694*cdf0e10cSrcweir         aParam.Name    = ::rtl::OUString::createFromAscii("nodepath");
695*cdf0e10cSrcweir         aParam.Value <<= ::rtl::OUString::createFromAscii("/org.openoffice.Setup/Product");
696*cdf0e10cSrcweir         lParams[0] = uno::makeAny(aParam);
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir         // open it
699*cdf0e10cSrcweir         uno::Reference< uno::XInterface > xCFG( xConfigProvider->createInstanceWithArguments(
700*cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"),
701*cdf0e10cSrcweir                     lParams) );
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xDirectAccess(xCFG, uno::UNO_QUERY);
704*cdf0e10cSrcweir         uno::Any aRet = xDirectAccess->getByName(::rtl::OUString::createFromAscii("ooSetupExtension"));
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir         aRet >>= setupextension;
707*cdf0e10cSrcweir     }
708*cdf0e10cSrcweir     catch ( uno::Exception& )
709*cdf0e10cSrcweir     {
710*cdf0e10cSrcweir     }
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir 	rtl::OUString productVersion( setupversion +
713*cdf0e10cSrcweir 								  rtl::OUString::createFromAscii( " " ) +
714*cdf0e10cSrcweir 								  setupextension );
715*cdf0e10cSrcweir 	rtl::OUString locale( getKey( xHierAccess,"L10N/ooLocale" ) );
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir 	// Determine fileurl from url and locale
719*cdf0e10cSrcweir 	rtl::OUString url;
720*cdf0e10cSrcweir 	osl::FileBase::RC errFile = osl::FileBase::getFileURLFromSystemPath( instPath,url );
721*cdf0e10cSrcweir 	if( errFile != osl::FileBase::E_None ) return configData;
722*cdf0e10cSrcweir 	if( url.lastIndexOf( sal_Unicode( '/' ) ) != url.getLength() - 1 )
723*cdf0e10cSrcweir 		url += rtl::OUString::createFromAscii( "/" );
724*cdf0e10cSrcweir 	rtl::OUString ret;
725*cdf0e10cSrcweir 	sal_Int32 idx;
726*cdf0e10cSrcweir 	osl::DirectoryItem aDirItem;
727*cdf0e10cSrcweir 	if( osl::FileBase::E_None == osl::DirectoryItem::get( url + locale,aDirItem ) )
728*cdf0e10cSrcweir 		ret = locale;
729*cdf0e10cSrcweir 	else if( ( ( idx = locale.indexOf( '-' ) ) != -1 ||
730*cdf0e10cSrcweir 			   ( idx = locale.indexOf( '_' ) ) != -1 ) &&
731*cdf0e10cSrcweir 			 osl::FileBase::E_None == osl::DirectoryItem::get( url + locale.copy( 0,idx ),
732*cdf0e10cSrcweir 															   aDirItem ) )
733*cdf0e10cSrcweir 		ret = locale.copy( 0,idx );
734*cdf0e10cSrcweir     else
735*cdf0e10cSrcweir         {
736*cdf0e10cSrcweir         locale = rtl::OUString::createFromAscii( "en-US" );
737*cdf0e10cSrcweir         ret = rtl::OUString::createFromAscii("en");
738*cdf0e10cSrcweir         }
739*cdf0e10cSrcweir 	url = url + ret;
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir 	// first of all, try do determine whether there are any *.tree files present
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir 	// Start with extensions to set them at the end of the list
744*cdf0e10cSrcweir 	TreeFileIterator aTreeIt( locale );
745*cdf0e10cSrcweir 	rtl::OUString aTreeFile;
746*cdf0e10cSrcweir 	sal_Int32 nFileSize;
747*cdf0e10cSrcweir 	while( (aTreeFile = aTreeIt.nextTreeFile( nFileSize ) ).getLength() > 0 )
748*cdf0e10cSrcweir 	{
749*cdf0e10cSrcweir 		configData.vFileLen.push_back( nFileSize );
750*cdf0e10cSrcweir 		configData.vFileURL.push_back( aTreeFile );
751*cdf0e10cSrcweir 	}
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir 	osl::Directory aDirectory( url );
754*cdf0e10cSrcweir 	osl::FileStatus aFileStatus( FileStatusMask_FileName | FileStatusMask_FileSize | FileStatusMask_FileURL );
755*cdf0e10cSrcweir 	if( osl::Directory::E_None == aDirectory.open() )
756*cdf0e10cSrcweir 	{
757*cdf0e10cSrcweir 		int idx_ = 0;
758*cdf0e10cSrcweir 		rtl::OUString aFileUrl, aFileName;
759*cdf0e10cSrcweir 		while( aDirectory.getNextItem( aDirItem ) == osl::FileBase::E_None &&
760*cdf0e10cSrcweir 			   aDirItem.getFileStatus( aFileStatus ) == osl::FileBase::E_None &&
761*cdf0e10cSrcweir 			   aFileStatus.isValid( FileStatusMask_FileURL ) &&
762*cdf0e10cSrcweir 			   aFileStatus.isValid( FileStatusMask_FileName ) )
763*cdf0e10cSrcweir 		  {
764*cdf0e10cSrcweir 			aFileUrl = aFileStatus.getFileURL();
765*cdf0e10cSrcweir 			aFileName = aFileStatus.getFileName();
766*cdf0e10cSrcweir 			idx_ = aFileName.lastIndexOf( sal_Unicode( '.' ) );
767*cdf0e10cSrcweir 			if( idx_ == -1 )
768*cdf0e10cSrcweir 			  continue;
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir 			const sal_Unicode* str = aFileName.getStr();
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir 			if( aFileName.getLength() == idx_ + 5                   &&
773*cdf0e10cSrcweir 				( str[idx_ + 1] == 't' || str[idx_ + 1] == 'T' )    &&
774*cdf0e10cSrcweir 				( str[idx_ + 2] == 'r' || str[idx_ + 2] == 'R' )    &&
775*cdf0e10cSrcweir 				( str[idx_ + 3] == 'e' || str[idx_ + 3] == 'E' )    &&
776*cdf0e10cSrcweir 				( str[idx_ + 4] == 'e' || str[idx_ + 4] == 'E' ) )
777*cdf0e10cSrcweir 			  {
778*cdf0e10cSrcweir 				OSL_ENSURE( aFileStatus.isValid( FileStatusMask_FileSize ),
779*cdf0e10cSrcweir                             "invalid file size" );
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir 				rtl::OUString baseName = aFileName.copy(0,idx_).toAsciiLowerCase();
782*cdf0e10cSrcweir 				if(! showBasic && baseName.compareToAscii("sbasic") == 0 )
783*cdf0e10cSrcweir 				  continue;
784*cdf0e10cSrcweir 
785*cdf0e10cSrcweir 				configData.vFileLen.push_back( aFileStatus.getFileSize() );
786*cdf0e10cSrcweir 				configData.vFileURL.push_back( aFileUrl );
787*cdf0e10cSrcweir 			  }
788*cdf0e10cSrcweir 		  }
789*cdf0e10cSrcweir 		aDirectory.close();
790*cdf0e10cSrcweir 	}
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir 	configData.m_vAdd[0] = 12;
793*cdf0e10cSrcweir 	configData.m_vAdd[1] = 15;
794*cdf0e10cSrcweir 	configData.m_vAdd[2] = 11;
795*cdf0e10cSrcweir 	configData.m_vAdd[3] = 14;
796*cdf0e10cSrcweir 	configData.m_vAdd[4] = 12;
797*cdf0e10cSrcweir 	configData.m_vReplacement[0] = productName;
798*cdf0e10cSrcweir 	configData.m_vReplacement[1] = productVersion;
799*cdf0e10cSrcweir 	// m_vReplacement[2...4] (vendorName/-Version/-Short) are empty strings
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir    	configData.system = system;
802*cdf0e10cSrcweir 	configData.locale = locale;
803*cdf0e10cSrcweir 	configData.appendix =
804*cdf0e10cSrcweir 		rtl::OUString::createFromAscii( "?Language=" ) +
805*cdf0e10cSrcweir 		configData.locale +
806*cdf0e10cSrcweir 		rtl::OUString::createFromAscii( "&System=" ) +
807*cdf0e10cSrcweir 		configData.system +
808*cdf0e10cSrcweir         rtl::OUString::createFromAscii( "&UseDB=no" ) ;
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir 	return configData;
811*cdf0e10cSrcweir }
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir 
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir 
821*cdf0e10cSrcweir Reference< XMultiServiceFactory >
822*cdf0e10cSrcweir TVChildTarget::getConfiguration(const Reference< XMultiServiceFactory >& m_xSMgr) const
823*cdf0e10cSrcweir {
824*cdf0e10cSrcweir 	Reference< XMultiServiceFactory > sProvider;
825*cdf0e10cSrcweir 	if( m_xSMgr.is() )
826*cdf0e10cSrcweir 	{
827*cdf0e10cSrcweir 		try
828*cdf0e10cSrcweir 		{
829*cdf0e10cSrcweir 			rtl::OUString sProviderService =
830*cdf0e10cSrcweir 				rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationProvider" );
831*cdf0e10cSrcweir 			sProvider =
832*cdf0e10cSrcweir 				Reference< XMultiServiceFactory >(
833*cdf0e10cSrcweir 					m_xSMgr->createInstance( sProviderService ),
834*cdf0e10cSrcweir 					UNO_QUERY );
835*cdf0e10cSrcweir 		}
836*cdf0e10cSrcweir 		catch( const com::sun::star::uno::Exception& )
837*cdf0e10cSrcweir 		{
838*cdf0e10cSrcweir 			OSL_ENSURE( sProvider.is(),"cant instantiate configuration" );
839*cdf0e10cSrcweir 		}
840*cdf0e10cSrcweir 	}
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir 	return sProvider;
843*cdf0e10cSrcweir }
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir 
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir Reference< XHierarchicalNameAccess >
848*cdf0e10cSrcweir TVChildTarget::getHierAccess( const Reference< XMultiServiceFactory >& sProvider,
849*cdf0e10cSrcweir 							  const char* file ) const
850*cdf0e10cSrcweir {
851*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xHierAccess;
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir 	if( sProvider.is() )
854*cdf0e10cSrcweir 	{
855*cdf0e10cSrcweir 		Sequence< Any > seq(1);
856*cdf0e10cSrcweir 		rtl::OUString sReaderService =
857*cdf0e10cSrcweir 			rtl::OUString::createFromAscii( "com.sun.star.configuration.ConfigurationAccess" );
858*cdf0e10cSrcweir 
859*cdf0e10cSrcweir 		seq[0] <<= rtl::OUString::createFromAscii( file );
860*cdf0e10cSrcweir 
861*cdf0e10cSrcweir 		try
862*cdf0e10cSrcweir 		{
863*cdf0e10cSrcweir 			xHierAccess =
864*cdf0e10cSrcweir 				Reference< XHierarchicalNameAccess >
865*cdf0e10cSrcweir 				( sProvider->createInstanceWithArguments( sReaderService,seq ),
866*cdf0e10cSrcweir 				  UNO_QUERY );
867*cdf0e10cSrcweir 		}
868*cdf0e10cSrcweir 		catch( const com::sun::star::uno::Exception& )
869*cdf0e10cSrcweir 		{
870*cdf0e10cSrcweir 		}
871*cdf0e10cSrcweir 	}
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir 	return xHierAccess;
874*cdf0e10cSrcweir }
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir rtl::OUString
879*cdf0e10cSrcweir TVChildTarget::getKey( const Reference< XHierarchicalNameAccess >& xHierAccess,
880*cdf0e10cSrcweir 					   const char* key ) const
881*cdf0e10cSrcweir {
882*cdf0e10cSrcweir     rtl::OUString instPath;
883*cdf0e10cSrcweir 	if( xHierAccess.is() )
884*cdf0e10cSrcweir 	{
885*cdf0e10cSrcweir 		Any aAny;
886*cdf0e10cSrcweir 		try
887*cdf0e10cSrcweir 		{
888*cdf0e10cSrcweir 			aAny =
889*cdf0e10cSrcweir 				xHierAccess->getByHierarchicalName( rtl::OUString::createFromAscii( key ) );
890*cdf0e10cSrcweir 		}
891*cdf0e10cSrcweir 		catch( const com::sun::star::container::NoSuchElementException& )
892*cdf0e10cSrcweir 		{
893*cdf0e10cSrcweir 		}
894*cdf0e10cSrcweir 		aAny >>= instPath;
895*cdf0e10cSrcweir 	}
896*cdf0e10cSrcweir 	return instPath;
897*cdf0e10cSrcweir }
898*cdf0e10cSrcweir 
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir sal_Bool
901*cdf0e10cSrcweir TVChildTarget::getBooleanKey(const Reference<
902*cdf0e10cSrcweir 							 XHierarchicalNameAccess >& xHierAccess,
903*cdf0e10cSrcweir 							 const char* key) const
904*cdf0e10cSrcweir {
905*cdf0e10cSrcweir   sal_Bool ret = sal_False;
906*cdf0e10cSrcweir   if( xHierAccess.is() )
907*cdf0e10cSrcweir 	{
908*cdf0e10cSrcweir 	  Any aAny;
909*cdf0e10cSrcweir 	  try
910*cdf0e10cSrcweir 		{
911*cdf0e10cSrcweir 		  aAny =
912*cdf0e10cSrcweir 			xHierAccess->getByHierarchicalName(
913*cdf0e10cSrcweir 											   rtl::OUString::createFromAscii(key));
914*cdf0e10cSrcweir 		}
915*cdf0e10cSrcweir 	  catch( const com::sun::star::container::NoSuchElementException& )
916*cdf0e10cSrcweir 		{
917*cdf0e10cSrcweir 		}
918*cdf0e10cSrcweir 	  aAny >>= ret;
919*cdf0e10cSrcweir 	}
920*cdf0e10cSrcweir   return ret;
921*cdf0e10cSrcweir }
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir void TVChildTarget::subst( const Reference< XMultiServiceFactory >& m_xSMgr,
925*cdf0e10cSrcweir 						   rtl::OUString& instpath ) const
926*cdf0e10cSrcweir {
927*cdf0e10cSrcweir 	Reference< XConfigManager >  xCfgMgr;
928*cdf0e10cSrcweir 	if( m_xSMgr.is() )
929*cdf0e10cSrcweir 	{
930*cdf0e10cSrcweir 		try
931*cdf0e10cSrcweir 		{
932*cdf0e10cSrcweir 			xCfgMgr =
933*cdf0e10cSrcweir 				Reference< XConfigManager >(
934*cdf0e10cSrcweir 					m_xSMgr->createInstance( rtl::OUString::createFromAscii( "com.sun.star.config.SpecialConfigManager" ) ),
935*cdf0e10cSrcweir 					UNO_QUERY );
936*cdf0e10cSrcweir 		}
937*cdf0e10cSrcweir 		catch( const com::sun::star::uno::Exception& )
938*cdf0e10cSrcweir 		{
939*cdf0e10cSrcweir 			OSL_ENSURE( xCfgMgr.is()," cant instantiate the special config manager " );
940*cdf0e10cSrcweir 		}
941*cdf0e10cSrcweir     }
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir 	OSL_ENSURE( xCfgMgr.is(), "specialconfigmanager not found\n" );
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir 	if( xCfgMgr.is() )
946*cdf0e10cSrcweir         instpath = xCfgMgr->substituteVariables( instpath );
947*cdf0e10cSrcweir }
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir //===================================================================
951*cdf0e10cSrcweir // class ExtensionIteratorBase
952*cdf0e10cSrcweir 
953*cdf0e10cSrcweir static rtl::OUString aSlash( rtl::OUString::createFromAscii( "/" ) );
954*cdf0e10cSrcweir static rtl::OUString aHelpFilesBaseName( rtl::OUString::createFromAscii( "help" ) );
955*cdf0e10cSrcweir static rtl::OUString aHelpMediaType( rtl::OUString::createFromAscii( "application/vnd.sun.star.help" ) );
956*cdf0e10cSrcweir 
957*cdf0e10cSrcweir ExtensionIteratorBase::ExtensionIteratorBase( const rtl::OUString& aLanguage )
958*cdf0e10cSrcweir 		: m_eState( USER_EXTENSIONS )
959*cdf0e10cSrcweir 		, m_aLanguage( aLanguage )
960*cdf0e10cSrcweir {
961*cdf0e10cSrcweir 	init();
962*cdf0e10cSrcweir }
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir void ExtensionIteratorBase::init()
965*cdf0e10cSrcweir {
966*cdf0e10cSrcweir 	Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
967*cdf0e10cSrcweir 	Reference< XPropertySet > xProps( xFactory, UNO_QUERY );
968*cdf0e10cSrcweir 	OSL_ASSERT( xProps.is() );
969*cdf0e10cSrcweir 	if (xProps.is())
970*cdf0e10cSrcweir 	{
971*cdf0e10cSrcweir 		xProps->getPropertyValue(
972*cdf0e10cSrcweir 			::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= m_xContext;
973*cdf0e10cSrcweir 		OSL_ASSERT( m_xContext.is() );
974*cdf0e10cSrcweir 	}
975*cdf0e10cSrcweir 	if( !m_xContext.is() )
976*cdf0e10cSrcweir 	{
977*cdf0e10cSrcweir 		throw RuntimeException(
978*cdf0e10cSrcweir 			::rtl::OUString::createFromAscii( "ExtensionIteratorBase::init(), no XComponentContext" ),
979*cdf0e10cSrcweir 			Reference< XInterface >() );
980*cdf0e10cSrcweir 	}
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir 	Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY );
983*cdf0e10cSrcweir 	m_xSFA = Reference< ucb::XSimpleFileAccess >(
984*cdf0e10cSrcweir 		xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ),
985*cdf0e10cSrcweir 		m_xContext ), UNO_QUERY_THROW );
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir 	m_bUserPackagesLoaded = false;
988*cdf0e10cSrcweir 	m_bSharedPackagesLoaded = false;
989*cdf0e10cSrcweir     m_bBundledPackagesLoaded = false;
990*cdf0e10cSrcweir 	m_iUserPackage = 0;
991*cdf0e10cSrcweir 	m_iSharedPackage = 0;
992*cdf0e10cSrcweir     m_iBundledPackage = 0;
993*cdf0e10cSrcweir }
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir Reference< deployment::XPackage > ExtensionIteratorBase::implGetHelpPackageFromPackage
996*cdf0e10cSrcweir 	( Reference< deployment::XPackage > xPackage, Reference< deployment::XPackage >& o_xParentPackageBundle )
997*cdf0e10cSrcweir {
998*cdf0e10cSrcweir 	o_xParentPackageBundle.clear();
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir 	Reference< deployment::XPackage > xHelpPackage;
1001*cdf0e10cSrcweir 	if( !xPackage.is() )
1002*cdf0e10cSrcweir 		return xHelpPackage;
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir 	// Check if parent package is registered
1005*cdf0e10cSrcweir     beans::Optional< beans::Ambiguous<sal_Bool> > option( xPackage->isRegistered
1006*cdf0e10cSrcweir 		( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() ) );
1007*cdf0e10cSrcweir 	bool bRegistered = false;
1008*cdf0e10cSrcweir     if( option.IsPresent )
1009*cdf0e10cSrcweir     {
1010*cdf0e10cSrcweir         beans::Ambiguous<sal_Bool> const & reg = option.Value;
1011*cdf0e10cSrcweir         if( !reg.IsAmbiguous && reg.Value )
1012*cdf0e10cSrcweir 			bRegistered = true;
1013*cdf0e10cSrcweir     }
1014*cdf0e10cSrcweir 	if( !bRegistered )
1015*cdf0e10cSrcweir 		return xHelpPackage;
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir 	if( xPackage->isBundle() )
1018*cdf0e10cSrcweir 	{
1019*cdf0e10cSrcweir 		Sequence< Reference< deployment::XPackage > > aPkgSeq = xPackage->getBundle
1020*cdf0e10cSrcweir 			( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() );
1021*cdf0e10cSrcweir 		sal_Int32 nPkgCount = aPkgSeq.getLength();
1022*cdf0e10cSrcweir 		const Reference< deployment::XPackage >* pSeq = aPkgSeq.getConstArray();
1023*cdf0e10cSrcweir 		for( sal_Int32 iPkg = 0 ; iPkg < nPkgCount ; ++iPkg )
1024*cdf0e10cSrcweir 		{
1025*cdf0e10cSrcweir 			const Reference< deployment::XPackage > xSubPkg = pSeq[ iPkg ];
1026*cdf0e10cSrcweir 			const Reference< deployment::XPackageTypeInfo > xPackageTypeInfo = xSubPkg->getPackageType();
1027*cdf0e10cSrcweir 			rtl::OUString aMediaType = xPackageTypeInfo->getMediaType();
1028*cdf0e10cSrcweir 			if( aMediaType.equals( aHelpMediaType ) )
1029*cdf0e10cSrcweir 			{
1030*cdf0e10cSrcweir 				xHelpPackage = xSubPkg;
1031*cdf0e10cSrcweir 				o_xParentPackageBundle = xPackage;
1032*cdf0e10cSrcweir 				break;
1033*cdf0e10cSrcweir 			}
1034*cdf0e10cSrcweir 		}
1035*cdf0e10cSrcweir 	}
1036*cdf0e10cSrcweir 	else
1037*cdf0e10cSrcweir 	{
1038*cdf0e10cSrcweir 		const Reference< deployment::XPackageTypeInfo > xPackageTypeInfo = xPackage->getPackageType();
1039*cdf0e10cSrcweir 		rtl::OUString aMediaType = xPackageTypeInfo->getMediaType();
1040*cdf0e10cSrcweir 		if( aMediaType.equals( aHelpMediaType ) )
1041*cdf0e10cSrcweir 			xHelpPackage = xPackage;
1042*cdf0e10cSrcweir 	}
1043*cdf0e10cSrcweir 
1044*cdf0e10cSrcweir 	return xHelpPackage;
1045*cdf0e10cSrcweir }
1046*cdf0e10cSrcweir 
1047*cdf0e10cSrcweir Reference< deployment::XPackage > ExtensionIteratorBase::implGetNextUserHelpPackage
1048*cdf0e10cSrcweir 	( Reference< deployment::XPackage >& o_xParentPackageBundle )
1049*cdf0e10cSrcweir {
1050*cdf0e10cSrcweir 	Reference< deployment::XPackage > xHelpPackage;
1051*cdf0e10cSrcweir 
1052*cdf0e10cSrcweir 	if( !m_bUserPackagesLoaded )
1053*cdf0e10cSrcweir 	{
1054*cdf0e10cSrcweir 		Reference< XPackageManager > xUserManager =
1055*cdf0e10cSrcweir 			thePackageManagerFactory::get( m_xContext )->getPackageManager( rtl::OUString::createFromAscii("user") );
1056*cdf0e10cSrcweir 		m_aUserPackagesSeq = xUserManager->getDeployedPackages
1057*cdf0e10cSrcweir 			( Reference< task::XAbortChannel >(), Reference< ucb::XCommandEnvironment >() );
1058*cdf0e10cSrcweir 
1059*cdf0e10cSrcweir 		m_bUserPackagesLoaded = true;
1060*cdf0e10cSrcweir 	}
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir 	if( m_iUserPackage == m_aUserPackagesSeq.getLength() )
1063*cdf0e10cSrcweir 	{
1064*cdf0e10cSrcweir 		m_eState = SHARED_EXTENSIONS;		// Later: SHARED_MODULE
1065*cdf0e10cSrcweir 	}
1066*cdf0e10cSrcweir 	else
1067*cdf0e10cSrcweir 	{
1068*cdf0e10cSrcweir 		const Reference< deployment::XPackage >* pUserPackages = m_aUserPackagesSeq.getConstArray();
1069*cdf0e10cSrcweir 		Reference< deployment::XPackage > xPackage = pUserPackages[ m_iUserPackage++ ];
1070*cdf0e10cSrcweir 		VOS_ENSURE( xPackage.is(), "ExtensionIteratorBase::implGetNextUserHelpPackage(): Invalid package" );
1071*cdf0e10cSrcweir 		xHelpPackage = implGetHelpPackageFromPackage( xPackage, o_xParentPackageBundle );
1072*cdf0e10cSrcweir 	}
1073*cdf0e10cSrcweir 
1074*cdf0e10cSrcweir 	return xHelpPackage;
1075*cdf0e10cSrcweir }
1076*cdf0e10cSrcweir 
1077*cdf0e10cSrcweir Reference< deployment::XPackage > ExtensionIteratorBase::implGetNextSharedHelpPackage
1078*cdf0e10cSrcweir 	( Reference< deployment::XPackage >& o_xParentPackageBundle )
1079*cdf0e10cSrcweir {
1080*cdf0e10cSrcweir 	Reference< deployment::XPackage > xHelpPackage;
1081*cdf0e10cSrcweir 
1082*cdf0e10cSrcweir 	if( !m_bSharedPackagesLoaded )
1083*cdf0e10cSrcweir 	{
1084*cdf0e10cSrcweir 		Reference< XPackageManager > xSharedManager =
1085*cdf0e10cSrcweir 			thePackageManagerFactory::get( m_xContext )->getPackageManager( rtl::OUString::createFromAscii("shared") );
1086*cdf0e10cSrcweir 		m_aSharedPackagesSeq = xSharedManager->getDeployedPackages
1087*cdf0e10cSrcweir 			( Reference< task::XAbortChannel >(), Reference< ucb::XCommandEnvironment >() );
1088*cdf0e10cSrcweir 
1089*cdf0e10cSrcweir 		m_bSharedPackagesLoaded = true;
1090*cdf0e10cSrcweir 	}
1091*cdf0e10cSrcweir 
1092*cdf0e10cSrcweir 	if( m_iSharedPackage == m_aSharedPackagesSeq.getLength() )
1093*cdf0e10cSrcweir 	{
1094*cdf0e10cSrcweir 		m_eState = BUNDLED_EXTENSIONS;
1095*cdf0e10cSrcweir 	}
1096*cdf0e10cSrcweir 	else
1097*cdf0e10cSrcweir 	{
1098*cdf0e10cSrcweir 		const Reference< deployment::XPackage >* pSharedPackages = m_aSharedPackagesSeq.getConstArray();
1099*cdf0e10cSrcweir 		Reference< deployment::XPackage > xPackage = pSharedPackages[ m_iSharedPackage++ ];
1100*cdf0e10cSrcweir 		VOS_ENSURE( xPackage.is(), "ExtensionIteratorBase::implGetNextSharedHelpPackage(): Invalid package" );
1101*cdf0e10cSrcweir 		xHelpPackage = implGetHelpPackageFromPackage( xPackage, o_xParentPackageBundle );
1102*cdf0e10cSrcweir 	}
1103*cdf0e10cSrcweir 
1104*cdf0e10cSrcweir 	return xHelpPackage;
1105*cdf0e10cSrcweir }
1106*cdf0e10cSrcweir 
1107*cdf0e10cSrcweir Reference< deployment::XPackage > ExtensionIteratorBase::implGetNextBundledHelpPackage
1108*cdf0e10cSrcweir 	( Reference< deployment::XPackage >& o_xParentPackageBundle )
1109*cdf0e10cSrcweir {
1110*cdf0e10cSrcweir 	Reference< deployment::XPackage > xHelpPackage;
1111*cdf0e10cSrcweir 
1112*cdf0e10cSrcweir 	if( !m_bBundledPackagesLoaded )
1113*cdf0e10cSrcweir 	{
1114*cdf0e10cSrcweir 		Reference< XPackageManager > xBundledManager =
1115*cdf0e10cSrcweir 			thePackageManagerFactory::get( m_xContext )->getPackageManager( rtl::OUString::createFromAscii("bundled") );
1116*cdf0e10cSrcweir 		m_aBundledPackagesSeq = xBundledManager->getDeployedPackages
1117*cdf0e10cSrcweir 			( Reference< task::XAbortChannel >(), Reference< ucb::XCommandEnvironment >() );
1118*cdf0e10cSrcweir 
1119*cdf0e10cSrcweir 		m_bBundledPackagesLoaded = true;
1120*cdf0e10cSrcweir 	}
1121*cdf0e10cSrcweir 
1122*cdf0e10cSrcweir 	if( m_iBundledPackage == m_aBundledPackagesSeq.getLength() )
1123*cdf0e10cSrcweir 	{
1124*cdf0e10cSrcweir 		m_eState = END_REACHED;
1125*cdf0e10cSrcweir 	}
1126*cdf0e10cSrcweir 	else
1127*cdf0e10cSrcweir 	{
1128*cdf0e10cSrcweir 		const Reference< deployment::XPackage >* pBundledPackages = m_aBundledPackagesSeq.getConstArray();
1129*cdf0e10cSrcweir 		Reference< deployment::XPackage > xPackage = pBundledPackages[ m_iBundledPackage++ ];
1130*cdf0e10cSrcweir 		VOS_ENSURE( xPackage.is(), "ExtensionIteratorBase::implGetNextBundledHelpPackage(): Invalid package" );
1131*cdf0e10cSrcweir 		xHelpPackage = implGetHelpPackageFromPackage( xPackage, o_xParentPackageBundle );
1132*cdf0e10cSrcweir 	}
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir 	return xHelpPackage;
1135*cdf0e10cSrcweir }
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir inline bool isLetter( sal_Unicode c )
1138*cdf0e10cSrcweir {
1139*cdf0e10cSrcweir 	bool bLetter = ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
1140*cdf0e10cSrcweir 	return bLetter;
1141*cdf0e10cSrcweir }
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir void ExtensionIteratorBase::implGetLanguageVectorFromPackage( ::std::vector< ::rtl::OUString > &rv,
1144*cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage )
1145*cdf0e10cSrcweir {
1146*cdf0e10cSrcweir 	rv.clear();
1147*cdf0e10cSrcweir 	rtl::OUString aExtensionPath = xPackage->getURL();
1148*cdf0e10cSrcweir 	Sequence< rtl::OUString > aEntrySeq = m_xSFA->getFolderContents( aExtensionPath, true );
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir 	const rtl::OUString* pSeq = aEntrySeq.getConstArray();
1151*cdf0e10cSrcweir     sal_Int32 nCount = aEntrySeq.getLength();
1152*cdf0e10cSrcweir 	for( sal_Int32 i = 0 ; i < nCount ; ++i )
1153*cdf0e10cSrcweir 	{
1154*cdf0e10cSrcweir 		rtl::OUString aEntry = pSeq[i];
1155*cdf0e10cSrcweir 		if( m_xSFA->isFolder( aEntry ) )
1156*cdf0e10cSrcweir 		{
1157*cdf0e10cSrcweir 			sal_Int32 nLastSlash = aEntry.lastIndexOf( '/' );
1158*cdf0e10cSrcweir 			if( nLastSlash != -1 )
1159*cdf0e10cSrcweir 			{
1160*cdf0e10cSrcweir 				rtl::OUString aPureEntry = aEntry.copy( nLastSlash + 1 );
1161*cdf0e10cSrcweir 
1162*cdf0e10cSrcweir 				// Check language sceme
1163*cdf0e10cSrcweir 				int nLen = aPureEntry.getLength();
1164*cdf0e10cSrcweir 				const sal_Unicode* pc = aPureEntry.getStr();
1165*cdf0e10cSrcweir 				bool bStartCanBeLanguage = ( nLen >= 2 && isLetter( pc[0] ) && isLetter( pc[1] ) );
1166*cdf0e10cSrcweir 				bool bIsLanguage = bStartCanBeLanguage &&
1167*cdf0e10cSrcweir 					( nLen == 2 || (nLen == 5 && pc[2] == '-' && isLetter( pc[3] ) && isLetter( pc[4] )) );
1168*cdf0e10cSrcweir 				if( bIsLanguage )
1169*cdf0e10cSrcweir 					rv.push_back( aPureEntry );
1170*cdf0e10cSrcweir 			}
1171*cdf0e10cSrcweir 		}
1172*cdf0e10cSrcweir 	}
1173*cdf0e10cSrcweir }
1174*cdf0e10cSrcweir 
1175*cdf0e10cSrcweir 
1176*cdf0e10cSrcweir //===================================================================
1177*cdf0e10cSrcweir // class TreeFileIterator
1178*cdf0e10cSrcweir 
1179*cdf0e10cSrcweir rtl::OUString TreeFileIterator::nextTreeFile( sal_Int32& rnFileSize )
1180*cdf0e10cSrcweir {
1181*cdf0e10cSrcweir 	rtl::OUString aRetFile;
1182*cdf0e10cSrcweir 
1183*cdf0e10cSrcweir 	while( !aRetFile.getLength() && m_eState != END_REACHED )
1184*cdf0e10cSrcweir 	{
1185*cdf0e10cSrcweir 		switch( m_eState )
1186*cdf0e10cSrcweir 		{
1187*cdf0e10cSrcweir 			case USER_EXTENSIONS:
1188*cdf0e10cSrcweir 			{
1189*cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1190*cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextUserHelpPackage( xParentPackageBundle );
1191*cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1192*cdf0e10cSrcweir 					break;
1193*cdf0e10cSrcweir 
1194*cdf0e10cSrcweir 				aRetFile = implGetTreeFileFromPackage( rnFileSize, xHelpPackage );
1195*cdf0e10cSrcweir 				break;
1196*cdf0e10cSrcweir 			}
1197*cdf0e10cSrcweir 
1198*cdf0e10cSrcweir 			case SHARED_EXTENSIONS:
1199*cdf0e10cSrcweir 			{
1200*cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1201*cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextSharedHelpPackage( xParentPackageBundle );
1202*cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1203*cdf0e10cSrcweir 					break;
1204*cdf0e10cSrcweir 
1205*cdf0e10cSrcweir 				aRetFile = implGetTreeFileFromPackage( rnFileSize, xHelpPackage );
1206*cdf0e10cSrcweir 				break;
1207*cdf0e10cSrcweir 			}
1208*cdf0e10cSrcweir 			case BUNDLED_EXTENSIONS:
1209*cdf0e10cSrcweir 			{
1210*cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1211*cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextBundledHelpPackage( xParentPackageBundle );
1212*cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1213*cdf0e10cSrcweir 					break;
1214*cdf0e10cSrcweir 
1215*cdf0e10cSrcweir 				aRetFile = implGetTreeFileFromPackage( rnFileSize, xHelpPackage );
1216*cdf0e10cSrcweir 				break;
1217*cdf0e10cSrcweir 			}
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir         case END_REACHED:
1220*cdf0e10cSrcweir 				VOS_ENSURE( false, "DataBaseIterator::nextTreeFile(): Invalid case END_REACHED" );
1221*cdf0e10cSrcweir 				break;
1222*cdf0e10cSrcweir 		}
1223*cdf0e10cSrcweir 	}
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir 	return aRetFile;
1226*cdf0e10cSrcweir }
1227*cdf0e10cSrcweir 
1228*cdf0e10cSrcweir rtl::OUString TreeFileIterator::expandURL( const rtl::OUString& aURL )
1229*cdf0e10cSrcweir {
1230*cdf0e10cSrcweir 	static Reference< util::XMacroExpander > xMacroExpander;
1231*cdf0e10cSrcweir 	static Reference< uri::XUriReferenceFactory > xFac;
1232*cdf0e10cSrcweir 
1233*cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
1234*cdf0e10cSrcweir 
1235*cdf0e10cSrcweir 	if( !xMacroExpander.is() || !xFac.is() )
1236*cdf0e10cSrcweir 	{
1237*cdf0e10cSrcweir 		Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY );
1238*cdf0e10cSrcweir 
1239*cdf0e10cSrcweir 		xFac = Reference< uri::XUriReferenceFactory >(
1240*cdf0e10cSrcweir 			xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii(
1241*cdf0e10cSrcweir 			"com.sun.star.uri.UriReferenceFactory"), m_xContext ) , UNO_QUERY );
1242*cdf0e10cSrcweir 		if( !xFac.is() )
1243*cdf0e10cSrcweir 		{
1244*cdf0e10cSrcweir 			throw RuntimeException(
1245*cdf0e10cSrcweir 				::rtl::OUString::createFromAscii( "Databases::expand(), could not instatiate UriReferenceFactory." ),
1246*cdf0e10cSrcweir 				Reference< XInterface >() );
1247*cdf0e10cSrcweir 		}
1248*cdf0e10cSrcweir 
1249*cdf0e10cSrcweir 		xMacroExpander = Reference< util::XMacroExpander >(
1250*cdf0e10cSrcweir 			m_xContext->getValueByName(
1251*cdf0e10cSrcweir 			::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ),
1252*cdf0e10cSrcweir 			UNO_QUERY_THROW );
1253*cdf0e10cSrcweir  	}
1254*cdf0e10cSrcweir 
1255*cdf0e10cSrcweir 	rtl::OUString aRetURL = aURL;
1256*cdf0e10cSrcweir 	if( xMacroExpander.is() )
1257*cdf0e10cSrcweir 	{
1258*cdf0e10cSrcweir 		Reference< uri::XUriReference > uriRef;
1259*cdf0e10cSrcweir 		for (;;)
1260*cdf0e10cSrcweir 		{
1261*cdf0e10cSrcweir 			uriRef = Reference< uri::XUriReference >( xFac->parse( aRetURL ), UNO_QUERY );
1262*cdf0e10cSrcweir 			if ( uriRef.is() )
1263*cdf0e10cSrcweir 			{
1264*cdf0e10cSrcweir 				Reference < uri::XVndSunStarExpandUrl > sxUri( uriRef, UNO_QUERY );
1265*cdf0e10cSrcweir 				if( !sxUri.is() )
1266*cdf0e10cSrcweir 					break;
1267*cdf0e10cSrcweir 
1268*cdf0e10cSrcweir 				aRetURL = sxUri->expand( xMacroExpander );
1269*cdf0e10cSrcweir 			}
1270*cdf0e10cSrcweir 		}
1271*cdf0e10cSrcweir  	}
1272*cdf0e10cSrcweir 	return aRetURL;
1273*cdf0e10cSrcweir }
1274*cdf0e10cSrcweir 
1275*cdf0e10cSrcweir rtl::OUString TreeFileIterator::implGetTreeFileFromPackage
1276*cdf0e10cSrcweir 	( sal_Int32& rnFileSize, Reference< deployment::XPackage > xPackage )
1277*cdf0e10cSrcweir {
1278*cdf0e10cSrcweir 	rtl::OUString aRetFile;
1279*cdf0e10cSrcweir 	rtl::OUString aLanguage = m_aLanguage;
1280*cdf0e10cSrcweir 	for( sal_Int32 iPass = 0 ; iPass < 2 ; ++iPass )
1281*cdf0e10cSrcweir 	{
1282*cdf0e10cSrcweir 		rtl::OUStringBuffer aStrBuf;
1283*cdf0e10cSrcweir 		aStrBuf.append( xPackage->getURL() );
1284*cdf0e10cSrcweir 		aStrBuf.append( aSlash );
1285*cdf0e10cSrcweir 		aStrBuf.append( aLanguage );
1286*cdf0e10cSrcweir 		aStrBuf.append( aSlash );
1287*cdf0e10cSrcweir 		aStrBuf.append( aHelpFilesBaseName );
1288*cdf0e10cSrcweir 		aStrBuf.appendAscii( ".tree" );
1289*cdf0e10cSrcweir 
1290*cdf0e10cSrcweir 		aRetFile = expandURL( aStrBuf.makeStringAndClear() );
1291*cdf0e10cSrcweir 		if( iPass == 0 )
1292*cdf0e10cSrcweir 		{
1293*cdf0e10cSrcweir 			if( m_xSFA->exists( aRetFile ) )
1294*cdf0e10cSrcweir 				break;
1295*cdf0e10cSrcweir 
1296*cdf0e10cSrcweir 			::std::vector< ::rtl::OUString > av;
1297*cdf0e10cSrcweir 			implGetLanguageVectorFromPackage( av, xPackage );
1298*cdf0e10cSrcweir 			::std::vector< ::rtl::OUString >::const_iterator pFound = av.end();
1299*cdf0e10cSrcweir 			try
1300*cdf0e10cSrcweir 			{
1301*cdf0e10cSrcweir 				pFound = ::comphelper::Locale::getFallback( av, m_aLanguage );
1302*cdf0e10cSrcweir 			}
1303*cdf0e10cSrcweir 			catch( ::comphelper::Locale::MalFormedLocaleException& )
1304*cdf0e10cSrcweir 			{}
1305*cdf0e10cSrcweir 			if( pFound != av.end() )
1306*cdf0e10cSrcweir 				aLanguage = *pFound;
1307*cdf0e10cSrcweir 		}
1308*cdf0e10cSrcweir 	}
1309*cdf0e10cSrcweir 
1310*cdf0e10cSrcweir 	rnFileSize = 0;
1311*cdf0e10cSrcweir 	if( m_xSFA->exists( aRetFile ) )
1312*cdf0e10cSrcweir 		rnFileSize = m_xSFA->getSize( aRetFile );
1313*cdf0e10cSrcweir 	else
1314*cdf0e10cSrcweir 		aRetFile = rtl::OUString();
1315*cdf0e10cSrcweir 
1316*cdf0e10cSrcweir 	return aRetFile;
1317*cdf0e10cSrcweir }
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir 
1320*cdf0e10cSrcweir 
1321