xref: /AOO41X/main/xmlhelp/source/cxxhelp/provider/databases.cxx (revision 70e197d992a972622ba2d0ef1e21a10194579c24)
189dcb3daSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
389dcb3daSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
489dcb3daSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
589dcb3daSAndrew Rist  * distributed with this work for additional information
689dcb3daSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
789dcb3daSAndrew Rist  * to you under the Apache License, Version 2.0 (the
889dcb3daSAndrew Rist  * "License"); you may not use this file except in compliance
989dcb3daSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1189dcb3daSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1389dcb3daSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1489dcb3daSAndrew Rist  * software distributed under the License is distributed on an
1589dcb3daSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1689dcb3daSAndrew Rist  * KIND, either express or implied.  See the License for the
1789dcb3daSAndrew Rist  * specific language governing permissions and limitations
1889dcb3daSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2089dcb3daSAndrew Rist  *************************************************************/
2189dcb3daSAndrew Rist 
2289dcb3daSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmlhelp.hxx"
26cdf0e10cSrcweir #include "db.hxx"
27cdf0e10cSrcweir #ifndef _VOS_DIAGNOSE_HXX_
28cdf0e10cSrcweir #include <vos/diagnose.hxx>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #include <osl/thread.h>
31cdf0e10cSrcweir #include <rtl/uri.hxx>
32cdf0e10cSrcweir #include <osl/file.hxx>
33cdf0e10cSrcweir #include <rtl/memory.h>
34cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
35cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
36cdf0e10cSrcweir #include "inputstream.hxx"
37cdf0e10cSrcweir #include <algorithm>
38cdf0e10cSrcweir #include <string.h>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // Extensible help
41cdf0e10cSrcweir #include "com/sun/star/deployment/ExtensionManager.hpp"
42cdf0e10cSrcweir #include "com/sun/star/deployment/thePackageManagerFactory.hpp"
43cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
44cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
45cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
46cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
47cdf0e10cSrcweir #include <com/sun/star/beans/Optional.hpp>
48cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
49cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
50cdf0e10cSrcweir #include <com/sun/star/frame/XConfigManager.hpp>
51cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp>
52cdf0e10cSrcweir #include <com/sun/star/uri/XUriReferenceFactory.hpp>
53cdf0e10cSrcweir #include <com/sun/star/uri/XVndSunStarExpandUrl.hpp>
54cdf0e10cSrcweir #include <com/sun/star/script/XInvocation.hpp>
55cdf0e10cSrcweir #include <comphelper/locale.hxx>
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #include <com/sun/star/awt/XToolkit.hpp>
58cdf0e10cSrcweir #include <com/sun/star/awt/XExtendedToolkit.hpp>
59cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp>
60cdf0e10cSrcweir #include <com/sun/star/awt/XVclWindowPeer.hpp>
61cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #include <l10ntools/compilehelp.hxx>
64cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
65cdf0e10cSrcweir 
66cdf0e10cSrcweir #include "databases.hxx"
67cdf0e10cSrcweir #include "urlparameter.hxx"
68cdf0e10cSrcweir 
69cdf0e10cSrcweir using namespace chelp;
70cdf0e10cSrcweir using namespace com::sun::star;
71cdf0e10cSrcweir using namespace com::sun::star::uno;
72cdf0e10cSrcweir using namespace com::sun::star::io;
73cdf0e10cSrcweir using namespace com::sun::star::container;
74cdf0e10cSrcweir using namespace com::sun::star::i18n;
75cdf0e10cSrcweir using namespace com::sun::star::lang;
76cdf0e10cSrcweir using namespace com::sun::star::deployment;
77cdf0e10cSrcweir using namespace com::sun::star::beans;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir static rtl::OUString aSlash( rtl::OUString::createFromAscii( "/" ) );
81cdf0e10cSrcweir static rtl::OUString aHelpFilesBaseName( rtl::OUString::createFromAscii( "help" ) );
82cdf0e10cSrcweir static rtl::OUString aHelpMediaType( rtl::OUString::createFromAscii( "application/vnd.sun.star.help" ) );
83cdf0e10cSrcweir 
84cdf0e10cSrcweir rtl::OUString Databases::expandURL( const rtl::OUString& aURL )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
87cdf0e10cSrcweir 	rtl::OUString aRetURL = expandURL( aURL, m_xContext );
88cdf0e10cSrcweir 	return aRetURL;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir rtl::OUString Databases::expandURL( const rtl::OUString& aURL, Reference< uno::XComponentContext > xContext )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 	static Reference< util::XMacroExpander > xMacroExpander;
94cdf0e10cSrcweir 	static Reference< uri::XUriReferenceFactory > xFac;
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	if( !xContext.is() )
97cdf0e10cSrcweir 		return rtl::OUString();
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	if( !xMacroExpander.is() || !xFac.is() )
100cdf0e10cSrcweir 	{
101cdf0e10cSrcweir 		Reference< XMultiComponentFactory > xSMgr( xContext->getServiceManager(), UNO_QUERY );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 		xFac = Reference< uri::XUriReferenceFactory >(
104cdf0e10cSrcweir 			xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii(
105cdf0e10cSrcweir 			"com.sun.star.uri.UriReferenceFactory"), xContext ) , UNO_QUERY );
106cdf0e10cSrcweir 		if( !xFac.is() )
107cdf0e10cSrcweir 		{
108cdf0e10cSrcweir 			throw RuntimeException(
109cdf0e10cSrcweir 				::rtl::OUString::createFromAscii( "Databases::expand(), could not instatiate UriReferenceFactory." ),
110cdf0e10cSrcweir 				Reference< XInterface >() );
111cdf0e10cSrcweir 		}
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		xMacroExpander = Reference< util::XMacroExpander >(
114cdf0e10cSrcweir 			xContext->getValueByName(
115cdf0e10cSrcweir 			::rtl::OUString::createFromAscii( "/singletons/com.sun.star.util.theMacroExpander" ) ),
116cdf0e10cSrcweir 			UNO_QUERY_THROW );
117cdf0e10cSrcweir  	}
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	rtl::OUString aRetURL = aURL;
120cdf0e10cSrcweir 	if( xMacroExpander.is() )
121cdf0e10cSrcweir 	{
122cdf0e10cSrcweir 		Reference< uri::XUriReference > uriRef;
123cdf0e10cSrcweir 		for (;;)
124cdf0e10cSrcweir 		{
125cdf0e10cSrcweir 			uriRef = Reference< uri::XUriReference >( xFac->parse( aRetURL ), UNO_QUERY );
126cdf0e10cSrcweir 			if ( uriRef.is() )
127cdf0e10cSrcweir 			{
128cdf0e10cSrcweir 				Reference < uri::XVndSunStarExpandUrl > sxUri( uriRef, UNO_QUERY );
129cdf0e10cSrcweir 				if( !sxUri.is() )
130cdf0e10cSrcweir 					break;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 				aRetURL = sxUri->expand( xMacroExpander );
133cdf0e10cSrcweir 			}
134cdf0e10cSrcweir 		}
135cdf0e10cSrcweir  	}
136cdf0e10cSrcweir 	return aRetURL;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir Databases::Databases( sal_Bool showBasic,
140cdf0e10cSrcweir 					  const rtl::OUString& instPath,
141cdf0e10cSrcweir 					  const com::sun::star::uno::Sequence< rtl::OUString >& imagesZipPaths,
142cdf0e10cSrcweir 					  const rtl::OUString& productName,
143cdf0e10cSrcweir 					  const rtl::OUString& productVersion,
144cdf0e10cSrcweir 					  const rtl::OUString& styleSheet,
145cdf0e10cSrcweir 					  Reference< uno::XComponentContext > xContext )
146cdf0e10cSrcweir 	: m_xContext( xContext ),
147cdf0e10cSrcweir 	  m_bShowBasic(showBasic),
148cdf0e10cSrcweir 	  m_nErrorDocLength( 0 ),
149cdf0e10cSrcweir 	  m_pErrorDoc( 0 ),
150cdf0e10cSrcweir 	  m_nCustomCSSDocLength( 0 ),
151cdf0e10cSrcweir 	  m_pCustomCSSDoc( 0 ),
152cdf0e10cSrcweir 	  m_aCSS(styleSheet.toAsciiLowerCase()),
153cdf0e10cSrcweir 	  newProdName(rtl::OUString::createFromAscii( "$[officename]" ) ),
154cdf0e10cSrcweir       newProdVersion(rtl::OUString::createFromAscii( "$[officeversion]" ) ),
155cdf0e10cSrcweir       prodName( rtl::OUString::createFromAscii( "%PRODUCTNAME" ) ),
156cdf0e10cSrcweir 	  prodVersion( rtl::OUString::createFromAscii( "%PRODUCTVERSION" ) ),
157cdf0e10cSrcweir 	  vendName( rtl::OUString::createFromAscii( "%VENDORNAME" ) ),
158cdf0e10cSrcweir 	  vendVersion( rtl::OUString::createFromAscii( "%VENDORVERSION" ) ),
159cdf0e10cSrcweir 	  vendShort( rtl::OUString::createFromAscii( "%VENDORSHORT" ) ),
160cdf0e10cSrcweir 	  m_aImagesZipPaths( imagesZipPaths ),
161cdf0e10cSrcweir 	  m_nSymbolsStyle( 0 )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir 	m_xSMgr = Reference< XMultiComponentFactory >( m_xContext->getServiceManager(), UNO_QUERY );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 	m_vAdd[0] = 12;
166cdf0e10cSrcweir 	m_vAdd[1] = 15;
167cdf0e10cSrcweir 	m_vAdd[2] = 11;
168cdf0e10cSrcweir 	m_vAdd[3] = 14;
169cdf0e10cSrcweir 	m_vAdd[4] = 12;
170cdf0e10cSrcweir 	m_vAdd[5] = 13;
171cdf0e10cSrcweir     m_vAdd[6] = 16;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	m_vReplacement[0] = productName;
174cdf0e10cSrcweir 	m_vReplacement[1] = productVersion;
175cdf0e10cSrcweir     // m_vReplacement[2...4] (vendorName/-Version/-Short) are empty strings
176cdf0e10cSrcweir 	m_vReplacement[5] = productName;
177cdf0e10cSrcweir     m_vReplacement[6] = productVersion;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 	setInstallPath( instPath );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	m_xSFA = Reference< ucb::XSimpleFileAccess >(
182cdf0e10cSrcweir 		m_xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ),
183cdf0e10cSrcweir 		m_xContext ), UNO_QUERY_THROW );
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir Databases::~Databases()
187cdf0e10cSrcweir {
188cdf0e10cSrcweir 	// release stylesheet
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	delete[] m_pCustomCSSDoc;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	// release errorDocument
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	delete[] m_pErrorDoc;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	// unload the databases
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	{
199cdf0e10cSrcweir 		// DatabasesTable
200cdf0e10cSrcweir 		DatabasesTable::iterator it = m_aDatabases.begin();
201cdf0e10cSrcweir 		while( it != m_aDatabases.end() )
202cdf0e10cSrcweir 		{
203cdf0e10cSrcweir             delete it->second;
204cdf0e10cSrcweir             ++it;
205cdf0e10cSrcweir 		}
206cdf0e10cSrcweir 	}
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		//  ModInfoTable
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 		ModInfoTable::iterator it = m_aModInfo.begin();
212cdf0e10cSrcweir 		while( it != m_aModInfo.end() )
213cdf0e10cSrcweir 		{
214cdf0e10cSrcweir 			delete it->second;
215cdf0e10cSrcweir 			++it;
216cdf0e10cSrcweir 		}
217cdf0e10cSrcweir 	}
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	{
220cdf0e10cSrcweir 		// KeywordInfoTable
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 		KeywordInfoTable::iterator it = m_aKeywordInfo.begin();
223cdf0e10cSrcweir 		while( it != m_aKeywordInfo.end() )
224cdf0e10cSrcweir 		{
225cdf0e10cSrcweir 			delete it->second;
226cdf0e10cSrcweir 			++it;
227cdf0e10cSrcweir 		}
228cdf0e10cSrcweir 	}
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir static bool impl_getZipFile(
232cdf0e10cSrcweir         Sequence< rtl::OUString > & rImagesZipPaths,
233cdf0e10cSrcweir         const rtl::OUString & rZipName,
234cdf0e10cSrcweir         rtl::OUString & rFileName )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir     const rtl::OUString *pPathArray = rImagesZipPaths.getArray();
237cdf0e10cSrcweir     for ( int i = 0; i < rImagesZipPaths.getLength(); ++i )
238cdf0e10cSrcweir     {
239cdf0e10cSrcweir         rFileName = pPathArray[ i ];
240cdf0e10cSrcweir         if ( rFileName.getLength() )
241cdf0e10cSrcweir         {
242cdf0e10cSrcweir             if ( 1 + rFileName.lastIndexOf( '/' ) != rFileName.getLength() )
243cdf0e10cSrcweir             {
244cdf0e10cSrcweir                 rFileName += rtl::OUString::createFromAscii( "/" );
245cdf0e10cSrcweir             }
246cdf0e10cSrcweir             rFileName += rZipName;
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             // test existence
249cdf0e10cSrcweir             osl::DirectoryItem aDirItem;
250cdf0e10cSrcweir             if ( osl::DirectoryItem::get( rFileName, aDirItem ) == osl::FileBase::E_None )
251cdf0e10cSrcweir                 return true;
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir     return false;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir rtl::OString Databases::getImagesZipFileURL()
258cdf0e10cSrcweir {
259cdf0e10cSrcweir     //sal_Int16 nSymbolsStyle = SvtMiscOptions().GetCurrentSymbolsStyle();
260cdf0e10cSrcweir     sal_Int16 nSymbolsStyle = 0;
261cdf0e10cSrcweir     try
262cdf0e10cSrcweir     {
263cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xConfigProvider(
264cdf0e10cSrcweir             m_xSMgr ->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"), m_xContext), uno::UNO_QUERY_THROW);
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         // set root path
267cdf0e10cSrcweir         uno::Sequence < uno::Any > lParams(1);
268cdf0e10cSrcweir         beans::PropertyValue                       aParam ;
269cdf0e10cSrcweir         aParam.Name    = ::rtl::OUString::createFromAscii("nodepath");
270cdf0e10cSrcweir         aParam.Value <<= ::rtl::OUString::createFromAscii("org.openoffice.Office.Common");
271cdf0e10cSrcweir         lParams[0] = uno::makeAny(aParam);
272cdf0e10cSrcweir 
273cdf0e10cSrcweir         // open it
274cdf0e10cSrcweir         uno::Reference< uno::XInterface > xCFG( xConfigProvider->createInstanceWithArguments(
275cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"),
276cdf0e10cSrcweir                     lParams) );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir         bool bChanged = false;
279cdf0e10cSrcweir 		uno::Reference< container::XHierarchicalNameAccess > xAccess(xCFG, uno::UNO_QUERY_THROW);
280cdf0e10cSrcweir         uno::Any aResult = xAccess->getByHierarchicalName(::rtl::OUString::createFromAscii("Misc/SymbolSet"));
281cdf0e10cSrcweir         if ( (aResult >>= nSymbolsStyle) && m_nSymbolsStyle != nSymbolsStyle )
282cdf0e10cSrcweir 		{
283cdf0e10cSrcweir 			m_nSymbolsStyle = nSymbolsStyle;
284cdf0e10cSrcweir 			bChanged = true;
285cdf0e10cSrcweir 		}
286cdf0e10cSrcweir 
287cdf0e10cSrcweir         if ( !m_aImagesZipFileURL.getLength() || bChanged )
288cdf0e10cSrcweir         {
289cdf0e10cSrcweir             rtl::OUString aImageZip, aSymbolsStyleName;
290cdf0e10cSrcweir 			aResult = xAccess->getByHierarchicalName(::rtl::OUString::createFromAscii("Misc/SymbolStyle"));
291cdf0e10cSrcweir 			aResult >>= aSymbolsStyleName;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir             bool bFound = false;
294cdf0e10cSrcweir             if ( aSymbolsStyleName.getLength() != 0 )
295cdf0e10cSrcweir             {
296cdf0e10cSrcweir                 rtl::OUString aZipName = rtl::OUString::createFromAscii( "images_" );
297cdf0e10cSrcweir                 aZipName += aSymbolsStyleName;
298cdf0e10cSrcweir                 aZipName += rtl::OUString::createFromAscii( ".zip" );
299cdf0e10cSrcweir 
300cdf0e10cSrcweir                 bFound = impl_getZipFile( m_aImagesZipPaths, aZipName, aImageZip );
301cdf0e10cSrcweir             }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir             if ( ! bFound )
304cdf0e10cSrcweir                 bFound = impl_getZipFile( m_aImagesZipPaths, rtl::OUString::createFromAscii( "images.zip" ), aImageZip );
305cdf0e10cSrcweir 
306cdf0e10cSrcweir             if ( ! bFound )
307cdf0e10cSrcweir                 aImageZip = rtl::OUString();
308cdf0e10cSrcweir 
309cdf0e10cSrcweir             m_aImagesZipFileURL = rtl::OUStringToOString(
310cdf0e10cSrcweir                         rtl::Uri::encode(
311cdf0e10cSrcweir                             aImageZip,
312cdf0e10cSrcweir                             rtl_UriCharClassPchar,
313cdf0e10cSrcweir                             rtl_UriEncodeIgnoreEscapes,
314cdf0e10cSrcweir                             RTL_TEXTENCODING_UTF8 ), RTL_TEXTENCODING_UTF8 );
315cdf0e10cSrcweir         }
316cdf0e10cSrcweir     }
317cdf0e10cSrcweir     catch ( NoSuchElementException const & )
318cdf0e10cSrcweir     {
319cdf0e10cSrcweir     }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     return m_aImagesZipFileURL;
322cdf0e10cSrcweir }
323cdf0e10cSrcweir 
324cdf0e10cSrcweir void Databases::replaceName( rtl::OUString& oustring ) const
325cdf0e10cSrcweir {
326cdf0e10cSrcweir 	sal_Int32 idx = -1,idx1 = -1,idx2 = -1,k = 0,off;
327cdf0e10cSrcweir 	bool cap = false;
328cdf0e10cSrcweir 	rtl::OUStringBuffer aStrBuf( 0 );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	while( true )
331cdf0e10cSrcweir 	{
332cdf0e10cSrcweir         ++idx;
333cdf0e10cSrcweir         idx1 = oustring.indexOf( sal_Unicode('%'),idx);
334cdf0e10cSrcweir         idx2 = oustring.indexOf( sal_Unicode('$'),idx);
335cdf0e10cSrcweir 
336cdf0e10cSrcweir         if(idx1 == -1 && idx2 == -1)
337cdf0e10cSrcweir             break;
338cdf0e10cSrcweir 
339cdf0e10cSrcweir         if(idx1 == -1)
340cdf0e10cSrcweir             idx = idx2;
341cdf0e10cSrcweir         else if(idx2 == -1)
342cdf0e10cSrcweir             idx = idx1;
343cdf0e10cSrcweir         else {
344cdf0e10cSrcweir             // no index is zero
345cdf0e10cSrcweir             if(idx1 < idx2)
346cdf0e10cSrcweir                 idx = idx1;
347cdf0e10cSrcweir             else if(idx2 < idx1 )
348cdf0e10cSrcweir                 idx = idx2;
349cdf0e10cSrcweir         }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 		if( oustring.indexOf( prodName,idx ) == idx )
352cdf0e10cSrcweir 			off = PRODUCTNAME;
353cdf0e10cSrcweir 		else if( oustring.indexOf( prodVersion,idx ) == idx )
354cdf0e10cSrcweir 			off = PRODUCTVERSION;
355cdf0e10cSrcweir 		else if( oustring.indexOf( vendName,idx ) == idx )
356cdf0e10cSrcweir 			off = VENDORNAME;
357cdf0e10cSrcweir 		else if( oustring.indexOf( vendVersion,idx ) == idx )
358cdf0e10cSrcweir 			off = VENDORVERSION;
359cdf0e10cSrcweir 		else if( oustring.indexOf( vendShort,idx ) == idx )
360cdf0e10cSrcweir 			off = VENDORSHORT;
361cdf0e10cSrcweir 		else if( oustring.indexOf( newProdName,idx ) == idx )
362cdf0e10cSrcweir 			off = NEWPRODUCTNAME;
363cdf0e10cSrcweir 		else if( oustring.indexOf( newProdVersion,idx ) == idx )
364cdf0e10cSrcweir 			off = NEWPRODUCTVERSION;
365cdf0e10cSrcweir 		else
366cdf0e10cSrcweir 			off = -1;
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 		if( off != -1 )
369cdf0e10cSrcweir 		{
370cdf0e10cSrcweir 			if( ! cap )
371cdf0e10cSrcweir 			{
372cdf0e10cSrcweir 				cap = true;
373cdf0e10cSrcweir 				aStrBuf.ensureCapacity( 256 );
374cdf0e10cSrcweir 			}
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 			aStrBuf.append( &oustring.getStr()[k],idx - k );
377cdf0e10cSrcweir 			aStrBuf.append( m_vReplacement[off] );
378cdf0e10cSrcweir 			k = idx + m_vAdd[off];
379cdf0e10cSrcweir 		}
380cdf0e10cSrcweir 	}
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 	if( cap )
383cdf0e10cSrcweir 	{
384cdf0e10cSrcweir 		if( k < oustring.getLength() )
385cdf0e10cSrcweir 			aStrBuf.append( &oustring.getStr()[k],oustring.getLength()-k );
386cdf0e10cSrcweir 		oustring = aStrBuf.makeStringAndClear();
387cdf0e10cSrcweir 	}
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 
393cdf0e10cSrcweir rtl::OUString Databases::getInstallPathAsSystemPath()
394cdf0e10cSrcweir {
395cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 	if( ! m_aInstallDirectoryAsSystemPath.getLength() )
398cdf0e10cSrcweir 	{
399cdf0e10cSrcweir #ifdef DBG_UTIL
400cdf0e10cSrcweir 		bool bla =
401cdf0e10cSrcweir 			osl::FileBase::E_None ==
402cdf0e10cSrcweir 			osl::FileBase::getSystemPathFromFileURL( m_aInstallDirectory,m_aInstallDirectoryAsSystemPath );
403cdf0e10cSrcweir         VOS_ENSURE( bla,"HelpProvider, no installpath" );
404cdf0e10cSrcweir #else
405cdf0e10cSrcweir         osl::FileBase::getSystemPathFromFileURL( m_aInstallDirectory,m_aInstallDirectoryAsSystemPath );
406cdf0e10cSrcweir #endif
407cdf0e10cSrcweir 	}
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 	return m_aInstallDirectoryAsSystemPath;
410cdf0e10cSrcweir }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir rtl::OUString Databases::getInstallPathAsURL()
413cdf0e10cSrcweir {
414cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
415cdf0e10cSrcweir 
416cdf0e10cSrcweir   	return m_aInstallDirectory;
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 
420cdf0e10cSrcweir const std::vector< rtl::OUString >& Databases::getModuleList( const rtl::OUString& Language )
421cdf0e10cSrcweir {
422cdf0e10cSrcweir 	if( m_avModules.size() == 0 )
423cdf0e10cSrcweir 	{
424cdf0e10cSrcweir 		rtl::OUString  fileName,dirName = getInstallPathAsURL() + processLang( Language );
425cdf0e10cSrcweir 		osl::Directory dirFile( dirName );
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 		osl::DirectoryItem aDirItem;
428cdf0e10cSrcweir 		osl::FileStatus    aStatus( FileStatusMask_FileName );
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 		sal_Int32 idx;
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 		if( osl::FileBase::E_None != dirFile.open() )
433cdf0e10cSrcweir 			return m_avModules;
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 		while( dirFile.getNextItem( aDirItem ) == osl::FileBase::E_None &&
436cdf0e10cSrcweir 			   aDirItem.getFileStatus( aStatus ) == osl::FileBase::E_None )
437cdf0e10cSrcweir 		{
438cdf0e10cSrcweir 			if( ! aStatus.isValid( FileStatusMask_FileName ) )
439cdf0e10cSrcweir 				continue;
440cdf0e10cSrcweir 
441cdf0e10cSrcweir 			fileName = aStatus.getFileName();
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 			// Check, whether fileName is of the form *.cfg
444cdf0e10cSrcweir 			idx = fileName.lastIndexOf(  sal_Unicode( '.' ) );
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 			if( idx == -1 )
447cdf0e10cSrcweir 				continue;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 			const sal_Unicode* str = fileName.getStr();
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 			if( fileName.getLength() == idx + 4                   &&
452cdf0e10cSrcweir 				( str[idx + 1] == 'c' || str[idx + 1] == 'C' )    &&
453cdf0e10cSrcweir 				( str[idx + 2] == 'f' || str[idx + 2] == 'F' )    &&
454cdf0e10cSrcweir 				( str[idx + 3] == 'g' || str[idx + 3] == 'G' )    &&
455cdf0e10cSrcweir 				( fileName = fileName.copy(0,idx).toAsciiLowerCase() ).compareToAscii( "picture" ) != 0 ) {
456cdf0e10cSrcweir 			  if(! m_bShowBasic && fileName.compareToAscii("sbasic") == 0 )
457cdf0e10cSrcweir 				continue;
458cdf0e10cSrcweir 			  m_avModules.push_back( fileName );
459cdf0e10cSrcweir 			}
460cdf0e10cSrcweir 		}
461cdf0e10cSrcweir 	}
462cdf0e10cSrcweir 	return m_avModules;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 
467cdf0e10cSrcweir StaticModuleInformation* Databases::getStaticInformationForModule( const rtl::OUString& Module,
468cdf0e10cSrcweir 																   const rtl::OUString& Language )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 	rtl::OUString key = processLang(Language) + rtl::OUString::createFromAscii( "/" ) + Module;
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 	std::pair< ModInfoTable::iterator,bool > aPair =
475cdf0e10cSrcweir 		m_aModInfo.insert( ModInfoTable::value_type( key,0 ) );
476cdf0e10cSrcweir 
477cdf0e10cSrcweir 	ModInfoTable::iterator it = aPair.first;
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 	if( aPair.second && ! it->second )
480cdf0e10cSrcweir 	{
481cdf0e10cSrcweir 		osl::File cfgFile( getInstallPathAsURL() +
482cdf0e10cSrcweir 						   key +
483cdf0e10cSrcweir 						   rtl::OUString::createFromAscii( ".cfg" ) );
484cdf0e10cSrcweir 
485cdf0e10cSrcweir 		if( osl::FileBase::E_None != cfgFile.open( OpenFlag_Read ) )
486cdf0e10cSrcweir 			it->second = 0;
487cdf0e10cSrcweir 		else
488cdf0e10cSrcweir 		{
489cdf0e10cSrcweir 			sal_uInt32 pos = 0;
490cdf0e10cSrcweir 			sal_uInt64 nRead;
491cdf0e10cSrcweir 			sal_Char buffer[2048];
492cdf0e10cSrcweir 			sal_Unicode lineBuffer[1028];
493cdf0e10cSrcweir 			rtl::OUString fileContent;
494cdf0e10cSrcweir 
495cdf0e10cSrcweir 			while( osl::FileBase::E_None == cfgFile.read( &buffer,2048,nRead ) && nRead )
496cdf0e10cSrcweir 				fileContent += rtl::OUString( buffer,sal_Int32( nRead ),RTL_TEXTENCODING_UTF8 );
497cdf0e10cSrcweir 
498cdf0e10cSrcweir 			cfgFile.close();
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 			const sal_Unicode* str = fileContent.getStr();
501cdf0e10cSrcweir 			rtl::OUString current,lang_,program,startid,title,heading,fulltext;
502cdf0e10cSrcweir             rtl::OUString order = rtl::OUString::createFromAscii( "1" );
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 			for( sal_Int32 i = 0;i < fileContent.getLength();i++ )
505cdf0e10cSrcweir 			{
506cdf0e10cSrcweir 				sal_Unicode ch = str[ i ];
507cdf0e10cSrcweir 				if( ch == sal_Unicode( '\n' ) || ch == sal_Unicode( '\r' ) )
508cdf0e10cSrcweir 				{
509cdf0e10cSrcweir 					if( pos )
510cdf0e10cSrcweir 					{
511cdf0e10cSrcweir 						current = rtl::OUString( lineBuffer,pos );
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 						if( current.compareToAscii( "Title",5 ) == 0 )
514cdf0e10cSrcweir 						{
515cdf0e10cSrcweir 							title = current.copy( current.indexOf(sal_Unicode( '=' ) ) + 1 );
516cdf0e10cSrcweir 						}
517cdf0e10cSrcweir 						else if( current.compareToAscii( "Start",5 ) == 0 )
518cdf0e10cSrcweir 						{
519cdf0e10cSrcweir 							startid = current.copy( current.indexOf('=') + 1 );
520cdf0e10cSrcweir 						}
521cdf0e10cSrcweir 						else if( current.compareToAscii( "Language",8 ) == 0 )
522cdf0e10cSrcweir 						{
523cdf0e10cSrcweir 							lang_ = current.copy( current.indexOf('=') + 1 );
524cdf0e10cSrcweir 						}
525cdf0e10cSrcweir 						else if( current.compareToAscii( "Program",7 ) == 0 )
526cdf0e10cSrcweir 						{
527cdf0e10cSrcweir 							program = current.copy( current.indexOf('=') + 1 );
528cdf0e10cSrcweir 						}
529cdf0e10cSrcweir 						else if( current.compareToAscii( "Heading",7 ) == 0 )
530cdf0e10cSrcweir 						{
531cdf0e10cSrcweir 							heading = current.copy( current.indexOf('=') + 1 );
532cdf0e10cSrcweir 						}
533cdf0e10cSrcweir 						else if( current.compareToAscii( "FullText",8 ) == 0 )
534cdf0e10cSrcweir 						{
535cdf0e10cSrcweir 							fulltext = current.copy( current.indexOf('=') + 1 );
536cdf0e10cSrcweir 						}
537cdf0e10cSrcweir 						else if( current.compareToAscii( "Order",5 ) == 0 )
538cdf0e10cSrcweir 						{
539cdf0e10cSrcweir 							order = current.copy( current.indexOf('=') + 1 );
540cdf0e10cSrcweir 						}
541cdf0e10cSrcweir 					}
542cdf0e10cSrcweir 					pos = 0;
543cdf0e10cSrcweir 				}
544cdf0e10cSrcweir 				else
545cdf0e10cSrcweir 					lineBuffer[ pos++ ] = ch;
546cdf0e10cSrcweir 			}
547cdf0e10cSrcweir 			replaceName( title );
548cdf0e10cSrcweir 			it->second = new StaticModuleInformation( title,
549cdf0e10cSrcweir 													  startid,
550cdf0e10cSrcweir 													  program,
551cdf0e10cSrcweir 													  heading,
552cdf0e10cSrcweir 													  fulltext,
553cdf0e10cSrcweir 													  order );
554cdf0e10cSrcweir 		}
555cdf0e10cSrcweir 	}
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 	return it->second;
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 
563cdf0e10cSrcweir rtl::OUString Databases::processLang( const rtl::OUString& Language )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	rtl::OUString ret;
568cdf0e10cSrcweir 	LangSetTable::iterator it = m_aLangSet.find( Language );
569cdf0e10cSrcweir 
570cdf0e10cSrcweir 	if( it == m_aLangSet.end() )
571cdf0e10cSrcweir 	{
572cdf0e10cSrcweir 		sal_Int32 idx;
573cdf0e10cSrcweir 		osl::DirectoryItem aDirItem;
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 		if( osl::FileBase::E_None == osl::DirectoryItem::get( getInstallPathAsURL() + Language,aDirItem ) )
576cdf0e10cSrcweir 		{
577cdf0e10cSrcweir 			ret = Language;
578cdf0e10cSrcweir 			m_aLangSet[ Language ] = ret;
579cdf0e10cSrcweir 		}
580cdf0e10cSrcweir 		else if( ( ( idx = Language.indexOf( '-' ) ) != -1 ||
581cdf0e10cSrcweir 				   ( idx = Language.indexOf( '_' ) ) != -1 ) &&
582cdf0e10cSrcweir 					osl::FileBase::E_None == osl::DirectoryItem::get( getInstallPathAsURL() + Language.copy( 0,idx ),
583cdf0e10cSrcweir 																   aDirItem ) )
584cdf0e10cSrcweir 		{
585cdf0e10cSrcweir 			ret = Language.copy( 0,idx );
586cdf0e10cSrcweir 			m_aLangSet[ Language ] = ret;
587cdf0e10cSrcweir 		}
588cdf0e10cSrcweir 	}
589cdf0e10cSrcweir 	else
590cdf0e10cSrcweir 		ret = it->second;
591cdf0e10cSrcweir 
592cdf0e10cSrcweir 	return ret;
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 
596cdf0e10cSrcweir rtl::OUString Databases::country( const rtl::OUString& Language )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir 	sal_Int32 idx;
599cdf0e10cSrcweir 	if( ( idx = Language.indexOf( '-' ) ) != -1 ||
600cdf0e10cSrcweir 		( idx = Language.indexOf( '_' ) ) != -1 )
601cdf0e10cSrcweir 		return Language.copy( 1+idx );
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 	return rtl::OUString();
604cdf0e10cSrcweir }
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 
608*70e197d9SHerbert Dürr helpdatafileproxy::Hdf* Databases::getHelpDataFile( const rtl::OUString& Database,
609cdf0e10cSrcweir 							const rtl::OUString& Language, bool helpText,
610cdf0e10cSrcweir 							const rtl::OUString* pExtensionPath )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir 	if( ! Database.getLength() || ! Language.getLength() )
613cdf0e10cSrcweir 		return 0;
614cdf0e10cSrcweir 
615cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 	rtl::OUString aFileExt( rtl::OUString::createFromAscii( helpText ? ".ht" : ".db" ) );
619cdf0e10cSrcweir 	rtl::OUString dbFileName = aSlash + Database + aFileExt;
620cdf0e10cSrcweir 	rtl::OUString key;
621cdf0e10cSrcweir 	if( pExtensionPath == NULL )
622cdf0e10cSrcweir 		key = processLang( Language ) + dbFileName;
623cdf0e10cSrcweir 	else
624cdf0e10cSrcweir 		key = *pExtensionPath + Language + dbFileName;		// make unique, don't change language
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 	std::pair< DatabasesTable::iterator,bool > aPair =
627cdf0e10cSrcweir 		m_aDatabases.insert( DatabasesTable::value_type( key,0 ) );
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 	DatabasesTable::iterator it = aPair.first;
630cdf0e10cSrcweir 
631cdf0e10cSrcweir 	if( aPair.second && ! it->second )
632cdf0e10cSrcweir 	{
633*70e197d9SHerbert Dürr 		helpdatafileproxy::Hdf* pHdf = 0;
634cdf0e10cSrcweir 
635cdf0e10cSrcweir 		rtl::OUString fileURL;
636cdf0e10cSrcweir 		if( pExtensionPath )
637cdf0e10cSrcweir             fileURL = expandURL(*pExtensionPath) + Language + dbFileName;
638cdf0e10cSrcweir 		else
639cdf0e10cSrcweir             fileURL = getInstallPathAsURL() + key;
640cdf0e10cSrcweir 
641*70e197d9SHerbert Dürr 		rtl::OUString fileNameHDFHelp( fileURL );
642cdf0e10cSrcweir         //Extensions always use the new format
643cdf0e10cSrcweir 		if( pExtensionPath != NULL )
644*70e197d9SHerbert Dürr 			fileNameHDFHelp += rtl::OUString::createFromAscii( "_" );
645cdf0e10cSrcweir         //SimpleFileAccess takes file URLs as arguments!!! Using filenames works accidentally but
646cdf0e10cSrcweir         //fails for example when using long path names on Windows (starting with \\?\)
647*70e197d9SHerbert Dürr 		if( m_xSFA->exists( fileNameHDFHelp ) )
648cdf0e10cSrcweir 		{
649*70e197d9SHerbert Dürr 			pHdf = new helpdatafileproxy::Hdf( fileNameHDFHelp, m_xSFA );
650cdf0e10cSrcweir 		}
651cdf0e10cSrcweir 
652*70e197d9SHerbert Dürr 		it->second = pHdf;
653cdf0e10cSrcweir 	}
654cdf0e10cSrcweir 
655cdf0e10cSrcweir 	return it->second;
656cdf0e10cSrcweir }
657cdf0e10cSrcweir 
658cdf0e10cSrcweir Reference< XCollator >
659cdf0e10cSrcweir Databases::getCollator( const rtl::OUString& Language,
660cdf0e10cSrcweir 						const rtl::OUString& System )
661cdf0e10cSrcweir {
662cdf0e10cSrcweir 	(void)System;
663cdf0e10cSrcweir 
664cdf0e10cSrcweir 	rtl::OUString key = Language;
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 	CollatorTable::iterator it =
669cdf0e10cSrcweir 		m_aCollatorTable.insert( CollatorTable::value_type( key,0 ) ).first;
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 	if( ! it->second.is() )
672cdf0e10cSrcweir 	{
673cdf0e10cSrcweir 		it->second =
674cdf0e10cSrcweir 			Reference< XCollator > (
675cdf0e10cSrcweir 				m_xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.i18n.Collator" ),
676cdf0e10cSrcweir 				m_xContext ), UNO_QUERY );
677cdf0e10cSrcweir 		rtl::OUString langStr = processLang(Language);
678cdf0e10cSrcweir 		rtl::OUString countryStr = country(Language);
679cdf0e10cSrcweir 		if( !countryStr.getLength() )
680cdf0e10cSrcweir 		{
681cdf0e10cSrcweir 			if( langStr.compareToAscii("de") == 0 )
682cdf0e10cSrcweir 				countryStr = rtl::OUString::createFromAscii("DE");
683cdf0e10cSrcweir 			else if( langStr.compareToAscii("en") == 0 )
684cdf0e10cSrcweir 				countryStr = rtl::OUString::createFromAscii("US");
685cdf0e10cSrcweir 			else if( langStr.compareToAscii("es") == 0 )
686cdf0e10cSrcweir 				countryStr = rtl::OUString::createFromAscii("ES");
687cdf0e10cSrcweir 			else if( langStr.compareToAscii("it") == 0 )
688cdf0e10cSrcweir 				countryStr = rtl::OUString::createFromAscii("IT");
689cdf0e10cSrcweir 			else if( langStr.compareToAscii("fr") == 0 )
690cdf0e10cSrcweir 				countryStr = rtl::OUString::createFromAscii("FR");
691cdf0e10cSrcweir 			else if( langStr.compareToAscii("sv") == 0 )
692cdf0e10cSrcweir 				countryStr = rtl::OUString::createFromAscii("SE");
693cdf0e10cSrcweir 			else if( langStr.compareToAscii("ja") == 0 )
694cdf0e10cSrcweir 				countryStr = rtl::OUString::createFromAscii("JP");
695cdf0e10cSrcweir 			else if( langStr.compareToAscii("ko") == 0 )
696cdf0e10cSrcweir 				countryStr = rtl::OUString::createFromAscii("KR");
697cdf0e10cSrcweir 		}
698cdf0e10cSrcweir 		it->second->loadDefaultCollator(  Locale( langStr,
699cdf0e10cSrcweir 												  countryStr,
700cdf0e10cSrcweir 												  rtl::OUString() ),
701cdf0e10cSrcweir 										  0 );
702cdf0e10cSrcweir 	}
703cdf0e10cSrcweir 
704cdf0e10cSrcweir 	return it->second;
705cdf0e10cSrcweir }
706cdf0e10cSrcweir 
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 
709cdf0e10cSrcweir namespace chelp {
710cdf0e10cSrcweir 
711cdf0e10cSrcweir     struct KeywordElementComparator
712cdf0e10cSrcweir     {
713cdf0e10cSrcweir         KeywordElementComparator( const Reference< XCollator >& xCollator )
714cdf0e10cSrcweir             : m_xCollator( xCollator )
715cdf0e10cSrcweir         { }
716cdf0e10cSrcweir 
717cdf0e10cSrcweir         bool operator()( const KeywordInfo::KeywordElement& la,
718cdf0e10cSrcweir                          const KeywordInfo::KeywordElement& ra ) const
719cdf0e10cSrcweir         {
720cdf0e10cSrcweir             const rtl::OUString& l = la.key;
721cdf0e10cSrcweir             const rtl::OUString& r = ra.key;
722cdf0e10cSrcweir 
723cdf0e10cSrcweir             bool ret;
724cdf0e10cSrcweir 
725cdf0e10cSrcweir             if( m_xCollator.is() )
726cdf0e10cSrcweir             {
727cdf0e10cSrcweir                 sal_Int32 l1 = l.indexOf( sal_Unicode( ';' ) );
728cdf0e10cSrcweir                 sal_Int32 l3 = ( l1 == -1 ? l.getLength() : l1 );
729cdf0e10cSrcweir 
730cdf0e10cSrcweir                 sal_Int32 r1 = r.indexOf( sal_Unicode( ';' ) );
731cdf0e10cSrcweir                 sal_Int32 r3 = ( r1 == -1 ? r.getLength() : r1 );
732cdf0e10cSrcweir 
733cdf0e10cSrcweir                 sal_Int32 c1 = m_xCollator->compareSubstring( l,0,l3,r,0,r3 );
734cdf0e10cSrcweir 
735cdf0e10cSrcweir                 if( c1 == +1 )
736cdf0e10cSrcweir                     ret = false;
737cdf0e10cSrcweir                 else if( c1 == 0 )
738cdf0e10cSrcweir                 {
739cdf0e10cSrcweir                     sal_Int32 l2 = l.getLength() - l1 - 1;
740cdf0e10cSrcweir                     sal_Int32 r2 = r.getLength() - r1 - 1;
741cdf0e10cSrcweir                     ret = ( m_xCollator->compareSubstring( l,1+l1,l2,r,1+r1,r2 ) < 0 );
742cdf0e10cSrcweir                 }
743cdf0e10cSrcweir                 else
744cdf0e10cSrcweir                     ret = true;
745cdf0e10cSrcweir             }
746cdf0e10cSrcweir             else
747cdf0e10cSrcweir                 ret = bool( l < r );
748cdf0e10cSrcweir 
749cdf0e10cSrcweir             return ret;
750cdf0e10cSrcweir         }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir         Reference< XCollator > m_xCollator;
753cdf0e10cSrcweir     }; // end struct KeywordElementComparator
754cdf0e10cSrcweir 
755cdf0e10cSrcweir }
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 
759cdf0e10cSrcweir KeywordInfo::KeywordElement::KeywordElement( Databases *pDatabases,
760*70e197d9SHerbert Dürr 											 helpdatafileproxy::Hdf* pHdf,
761cdf0e10cSrcweir 											 rtl::OUString& ky,
762cdf0e10cSrcweir 											 rtl::OUString& data )
763cdf0e10cSrcweir 	: key( ky )
764cdf0e10cSrcweir {
765cdf0e10cSrcweir 	pDatabases->replaceName( key );
766*70e197d9SHerbert Dürr 	init( pDatabases,pHdf,data );
767cdf0e10cSrcweir }
768cdf0e10cSrcweir 
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 
771*70e197d9SHerbert Dürr void KeywordInfo::KeywordElement::init( Databases *pDatabases,helpdatafileproxy::Hdf* pHdf,const rtl::OUString& ids )
772cdf0e10cSrcweir {
773cdf0e10cSrcweir 	const sal_Unicode* idstr = ids.getStr();
774cdf0e10cSrcweir 	std::vector< rtl::OUString > id,anchor;
775cdf0e10cSrcweir 	int idx = -1,k;
776cdf0e10cSrcweir 	while( ( idx = ids.indexOf( ';',k = ++idx ) ) != -1 )
777cdf0e10cSrcweir 	{
778cdf0e10cSrcweir 		int h = ids.indexOf( sal_Unicode( '#' ),k );
779cdf0e10cSrcweir 		if( h < idx )
780cdf0e10cSrcweir 		{
781cdf0e10cSrcweir 			// found an anchor
782cdf0e10cSrcweir 			id.push_back( rtl::OUString( &idstr[k],h-k ) );
783cdf0e10cSrcweir 			anchor.push_back( rtl::OUString( &idstr[h+1],idx-h-1 ) );
784cdf0e10cSrcweir 		}
785cdf0e10cSrcweir 		else
786cdf0e10cSrcweir 		{
787cdf0e10cSrcweir 			id.push_back( rtl::OUString( &idstr[k],idx-k ) );
788cdf0e10cSrcweir 			anchor.push_back( rtl::OUString() );
789cdf0e10cSrcweir 		}
790cdf0e10cSrcweir 	}
791cdf0e10cSrcweir 
792cdf0e10cSrcweir 	listId.realloc( id.size() );
793cdf0e10cSrcweir 	listAnchor.realloc( id.size() );
794cdf0e10cSrcweir 	listTitle.realloc( id.size() );
795cdf0e10cSrcweir 
796cdf0e10cSrcweir 	int nSize = 0;
797cdf0e10cSrcweir 	const sal_Char* pData = NULL;
798cdf0e10cSrcweir 	const sal_Char pEmpty[] = "";
799cdf0e10cSrcweir 
800cdf0e10cSrcweir 	for( sal_uInt32 i = 0; i < id.size(); ++i )
801cdf0e10cSrcweir 	{
802cdf0e10cSrcweir 		listId[i] = id[i];
803cdf0e10cSrcweir 		listAnchor[i] = anchor[i];
804cdf0e10cSrcweir 
805cdf0e10cSrcweir 		nSize = 0;
806cdf0e10cSrcweir 		pData = pEmpty;
807*70e197d9SHerbert Dürr 		if( pHdf )
808cdf0e10cSrcweir 		{
809cdf0e10cSrcweir 			rtl::OString idi( id[i].getStr(),id[i].getLength(),RTL_TEXTENCODING_UTF8 );
810*70e197d9SHerbert Dürr 			helpdatafileproxy::HDFData aHDFData;
811*70e197d9SHerbert Dürr 			bool bSuccess = pHdf->getValueForKey( idi, aHDFData );
812cdf0e10cSrcweir 			if( bSuccess )
813cdf0e10cSrcweir 			{
814*70e197d9SHerbert Dürr 				nSize = aHDFData.getSize();
815*70e197d9SHerbert Dürr 				pData = aHDFData.getData();
816cdf0e10cSrcweir 			}
817cdf0e10cSrcweir 		}
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 		DbtToStringConverter converter( pData, nSize );
820cdf0e10cSrcweir 
821cdf0e10cSrcweir 		rtl::OUString title = converter.getTitle();
822cdf0e10cSrcweir 		pDatabases->replaceName( title );
823cdf0e10cSrcweir 		listTitle[i] = title;
824cdf0e10cSrcweir 	}
825cdf0e10cSrcweir }
826cdf0e10cSrcweir 
827cdf0e10cSrcweir 
828cdf0e10cSrcweir 
829cdf0e10cSrcweir KeywordInfo::KeywordInfo( const std::vector< KeywordElement >& aVec )
830cdf0e10cSrcweir 	: listKey( aVec.size() ),
831cdf0e10cSrcweir 	  listId( aVec.size() ),
832cdf0e10cSrcweir 	  listAnchor( aVec.size() ),
833cdf0e10cSrcweir 	  listTitle( aVec.size() )
834cdf0e10cSrcweir {
835cdf0e10cSrcweir     for( unsigned int i = 0; i < aVec.size(); ++i )
836cdf0e10cSrcweir 	{
837cdf0e10cSrcweir 		listKey[i] = aVec[i].key;
838cdf0e10cSrcweir 		listId[i] = aVec[i].listId;
839cdf0e10cSrcweir 		listAnchor[i] = aVec[i].listAnchor;
840cdf0e10cSrcweir 		listTitle[i] = aVec[i].listTitle;
841cdf0e10cSrcweir 	}
842cdf0e10cSrcweir }
843cdf0e10cSrcweir 
844cdf0e10cSrcweir bool Databases::checkModuleMatchForExtension
845cdf0e10cSrcweir 	( const rtl::OUString& Database, const rtl::OUString& doclist )
846cdf0e10cSrcweir {
847cdf0e10cSrcweir 	bool bBelongsToDatabase = true;
848cdf0e10cSrcweir 
849cdf0e10cSrcweir 	// Analyse doclist string to find module assignments
850cdf0e10cSrcweir 	bool bFoundAtLeastOneModule = false;
851cdf0e10cSrcweir 	bool bModuleMatch = false;
852cdf0e10cSrcweir 	sal_Int32 nLen = doclist.getLength();
853cdf0e10cSrcweir 	sal_Int32 nLastFound = doclist.lastIndexOf( sal_Unicode(';') );
854cdf0e10cSrcweir 	if( nLastFound == -1 )
855cdf0e10cSrcweir 		nLastFound = nLen;
856cdf0e10cSrcweir 	const sal_Unicode* pStr = doclist.getStr();
857cdf0e10cSrcweir 	sal_Int32 nFound = doclist.lastIndexOf( sal_Unicode('_') );
858cdf0e10cSrcweir 	while( nFound != -1 )
859cdf0e10cSrcweir 	{
860cdf0e10cSrcweir 		// Simple optimization, stop if '_' is followed by "id"
861cdf0e10cSrcweir 		if( nLen - nFound > 2 )
862cdf0e10cSrcweir 		{
863cdf0e10cSrcweir 			if( pStr[ nFound + 1 ] == sal_Unicode('i') &&
864cdf0e10cSrcweir 				pStr[ nFound + 2 ] == sal_Unicode('d') )
865cdf0e10cSrcweir 					break;
866cdf0e10cSrcweir 		}
867cdf0e10cSrcweir 
868cdf0e10cSrcweir 		rtl::OUString aModule = doclist.copy( nFound + 1, nLastFound - nFound - 1 );
869cdf0e10cSrcweir 		std::vector< rtl::OUString >::iterator result = std::find( m_avModules.begin(), m_avModules.end(), aModule );
870cdf0e10cSrcweir 		if( result != m_avModules.end() )
871cdf0e10cSrcweir 		{
872cdf0e10cSrcweir 			bFoundAtLeastOneModule = true;
873cdf0e10cSrcweir 			if( Database == aModule )
874cdf0e10cSrcweir 			{
875cdf0e10cSrcweir 				bModuleMatch = true;
876cdf0e10cSrcweir 				break;
877cdf0e10cSrcweir 			}
878cdf0e10cSrcweir 		}
879cdf0e10cSrcweir 
880cdf0e10cSrcweir 		nLastFound = nFound;
881cdf0e10cSrcweir 		if( nLastFound == 0 )
882cdf0e10cSrcweir 			break;
883cdf0e10cSrcweir 		nFound = doclist.lastIndexOf( sal_Unicode('_'), nLastFound - 1 );
884cdf0e10cSrcweir 	}
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 	if( bFoundAtLeastOneModule && !bModuleMatch )
887cdf0e10cSrcweir 		bBelongsToDatabase = false;
888cdf0e10cSrcweir 
889cdf0e10cSrcweir 	return bBelongsToDatabase;
890cdf0e10cSrcweir }
891cdf0e10cSrcweir 
892cdf0e10cSrcweir 
893cdf0e10cSrcweir KeywordInfo* Databases::getKeyword( const rtl::OUString& Database,
894cdf0e10cSrcweir 									const rtl::OUString& Language )
895cdf0e10cSrcweir {
896cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
897cdf0e10cSrcweir 
898cdf0e10cSrcweir 	rtl::OUString key = processLang(Language) + rtl::OUString::createFromAscii( "/" ) + Database;
899cdf0e10cSrcweir 
900cdf0e10cSrcweir     std::pair< KeywordInfoTable::iterator,bool > aPair =
901cdf0e10cSrcweir 		m_aKeywordInfo.insert( KeywordInfoTable::value_type( key,0 ) );
902cdf0e10cSrcweir 
903cdf0e10cSrcweir 	KeywordInfoTable::iterator it = aPair.first;
904cdf0e10cSrcweir 
905cdf0e10cSrcweir 	if( aPair.second && ! it->second )
906cdf0e10cSrcweir 	{
907cdf0e10cSrcweir 		std::vector<KeywordInfo::KeywordElement> aVector;
908cdf0e10cSrcweir 
909cdf0e10cSrcweir 		KeyDataBaseFileIterator aDbFileIt( m_xContext, *this, Database, Language );
910cdf0e10cSrcweir 		rtl::OUString fileURL;
911cdf0e10cSrcweir 		bool bExtension = false;
912cdf0e10cSrcweir 		while( (fileURL = aDbFileIt.nextDbFile( bExtension )).getLength() > 0 )
913cdf0e10cSrcweir 		{
914*70e197d9SHerbert Dürr 			rtl::OUString fileNameHDFHelp( fileURL );
915cdf0e10cSrcweir 			if( bExtension )
916*70e197d9SHerbert Dürr 				fileNameHDFHelp += rtl::OUString::createFromAscii( "_" );
917*70e197d9SHerbert Dürr 			if( m_xSFA->exists( fileNameHDFHelp ) )
918cdf0e10cSrcweir 			{
919*70e197d9SHerbert Dürr 				helpdatafileproxy::Hdf aHdf( fileNameHDFHelp, m_xSFA );
920cdf0e10cSrcweir 
921*70e197d9SHerbert Dürr 				helpdatafileproxy::HDFData aKey;
922*70e197d9SHerbert Dürr 				helpdatafileproxy::HDFData aValue;
923*70e197d9SHerbert Dürr 				if( aHdf.startIteration() )
924cdf0e10cSrcweir 				{
925*70e197d9SHerbert Dürr 				    helpdatafileproxy::Hdf* pHdf = getHelpDataFile( Database,Language );
926*70e197d9SHerbert Dürr 					if( pHdf != NULL )
927cdf0e10cSrcweir 					{
928cdf0e10cSrcweir 						bool bOptimizeForPerformance = true;
929*70e197d9SHerbert Dürr 						pHdf->releaseHashMap();
930*70e197d9SHerbert Dürr 						pHdf->createHashMap( bOptimizeForPerformance );
931cdf0e10cSrcweir 					}
932cdf0e10cSrcweir 
933*70e197d9SHerbert Dürr 					while( aHdf.getNextKeyAndValue( aKey, aValue ) )
934cdf0e10cSrcweir 					{
935cdf0e10cSrcweir 						rtl::OUString keyword( aKey.getData(), aKey.getSize(),
936cdf0e10cSrcweir 											   RTL_TEXTENCODING_UTF8 );
937cdf0e10cSrcweir 						rtl::OUString doclist( aValue.getData(), aValue.getSize(),
938cdf0e10cSrcweir 											   RTL_TEXTENCODING_UTF8 );
939cdf0e10cSrcweir 
940cdf0e10cSrcweir 						bool bBelongsToDatabase = true;
941cdf0e10cSrcweir 						if( bExtension )
942cdf0e10cSrcweir 							bBelongsToDatabase = checkModuleMatchForExtension( Database, doclist );
943cdf0e10cSrcweir 
944cdf0e10cSrcweir 						if( !bBelongsToDatabase )
945cdf0e10cSrcweir 							continue;
946cdf0e10cSrcweir 
947cdf0e10cSrcweir 						aVector.push_back( KeywordInfo::KeywordElement( this,
948*70e197d9SHerbert Dürr 																		pHdf,
949cdf0e10cSrcweir 																		keyword,
950cdf0e10cSrcweir 																		doclist ) );
951cdf0e10cSrcweir 					}
952*70e197d9SHerbert Dürr 					aHdf.stopIteration();
953cdf0e10cSrcweir 
954*70e197d9SHerbert Dürr 					if( pHdf != NULL )
955*70e197d9SHerbert Dürr 						pHdf->releaseHashMap();
956cdf0e10cSrcweir 				}
957cdf0e10cSrcweir 			}
958cdf0e10cSrcweir 		}
959cdf0e10cSrcweir 
960cdf0e10cSrcweir 		// sorting
961cdf0e10cSrcweir 		Reference< XCollator > xCollator = getCollator( Language,rtl::OUString());
962cdf0e10cSrcweir 		KeywordElementComparator aComparator( xCollator );
963cdf0e10cSrcweir 		std::sort(aVector.begin(),aVector.end(),aComparator);
964cdf0e10cSrcweir 
965cdf0e10cSrcweir 		KeywordInfo* pInfo = it->second = new KeywordInfo( aVector );
966cdf0e10cSrcweir 		(void)pInfo;
967cdf0e10cSrcweir 	}
968cdf0e10cSrcweir 
969cdf0e10cSrcweir 	return it->second;
970cdf0e10cSrcweir }
971cdf0e10cSrcweir 
972cdf0e10cSrcweir Reference< XHierarchicalNameAccess > Databases::jarFile( const rtl::OUString& jar,
973cdf0e10cSrcweir 														 const rtl::OUString& Language )
974cdf0e10cSrcweir {
975cdf0e10cSrcweir 	if( ! jar.getLength() ||
976cdf0e10cSrcweir 		! Language.getLength() )
977cdf0e10cSrcweir     {
978cdf0e10cSrcweir 		return Reference< XHierarchicalNameAccess >( 0 );
979cdf0e10cSrcweir     }
980cdf0e10cSrcweir 	rtl::OUString key = processLang(Language) + aSlash + jar;
981cdf0e10cSrcweir 
982cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
983cdf0e10cSrcweir 
984cdf0e10cSrcweir 	ZipFileTable::iterator it =
985cdf0e10cSrcweir 		m_aZipFileTable.insert( ZipFileTable::value_type( key,Reference< XHierarchicalNameAccess >(0) ) ).first;
986cdf0e10cSrcweir 
987cdf0e10cSrcweir 	if( ! it->second.is() )
988cdf0e10cSrcweir 	{
989cdf0e10cSrcweir         rtl::OUString zipFile;
990cdf0e10cSrcweir 		try
991cdf0e10cSrcweir 		{
992cdf0e10cSrcweir 			// Extension jar file? Search for ?
993cdf0e10cSrcweir 	        sal_Int32 nQuestionMark1 = jar.indexOf( sal_Unicode('?') );
994cdf0e10cSrcweir 	        sal_Int32 nQuestionMark2 = jar.lastIndexOf( sal_Unicode('?') );
995cdf0e10cSrcweir 			if( nQuestionMark1 != -1 && nQuestionMark2 != -1 && nQuestionMark1 != nQuestionMark2 )
996cdf0e10cSrcweir 			{
997cdf0e10cSrcweir 				::rtl::OUString aExtensionPath = jar.copy( nQuestionMark1 + 1, nQuestionMark2 - nQuestionMark1 - 1 );
998cdf0e10cSrcweir 				::rtl::OUString aPureJar = jar.copy( nQuestionMark2 + 1 );
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir 				rtl::OUStringBuffer aStrBuf;
1001cdf0e10cSrcweir 				aStrBuf.append( aExtensionPath );
1002cdf0e10cSrcweir 				aStrBuf.append( aSlash );
1003cdf0e10cSrcweir 				aStrBuf.append( aPureJar );
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir 				zipFile = expandURL( aStrBuf.makeStringAndClear() );
1006cdf0e10cSrcweir 			}
1007cdf0e10cSrcweir 			else
1008cdf0e10cSrcweir 			{
1009cdf0e10cSrcweir 	            zipFile = getInstallPathAsURL() + key;
1010cdf0e10cSrcweir 			}
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir             Sequence< Any > aArguments( 2 );
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir             XInputStream_impl* p = new XInputStream_impl( zipFile );
1015cdf0e10cSrcweir             if( p->CtorSuccess() )
1016cdf0e10cSrcweir             {
1017cdf0e10cSrcweir                 Reference< XInputStream > xInputStream( p );
1018cdf0e10cSrcweir                 aArguments[ 0 ] <<= xInputStream;
1019cdf0e10cSrcweir             }
1020cdf0e10cSrcweir             else
1021cdf0e10cSrcweir             {
1022cdf0e10cSrcweir                 delete p;
1023cdf0e10cSrcweir                 aArguments[ 0 ] <<= zipFile;
1024cdf0e10cSrcweir             }
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir             // let ZipPackage be used ( no manifest.xml is required )
1027cdf0e10cSrcweir             beans::NamedValue aArg;
1028cdf0e10cSrcweir             aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) );
1029cdf0e10cSrcweir             aArg.Value <<= ZIP_STORAGE_FORMAT_STRING;
1030cdf0e10cSrcweir             aArguments[ 1 ] <<= aArg;
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir 			Reference< XInterface > xIfc
1033cdf0e10cSrcweir 				= m_xSMgr->createInstanceWithArgumentsAndContext(
1034cdf0e10cSrcweir 					rtl::OUString::createFromAscii(
1035cdf0e10cSrcweir 						"com.sun.star.packages.comp.ZipPackage" ),
1036cdf0e10cSrcweir 					aArguments, m_xContext );
1037cdf0e10cSrcweir 
1038cdf0e10cSrcweir 			if ( xIfc.is() )
1039cdf0e10cSrcweir 			{
1040cdf0e10cSrcweir 				it->second = Reference< XHierarchicalNameAccess >( xIfc, UNO_QUERY );
1041cdf0e10cSrcweir 
1042cdf0e10cSrcweir 				VOS_ENSURE( it->second.is(),
1043cdf0e10cSrcweir 							"ContentProvider::createPackage - "
1044cdf0e10cSrcweir 							"Got no hierarchical name access!" );
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir 			}
1047cdf0e10cSrcweir 		}
1048cdf0e10cSrcweir 		catch ( RuntimeException & )
1049cdf0e10cSrcweir 		{
1050cdf0e10cSrcweir 		}
1051cdf0e10cSrcweir 		catch ( Exception & )
1052cdf0e10cSrcweir 		{
1053cdf0e10cSrcweir 		}
1054cdf0e10cSrcweir 	}
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir 	return it->second;
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir 
1059cdf0e10cSrcweir Reference< XHierarchicalNameAccess > Databases::findJarFileForPath
1060cdf0e10cSrcweir 	( const rtl::OUString& jar, const rtl::OUString& Language,
1061cdf0e10cSrcweir 	  const rtl::OUString& path, rtl::OUString* o_pExtensionPath,
1062cdf0e10cSrcweir       rtl::OUString* o_pExtensionRegistryPath )
1063cdf0e10cSrcweir {
1064cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xNA;
1065cdf0e10cSrcweir 	if( ! jar.getLength() ||
1066cdf0e10cSrcweir 		! Language.getLength() )
1067cdf0e10cSrcweir     {
1068cdf0e10cSrcweir 		return xNA;
1069cdf0e10cSrcweir     }
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir 	JarFileIterator aJarFileIt( m_xContext, *this, jar, Language );
1072cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xTestNA;
1073cdf0e10cSrcweir 	Reference< deployment::XPackage > xParentPackageBundle;
1074cdf0e10cSrcweir 	while( (xTestNA = aJarFileIt.nextJarFile( xParentPackageBundle, o_pExtensionPath, o_pExtensionRegistryPath )).is() )
1075cdf0e10cSrcweir 	{
1076cdf0e10cSrcweir 		if( xTestNA.is() && xTestNA->hasByHierarchicalName( path ) )
1077cdf0e10cSrcweir 		{
1078cdf0e10cSrcweir 			bool bSuccess = true;
1079cdf0e10cSrcweir 			if( xParentPackageBundle.is() )
1080cdf0e10cSrcweir 			{
1081cdf0e10cSrcweir 				rtl::OUString aIdentifierInPath;
1082cdf0e10cSrcweir 				sal_Int32 nFindSlash = path.indexOf( '/' );
1083cdf0e10cSrcweir 				if( nFindSlash != -1 )
1084cdf0e10cSrcweir 					aIdentifierInPath = path.copy( 0, nFindSlash );
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir 				beans::Optional<rtl::OUString> aIdentifierOptional = xParentPackageBundle->getIdentifier();
1087cdf0e10cSrcweir 				if( aIdentifierInPath.getLength() && aIdentifierOptional.IsPresent )
1088cdf0e10cSrcweir 				{
1089cdf0e10cSrcweir 					rtl::OUString aUnencodedIdentifier = aIdentifierOptional.Value;
1090cdf0e10cSrcweir 					rtl::OUString aIdentifier = rtl::Uri::encode( aUnencodedIdentifier,
1091cdf0e10cSrcweir 						rtl_UriCharClassPchar, rtl_UriEncodeIgnoreEscapes, RTL_TEXTENCODING_UTF8 );
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir 					if( !aIdentifierInPath.equals( aIdentifier ) )
1094cdf0e10cSrcweir 					{
1095cdf0e10cSrcweir 						// path does not start with extension identifier -> ignore
1096cdf0e10cSrcweir 						bSuccess = false;
1097cdf0e10cSrcweir 					}
1098cdf0e10cSrcweir 				}
1099cdf0e10cSrcweir 				else
1100cdf0e10cSrcweir 				{
1101cdf0e10cSrcweir 					// No identifier -> ignore
1102cdf0e10cSrcweir 					bSuccess = false;
1103cdf0e10cSrcweir 				}
1104cdf0e10cSrcweir 			}
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir 			if( bSuccess )
1107cdf0e10cSrcweir 			{
1108cdf0e10cSrcweir 				xNA = xTestNA;
1109cdf0e10cSrcweir 				break;
1110cdf0e10cSrcweir 			}
1111cdf0e10cSrcweir 		}
1112cdf0e10cSrcweir 	}
1113cdf0e10cSrcweir 
1114cdf0e10cSrcweir 	return xNA;
1115cdf0e10cSrcweir }
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir void Databases::popupDocument( URLParameter* urlPar,char **buffer,int *byteCount )
1118cdf0e10cSrcweir {
1119cdf0e10cSrcweir 	const char* pop1 =
1120cdf0e10cSrcweir 		" <html>                                                                "
1121cdf0e10cSrcweir 		" <head>                                                                "
1122cdf0e10cSrcweir 		" <help:css-file-link xmlns:help=\"http://openoffice.org/2000/help\"/>  "
1123cdf0e10cSrcweir 		" </head>                                                               "
1124cdf0e10cSrcweir 		" <body>                                                                "
1125cdf0e10cSrcweir 		" <help:popup-cut Id=\"";
1126cdf0e10cSrcweir 	const sal_Int32 l1 = strlen( pop1 );
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir 	const char* pop3 = "\" Eid=\"";
1129cdf0e10cSrcweir 	const sal_Int32 l3 = strlen( pop3 );
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir 	const char* pop5 =
1132cdf0e10cSrcweir 		"\" xmlns:help=\"http://openoffice.org/2000/help\"></help:popup-cut>  "
1133cdf0e10cSrcweir 		" </body>                                                             "
1134cdf0e10cSrcweir 		" </html>";
1135cdf0e10cSrcweir 	const sal_Int32 l5 = strlen( pop5 );
1136cdf0e10cSrcweir 	sal_Int32 l2,l4;
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir 	rtl::OUString val = urlPar->get_id();
1139cdf0e10cSrcweir 	rtl::OString pop2O( val.getStr(),l2 = val.getLength(),RTL_TEXTENCODING_UTF8 );
1140cdf0e10cSrcweir 	const char* pop2 = pop2O.getStr();
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir 	val = urlPar->get_eid();
1143cdf0e10cSrcweir 	rtl::OString pop4O( val.getStr(),l4 = val.getLength(),RTL_TEXTENCODING_UTF8 );
1144cdf0e10cSrcweir 	const char* pop4 = pop4O.getStr();
1145cdf0e10cSrcweir 
1146cdf0e10cSrcweir 	(*byteCount) = l1 + l2 + l3 + l4 + l5;
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir 	*buffer = new char[ 1+*byteCount ];
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir 	rtl_copyMemory( *buffer,pop1,l1 );
1151cdf0e10cSrcweir 	rtl_copyMemory( *buffer+l1,pop2,l2 );
1152cdf0e10cSrcweir 	rtl_copyMemory( *buffer+(l1+l2),pop3,l3 );
1153cdf0e10cSrcweir 	rtl_copyMemory( *buffer+(l1+l2+l3),pop4,l4 );
1154cdf0e10cSrcweir 	rtl_copyMemory( *buffer+(l1+l2+l3+l4),pop5,l5 );
1155cdf0e10cSrcweir 	(*buffer)[*byteCount] = 0;
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir void Databases::changeCSS(const rtl::OUString& newStyleSheet)
1160cdf0e10cSrcweir {
1161cdf0e10cSrcweir 	m_aCSS = newStyleSheet.toAsciiLowerCase();
1162cdf0e10cSrcweir 	delete[] m_pCustomCSSDoc, m_pCustomCSSDoc = 0,m_nCustomCSSDocLength = 0;
1163cdf0e10cSrcweir }
1164cdf0e10cSrcweir 
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir void Databases::cascadingStylesheet( const rtl::OUString& Language,
1168cdf0e10cSrcweir 									 char** buffer,
1169cdf0e10cSrcweir 									 int* byteCount )
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir 	if( ! m_pCustomCSSDoc )
1172cdf0e10cSrcweir 	{
1173cdf0e10cSrcweir 		int retry = 2;
1174cdf0e10cSrcweir 		bool error = true;
1175cdf0e10cSrcweir 		rtl::OUString fileURL;
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir         sal_Bool bHighContrastMode = sal_False;
1178cdf0e10cSrcweir         rtl::OUString aCSS( m_aCSS );
1179cdf0e10cSrcweir         if ( aCSS.compareToAscii( "default" ) == 0 )
1180cdf0e10cSrcweir         {
1181cdf0e10cSrcweir             // #i50760: "default" needs to adapt HC mode
1182cdf0e10cSrcweir             uno::Reference< awt::XToolkit > xToolkit = uno::Reference< awt::XToolkit >(
1183cdf0e10cSrcweir                     ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ) ) ), uno::UNO_QUERY );
1184cdf0e10cSrcweir             if ( xToolkit.is() )
1185cdf0e10cSrcweir             {
1186cdf0e10cSrcweir                 uno::Reference< awt::XExtendedToolkit > xExtToolkit( xToolkit, uno::UNO_QUERY );
1187cdf0e10cSrcweir                 if ( xExtToolkit.is() )
1188cdf0e10cSrcweir                 {
1189cdf0e10cSrcweir                     uno::Reference< awt::XTopWindow > xTopWindow = xExtToolkit->getActiveTopWindow();
1190cdf0e10cSrcweir                     if ( xTopWindow.is() )
1191cdf0e10cSrcweir                     {
1192cdf0e10cSrcweir                         uno::Reference< awt::XVclWindowPeer > xVclWindowPeer( xTopWindow, uno::UNO_QUERY );
1193cdf0e10cSrcweir                         if ( xVclWindowPeer.is() )
1194cdf0e10cSrcweir                         {
1195cdf0e10cSrcweir                             uno::Any aHCMode = xVclWindowPeer->getProperty( rtl::OUString::createFromAscii( "HighContrastMode" ) );
1196cdf0e10cSrcweir                             if ( ( aHCMode >>= bHighContrastMode ) && bHighContrastMode )
1197cdf0e10cSrcweir                                 aCSS = rtl::OUString::createFromAscii( "highcontrastblack" );
1198cdf0e10cSrcweir                         }
1199cdf0e10cSrcweir                     }
1200cdf0e10cSrcweir                 }
1201cdf0e10cSrcweir             }
1202cdf0e10cSrcweir         }
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir 		while( error && retry )
1205cdf0e10cSrcweir 		{
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir 			if( retry == 2 )
1208cdf0e10cSrcweir 				fileURL =
1209cdf0e10cSrcweir 					getInstallPathAsURL()  +
1210cdf0e10cSrcweir 					processLang( Language )       +
1211cdf0e10cSrcweir 					rtl::OUString::createFromAscii( "/" ) +
1212cdf0e10cSrcweir 					aCSS +
1213cdf0e10cSrcweir 					rtl::OUString::createFromAscii( ".css" );
1214cdf0e10cSrcweir 			else if( retry == 1 )
1215cdf0e10cSrcweir 				fileURL =
1216cdf0e10cSrcweir 					getInstallPathAsURL()  +
1217cdf0e10cSrcweir 					aCSS +
1218cdf0e10cSrcweir 					rtl::OUString::createFromAscii( ".css" );
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir 			osl::DirectoryItem aDirItem;
1221cdf0e10cSrcweir 			osl::File aFile( fileURL );
1222cdf0e10cSrcweir 			osl::FileStatus aStatus( FileStatusMask_FileSize );
1223cdf0e10cSrcweir 
1224cdf0e10cSrcweir 			if( osl::FileBase::E_None == osl::DirectoryItem::get( fileURL,aDirItem ) &&
1225cdf0e10cSrcweir 				osl::FileBase::E_None == aFile.open( OpenFlag_Read )                 &&
1226cdf0e10cSrcweir 				osl::FileBase::E_None == aDirItem.getFileStatus( aStatus ) )
1227cdf0e10cSrcweir 			{
1228cdf0e10cSrcweir 				m_nCustomCSSDocLength = int( aStatus.getFileSize() );
1229cdf0e10cSrcweir 				m_pCustomCSSDoc = new char[ 1 + m_nCustomCSSDocLength ];
1230cdf0e10cSrcweir 				m_pCustomCSSDoc[ m_nCustomCSSDocLength ] = 0;
1231cdf0e10cSrcweir 				sal_uInt64 a = m_nCustomCSSDocLength,b = m_nCustomCSSDocLength;
1232cdf0e10cSrcweir 				aFile.read( m_pCustomCSSDoc,a,b );
1233cdf0e10cSrcweir 				aFile.close();
1234cdf0e10cSrcweir 				error = false;
1235cdf0e10cSrcweir 			}
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir 			--retry;
1238cdf0e10cSrcweir 			if ( !retry && error && bHighContrastMode )
1239cdf0e10cSrcweir 			{
1240cdf0e10cSrcweir 			    // fall back to default css
1241cdf0e10cSrcweir 			    aCSS = rtl::OUString::createFromAscii( "default" );
1242cdf0e10cSrcweir 			    retry = 2;
1243cdf0e10cSrcweir 			    bHighContrastMode = sal_False;
1244cdf0e10cSrcweir 			}
1245cdf0e10cSrcweir 		}
1246cdf0e10cSrcweir 
1247cdf0e10cSrcweir 		if( error )
1248cdf0e10cSrcweir 		{
1249cdf0e10cSrcweir 			m_nCustomCSSDocLength = 0;
1250cdf0e10cSrcweir 			m_pCustomCSSDoc = new char[ 1 ]; // Initialize with 1 to avoid gcc compiler warning
1251cdf0e10cSrcweir 		}
1252cdf0e10cSrcweir 	}
1253cdf0e10cSrcweir 
1254cdf0e10cSrcweir 	*byteCount = m_nCustomCSSDocLength;
1255cdf0e10cSrcweir 	*buffer = new char[ 1 + *byteCount ];
1256cdf0e10cSrcweir 	(*buffer)[*byteCount] = 0;
1257cdf0e10cSrcweir 	rtl_copyMemory( *buffer,m_pCustomCSSDoc,m_nCustomCSSDocLength );
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir }
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir 
1262cdf0e10cSrcweir void Databases::setActiveText( const rtl::OUString& Module,
1263cdf0e10cSrcweir 							   const rtl::OUString& Language,
1264cdf0e10cSrcweir 							   const rtl::OUString& Id,
1265cdf0e10cSrcweir 							   char** buffer,
1266cdf0e10cSrcweir 							   int* byteCount )
1267cdf0e10cSrcweir {
1268cdf0e10cSrcweir 	DataBaseIterator aDbIt( m_xContext, *this, Module, Language, true );
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir 	// #i84550 Cache information about failed ids
1271cdf0e10cSrcweir 	rtl::OString id( Id.getStr(),Id.getLength(),RTL_TEXTENCODING_UTF8 );
1272cdf0e10cSrcweir 	EmptyActiveTextSet::iterator it = m_aEmptyActiveTextSet.find( id );
1273cdf0e10cSrcweir 	bool bFoundAsEmpty = ( it != m_aEmptyActiveTextSet.end() );
1274*70e197d9SHerbert Dürr 	helpdatafileproxy::HDFData aHDFData;
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir 	int nSize = 0;
1277cdf0e10cSrcweir 	const sal_Char* pData = NULL;
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir 	bool bSuccess = false;
1280cdf0e10cSrcweir 	if( !bFoundAsEmpty )
1281cdf0e10cSrcweir 	{
1282*70e197d9SHerbert Dürr 		helpdatafileproxy::Hdf* pHdf = 0;
1283*70e197d9SHerbert Dürr 		while( !bSuccess && (pHdf = aDbIt.nextHdf()) != NULL )
1284cdf0e10cSrcweir 		{
1285*70e197d9SHerbert Dürr 			bSuccess = pHdf->getValueForKey( id, aHDFData );
1286*70e197d9SHerbert Dürr 			nSize = aHDFData.getSize();
1287*70e197d9SHerbert Dürr 			pData = aHDFData.getData();
1288cdf0e10cSrcweir 		}
1289cdf0e10cSrcweir 	}
1290cdf0e10cSrcweir 
1291cdf0e10cSrcweir 	if( bSuccess )
1292cdf0e10cSrcweir 	{
1293cdf0e10cSrcweir 		// ensure existence of tmp after for
1294cdf0e10cSrcweir 		rtl::OString tmp;
1295cdf0e10cSrcweir 		for( int i = 0; i < nSize; ++i )
1296cdf0e10cSrcweir 			if( pData[i] == '%' || pData[i] == '$' )
1297cdf0e10cSrcweir 			{
1298cdf0e10cSrcweir 				// need of replacement
1299cdf0e10cSrcweir 				rtl::OUString temp = rtl::OUString( pData, nSize, RTL_TEXTENCODING_UTF8 );
1300cdf0e10cSrcweir 				replaceName( temp );
1301cdf0e10cSrcweir 				tmp = rtl::OString( temp.getStr(),
1302cdf0e10cSrcweir 									temp.getLength(),
1303cdf0e10cSrcweir 									RTL_TEXTENCODING_UTF8 );
1304cdf0e10cSrcweir 				nSize = tmp.getLength();
1305cdf0e10cSrcweir 				pData = tmp.getStr();
1306cdf0e10cSrcweir 				break;
1307cdf0e10cSrcweir 			}
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir 		*byteCount = nSize;
1310cdf0e10cSrcweir 		*buffer = new char[ 1 + nSize ];
1311cdf0e10cSrcweir 		(*buffer)[nSize] = 0;
1312cdf0e10cSrcweir 		rtl_copyMemory( *buffer, pData, nSize );
1313cdf0e10cSrcweir 	}
1314cdf0e10cSrcweir 	else
1315cdf0e10cSrcweir 	{
1316cdf0e10cSrcweir 		*byteCount = 0;
1317cdf0e10cSrcweir 		*buffer = new char[1]; // Initialize with 1 to avoid compiler warnings
1318cdf0e10cSrcweir 		if( !bFoundAsEmpty )
1319cdf0e10cSrcweir 			m_aEmptyActiveTextSet.insert( id );
1320cdf0e10cSrcweir 	}
1321cdf0e10cSrcweir }
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir 
1324cdf0e10cSrcweir void Databases::setInstallPath( const rtl::OUString& aInstDir )
1325cdf0e10cSrcweir {
1326cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir     osl::FileBase::getFileURLFromSystemPath( aInstDir,m_aInstallDirectory );
1329cdf0e10cSrcweir         //TODO: check returned error code
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir 	if( m_aInstallDirectory.lastIndexOf( sal_Unicode( '/' ) ) != m_aInstallDirectory.getLength() - 1 )
1332cdf0e10cSrcweir 		m_aInstallDirectory += rtl::OUString::createFromAscii( "/" );
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir 	m_aInstallDirectoryWithoutEncoding = rtl::Uri::decode( m_aInstallDirectory,
1335cdf0e10cSrcweir 														   rtl_UriDecodeWithCharset,
1336cdf0e10cSrcweir 														   RTL_TEXTENCODING_UTF8 );
1337cdf0e10cSrcweir }
1338cdf0e10cSrcweir 
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir //===================================================================
1341cdf0e10cSrcweir // class ExtensionIteratorBase
1342cdf0e10cSrcweir 
1343cdf0e10cSrcweir ExtensionHelpExistanceMap ExtensionIteratorBase::aHelpExistanceMap;
1344cdf0e10cSrcweir 
1345cdf0e10cSrcweir ExtensionIteratorBase::ExtensionIteratorBase( Reference< XComponentContext > xContext,
1346cdf0e10cSrcweir 	Databases& rDatabases, const rtl::OUString& aInitialModule, const rtl::OUString& aLanguage )
1347cdf0e10cSrcweir 		: m_xContext( xContext )
1348cdf0e10cSrcweir 		, m_rDatabases( rDatabases )
1349cdf0e10cSrcweir 		, m_eState( INITIAL_MODULE )
1350cdf0e10cSrcweir 		, m_aInitialModule( aInitialModule )
1351cdf0e10cSrcweir 		, m_aLanguage( aLanguage )
1352cdf0e10cSrcweir {
1353cdf0e10cSrcweir 	init();
1354cdf0e10cSrcweir }
1355cdf0e10cSrcweir 
1356cdf0e10cSrcweir ExtensionIteratorBase::ExtensionIteratorBase( Databases& rDatabases,
1357cdf0e10cSrcweir 	const rtl::OUString& aInitialModule, const rtl::OUString& aLanguage )
1358cdf0e10cSrcweir 		: m_rDatabases( rDatabases )
1359cdf0e10cSrcweir 		, m_eState( INITIAL_MODULE )
1360cdf0e10cSrcweir 		, m_aInitialModule( aInitialModule )
1361cdf0e10cSrcweir 		, m_aLanguage( aLanguage )
1362cdf0e10cSrcweir {
1363cdf0e10cSrcweir 	init();
1364cdf0e10cSrcweir }
1365cdf0e10cSrcweir 
1366cdf0e10cSrcweir void ExtensionIteratorBase::init()
1367cdf0e10cSrcweir {
1368cdf0e10cSrcweir 	if( !m_xContext.is() )
1369cdf0e10cSrcweir 	{
1370cdf0e10cSrcweir 		Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
1371cdf0e10cSrcweir 		Reference< XPropertySet > xProps( xFactory, UNO_QUERY );
1372cdf0e10cSrcweir 		OSL_ASSERT( xProps.is() );
1373cdf0e10cSrcweir 		if (xProps.is())
1374cdf0e10cSrcweir 		{
1375cdf0e10cSrcweir 			xProps->getPropertyValue(
1376cdf0e10cSrcweir 				::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= m_xContext;
1377cdf0e10cSrcweir 			OSL_ASSERT( m_xContext.is() );
1378cdf0e10cSrcweir 		}
1379cdf0e10cSrcweir 	}
1380cdf0e10cSrcweir 	if( !m_xContext.is() )
1381cdf0e10cSrcweir 	{
1382cdf0e10cSrcweir 		throw RuntimeException(
1383cdf0e10cSrcweir 			::rtl::OUString::createFromAscii( "ExtensionIteratorBase::init(), no XComponentContext" ),
1384cdf0e10cSrcweir 			Reference< XInterface >() );
1385cdf0e10cSrcweir 	}
1386cdf0e10cSrcweir 
1387cdf0e10cSrcweir 	Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager(), UNO_QUERY );
1388cdf0e10cSrcweir 	m_xSFA = Reference< ucb::XSimpleFileAccess >(
1389cdf0e10cSrcweir 		xSMgr->createInstanceWithContext( rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ),
1390cdf0e10cSrcweir 		m_xContext ), UNO_QUERY_THROW );
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir 	m_bUserPackagesLoaded = false;
1393cdf0e10cSrcweir 	m_bSharedPackagesLoaded = false;
1394cdf0e10cSrcweir     m_bBundledPackagesLoaded = false;
1395cdf0e10cSrcweir 	m_iUserPackage = 0;
1396cdf0e10cSrcweir 	m_iSharedPackage = 0;
1397cdf0e10cSrcweir     m_iBundledPackage = 0;
1398cdf0e10cSrcweir }
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir Reference< deployment::XPackage > ExtensionIteratorBase::implGetHelpPackageFromPackage
1401cdf0e10cSrcweir 	( Reference< deployment::XPackage > xPackage, Reference< deployment::XPackage >& o_xParentPackageBundle )
1402cdf0e10cSrcweir {
1403cdf0e10cSrcweir 	o_xParentPackageBundle.clear();
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir 	Reference< deployment::XPackage > xHelpPackage;
1406cdf0e10cSrcweir 	if( !xPackage.is() )
1407cdf0e10cSrcweir 		return xHelpPackage;
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir 	// #i84550 Cache information about help content in extension
1410cdf0e10cSrcweir 	rtl::OUString aExtensionPath = xPackage->getURL();
1411cdf0e10cSrcweir 	ExtensionHelpExistanceMap::iterator it = aHelpExistanceMap.find( aExtensionPath );
1412cdf0e10cSrcweir 	bool bFound = ( it != aHelpExistanceMap.end() );
1413cdf0e10cSrcweir 	bool bHasHelp = bFound ? it->second : false;
1414cdf0e10cSrcweir 	if( bFound && !bHasHelp )
1415cdf0e10cSrcweir 		return xHelpPackage;
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir 	// Check if parent package is registered
1418cdf0e10cSrcweir     beans::Optional< beans::Ambiguous<sal_Bool> > option( xPackage->isRegistered
1419cdf0e10cSrcweir 		( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() ) );
1420cdf0e10cSrcweir 	bool bRegistered = false;
1421cdf0e10cSrcweir     if( option.IsPresent )
1422cdf0e10cSrcweir     {
1423cdf0e10cSrcweir         beans::Ambiguous<sal_Bool> const & reg = option.Value;
1424cdf0e10cSrcweir         if( !reg.IsAmbiguous && reg.Value )
1425cdf0e10cSrcweir 			bRegistered = true;
1426cdf0e10cSrcweir     }
1427cdf0e10cSrcweir 	if( bRegistered )
1428cdf0e10cSrcweir 	{
1429cdf0e10cSrcweir 		if( xPackage->isBundle() )
1430cdf0e10cSrcweir 		{
1431cdf0e10cSrcweir 			Sequence< Reference< deployment::XPackage > > aPkgSeq = xPackage->getBundle
1432cdf0e10cSrcweir 				( Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>() );
1433cdf0e10cSrcweir 			sal_Int32 nPkgCount = aPkgSeq.getLength();
1434cdf0e10cSrcweir 			const Reference< deployment::XPackage >* pSeq = aPkgSeq.getConstArray();
1435cdf0e10cSrcweir 			for( sal_Int32 iPkg = 0 ; iPkg < nPkgCount ; ++iPkg )
1436cdf0e10cSrcweir 			{
1437cdf0e10cSrcweir 				const Reference< deployment::XPackage > xSubPkg = pSeq[ iPkg ];
1438cdf0e10cSrcweir 				const Reference< deployment::XPackageTypeInfo > xPackageTypeInfo = xSubPkg->getPackageType();
1439cdf0e10cSrcweir 				rtl::OUString aMediaType = xPackageTypeInfo->getMediaType();
1440cdf0e10cSrcweir 				if( aMediaType.equals( aHelpMediaType ) )
1441cdf0e10cSrcweir 				{
1442cdf0e10cSrcweir 					xHelpPackage = xSubPkg;
1443cdf0e10cSrcweir 					o_xParentPackageBundle = xPackage;
1444cdf0e10cSrcweir 					break;
1445cdf0e10cSrcweir 				}
1446cdf0e10cSrcweir 			}
1447cdf0e10cSrcweir 		}
1448cdf0e10cSrcweir 		else
1449cdf0e10cSrcweir 		{
1450cdf0e10cSrcweir 			const Reference< deployment::XPackageTypeInfo > xPackageTypeInfo = xPackage->getPackageType();
1451cdf0e10cSrcweir 			rtl::OUString aMediaType = xPackageTypeInfo->getMediaType();
1452cdf0e10cSrcweir 			if( aMediaType.equals( aHelpMediaType ) )
1453cdf0e10cSrcweir 				xHelpPackage = xPackage;
1454cdf0e10cSrcweir 		}
1455cdf0e10cSrcweir 	}
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir 	if( !bFound )
1458cdf0e10cSrcweir 		aHelpExistanceMap[ aExtensionPath ] = xHelpPackage.is();
1459cdf0e10cSrcweir 
1460cdf0e10cSrcweir 	return xHelpPackage;
1461cdf0e10cSrcweir }
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir Reference< deployment::XPackage > ExtensionIteratorBase::implGetNextUserHelpPackage
1464cdf0e10cSrcweir 	( Reference< deployment::XPackage >& o_xParentPackageBundle )
1465cdf0e10cSrcweir {
1466cdf0e10cSrcweir 	Reference< deployment::XPackage > xHelpPackage;
1467cdf0e10cSrcweir 
1468cdf0e10cSrcweir 	if( !m_bUserPackagesLoaded )
1469cdf0e10cSrcweir 	{
1470cdf0e10cSrcweir         Reference< XExtensionManager > xExtensionManager = ExtensionManager::get(m_xContext);
1471cdf0e10cSrcweir 		m_aUserPackagesSeq = xExtensionManager->getDeployedExtensions
1472cdf0e10cSrcweir 			( rtl::OUString::createFromAscii("user"), Reference< task::XAbortChannel >(), Reference< ucb::XCommandEnvironment >() );
1473cdf0e10cSrcweir 		m_bUserPackagesLoaded = true;
1474cdf0e10cSrcweir 	}
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir 	if( m_iUserPackage == m_aUserPackagesSeq.getLength() )
1477cdf0e10cSrcweir 	{
1478cdf0e10cSrcweir 		m_eState = SHARED_EXTENSIONS;		// Later: SHARED_MODULE
1479cdf0e10cSrcweir 	}
1480cdf0e10cSrcweir 	else
1481cdf0e10cSrcweir 	{
1482cdf0e10cSrcweir 		const Reference< deployment::XPackage >* pUserPackages = m_aUserPackagesSeq.getConstArray();
1483cdf0e10cSrcweir 		Reference< deployment::XPackage > xPackage = pUserPackages[ m_iUserPackage++ ];
1484cdf0e10cSrcweir 		VOS_ENSURE( xPackage.is(), "ExtensionIteratorBase::implGetNextUserHelpPackage(): Invalid package" );
1485cdf0e10cSrcweir 		xHelpPackage = implGetHelpPackageFromPackage( xPackage, o_xParentPackageBundle );
1486cdf0e10cSrcweir 	}
1487cdf0e10cSrcweir 
1488cdf0e10cSrcweir 	return xHelpPackage;
1489cdf0e10cSrcweir }
1490cdf0e10cSrcweir 
1491cdf0e10cSrcweir Reference< deployment::XPackage > ExtensionIteratorBase::implGetNextSharedHelpPackage
1492cdf0e10cSrcweir 	( Reference< deployment::XPackage >& o_xParentPackageBundle )
1493cdf0e10cSrcweir {
1494cdf0e10cSrcweir 	Reference< deployment::XPackage > xHelpPackage;
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir 	if( !m_bSharedPackagesLoaded )
1497cdf0e10cSrcweir 	{
1498cdf0e10cSrcweir 		Reference< XExtensionManager > xExtensionManager = ExtensionManager::get(m_xContext);
1499cdf0e10cSrcweir 		m_aSharedPackagesSeq = xExtensionManager->getDeployedExtensions
1500cdf0e10cSrcweir 			( rtl::OUString::createFromAscii("shared"), Reference< task::XAbortChannel >(), Reference< ucb::XCommandEnvironment >() );
1501cdf0e10cSrcweir 		m_bSharedPackagesLoaded = true;
1502cdf0e10cSrcweir 	}
1503cdf0e10cSrcweir 
1504cdf0e10cSrcweir 	if( m_iSharedPackage == m_aSharedPackagesSeq.getLength() )
1505cdf0e10cSrcweir 	{
1506cdf0e10cSrcweir 		m_eState = BUNDLED_EXTENSIONS;
1507cdf0e10cSrcweir 	}
1508cdf0e10cSrcweir 	else
1509cdf0e10cSrcweir 	{
1510cdf0e10cSrcweir 		const Reference< deployment::XPackage >* pSharedPackages = m_aSharedPackagesSeq.getConstArray();
1511cdf0e10cSrcweir 		Reference< deployment::XPackage > xPackage = pSharedPackages[ m_iSharedPackage++ ];
1512cdf0e10cSrcweir 		VOS_ENSURE( xPackage.is(), "ExtensionIteratorBase::implGetNextSharedHelpPackage(): Invalid package" );
1513cdf0e10cSrcweir 		xHelpPackage = implGetHelpPackageFromPackage( xPackage, o_xParentPackageBundle );
1514cdf0e10cSrcweir 	}
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 	return xHelpPackage;
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir Reference< deployment::XPackage > ExtensionIteratorBase::implGetNextBundledHelpPackage
1520cdf0e10cSrcweir 	( Reference< deployment::XPackage >& o_xParentPackageBundle )
1521cdf0e10cSrcweir {
1522cdf0e10cSrcweir 	Reference< deployment::XPackage > xHelpPackage;
1523cdf0e10cSrcweir 
1524cdf0e10cSrcweir 	if( !m_bBundledPackagesLoaded )
1525cdf0e10cSrcweir 	{
1526cdf0e10cSrcweir 		Reference< XExtensionManager > xExtensionManager = ExtensionManager::get(m_xContext);
1527cdf0e10cSrcweir 		m_aBundledPackagesSeq = xExtensionManager->getDeployedExtensions
1528cdf0e10cSrcweir 			( rtl::OUString::createFromAscii("bundled"), Reference< task::XAbortChannel >(), Reference< ucb::XCommandEnvironment >() );
1529cdf0e10cSrcweir 		m_bBundledPackagesLoaded = true;
1530cdf0e10cSrcweir 	}
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir 	if( m_iBundledPackage == m_aBundledPackagesSeq.getLength() )
1533cdf0e10cSrcweir 	{
1534cdf0e10cSrcweir 		m_eState = END_REACHED;
1535cdf0e10cSrcweir 	}
1536cdf0e10cSrcweir 	else
1537cdf0e10cSrcweir 	{
1538cdf0e10cSrcweir 		const Reference< deployment::XPackage >* pBundledPackages =
1539cdf0e10cSrcweir             m_aBundledPackagesSeq.getConstArray();
1540cdf0e10cSrcweir 		Reference< deployment::XPackage > xPackage = pBundledPackages[ m_iBundledPackage++ ];
1541cdf0e10cSrcweir 		VOS_ENSURE( xPackage.is(), "ExtensionIteratorBase::implGetNextBundledHelpPackage(): Invalid package" );
1542cdf0e10cSrcweir 		xHelpPackage = implGetHelpPackageFromPackage( xPackage, o_xParentPackageBundle );
1543cdf0e10cSrcweir 	}
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 	return xHelpPackage;
1546cdf0e10cSrcweir }
1547cdf0e10cSrcweir 
1548cdf0e10cSrcweir rtl::OUString ExtensionIteratorBase::implGetFileFromPackage(
1549cdf0e10cSrcweir 	const rtl::OUString& rFileExtension, Reference< deployment::XPackage > xPackage )
1550cdf0e10cSrcweir {
1551cdf0e10cSrcweir 	// No extension -> search for pure language folder
1552cdf0e10cSrcweir 	bool bLangFolderOnly = (rFileExtension.getLength() == 0);
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir 	rtl::OUString aFile;
1555cdf0e10cSrcweir 	rtl::OUString aLanguage = m_aLanguage;
1556cdf0e10cSrcweir 	for( sal_Int32 iPass = 0 ; iPass < 2 ; ++iPass )
1557cdf0e10cSrcweir 	{
1558cdf0e10cSrcweir 		rtl::OUStringBuffer aStrBuf;
1559cdf0e10cSrcweir 		aStrBuf.append( xPackage->getRegistrationDataURL().Value);
1560cdf0e10cSrcweir 		aStrBuf.append( aSlash );
1561cdf0e10cSrcweir 		aStrBuf.append( aLanguage );
1562cdf0e10cSrcweir 		if( !bLangFolderOnly )
1563cdf0e10cSrcweir 		{
1564cdf0e10cSrcweir 			aStrBuf.append( aSlash );
1565cdf0e10cSrcweir 			aStrBuf.append( aHelpFilesBaseName );
1566cdf0e10cSrcweir 			aStrBuf.append( rFileExtension );
1567cdf0e10cSrcweir 		}
1568cdf0e10cSrcweir 
1569cdf0e10cSrcweir 		aFile = m_rDatabases.expandURL( aStrBuf.makeStringAndClear() );
1570cdf0e10cSrcweir 		if( iPass == 0 )
1571cdf0e10cSrcweir 		{
1572cdf0e10cSrcweir 			if( m_xSFA->exists( aFile ) )
1573cdf0e10cSrcweir 				break;
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir 			::std::vector< ::rtl::OUString > av;
1576cdf0e10cSrcweir 			implGetLanguageVectorFromPackage( av, xPackage );
1577cdf0e10cSrcweir 			::std::vector< ::rtl::OUString >::const_iterator pFound = av.end();
1578cdf0e10cSrcweir 			try
1579cdf0e10cSrcweir 			{
1580cdf0e10cSrcweir 				pFound = ::comphelper::Locale::getFallback( av, m_aLanguage );
1581cdf0e10cSrcweir 			}
1582cdf0e10cSrcweir 			catch( ::comphelper::Locale::MalFormedLocaleException& )
1583cdf0e10cSrcweir 			{}
1584cdf0e10cSrcweir 			if( pFound != av.end() )
1585cdf0e10cSrcweir 				aLanguage = *pFound;
1586cdf0e10cSrcweir 		}
1587cdf0e10cSrcweir 	}
1588cdf0e10cSrcweir 	return aFile;
1589cdf0e10cSrcweir }
1590cdf0e10cSrcweir 
1591cdf0e10cSrcweir inline bool isLetter( sal_Unicode c )
1592cdf0e10cSrcweir {
1593cdf0e10cSrcweir 	bool bLetter = ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
1594cdf0e10cSrcweir 	return bLetter;
1595cdf0e10cSrcweir }
1596cdf0e10cSrcweir 
1597cdf0e10cSrcweir void ExtensionIteratorBase::implGetLanguageVectorFromPackage( ::std::vector< ::rtl::OUString > &rv,
1598cdf0e10cSrcweir 	com::sun::star::uno::Reference< com::sun::star::deployment::XPackage > xPackage )
1599cdf0e10cSrcweir {
1600cdf0e10cSrcweir 	rv.clear();
1601cdf0e10cSrcweir 	rtl::OUString aExtensionPath = xPackage->getURL();
1602cdf0e10cSrcweir 	Sequence< rtl::OUString > aEntrySeq = m_xSFA->getFolderContents( aExtensionPath, true );
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir 	const rtl::OUString* pSeq = aEntrySeq.getConstArray();
1605cdf0e10cSrcweir     sal_Int32 nCount = aEntrySeq.getLength();
1606cdf0e10cSrcweir 	for( sal_Int32 i = 0 ; i < nCount ; ++i )
1607cdf0e10cSrcweir 	{
1608cdf0e10cSrcweir 		rtl::OUString aEntry = pSeq[i];
1609cdf0e10cSrcweir 		if( m_xSFA->isFolder( aEntry ) )
1610cdf0e10cSrcweir 		{
1611cdf0e10cSrcweir 			sal_Int32 nLastSlash = aEntry.lastIndexOf( '/' );
1612cdf0e10cSrcweir 			if( nLastSlash != -1 )
1613cdf0e10cSrcweir 			{
1614cdf0e10cSrcweir 				rtl::OUString aPureEntry = aEntry.copy( nLastSlash + 1 );
1615cdf0e10cSrcweir 
1616cdf0e10cSrcweir 				// Check language sceme
1617cdf0e10cSrcweir 				int nLen = aPureEntry.getLength();
1618cdf0e10cSrcweir 				const sal_Unicode* pc = aPureEntry.getStr();
1619cdf0e10cSrcweir 				bool bStartCanBeLanguage = ( nLen >= 2 && isLetter( pc[0] ) && isLetter( pc[1] ) );
1620cdf0e10cSrcweir 				bool bIsLanguage = bStartCanBeLanguage &&
1621cdf0e10cSrcweir 					( nLen == 2 || (nLen == 5 && pc[2] == '-' && isLetter( pc[3] ) && isLetter( pc[4] )) );
1622cdf0e10cSrcweir 				if( bIsLanguage )
1623cdf0e10cSrcweir 					rv.push_back( aPureEntry );
1624cdf0e10cSrcweir 			}
1625cdf0e10cSrcweir 		}
1626cdf0e10cSrcweir 	}
1627cdf0e10cSrcweir }
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir //===================================================================
1631cdf0e10cSrcweir // class DataBaseIterator
1632cdf0e10cSrcweir 
1633*70e197d9SHerbert Dürr helpdatafileproxy::Hdf* DataBaseIterator::nextHdf( rtl::OUString* o_pExtensionPath, rtl::OUString* o_pExtensionRegistryPath )
1634cdf0e10cSrcweir {
1635*70e197d9SHerbert Dürr 	helpdatafileproxy::Hdf* pRetHdf = NULL;
1636cdf0e10cSrcweir 
1637*70e197d9SHerbert Dürr 	while( !pRetHdf && m_eState != END_REACHED )
1638cdf0e10cSrcweir 	{
1639cdf0e10cSrcweir 		switch( m_eState )
1640cdf0e10cSrcweir 		{
1641cdf0e10cSrcweir 			case INITIAL_MODULE:
1642*70e197d9SHerbert Dürr 				pRetHdf = m_rDatabases.getHelpDataFile( m_aInitialModule, m_aLanguage, m_bHelpText );
1643cdf0e10cSrcweir 				m_eState = USER_EXTENSIONS;		// Later: SHARED_MODULE
1644cdf0e10cSrcweir 				break;
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir 			// Later:
1647cdf0e10cSrcweir 			//case SHARED_MODULE
1648cdf0e10cSrcweir 				//...
1649cdf0e10cSrcweir 
1650cdf0e10cSrcweir 			case USER_EXTENSIONS:
1651cdf0e10cSrcweir 			{
1652cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1653cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextUserHelpPackage( xParentPackageBundle );
1654cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1655cdf0e10cSrcweir 					break;
1656*70e197d9SHerbert Dürr 				pRetHdf = implGetHdfFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath );
1657cdf0e10cSrcweir 				break;
1658cdf0e10cSrcweir 			}
1659cdf0e10cSrcweir 
1660cdf0e10cSrcweir 			case SHARED_EXTENSIONS:
1661cdf0e10cSrcweir 			{
1662cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1663cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextSharedHelpPackage( xParentPackageBundle );
1664cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1665cdf0e10cSrcweir 					break;
1666cdf0e10cSrcweir 
1667*70e197d9SHerbert Dürr 				pRetHdf = implGetHdfFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath );
1668cdf0e10cSrcweir 				break;
1669cdf0e10cSrcweir 			}
1670cdf0e10cSrcweir 
1671cdf0e10cSrcweir    			case BUNDLED_EXTENSIONS:
1672cdf0e10cSrcweir 			{
1673cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1674cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextBundledHelpPackage( xParentPackageBundle );
1675cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1676cdf0e10cSrcweir 					break;
1677cdf0e10cSrcweir 
1678*70e197d9SHerbert Dürr 				pRetHdf = implGetHdfFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath );
1679cdf0e10cSrcweir 				break;
1680cdf0e10cSrcweir 			}
1681cdf0e10cSrcweir 
1682cdf0e10cSrcweir 			case END_REACHED:
1683cdf0e10cSrcweir 				VOS_ENSURE( false, "DataBaseIterator::nextDb(): Invalid case END_REACHED" );
1684cdf0e10cSrcweir 				break;
1685cdf0e10cSrcweir 		}
1686cdf0e10cSrcweir 	}
1687cdf0e10cSrcweir 
1688*70e197d9SHerbert Dürr 	return pRetHdf;
1689cdf0e10cSrcweir }
1690cdf0e10cSrcweir 
1691*70e197d9SHerbert Dürr helpdatafileproxy::Hdf* DataBaseIterator::implGetHdfFromPackage( Reference< deployment::XPackage > xPackage,
1692cdf0e10cSrcweir             rtl::OUString* o_pExtensionPath, rtl::OUString* o_pExtensionRegistryPath )
1693cdf0e10cSrcweir {
1694cdf0e10cSrcweir 
1695cdf0e10cSrcweir     beans::Optional< ::rtl::OUString> optRegData;
1696cdf0e10cSrcweir     try
1697cdf0e10cSrcweir     {
1698cdf0e10cSrcweir         optRegData = xPackage->getRegistrationDataURL();
1699cdf0e10cSrcweir     }
1700cdf0e10cSrcweir     catch ( deployment::ExtensionRemovedException&)
1701cdf0e10cSrcweir     {
1702cdf0e10cSrcweir         return NULL;
1703cdf0e10cSrcweir     }
1704cdf0e10cSrcweir 
1705*70e197d9SHerbert Dürr     helpdatafileproxy::Hdf* pRetHdf = NULL;
1706cdf0e10cSrcweir     if (optRegData.IsPresent && optRegData.Value.getLength() > 0)
1707cdf0e10cSrcweir     {
1708cdf0e10cSrcweir         rtl::OUString aRegDataUrl(optRegData.Value);
1709cdf0e10cSrcweir         aRegDataUrl += aSlash;
1710cdf0e10cSrcweir 
1711cdf0e10cSrcweir         rtl::OUString aUsedLanguage = m_aLanguage;
1712*70e197d9SHerbert Dürr         pRetHdf = m_rDatabases.getHelpDataFile(
1713cdf0e10cSrcweir             aHelpFilesBaseName, aUsedLanguage, m_bHelpText, &aRegDataUrl);
1714cdf0e10cSrcweir 
1715cdf0e10cSrcweir         // Language fallback
1716*70e197d9SHerbert Dürr         if( !pRetHdf )
1717cdf0e10cSrcweir         {
1718cdf0e10cSrcweir             ::std::vector< ::rtl::OUString > av;
1719cdf0e10cSrcweir             implGetLanguageVectorFromPackage( av, xPackage );
1720cdf0e10cSrcweir             ::std::vector< ::rtl::OUString >::const_iterator pFound = av.end();
1721cdf0e10cSrcweir             try
1722cdf0e10cSrcweir             {
1723cdf0e10cSrcweir                 pFound = ::comphelper::Locale::getFallback( av, m_aLanguage );
1724cdf0e10cSrcweir             }
1725cdf0e10cSrcweir             catch( ::comphelper::Locale::MalFormedLocaleException& )
1726cdf0e10cSrcweir             {}
1727cdf0e10cSrcweir             if( pFound != av.end() )
1728cdf0e10cSrcweir             {
1729cdf0e10cSrcweir                 aUsedLanguage = *pFound;
1730*70e197d9SHerbert Dürr                 pRetHdf = m_rDatabases.getHelpDataFile(
1731cdf0e10cSrcweir                     aHelpFilesBaseName, aUsedLanguage, m_bHelpText, &aRegDataUrl);
1732cdf0e10cSrcweir             }
1733cdf0e10cSrcweir         }
1734cdf0e10cSrcweir 
1735cdf0e10cSrcweir         if( o_pExtensionPath )
1736cdf0e10cSrcweir             *o_pExtensionPath = aRegDataUrl + aUsedLanguage;
1737cdf0e10cSrcweir 
1738cdf0e10cSrcweir         if( o_pExtensionRegistryPath )
1739cdf0e10cSrcweir             *o_pExtensionRegistryPath = xPackage->getURL() + aSlash + aUsedLanguage;
1740cdf0e10cSrcweir     }
1741cdf0e10cSrcweir 
1742*70e197d9SHerbert Dürr 	return pRetHdf;
1743cdf0e10cSrcweir }
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir 
1746cdf0e10cSrcweir //===================================================================
1747cdf0e10cSrcweir // class KeyDataBaseFileIterator
1748cdf0e10cSrcweir 
1749cdf0e10cSrcweir //returns a file URL
1750cdf0e10cSrcweir rtl::OUString KeyDataBaseFileIterator::nextDbFile( bool& o_rbExtension )
1751cdf0e10cSrcweir {
1752cdf0e10cSrcweir 	rtl::OUString aRetFile;
1753cdf0e10cSrcweir 
1754cdf0e10cSrcweir 	while( !aRetFile.getLength() && m_eState != END_REACHED )
1755cdf0e10cSrcweir 	{
1756cdf0e10cSrcweir 		switch( m_eState )
1757cdf0e10cSrcweir 		{
1758cdf0e10cSrcweir 			case INITIAL_MODULE:
1759cdf0e10cSrcweir 				aRetFile =
1760cdf0e10cSrcweir                     m_rDatabases.getInstallPathAsURL() +
1761cdf0e10cSrcweir 					m_rDatabases.processLang( m_aLanguage ) + aSlash + m_aInitialModule +
1762cdf0e10cSrcweir 					rtl::OUString::createFromAscii( ".key" );
1763cdf0e10cSrcweir 
1764cdf0e10cSrcweir 				o_rbExtension = false;
1765cdf0e10cSrcweir 
1766cdf0e10cSrcweir 				m_eState = USER_EXTENSIONS;		// Later: SHARED_MODULE
1767cdf0e10cSrcweir 				break;
1768cdf0e10cSrcweir 
1769cdf0e10cSrcweir 			// Later:
1770cdf0e10cSrcweir 			//case SHARED_MODULE
1771cdf0e10cSrcweir 				//...
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir 			case USER_EXTENSIONS:
1774cdf0e10cSrcweir 			{
1775cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1776cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextUserHelpPackage( xParentPackageBundle );
1777cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1778cdf0e10cSrcweir 					break;
1779cdf0e10cSrcweir 
1780cdf0e10cSrcweir 				aRetFile = implGetDbFileFromPackage( xHelpPackage );
1781cdf0e10cSrcweir 				o_rbExtension = true;
1782cdf0e10cSrcweir 				break;
1783cdf0e10cSrcweir 			}
1784cdf0e10cSrcweir 
1785cdf0e10cSrcweir 			case SHARED_EXTENSIONS:
1786cdf0e10cSrcweir 			{
1787cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1788cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextSharedHelpPackage( xParentPackageBundle );
1789cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1790cdf0e10cSrcweir 					break;
1791cdf0e10cSrcweir 
1792cdf0e10cSrcweir 				aRetFile = implGetDbFileFromPackage( xHelpPackage );
1793cdf0e10cSrcweir 				o_rbExtension = true;
1794cdf0e10cSrcweir 				break;
1795cdf0e10cSrcweir 			}
1796cdf0e10cSrcweir 
1797cdf0e10cSrcweir             case BUNDLED_EXTENSIONS:
1798cdf0e10cSrcweir 			{
1799cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1800cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextBundledHelpPackage( xParentPackageBundle );
1801cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1802cdf0e10cSrcweir 					break;
1803cdf0e10cSrcweir 
1804cdf0e10cSrcweir 				aRetFile = implGetDbFileFromPackage( xHelpPackage );
1805cdf0e10cSrcweir 				o_rbExtension = true;
1806cdf0e10cSrcweir 				break;
1807cdf0e10cSrcweir 			}
1808cdf0e10cSrcweir 
1809cdf0e10cSrcweir             case END_REACHED:
1810cdf0e10cSrcweir 				VOS_ENSURE( false, "DataBaseIterator::nextDbFile(): Invalid case END_REACHED" );
1811cdf0e10cSrcweir 				break;
1812cdf0e10cSrcweir 		}
1813cdf0e10cSrcweir 	}
1814cdf0e10cSrcweir 
1815cdf0e10cSrcweir 	return aRetFile;
1816cdf0e10cSrcweir }
1817cdf0e10cSrcweir 
1818cdf0e10cSrcweir //Returns a file URL, that does not contain macros
1819cdf0e10cSrcweir rtl::OUString KeyDataBaseFileIterator::implGetDbFileFromPackage
1820cdf0e10cSrcweir 	( Reference< deployment::XPackage > xPackage )
1821cdf0e10cSrcweir {
1822cdf0e10cSrcweir 	rtl::OUString aExpandedURL =
1823cdf0e10cSrcweir 		implGetFileFromPackage( rtl::OUString::createFromAscii( ".key" ), xPackage );
1824cdf0e10cSrcweir 
1825cdf0e10cSrcweir     return aExpandedURL;
1826cdf0e10cSrcweir }
1827cdf0e10cSrcweir 
1828cdf0e10cSrcweir 
1829cdf0e10cSrcweir //===================================================================
1830cdf0e10cSrcweir // class JarFileIterator
1831cdf0e10cSrcweir 
1832cdf0e10cSrcweir Reference< XHierarchicalNameAccess > JarFileIterator::nextJarFile
1833cdf0e10cSrcweir 	( Reference< deployment::XPackage >& o_xParentPackageBundle,
1834cdf0e10cSrcweir         rtl::OUString* o_pExtensionPath, rtl::OUString* o_pExtensionRegistryPath )
1835cdf0e10cSrcweir {
1836cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xNA;
1837cdf0e10cSrcweir 
1838cdf0e10cSrcweir 	while( !xNA.is() && m_eState != END_REACHED )
1839cdf0e10cSrcweir 	{
1840cdf0e10cSrcweir 		switch( m_eState )
1841cdf0e10cSrcweir 		{
1842cdf0e10cSrcweir 			case INITIAL_MODULE:
1843cdf0e10cSrcweir 				xNA = m_rDatabases.jarFile( m_aInitialModule, m_aLanguage );
1844cdf0e10cSrcweir 				m_eState = USER_EXTENSIONS;		// Later: SHARED_MODULE
1845cdf0e10cSrcweir 				break;
1846cdf0e10cSrcweir 
1847cdf0e10cSrcweir 			// Later:
1848cdf0e10cSrcweir 			//case SHARED_MODULE
1849cdf0e10cSrcweir 				//...
1850cdf0e10cSrcweir 
1851cdf0e10cSrcweir 			case USER_EXTENSIONS:
1852cdf0e10cSrcweir 			{
1853cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextUserHelpPackage( o_xParentPackageBundle );
1854cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1855cdf0e10cSrcweir 					break;
1856cdf0e10cSrcweir 
1857cdf0e10cSrcweir 				xNA = implGetJarFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath );
1858cdf0e10cSrcweir 				break;
1859cdf0e10cSrcweir 			}
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir 			case SHARED_EXTENSIONS:
1862cdf0e10cSrcweir 			{
1863cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextSharedHelpPackage( o_xParentPackageBundle );
1864cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1865cdf0e10cSrcweir 					break;
1866cdf0e10cSrcweir 
1867cdf0e10cSrcweir 				xNA = implGetJarFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath );
1868cdf0e10cSrcweir 				break;
1869cdf0e10cSrcweir 			}
1870cdf0e10cSrcweir 
1871cdf0e10cSrcweir 			case BUNDLED_EXTENSIONS:
1872cdf0e10cSrcweir 			{
1873cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextBundledHelpPackage( o_xParentPackageBundle );
1874cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1875cdf0e10cSrcweir 					break;
1876cdf0e10cSrcweir 
1877cdf0e10cSrcweir 				xNA = implGetJarFromPackage( xHelpPackage, o_pExtensionPath, o_pExtensionRegistryPath );
1878cdf0e10cSrcweir 				break;
1879cdf0e10cSrcweir 			}
1880cdf0e10cSrcweir 
1881cdf0e10cSrcweir             case END_REACHED:
1882cdf0e10cSrcweir 				VOS_ENSURE( false, "JarFileIterator::nextJarFile(): Invalid case END_REACHED" );
1883cdf0e10cSrcweir 				break;
1884cdf0e10cSrcweir 		}
1885cdf0e10cSrcweir 	}
1886cdf0e10cSrcweir 
1887cdf0e10cSrcweir 	return xNA;
1888cdf0e10cSrcweir }
1889cdf0e10cSrcweir 
1890cdf0e10cSrcweir Reference< XHierarchicalNameAccess > JarFileIterator::implGetJarFromPackage
1891cdf0e10cSrcweir ( Reference< deployment::XPackage > xPackage, rtl::OUString* o_pExtensionPath, rtl::OUString* o_pExtensionRegistryPath )
1892cdf0e10cSrcweir {
1893cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xNA;
1894cdf0e10cSrcweir 
1895cdf0e10cSrcweir 	rtl::OUString zipFile =
1896cdf0e10cSrcweir 		implGetFileFromPackage( rtl::OUString::createFromAscii( ".jar" ), xPackage );
1897cdf0e10cSrcweir 
1898cdf0e10cSrcweir 	try
1899cdf0e10cSrcweir 	{
1900cdf0e10cSrcweir         Sequence< Any > aArguments( 2 );
1901cdf0e10cSrcweir         aArguments[ 0 ] <<= zipFile;
1902cdf0e10cSrcweir 
1903cdf0e10cSrcweir         // let ZipPackage be used ( no manifest.xml is required )
1904cdf0e10cSrcweir         beans::NamedValue aArg;
1905cdf0e10cSrcweir         aArg.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) );
1906cdf0e10cSrcweir         aArg.Value <<= ZIP_STORAGE_FORMAT_STRING;
1907cdf0e10cSrcweir         aArguments[ 1 ] <<= aArg;
1908cdf0e10cSrcweir 
1909cdf0e10cSrcweir 		Reference< XMultiComponentFactory >xSMgr( m_xContext->getServiceManager(), UNO_QUERY );
1910cdf0e10cSrcweir 		Reference< XInterface > xIfc
1911cdf0e10cSrcweir 			= xSMgr->createInstanceWithArgumentsAndContext(
1912cdf0e10cSrcweir 				rtl::OUString::createFromAscii(
1913cdf0e10cSrcweir 					"com.sun.star.packages.comp.ZipPackage" ),
1914cdf0e10cSrcweir 				aArguments, m_xContext );
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir 		if ( xIfc.is() )
1917cdf0e10cSrcweir 		{
1918cdf0e10cSrcweir 			xNA = Reference< XHierarchicalNameAccess >( xIfc, UNO_QUERY );
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir 			VOS_ENSURE( xNA.is(),
1921cdf0e10cSrcweir 				"JarFileIterator::implGetJarFromPackage() - "
1922cdf0e10cSrcweir 				"Got no hierarchical name access!" );
1923cdf0e10cSrcweir 		}
1924cdf0e10cSrcweir 	}
1925cdf0e10cSrcweir 	catch ( RuntimeException & )
1926cdf0e10cSrcweir 	{}
1927cdf0e10cSrcweir 	catch ( Exception & )
1928cdf0e10cSrcweir 	{}
1929cdf0e10cSrcweir 
1930cdf0e10cSrcweir 	if( xNA.is() && o_pExtensionPath != NULL )
1931cdf0e10cSrcweir 	{
1932cdf0e10cSrcweir 		// Extract path including language from file name
1933cdf0e10cSrcweir 		sal_Int32 nLastSlash = zipFile.lastIndexOf( '/' );
1934cdf0e10cSrcweir 		if( nLastSlash != -1 )
1935cdf0e10cSrcweir 			*o_pExtensionPath = zipFile.copy( 0, nLastSlash );
1936cdf0e10cSrcweir 
1937cdf0e10cSrcweir         if( o_pExtensionRegistryPath != NULL )
1938cdf0e10cSrcweir         {
1939cdf0e10cSrcweir             rtl::OUString& rPath = *o_pExtensionPath;
1940cdf0e10cSrcweir             sal_Int32 nLastSlashInPath = rPath.lastIndexOf( '/', rPath.getLength() - 1 );
1941cdf0e10cSrcweir 
1942cdf0e10cSrcweir             *o_pExtensionRegistryPath = xPackage->getURL();
1943cdf0e10cSrcweir             *o_pExtensionRegistryPath += rPath.copy( nLastSlashInPath);
1944cdf0e10cSrcweir         }
1945cdf0e10cSrcweir 	}
1946cdf0e10cSrcweir 
1947cdf0e10cSrcweir 	return xNA;
1948cdf0e10cSrcweir }
1949cdf0e10cSrcweir 
1950cdf0e10cSrcweir 
1951cdf0e10cSrcweir //===================================================================
1952cdf0e10cSrcweir // class IndexFolderIterator
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir rtl::OUString IndexFolderIterator::nextIndexFolder( bool& o_rbExtension, bool& o_rbTemporary )
1955cdf0e10cSrcweir {
1956cdf0e10cSrcweir 	rtl::OUString aIndexFolder;
1957cdf0e10cSrcweir 
1958cdf0e10cSrcweir 	while( !aIndexFolder.getLength() && m_eState != END_REACHED )
1959cdf0e10cSrcweir 	{
1960cdf0e10cSrcweir 		switch( m_eState )
1961cdf0e10cSrcweir 		{
1962cdf0e10cSrcweir 			case INITIAL_MODULE:
1963cdf0e10cSrcweir 				aIndexFolder =
1964cdf0e10cSrcweir 					m_rDatabases.getInstallPathAsURL() +
1965cdf0e10cSrcweir 					m_rDatabases.processLang( m_aLanguage ) + aSlash + m_aInitialModule +
1966cdf0e10cSrcweir 					rtl::OUString::createFromAscii( ".idxl" );
1967cdf0e10cSrcweir 
1968cdf0e10cSrcweir 				o_rbTemporary = false;
1969cdf0e10cSrcweir 				o_rbExtension = false;
1970cdf0e10cSrcweir 
1971cdf0e10cSrcweir 				m_eState = USER_EXTENSIONS;		// Later: SHARED_MODULE
1972cdf0e10cSrcweir 				break;
1973cdf0e10cSrcweir 
1974cdf0e10cSrcweir 			// Later:
1975cdf0e10cSrcweir 			//case SHARED_MODULE
1976cdf0e10cSrcweir 				//...
1977cdf0e10cSrcweir 
1978cdf0e10cSrcweir 			case USER_EXTENSIONS:
1979cdf0e10cSrcweir 			{
1980cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1981cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextUserHelpPackage( xParentPackageBundle );
1982cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1983cdf0e10cSrcweir 					break;
1984cdf0e10cSrcweir 
1985cdf0e10cSrcweir 				aIndexFolder = implGetIndexFolderFromPackage( o_rbTemporary, xHelpPackage );
1986cdf0e10cSrcweir 				o_rbExtension = true;
1987cdf0e10cSrcweir 				break;
1988cdf0e10cSrcweir 			}
1989cdf0e10cSrcweir 
1990cdf0e10cSrcweir 			case SHARED_EXTENSIONS:
1991cdf0e10cSrcweir 			{
1992cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
1993cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextSharedHelpPackage( xParentPackageBundle );
1994cdf0e10cSrcweir 				if( !xHelpPackage.is() )
1995cdf0e10cSrcweir 					break;
1996cdf0e10cSrcweir 
1997cdf0e10cSrcweir 				aIndexFolder = implGetIndexFolderFromPackage( o_rbTemporary, xHelpPackage );
1998cdf0e10cSrcweir 				o_rbExtension = true;
1999cdf0e10cSrcweir 				break;
2000cdf0e10cSrcweir 			}
2001cdf0e10cSrcweir 
2002cdf0e10cSrcweir 			case BUNDLED_EXTENSIONS:
2003cdf0e10cSrcweir 			{
2004cdf0e10cSrcweir 				Reference< deployment::XPackage > xParentPackageBundle;
2005cdf0e10cSrcweir 				Reference< deployment::XPackage > xHelpPackage = implGetNextBundledHelpPackage( xParentPackageBundle );
2006cdf0e10cSrcweir 				if( !xHelpPackage.is() )
2007cdf0e10cSrcweir 					break;
2008cdf0e10cSrcweir 
2009cdf0e10cSrcweir 				aIndexFolder = implGetIndexFolderFromPackage( o_rbTemporary, xHelpPackage );
2010cdf0e10cSrcweir 				o_rbExtension = true;
2011cdf0e10cSrcweir 				break;
2012cdf0e10cSrcweir 			}
2013cdf0e10cSrcweir 
2014cdf0e10cSrcweir             case END_REACHED:
2015cdf0e10cSrcweir 				VOS_ENSURE( false, "IndexFolderIterator::nextIndexFolder(): Invalid case END_REACHED" );
2016cdf0e10cSrcweir 				break;
2017cdf0e10cSrcweir 		}
2018cdf0e10cSrcweir 	}
2019cdf0e10cSrcweir 
2020cdf0e10cSrcweir 	return aIndexFolder;
2021cdf0e10cSrcweir }
2022cdf0e10cSrcweir 
2023cdf0e10cSrcweir rtl::OUString IndexFolderIterator::implGetIndexFolderFromPackage( bool& o_rbTemporary, Reference< deployment::XPackage > xPackage )
2024cdf0e10cSrcweir {
2025cdf0e10cSrcweir 	rtl::OUString aIndexFolder =
2026cdf0e10cSrcweir 		implGetFileFromPackage( rtl::OUString::createFromAscii( ".idxl" ), xPackage );
2027cdf0e10cSrcweir 
2028cdf0e10cSrcweir 	o_rbTemporary = false;
2029cdf0e10cSrcweir 	if( !m_xSFA->isFolder( aIndexFolder ) )
2030cdf0e10cSrcweir 	{
2031cdf0e10cSrcweir 		// i98680: Missing index? Try to generate now
2032cdf0e10cSrcweir 		rtl::OUString aLangURL = implGetFileFromPackage( rtl::OUString(), xPackage );
2033cdf0e10cSrcweir 		if( m_xSFA->isFolder( aLangURL ) )
2034cdf0e10cSrcweir 		{
2035cdf0e10cSrcweir 			// Test write access (shared extension may be read only)
2036cdf0e10cSrcweir 			bool bIsWriteAccess = false;
2037cdf0e10cSrcweir 			try
2038cdf0e10cSrcweir 			{
2039cdf0e10cSrcweir 				rtl::OUString aCreateTestFolder = aLangURL + rtl::OUString::createFromAscii( "CreateTestFolder" );
2040cdf0e10cSrcweir 				m_xSFA->createFolder( aCreateTestFolder );
2041cdf0e10cSrcweir 				if( m_xSFA->isFolder( aCreateTestFolder  ) )
2042cdf0e10cSrcweir 					bIsWriteAccess = true;
2043cdf0e10cSrcweir 
2044cdf0e10cSrcweir 				m_xSFA->kill( aCreateTestFolder );
2045cdf0e10cSrcweir 			}
2046cdf0e10cSrcweir 			catch (Exception &)
2047cdf0e10cSrcweir 			{}
2048cdf0e10cSrcweir 
2049cdf0e10cSrcweir 			// TEST
2050cdf0e10cSrcweir 			//bIsWriteAccess = false;
2051cdf0e10cSrcweir 
2052cdf0e10cSrcweir 			Reference< script::XInvocation > xInvocation;
2053cdf0e10cSrcweir 			Reference< XMultiComponentFactory >xSMgr( m_xContext->getServiceManager(), UNO_QUERY );
2054cdf0e10cSrcweir 			try
2055cdf0e10cSrcweir 			{
2056cdf0e10cSrcweir 				xInvocation = Reference< script::XInvocation >(
2057cdf0e10cSrcweir 					m_xContext->getServiceManager()->createInstanceWithContext( rtl::OUString::createFromAscii(
2058cdf0e10cSrcweir 					"com.sun.star.help.HelpIndexer" ), m_xContext ) , UNO_QUERY );
2059cdf0e10cSrcweir 
2060cdf0e10cSrcweir 				if( xInvocation.is() )
2061cdf0e10cSrcweir 				{
2062cdf0e10cSrcweir 					Sequence<uno::Any> aParamsSeq( bIsWriteAccess ? 6 : 8 );
2063cdf0e10cSrcweir 
2064cdf0e10cSrcweir 					aParamsSeq[0] = uno::makeAny( rtl::OUString::createFromAscii( "-lang" ) );
2065cdf0e10cSrcweir 
2066cdf0e10cSrcweir 					rtl::OUString aLang;
2067cdf0e10cSrcweir 					sal_Int32 nLastSlash = aLangURL.lastIndexOf( '/' );
2068cdf0e10cSrcweir 					if( nLastSlash != -1 )
2069cdf0e10cSrcweir 						aLang = aLangURL.copy( nLastSlash + 1 );
2070cdf0e10cSrcweir 					else
2071cdf0e10cSrcweir 						aLang = rtl::OUString::createFromAscii( "en" );
2072cdf0e10cSrcweir 					aParamsSeq[1] = uno::makeAny( aLang );
2073cdf0e10cSrcweir 
2074cdf0e10cSrcweir 					aParamsSeq[2] = uno::makeAny( rtl::OUString::createFromAscii( "-mod" ) );
2075cdf0e10cSrcweir 					aParamsSeq[3] = uno::makeAny( rtl::OUString::createFromAscii( "help" ) );
2076cdf0e10cSrcweir 
2077cdf0e10cSrcweir 					rtl::OUString aZipDir = aLangURL;
2078cdf0e10cSrcweir 					if( !bIsWriteAccess )
2079cdf0e10cSrcweir 					{
2080cdf0e10cSrcweir 						rtl::OUString aTempFileURL;
2081cdf0e10cSrcweir 						::osl::FileBase::RC eErr = ::osl::File::createTempFile( 0, 0, &aTempFileURL );
2082cdf0e10cSrcweir 						if( eErr == ::osl::FileBase::E_None )
2083cdf0e10cSrcweir 						{
2084cdf0e10cSrcweir 							rtl::OUString aTempDirURL = aTempFileURL;
2085cdf0e10cSrcweir 							try
2086cdf0e10cSrcweir 							{
2087cdf0e10cSrcweir 								m_xSFA->kill( aTempDirURL );
2088cdf0e10cSrcweir 							}
2089cdf0e10cSrcweir 							catch (Exception &)
2090cdf0e10cSrcweir 							{}
2091cdf0e10cSrcweir 							m_xSFA->createFolder( aTempDirURL );
2092cdf0e10cSrcweir 
2093cdf0e10cSrcweir 							aZipDir = aTempDirURL;
2094cdf0e10cSrcweir 							o_rbTemporary = true;
2095cdf0e10cSrcweir 						}
2096cdf0e10cSrcweir 					}
2097cdf0e10cSrcweir 
2098cdf0e10cSrcweir 					aParamsSeq[4] = uno::makeAny( rtl::OUString::createFromAscii( "-zipdir" ) );
2099cdf0e10cSrcweir 					rtl::OUString aSystemPath;
2100cdf0e10cSrcweir 					osl::FileBase::getSystemPathFromFileURL( aZipDir, aSystemPath );
2101cdf0e10cSrcweir 					aParamsSeq[5] = uno::makeAny( aSystemPath );
2102cdf0e10cSrcweir 
2103cdf0e10cSrcweir 					if( !bIsWriteAccess )
2104cdf0e10cSrcweir 					{
2105cdf0e10cSrcweir 						aParamsSeq[6] = uno::makeAny( rtl::OUString::createFromAscii( "-srcdir" ) );
2106cdf0e10cSrcweir 						rtl::OUString aSrcDirVal;
2107cdf0e10cSrcweir 						osl::FileBase::getSystemPathFromFileURL( aLangURL, aSrcDirVal );
2108cdf0e10cSrcweir 						aParamsSeq[7] = uno::makeAny( aSrcDirVal );
2109cdf0e10cSrcweir 					}
2110cdf0e10cSrcweir 
2111cdf0e10cSrcweir 					Sequence< sal_Int16 > aOutParamIndex;
2112cdf0e10cSrcweir 					Sequence< uno::Any > aOutParam;
2113cdf0e10cSrcweir 					uno::Any aRet = xInvocation->invoke( rtl::OUString::createFromAscii( "createIndex" ),
2114cdf0e10cSrcweir 						aParamsSeq, aOutParamIndex, aOutParam );
2115cdf0e10cSrcweir 
2116cdf0e10cSrcweir 					if( bIsWriteAccess )
2117cdf0e10cSrcweir 						aIndexFolder = implGetFileFromPackage( rtl::OUString::createFromAscii( ".idxl" ), xPackage );
2118cdf0e10cSrcweir 					else
2119cdf0e10cSrcweir 						aIndexFolder = aZipDir + rtl::OUString::createFromAscii( "/help.idxl" );
2120cdf0e10cSrcweir 				}
2121cdf0e10cSrcweir 			}
2122cdf0e10cSrcweir 			catch (Exception &)
2123cdf0e10cSrcweir 			{}
2124cdf0e10cSrcweir 		}
2125cdf0e10cSrcweir 	}
2126cdf0e10cSrcweir 
2127cdf0e10cSrcweir 	return aIndexFolder;
2128cdf0e10cSrcweir }
2129cdf0e10cSrcweir 
2130cdf0e10cSrcweir void IndexFolderIterator::deleteTempIndexFolder( const rtl::OUString& aIndexFolder )
2131cdf0e10cSrcweir {
2132cdf0e10cSrcweir 	sal_Int32 nLastSlash = aIndexFolder.lastIndexOf( '/' );
2133cdf0e10cSrcweir 	if( nLastSlash != -1 )
2134cdf0e10cSrcweir 	{
2135cdf0e10cSrcweir 		rtl::OUString aTmpFolder = aIndexFolder.copy( 0, nLastSlash );
2136cdf0e10cSrcweir 		try
2137cdf0e10cSrcweir 		{
2138cdf0e10cSrcweir 			m_xSFA->kill( aTmpFolder );
2139cdf0e10cSrcweir 		}
2140cdf0e10cSrcweir 		catch (Exception &)
2141cdf0e10cSrcweir 		{}
2142cdf0e10cSrcweir 	}
2143cdf0e10cSrcweir }
2144