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