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