1*d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*d119d52dSAndrew Rist * distributed with this work for additional information 6*d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9*d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*d119d52dSAndrew Rist * software distributed under the License is distributed on an 15*d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17*d119d52dSAndrew Rist * specific language governing permissions and limitations 18*d119d52dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*d119d52dSAndrew Rist *************************************************************/ 21*d119d52dSAndrew Rist 22*d119d52dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "fltfnc.hxx" 28cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp> 29cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 30cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 31cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 32cdf0e10cSrcweir #include <com/sun/star/container/XEnumeration.hpp> 33cdf0e10cSrcweir #include <com/sun/star/datatransfer/DataFlavor.hpp> 34cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp> 35cdf0e10cSrcweir #include <com/sun/star/container/XContainerQuery.hpp> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx> 38cdf0e10cSrcweir 39cdf0e10cSrcweir #ifndef _EXCHANGE_HXX //autogen 40cdf0e10cSrcweir #include <sot/exchange.hxx> 41cdf0e10cSrcweir #endif 42cdf0e10cSrcweir #include <tools/config.hxx> 43cdf0e10cSrcweir #include <basic/sbmeth.hxx> 44cdf0e10cSrcweir #include <basic/basmgr.hxx> 45cdf0e10cSrcweir #include <basic/sbstar.hxx> 46cdf0e10cSrcweir #include <basic/sbxobj.hxx> 47cdf0e10cSrcweir #include <basic/sbxmeth.hxx> 48cdf0e10cSrcweir #include <basic/sbxcore.hxx> 49cdf0e10cSrcweir #ifndef _MSGBOX_HXX //autogen 50cdf0e10cSrcweir #include <vcl/msgbox.hxx> 51cdf0e10cSrcweir #endif 52cdf0e10cSrcweir #ifndef _RTL_USTRING_HXX //autogen 53cdf0e10cSrcweir #include <rtl/ustring.hxx> 54cdf0e10cSrcweir #endif 55cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 56cdf0e10cSrcweir #include <svl/eitem.hxx> 57cdf0e10cSrcweir #include <svl/intitem.hxx> 58cdf0e10cSrcweir #include <svl/stritem.hxx> 59cdf0e10cSrcweir #include <svl/lckbitem.hxx> 60cdf0e10cSrcweir #include <svl/inettype.hxx> 61cdf0e10cSrcweir #include <svl/rectitem.hxx> 62cdf0e10cSrcweir 63cdf0e10cSrcweir #include <sot/storage.hxx> 64cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterceptor.hpp> 65cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp> 66cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 67cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp> 68cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 69cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp> 70cdf0e10cSrcweir #include <com/sun/star/frame/FeatureStateEvent.hpp> 71cdf0e10cSrcweir #include <com/sun/star/frame/DispatchDescriptor.hpp> 72cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp> 73cdf0e10cSrcweir #include <com/sun/star/frame/XFrameActionListener.hpp> 74cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 75cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 76cdf0e10cSrcweir #include <com/sun/star/frame/FrameActionEvent.hpp> 77cdf0e10cSrcweir #include <com/sun/star/frame/FrameAction.hpp> 78cdf0e10cSrcweir #include <com/sun/star/frame/XFrameLoader.hpp> 79cdf0e10cSrcweir #include <com/sun/star/frame/XLoadEventListener.hpp> 80cdf0e10cSrcweir #include <com/sun/star/frame/XFilterDetect.hpp> 81cdf0e10cSrcweir #include <com/sun/star/loader/XImplementationLoader.hpp> 82cdf0e10cSrcweir #include <com/sun/star/loader/CannotActivateFactoryException.hpp> 83cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 84cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 85cdf0e10cSrcweir #endif 86cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 87cdf0e10cSrcweir 88cdf0e10cSrcweir #include <sal/types.h> 89cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 90cdf0e10cSrcweir #include <com/sun/star/ucb/XContent.hpp> 91cdf0e10cSrcweir #include <rtl/ustring.hxx> 92cdf0e10cSrcweir #include <vos/process.hxx> 93cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 94cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 95cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx> 96cdf0e10cSrcweir #include <tools/urlobj.hxx> 97cdf0e10cSrcweir 98cdf0e10cSrcweir #include <rtl/logfile.hxx> 99cdf0e10cSrcweir 100cdf0e10cSrcweir using namespace ::com::sun::star::uno; 101cdf0e10cSrcweir using namespace ::com::sun::star::ucb; 102cdf0e10cSrcweir using namespace ::com::sun::star::document; 103cdf0e10cSrcweir using namespace ::com::sun::star::beans; 104cdf0e10cSrcweir using namespace ::vos; 105cdf0e10cSrcweir #include <svl/ctypeitm.hxx> 106cdf0e10cSrcweir #include <svtools/sfxecode.hxx> 107cdf0e10cSrcweir #include <unotools/syslocale.hxx> 108cdf0e10cSrcweir 109cdf0e10cSrcweir #include "sfx2/sfxhelp.hxx" 110cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 111cdf0e10cSrcweir #include <sfx2/docfac.hxx> 112cdf0e10cSrcweir #include "sfxtypes.hxx" 113cdf0e10cSrcweir #include <sfx2/sfxuno.hxx> 114cdf0e10cSrcweir #include <sfx2/docfile.hxx> 115cdf0e10cSrcweir #include <sfx2/progress.hxx> 116cdf0e10cSrcweir #include "openflag.hxx" 117cdf0e10cSrcweir #include "bastyp.hrc" 118cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 119cdf0e10cSrcweir #include <sfx2/doctempl.hxx> 120cdf0e10cSrcweir #include <sfx2/frame.hxx> 121cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 122cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 123cdf0e10cSrcweir #include "helper.hxx" 124cdf0e10cSrcweir #include "fltlst.hxx" 125cdf0e10cSrcweir #include <sfx2/request.hxx> 126cdf0e10cSrcweir #include "arrdecl.hxx" 127cdf0e10cSrcweir #include <sfx2/appuno.hxx> 128cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 129cdf0e10cSrcweir 130cdf0e10cSrcweir static SfxFilterList_Impl* pFilterArr = 0; 131cdf0e10cSrcweir static sal_Bool bFirstRead = sal_True; 132cdf0e10cSrcweir 133cdf0e10cSrcweir static void CreateFilterArr() 134cdf0e10cSrcweir { 135cdf0e10cSrcweir pFilterArr = new SfxFilterList_Impl; 136cdf0e10cSrcweir new SfxFilterListener(); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir //---------------------------------------------------------------- 140cdf0e10cSrcweir inline String ToUpper_Impl( const String &rStr ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir return SvtSysLocale().GetCharClass().upper( rStr ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir //---------------------------------------------------------------- 146cdf0e10cSrcweir class SfxFilterContainer_Impl 147cdf0e10cSrcweir { 148cdf0e10cSrcweir public: 149cdf0e10cSrcweir String aName; 150cdf0e10cSrcweir String aServiceName; 151cdf0e10cSrcweir 152cdf0e10cSrcweir SfxFilterContainer_Impl( const String& rName ) 153cdf0e10cSrcweir : aName( rName ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir aServiceName = SfxObjectShell::GetServiceNameFromFactory( rName ); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir }; 158cdf0e10cSrcweir 159cdf0e10cSrcweir #define IMPL_FORWARD_LOOP( aMethod, ArgType, aArg ) \ 160cdf0e10cSrcweir const SfxFilter* SfxFilterContainer::aMethod( ArgType aArg, SfxFilterFlags nMust, SfxFilterFlags nDont ) const \ 161cdf0e10cSrcweir {\ 162cdf0e10cSrcweir SfxFilterMatcher aMatch( pImpl->aName ); \ 163cdf0e10cSrcweir return aMatch.aMethod( aArg, nMust, nDont ); \ 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir IMPL_FORWARD_LOOP( GetFilter4Mime, const String&, rMime ); 167cdf0e10cSrcweir IMPL_FORWARD_LOOP( GetFilter4ClipBoardId, sal_uInt32, nId ); 168cdf0e10cSrcweir IMPL_FORWARD_LOOP( GetFilter4EA, const String&, rEA ); 169cdf0e10cSrcweir IMPL_FORWARD_LOOP( GetFilter4Extension, const String&, rExt ); 170cdf0e10cSrcweir IMPL_FORWARD_LOOP( GetFilter4FilterName, const String&, rName ); 171cdf0e10cSrcweir IMPL_FORWARD_LOOP( GetFilter4UIName, const String&, rName ); 172cdf0e10cSrcweir 173cdf0e10cSrcweir const SfxFilter* SfxFilterContainer::GetAnyFilter( SfxFilterFlags nMust, SfxFilterFlags nDont ) const 174cdf0e10cSrcweir { 175cdf0e10cSrcweir SfxFilterMatcher aMatch( pImpl->aName ); 176cdf0e10cSrcweir return aMatch.GetAnyFilter( nMust, nDont ); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir //---------------------------------------------------------------- 180cdf0e10cSrcweir 181cdf0e10cSrcweir SfxFilterContainer::SfxFilterContainer( const String& rName ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir pImpl = new SfxFilterContainer_Impl( rName ); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir //---------------------------------------------------------------- 187cdf0e10cSrcweir 188cdf0e10cSrcweir SfxFilterContainer::~SfxFilterContainer() 189cdf0e10cSrcweir { 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir //---------------------------------------------------------------- 193cdf0e10cSrcweir 194cdf0e10cSrcweir const String SfxFilterContainer::GetName() const 195cdf0e10cSrcweir { 196cdf0e10cSrcweir return pImpl->aName; 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir const SfxFilter* SfxFilterContainer::GetDefaultFilter_Impl( const String& rName ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir // Try to find out the type of factory. 202cdf0e10cSrcweir // Interpret given name as Service- and ShortName! 203cdf0e10cSrcweir SvtModuleOptions aOpt; 204cdf0e10cSrcweir SvtModuleOptions::EFactory eFactory = aOpt.ClassifyFactoryByServiceName(rName); 205cdf0e10cSrcweir if (eFactory == SvtModuleOptions::E_UNKNOWN_FACTORY) 206cdf0e10cSrcweir eFactory = aOpt.ClassifyFactoryByShortName(rName); 207cdf0e10cSrcweir 208cdf0e10cSrcweir // could not classify factory by its service nor by its short name. 209cdf0e10cSrcweir // Must be an unknown factory! => return NULL 210cdf0e10cSrcweir if (eFactory == SvtModuleOptions::E_UNKNOWN_FACTORY) 211cdf0e10cSrcweir return NULL; 212cdf0e10cSrcweir 213cdf0e10cSrcweir // For the following code we need some additional informations. 214cdf0e10cSrcweir String sServiceName = aOpt.GetFactoryName(eFactory); 215cdf0e10cSrcweir String sShortName = aOpt.GetFactoryShortName(eFactory); 216cdf0e10cSrcweir String sDefaultFilter = aOpt.GetFactoryDefaultFilter(eFactory); 217cdf0e10cSrcweir 218cdf0e10cSrcweir // Try to get the default filter. Dont fiorget to verify it. 219cdf0e10cSrcweir // May the set default filter does not exists any longer or 220cdf0e10cSrcweir // does not fit the given factory. 221cdf0e10cSrcweir const SfxFilterMatcher aMatcher; 222cdf0e10cSrcweir const SfxFilter* pFilter = aMatcher.GetFilter4FilterName(sDefaultFilter); 223cdf0e10cSrcweir 224cdf0e10cSrcweir if ( 225cdf0e10cSrcweir (pFilter ) && 226cdf0e10cSrcweir (pFilter->GetServiceName().CompareIgnoreCaseToAscii( sServiceName ) != COMPARE_EQUAL) 227cdf0e10cSrcweir ) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir pFilter = 0; 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir // If at least no default filter could be located - use any filter of this 233cdf0e10cSrcweir // factory. 234cdf0e10cSrcweir if (!pFilter) 235cdf0e10cSrcweir { 236cdf0e10cSrcweir if ( bFirstRead ) 237cdf0e10cSrcweir ReadFilters_Impl(); 238cdf0e10cSrcweir 239cdf0e10cSrcweir sal_uInt16 nCount = ( sal_uInt16 ) pFilterArr->Count(); 240cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nCount; n++ ) 241cdf0e10cSrcweir { 242cdf0e10cSrcweir const SfxFilter* pCheckFilter = pFilterArr->GetObject( n ); 243cdf0e10cSrcweir if ( pCheckFilter->GetServiceName().CompareIgnoreCaseToAscii( sServiceName ) == COMPARE_EQUAL ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir pFilter = pCheckFilter; 246cdf0e10cSrcweir break; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir } 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir return pFilter; 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir 255cdf0e10cSrcweir //---------------------------------------------------------------- 256cdf0e10cSrcweir 257cdf0e10cSrcweir class SfxFilterMatcherArr_Impl; 258cdf0e10cSrcweir static SfxFilterMatcherArr_Impl* pImplArr = 0; 259cdf0e10cSrcweir 260cdf0e10cSrcweir // Impl-Data is shared between all FilterMatchers of the same factory 261cdf0e10cSrcweir class SfxFilterMatcher_Impl 262cdf0e10cSrcweir { 263cdf0e10cSrcweir public: 264cdf0e10cSrcweir ::rtl::OUString aName; 265cdf0e10cSrcweir SfxFilterList_Impl* pList; // is created on demand 266cdf0e10cSrcweir 267cdf0e10cSrcweir void InitForIterating() const; 268cdf0e10cSrcweir void Update(); 269cdf0e10cSrcweir SfxFilterMatcher_Impl() 270cdf0e10cSrcweir : pList(0) 271cdf0e10cSrcweir {} 272cdf0e10cSrcweir }; 273cdf0e10cSrcweir 274cdf0e10cSrcweir DECL_PTRARRAY( SfxFilterMatcherArr_Impl, SfxFilterMatcher_Impl*, 2, 2 ) 275cdf0e10cSrcweir 276cdf0e10cSrcweir SfxFilterMatcher::SfxFilterMatcher( const String& rName ) 277cdf0e10cSrcweir : pImpl( 0 ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir if ( !pImplArr ) 280cdf0e10cSrcweir // keep track of created filter matchers to recycle the FilterLists 281cdf0e10cSrcweir pImplArr = new SfxFilterMatcherArr_Impl; 282cdf0e10cSrcweir 283cdf0e10cSrcweir String aName = SfxObjectShell::GetServiceNameFromFactory( rName ); 284cdf0e10cSrcweir DBG_ASSERT(aName.Len(), "Found boes type :-)"); 285cdf0e10cSrcweir for ( sal_uInt16 n=0; n<pImplArr->Count(); n++ ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir // find the impl-Data of any comparable FilterMatcher that was created before 288cdf0e10cSrcweir SfxFilterMatcher_Impl* pImp = pImplArr->GetObject(n); 289cdf0e10cSrcweir if ( String(pImp->aName) == aName ) 290cdf0e10cSrcweir pImpl = pImp; 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir if ( !pImpl ) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir // first Matcher created for this factory 296cdf0e10cSrcweir pImpl = new SfxFilterMatcher_Impl; 297cdf0e10cSrcweir pImpl->aName = aName; 298cdf0e10cSrcweir pImplArr->Insert( pImplArr->Count(), pImpl ); 299cdf0e10cSrcweir } 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir SfxFilterMatcher::SfxFilterMatcher() 303cdf0e10cSrcweir { 304cdf0e10cSrcweir // global FilterMatcher always uses global filter array (also created on demand) 305cdf0e10cSrcweir pImpl = new SfxFilterMatcher_Impl; 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir SfxFilterMatcher::~SfxFilterMatcher() 309cdf0e10cSrcweir { 310cdf0e10cSrcweir if ( !pImpl->aName.getLength() ) 311cdf0e10cSrcweir // only the global Matcher owns his ImplData 312cdf0e10cSrcweir delete pImpl; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir void SfxFilterMatcher_Impl::Update() 316cdf0e10cSrcweir { 317cdf0e10cSrcweir if ( pList ) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir // this List was already used 320cdf0e10cSrcweir pList->Clear(); 321cdf0e10cSrcweir for ( sal_uInt16 n=0; n<pFilterArr->Count(); n++ ) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir SfxFilter* pFilter = pFilterArr->GetObject(n); 324cdf0e10cSrcweir if ( pFilter->GetServiceName() == String(aName) ) 325cdf0e10cSrcweir pList->Insert( pFilter, LIST_APPEND ); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir } 328cdf0e10cSrcweir } 329cdf0e10cSrcweir 330cdf0e10cSrcweir void SfxFilterMatcher_Impl::InitForIterating() const 331cdf0e10cSrcweir { 332cdf0e10cSrcweir if ( pList ) 333cdf0e10cSrcweir return; 334cdf0e10cSrcweir 335cdf0e10cSrcweir if ( bFirstRead ) 336cdf0e10cSrcweir // global filter array has not been created yet 337cdf0e10cSrcweir SfxFilterContainer::ReadFilters_Impl(); 338cdf0e10cSrcweir 339cdf0e10cSrcweir if ( aName.getLength() ) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir // matcher of factory: use only filters of that document type 342cdf0e10cSrcweir ((SfxFilterMatcher_Impl*)this)->pList = new SfxFilterList_Impl; 343cdf0e10cSrcweir ((SfxFilterMatcher_Impl*)this)->Update(); 344cdf0e10cSrcweir } 345cdf0e10cSrcweir else 346cdf0e10cSrcweir { 347cdf0e10cSrcweir // global matcher: use global filter array 348cdf0e10cSrcweir ((SfxFilterMatcher_Impl*)this)->pList = pFilterArr; 349cdf0e10cSrcweir } 350cdf0e10cSrcweir } 351cdf0e10cSrcweir 352cdf0e10cSrcweir const SfxFilter* SfxFilterMatcher::GetAnyFilter( SfxFilterFlags nMust, SfxFilterFlags nDont ) const 353cdf0e10cSrcweir { 354cdf0e10cSrcweir pImpl->InitForIterating(); 355cdf0e10cSrcweir sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); 356cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nCount; n++ ) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir const SfxFilter* pFilter = pImpl->pList->GetObject( n ); 359cdf0e10cSrcweir SfxFilterFlags nFlags = pFilter->GetFilterFlags(); 360cdf0e10cSrcweir if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) ) 361cdf0e10cSrcweir return pFilter; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir 364cdf0e10cSrcweir return NULL; 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir //---------------------------------------------------------------- 368cdf0e10cSrcweir 369cdf0e10cSrcweir sal_uInt32 SfxFilterMatcher::GuessFilterIgnoringContent( 370cdf0e10cSrcweir SfxMedium& rMedium, 371cdf0e10cSrcweir const SfxFilter**ppFilter, 372cdf0e10cSrcweir SfxFilterFlags /*nMust*/, 373cdf0e10cSrcweir SfxFilterFlags /*nDont*/ ) const 374cdf0e10cSrcweir { 375cdf0e10cSrcweir Reference< XTypeDetection > xDetection( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection")), UNO_QUERY ); 376cdf0e10cSrcweir ::rtl::OUString sTypeName; 377cdf0e10cSrcweir try 378cdf0e10cSrcweir { 379cdf0e10cSrcweir //!MBA: nmust, ndont? 380cdf0e10cSrcweir sTypeName = xDetection->queryTypeByURL( rMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ); 381cdf0e10cSrcweir } 382cdf0e10cSrcweir catch( Exception& ) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir } 385cdf0e10cSrcweir 386cdf0e10cSrcweir *ppFilter = NULL; 387cdf0e10cSrcweir if ( sTypeName.getLength() ) 388cdf0e10cSrcweir *ppFilter = GetFilter4EA( sTypeName ); 389cdf0e10cSrcweir 390cdf0e10cSrcweir return *ppFilter ? ERRCODE_NONE : ERRCODE_ABORT; 391cdf0e10cSrcweir } 392cdf0e10cSrcweir 393cdf0e10cSrcweir //---------------------------------------------------------------- 394cdf0e10cSrcweir 395cdf0e10cSrcweir #define CHECKERROR() \ 396cdf0e10cSrcweir if( nErr == 1 || nErr == USHRT_MAX || nErr == ULONG_MAX ) \ 397cdf0e10cSrcweir { \ 398cdf0e10cSrcweir ByteString aText = "Fehler in FilterDetection: Returnwert ";\ 399cdf0e10cSrcweir aText += ByteString::CreateFromInt32(nErr); \ 400cdf0e10cSrcweir if( pFilter ) \ 401cdf0e10cSrcweir { \ 402cdf0e10cSrcweir aText += ' '; \ 403cdf0e10cSrcweir aText += ByteString(U2S(pFilter->GetFilterName())); \ 404cdf0e10cSrcweir } \ 405cdf0e10cSrcweir DBG_ERROR( aText.GetBuffer() ); \ 406cdf0e10cSrcweir nErr = ERRCODE_ABORT; \ 407cdf0e10cSrcweir } 408cdf0e10cSrcweir 409cdf0e10cSrcweir //---------------------------------------------------------------- 410cdf0e10cSrcweir 411cdf0e10cSrcweir sal_uInt32 SfxFilterMatcher::GuessFilter( SfxMedium& rMedium, const SfxFilter**ppFilter, SfxFilterFlags nMust, SfxFilterFlags nDont ) const 412cdf0e10cSrcweir { 413cdf0e10cSrcweir return GuessFilterControlDefaultUI( rMedium, ppFilter, nMust, nDont, sal_True ); 414cdf0e10cSrcweir } 415cdf0e10cSrcweir 416cdf0e10cSrcweir //---------------------------------------------------------------- 417cdf0e10cSrcweir 418cdf0e10cSrcweir sal_uInt32 SfxFilterMatcher::GuessFilterControlDefaultUI( SfxMedium& rMedium, const SfxFilter** ppFilter, SfxFilterFlags nMust, SfxFilterFlags nDont, sal_Bool /*bDefUI*/ ) const 419cdf0e10cSrcweir { 420cdf0e10cSrcweir const SfxFilter* pOldFilter = *ppFilter; 421cdf0e10cSrcweir 422cdf0e10cSrcweir // no detection service -> nothing to do ! 423cdf0e10cSrcweir Reference< XTypeDetection > xDetection( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection")), UNO_QUERY ); 424cdf0e10cSrcweir if (!xDetection.is()) 425cdf0e10cSrcweir return ERRCODE_ABORT; 426cdf0e10cSrcweir 427cdf0e10cSrcweir ::rtl::OUString sTypeName; 428cdf0e10cSrcweir try 429cdf0e10cSrcweir { 430cdf0e10cSrcweir // open the stream one times only ... 431cdf0e10cSrcweir // Otherwhise it will be tried more then once and show the same interaction more then once ... 432cdf0e10cSrcweir 433cdf0e10cSrcweir ::rtl::OUString sURL( rMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) ); 434cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInStream = rMedium.GetInputStream(); 435cdf0e10cSrcweir 436cdf0e10cSrcweir // stream exists => deep detection (with preselection ... if possible) 437cdf0e10cSrcweir if (xInStream.is()) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir ::comphelper::MediaDescriptor aDescriptor; 440cdf0e10cSrcweir 441cdf0e10cSrcweir aDescriptor[::comphelper::MediaDescriptor::PROP_URL() ] <<= sURL; 442cdf0e10cSrcweir aDescriptor[::comphelper::MediaDescriptor::PROP_INPUTSTREAM() ] <<= xInStream; 443cdf0e10cSrcweir aDescriptor[::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= rMedium.GetInteractionHandler(); 444cdf0e10cSrcweir 445cdf0e10cSrcweir if ( pImpl->aName.getLength() ) 446cdf0e10cSrcweir aDescriptor[::comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE()] <<= pImpl->aName; 447cdf0e10cSrcweir 448cdf0e10cSrcweir if ( pOldFilter ) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME() ] <<= ::rtl::OUString( pOldFilter->GetTypeName() ); 451cdf0e10cSrcweir aDescriptor[::comphelper::MediaDescriptor::PROP_FILTERNAME()] <<= ::rtl::OUString( pOldFilter->GetFilterName() ); 452cdf0e10cSrcweir } 453cdf0e10cSrcweir 454cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lDescriptor = aDescriptor.getAsConstPropertyValueList(); 455cdf0e10cSrcweir sTypeName = xDetection->queryTypeByDescriptor(lDescriptor, sal_True); // lDescriptor is used as In/Out param ... dont use aDescriptor.getAsConstPropertyValueList() directly! 456cdf0e10cSrcweir } 457cdf0e10cSrcweir // no stream exists => try flat detection without preselection as fallback 458cdf0e10cSrcweir else 459cdf0e10cSrcweir sTypeName = xDetection->queryTypeByURL(sURL); 460cdf0e10cSrcweir 461cdf0e10cSrcweir if (sTypeName.getLength()) 462cdf0e10cSrcweir { 463cdf0e10cSrcweir // detect filter by given type 464cdf0e10cSrcweir // In case of this matcher is bound to a particular document type: 465cdf0e10cSrcweir // If there is no acceptable type for this document at all, the type detection has possibly returned something else. 466cdf0e10cSrcweir // The DocumentService property is only a preselection, and all preselections are considered as optional! 467cdf0e10cSrcweir // This "wrong" type will be sorted out now because we match only allowed filters to the detected type 468cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > lQuery(1); 469cdf0e10cSrcweir lQuery[0].Name = ::rtl::OUString::createFromAscii("Name"); 470cdf0e10cSrcweir lQuery[0].Value <<= sTypeName; 471cdf0e10cSrcweir 472cdf0e10cSrcweir const SfxFilter* pFilter = GetFilterForProps(lQuery, nMust, nDont); 473cdf0e10cSrcweir if (pFilter) 474cdf0e10cSrcweir { 475cdf0e10cSrcweir *ppFilter = pFilter; 476cdf0e10cSrcweir return ERRCODE_NONE; 477cdf0e10cSrcweir } 478cdf0e10cSrcweir } 479cdf0e10cSrcweir } 480cdf0e10cSrcweir catch(const Exception&) 481cdf0e10cSrcweir {} 482cdf0e10cSrcweir 483cdf0e10cSrcweir return ERRCODE_ABORT; 484cdf0e10cSrcweir } 485cdf0e10cSrcweir 486cdf0e10cSrcweir //---------------------------------------------------------------- 487cdf0e10cSrcweir sal_Bool SfxFilterMatcher::IsFilterInstalled_Impl( const SfxFilter* pFilter ) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir if ( pFilter->GetFilterFlags() & SFX_FILTER_MUSTINSTALL ) 490cdf0e10cSrcweir { 491cdf0e10cSrcweir // Hier k"onnte noch eine Nachinstallation angeboten werden 492cdf0e10cSrcweir String aText( SfxResId( STR_FILTER_NOT_INSTALLED ) ); 493cdf0e10cSrcweir aText.SearchAndReplaceAscii( "$(FILTER)", pFilter->GetUIName() ); 494cdf0e10cSrcweir QueryBox aQuery( NULL, WB_YES_NO | WB_DEF_YES, aText ); 495cdf0e10cSrcweir short nRet = aQuery.Execute(); 496cdf0e10cSrcweir if ( nRet == RET_YES ) 497cdf0e10cSrcweir { 498cdf0e10cSrcweir #ifdef DBG_UTIL 499cdf0e10cSrcweir // Setup starten 500cdf0e10cSrcweir InfoBox( NULL, DEFINE_CONST_UNICODE("Hier soll jetzt das Setup starten!") ).Execute(); 501cdf0e10cSrcweir #endif 502cdf0e10cSrcweir // Installation mu\s hier noch mitteilen, ob es geklappt hat, dann kann das 503cdf0e10cSrcweir // Filterflag gel"oscht werden 504cdf0e10cSrcweir } 505cdf0e10cSrcweir 506cdf0e10cSrcweir return ( !(pFilter->GetFilterFlags() & SFX_FILTER_MUSTINSTALL) ); 507cdf0e10cSrcweir } 508cdf0e10cSrcweir else if ( pFilter->GetFilterFlags() & SFX_FILTER_CONSULTSERVICE ) 509cdf0e10cSrcweir { 510cdf0e10cSrcweir String aText( SfxResId( STR_FILTER_CONSULT_SERVICE ) ); 511cdf0e10cSrcweir aText.SearchAndReplaceAscii( "$(FILTER)", pFilter->GetUIName() ); 512cdf0e10cSrcweir InfoBox ( NULL, aText ).Execute(); 513cdf0e10cSrcweir return sal_False; 514cdf0e10cSrcweir } 515cdf0e10cSrcweir else 516cdf0e10cSrcweir return sal_True; 517cdf0e10cSrcweir } 518cdf0e10cSrcweir 519cdf0e10cSrcweir 520cdf0e10cSrcweir sal_uInt32 SfxFilterMatcher::DetectFilter( SfxMedium& rMedium, const SfxFilter**ppFilter, sal_Bool /*bPlugIn*/, sal_Bool bAPI ) const 521cdf0e10cSrcweir /* [Beschreibung] 522cdf0e10cSrcweir 523cdf0e10cSrcweir Hier wird noch die Filterauswahlbox hochgezogen. Sonst GuessFilter 524cdf0e10cSrcweir */ 525cdf0e10cSrcweir 526cdf0e10cSrcweir { 527cdf0e10cSrcweir const SfxFilter* pOldFilter = rMedium.GetFilter(); 528cdf0e10cSrcweir if ( pOldFilter ) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir if( !IsFilterInstalled_Impl( pOldFilter ) ) 531cdf0e10cSrcweir pOldFilter = 0; 532cdf0e10cSrcweir else 533cdf0e10cSrcweir { 534cdf0e10cSrcweir SFX_ITEMSET_ARG( rMedium.GetItemSet(), pSalvageItem, SfxStringItem, SID_DOC_SALVAGE, sal_False); 535cdf0e10cSrcweir if ( ( pOldFilter->GetFilterFlags() & SFX_FILTER_PACKED ) && pSalvageItem ) 536cdf0e10cSrcweir // Salvage is always done without packing 537cdf0e10cSrcweir pOldFilter = 0; 538cdf0e10cSrcweir } 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir const SfxFilter* pFilter = pOldFilter; 542cdf0e10cSrcweir 543cdf0e10cSrcweir sal_Bool bPreview = rMedium.IsPreview_Impl(); 544cdf0e10cSrcweir SFX_ITEMSET_ARG(rMedium.GetItemSet(), pReferer, SfxStringItem, SID_REFERER, sal_False); 545cdf0e10cSrcweir if ( bPreview && rMedium.IsRemote() && ( !pReferer || pReferer->GetValue().CompareToAscii("private:searchfolder:",21 ) != COMPARE_EQUAL ) ) 546cdf0e10cSrcweir return ERRCODE_ABORT; 547cdf0e10cSrcweir 548cdf0e10cSrcweir ErrCode nErr = GuessFilter( rMedium, &pFilter ); 549cdf0e10cSrcweir if ( nErr == ERRCODE_ABORT ) 550cdf0e10cSrcweir return nErr; 551cdf0e10cSrcweir 552cdf0e10cSrcweir if ( nErr == ERRCODE_IO_PENDING ) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir *ppFilter = pFilter; 555cdf0e10cSrcweir return nErr; 556cdf0e10cSrcweir } 557cdf0e10cSrcweir 558cdf0e10cSrcweir if ( !pFilter ) 559cdf0e10cSrcweir { 560cdf0e10cSrcweir const SfxFilter* pInstallFilter = NULL; 561cdf0e10cSrcweir 562cdf0e10cSrcweir // Jetzt auch Filter testen, die nicht installiert sind ( ErrCode ist irrelevant ) 563cdf0e10cSrcweir GuessFilter( rMedium, &pInstallFilter, SFX_FILTER_IMPORT, SFX_FILTER_CONSULTSERVICE ); 564cdf0e10cSrcweir if ( pInstallFilter ) 565cdf0e10cSrcweir { 566cdf0e10cSrcweir if ( IsFilterInstalled_Impl( pInstallFilter ) ) 567cdf0e10cSrcweir // Eventuell wurde der Filter nachinstalliert 568cdf0e10cSrcweir pFilter = pInstallFilter; 569cdf0e10cSrcweir } 570cdf0e10cSrcweir else 571cdf0e10cSrcweir { 572cdf0e10cSrcweir // Jetzt auch Filter testen, die erst von Star bezogen werden m"ussen ( ErrCode ist irrelevant ) 573cdf0e10cSrcweir GuessFilter( rMedium, &pInstallFilter, SFX_FILTER_IMPORT, 0 ); 574cdf0e10cSrcweir if ( pInstallFilter ) 575cdf0e10cSrcweir IsFilterInstalled_Impl( pInstallFilter ); 576cdf0e10cSrcweir } 577cdf0e10cSrcweir } 578cdf0e10cSrcweir 579cdf0e10cSrcweir sal_Bool bHidden = bPreview; 580cdf0e10cSrcweir SFX_ITEMSET_ARG( rMedium.GetItemSet(), pFlags, SfxStringItem, SID_OPTIONS, sal_False); 581cdf0e10cSrcweir if ( !bHidden && pFlags ) 582cdf0e10cSrcweir { 583cdf0e10cSrcweir String aFlags( pFlags->GetValue() ); 584cdf0e10cSrcweir aFlags.ToUpperAscii(); 585cdf0e10cSrcweir if( STRING_NOTFOUND != aFlags.Search( 'H' ) ) 586cdf0e10cSrcweir bHidden = sal_True; 587cdf0e10cSrcweir } 588cdf0e10cSrcweir *ppFilter = pFilter; 589cdf0e10cSrcweir 590cdf0e10cSrcweir if ( bHidden || (bAPI && nErr == ERRCODE_SFX_CONSULTUSER) ) 591cdf0e10cSrcweir nErr = pFilter ? ERRCODE_NONE : ERRCODE_ABORT; 592cdf0e10cSrcweir return nErr; 593cdf0e10cSrcweir } 594cdf0e10cSrcweir 595cdf0e10cSrcweir const SfxFilter* SfxFilterMatcher::GetFilterForProps( const com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue >& aSeq, SfxFilterFlags nMust, SfxFilterFlags nDont ) const 596cdf0e10cSrcweir { 597cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory(); 598cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerQuery > xTypeCFG; 599cdf0e10cSrcweir if( xServiceManager.is() == sal_True ) 600cdf0e10cSrcweir xTypeCFG = ::com::sun::star::uno::Reference < com::sun::star::container::XContainerQuery >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), ::com::sun::star::uno::UNO_QUERY ); 601cdf0e10cSrcweir if ( xTypeCFG.is() ) 602cdf0e10cSrcweir { 603cdf0e10cSrcweir // make query for all types matching the properties 604cdf0e10cSrcweir ::com::sun::star::uno::Reference < com::sun::star::container::XEnumeration > xEnum = xTypeCFG->createSubSetEnumerationByProperties( aSeq ); 605cdf0e10cSrcweir while ( xEnum->hasMoreElements() ) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir ::comphelper::SequenceAsHashMap aProps( xEnum->nextElement() ); 608cdf0e10cSrcweir ::rtl::OUString aValue; 609cdf0e10cSrcweir 610cdf0e10cSrcweir // try to get the preferred filter (works without loading all filters!) 611cdf0e10cSrcweir if ( (aProps[::rtl::OUString::createFromAscii("PreferredFilter")] >>= aValue) && aValue.getLength() ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir const SfxFilter* pFilter = SfxFilter::GetFilterByName( aValue ); 614cdf0e10cSrcweir if ( !pFilter || (pFilter->GetFilterFlags() & nMust) != nMust || (pFilter->GetFilterFlags() & nDont ) ) 615cdf0e10cSrcweir // check for filter flags 616cdf0e10cSrcweir // pFilter == 0: if preferred filter is a Writer filter, but Writer module is not installed 617cdf0e10cSrcweir continue; 618cdf0e10cSrcweir 619cdf0e10cSrcweir if ( pImpl->aName.getLength() ) 620cdf0e10cSrcweir { 621cdf0e10cSrcweir // if this is not the global FilterMatcher: check if filter matches the document type 622cdf0e10cSrcweir ::rtl::OUString aService; 623cdf0e10cSrcweir if ( pFilter->GetServiceName() != String(pImpl->aName) ) 624cdf0e10cSrcweir { 625cdf0e10cSrcweir // preferred filter belongs to another document type; now we must search the filter 626cdf0e10cSrcweir pImpl->InitForIterating(); 627cdf0e10cSrcweir aProps[::rtl::OUString::createFromAscii("Name")] >>= aValue; 628cdf0e10cSrcweir pFilter = GetFilter4EA( aValue, nMust, nDont ); 629cdf0e10cSrcweir if ( pFilter ) 630cdf0e10cSrcweir return pFilter; 631cdf0e10cSrcweir } 632cdf0e10cSrcweir else 633cdf0e10cSrcweir return pFilter; 634cdf0e10cSrcweir } 635cdf0e10cSrcweir else 636cdf0e10cSrcweir return pFilter; 637cdf0e10cSrcweir } 638cdf0e10cSrcweir } 639cdf0e10cSrcweir } 640cdf0e10cSrcweir 641cdf0e10cSrcweir return 0; 642cdf0e10cSrcweir } 643cdf0e10cSrcweir 644cdf0e10cSrcweir const SfxFilter* SfxFilterMatcher::GetFilter4Mime( const String& rMediaType,SfxFilterFlags nMust, SfxFilterFlags nDont ) const 645cdf0e10cSrcweir { 646cdf0e10cSrcweir if ( pImpl->pList ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); 649cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nCount; n++ ) 650cdf0e10cSrcweir { 651cdf0e10cSrcweir const SfxFilter* pFilter = pImpl->pList->GetObject( n ); 652cdf0e10cSrcweir SfxFilterFlags nFlags = pFilter->GetFilterFlags(); 653cdf0e10cSrcweir if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetMimeType() == rMediaType ) 654cdf0e10cSrcweir return pFilter; 655cdf0e10cSrcweir } 656cdf0e10cSrcweir 657cdf0e10cSrcweir return 0; 658cdf0e10cSrcweir } 659cdf0e10cSrcweir 660cdf0e10cSrcweir com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1); 661cdf0e10cSrcweir aSeq[0].Name = ::rtl::OUString::createFromAscii("MediaType"); 662cdf0e10cSrcweir aSeq[0].Value <<= ::rtl::OUString( rMediaType ); 663cdf0e10cSrcweir return GetFilterForProps( aSeq, nMust, nDont ); 664cdf0e10cSrcweir } 665cdf0e10cSrcweir 666cdf0e10cSrcweir const SfxFilter* SfxFilterMatcher::GetFilter4EA( const String& rType,SfxFilterFlags nMust, SfxFilterFlags nDont ) const 667cdf0e10cSrcweir { 668cdf0e10cSrcweir if ( pImpl->pList ) 669cdf0e10cSrcweir { 670cdf0e10cSrcweir sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); 671cdf0e10cSrcweir const SfxFilter* pFirst = 0; 672cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nCount; n++ ) 673cdf0e10cSrcweir { 674cdf0e10cSrcweir const SfxFilter* pFilter = pImpl->pList->GetObject( n ); 675cdf0e10cSrcweir SfxFilterFlags nFlags = pFilter->GetFilterFlags(); 676cdf0e10cSrcweir if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetTypeName() == rType ) 677cdf0e10cSrcweir { 678cdf0e10cSrcweir if (nFlags & SFX_FILTER_PREFERED) 679cdf0e10cSrcweir return pFilter; 680cdf0e10cSrcweir if (!pFirst) 681cdf0e10cSrcweir pFirst = pFilter; 682cdf0e10cSrcweir } 683cdf0e10cSrcweir } 684cdf0e10cSrcweir if (pFirst) 685cdf0e10cSrcweir return pFirst; 686cdf0e10cSrcweir 687cdf0e10cSrcweir return 0; 688cdf0e10cSrcweir } 689cdf0e10cSrcweir 690cdf0e10cSrcweir com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1); 691cdf0e10cSrcweir aSeq[0].Name = ::rtl::OUString::createFromAscii("Name"); 692cdf0e10cSrcweir aSeq[0].Value <<= ::rtl::OUString( rType ); 693cdf0e10cSrcweir return GetFilterForProps( aSeq, nMust, nDont ); 694cdf0e10cSrcweir } 695cdf0e10cSrcweir 696cdf0e10cSrcweir const SfxFilter* SfxFilterMatcher::GetFilter4Extension( const String& rExt, SfxFilterFlags nMust, SfxFilterFlags nDont ) const 697cdf0e10cSrcweir { 698cdf0e10cSrcweir if ( pImpl->pList ) 699cdf0e10cSrcweir { 700cdf0e10cSrcweir sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); 701cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nCount; n++ ) 702cdf0e10cSrcweir { 703cdf0e10cSrcweir const SfxFilter* pFilter = pImpl->pList->GetObject( n ); 704cdf0e10cSrcweir SfxFilterFlags nFlags = pFilter->GetFilterFlags(); 705cdf0e10cSrcweir if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) ) 706cdf0e10cSrcweir { 707cdf0e10cSrcweir String sWildCard = ToUpper_Impl( pFilter->GetWildcard().GetWildCard() ); 708cdf0e10cSrcweir String sExt = ToUpper_Impl( rExt ); 709cdf0e10cSrcweir 710cdf0e10cSrcweir if (!sExt.Len()) 711cdf0e10cSrcweir continue; 712cdf0e10cSrcweir 713cdf0e10cSrcweir if (sExt.GetChar(0) != (sal_Unicode)'.') 714cdf0e10cSrcweir sExt.Insert((sal_Unicode)'.', 0); 715cdf0e10cSrcweir 716cdf0e10cSrcweir WildCard aCheck(sWildCard, ';'); 717cdf0e10cSrcweir if (aCheck.Matches(sExt)) 718cdf0e10cSrcweir return pFilter; 719cdf0e10cSrcweir } 720cdf0e10cSrcweir } 721cdf0e10cSrcweir 722cdf0e10cSrcweir return 0; 723cdf0e10cSrcweir } 724cdf0e10cSrcweir 725cdf0e10cSrcweir // Use extension without dot! 726cdf0e10cSrcweir String sExt( rExt ); 727cdf0e10cSrcweir if ( sExt.Len() && ( sExt.GetChar(0) == (sal_Unicode)'.' )) 728cdf0e10cSrcweir sExt.Erase(0,1); 729cdf0e10cSrcweir 730cdf0e10cSrcweir com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1); 731cdf0e10cSrcweir aSeq[0].Name = ::rtl::OUString::createFromAscii("Extensions"); 732cdf0e10cSrcweir ::com::sun::star::uno::Sequence < ::rtl::OUString > aExts(1); 733cdf0e10cSrcweir aExts[0] = sExt; 734cdf0e10cSrcweir aSeq[0].Value <<= aExts; 735cdf0e10cSrcweir return GetFilterForProps( aSeq, nMust, nDont ); 736cdf0e10cSrcweir } 737cdf0e10cSrcweir 738cdf0e10cSrcweir const SfxFilter* SfxFilterMatcher::GetFilter4ClipBoardId( sal_uInt32 nId, SfxFilterFlags nMust, SfxFilterFlags nDont ) const 739cdf0e10cSrcweir { 740cdf0e10cSrcweir if (nId == 0) 741cdf0e10cSrcweir return 0; 742cdf0e10cSrcweir 743cdf0e10cSrcweir com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aSeq(1); 744cdf0e10cSrcweir ::rtl::OUString aName = SotExchange::GetFormatName( nId ); 745cdf0e10cSrcweir aSeq[0].Name = ::rtl::OUString::createFromAscii("ClipboardFormat"); 746cdf0e10cSrcweir aSeq[0].Value <<= aName; 747cdf0e10cSrcweir return GetFilterForProps( aSeq, nMust, nDont ); 748cdf0e10cSrcweir } 749cdf0e10cSrcweir 750cdf0e10cSrcweir const SfxFilter* SfxFilterMatcher::GetFilter4UIName( const String& rName, SfxFilterFlags nMust, SfxFilterFlags nDont ) const 751cdf0e10cSrcweir { 752cdf0e10cSrcweir pImpl->InitForIterating(); 753cdf0e10cSrcweir const SfxFilter* pFirstFilter=0; 754cdf0e10cSrcweir sal_uInt16 nCount = ( sal_uInt16 ) pImpl->pList->Count(); 755cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nCount; n++ ) 756cdf0e10cSrcweir { 757cdf0e10cSrcweir const SfxFilter* pFilter = pImpl->pList->GetObject( n ); 758cdf0e10cSrcweir SfxFilterFlags nFlags = pFilter->GetFilterFlags(); 759cdf0e10cSrcweir if ( (nFlags & nMust) == nMust && 760cdf0e10cSrcweir !(nFlags & nDont ) && pFilter->GetUIName() == rName ) 761cdf0e10cSrcweir { 762cdf0e10cSrcweir if ( pFilter->GetFilterFlags() & SFX_FILTER_PREFERED ) 763cdf0e10cSrcweir return pFilter; 764cdf0e10cSrcweir else if ( !pFirstFilter ) 765cdf0e10cSrcweir pFirstFilter = pFilter; 766cdf0e10cSrcweir } 767cdf0e10cSrcweir } 768cdf0e10cSrcweir return pFirstFilter; 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir const SfxFilter* SfxFilterMatcher::GetFilter4FilterName( const String& rName, SfxFilterFlags nMust, SfxFilterFlags nDont ) const 772cdf0e10cSrcweir { 773cdf0e10cSrcweir String aName( rName ); 774cdf0e10cSrcweir sal_uInt16 nIndex = aName.SearchAscii(": "); 775cdf0e10cSrcweir if ( nIndex != STRING_NOTFOUND ) 776cdf0e10cSrcweir { 777cdf0e10cSrcweir DBG_ERROR("Old filter name used!"); 778cdf0e10cSrcweir aName = rName.Copy( nIndex + 2 ); 779cdf0e10cSrcweir } 780cdf0e10cSrcweir 781cdf0e10cSrcweir if ( bFirstRead ) 782cdf0e10cSrcweir { 783cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory(); 784cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xFilterCFG ; 785cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xTypeCFG ; 786cdf0e10cSrcweir if( xServiceManager.is() == sal_True ) 787cdf0e10cSrcweir { 788cdf0e10cSrcweir xFilterCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), ::com::sun::star::uno::UNO_QUERY ); 789cdf0e10cSrcweir xTypeCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), ::com::sun::star::uno::UNO_QUERY ); 790cdf0e10cSrcweir } 791cdf0e10cSrcweir 792cdf0e10cSrcweir if( xFilterCFG.is() && xTypeCFG.is() ) 793cdf0e10cSrcweir { 794cdf0e10cSrcweir if ( !pFilterArr ) 795cdf0e10cSrcweir CreateFilterArr(); 796cdf0e10cSrcweir else 797cdf0e10cSrcweir { 798cdf0e10cSrcweir for( sal_uInt16 n=0; n<pFilterArr->Count(); n++ ) 799cdf0e10cSrcweir { 800cdf0e10cSrcweir const SfxFilter* pFilter = pFilterArr->GetObject( n ); 801cdf0e10cSrcweir SfxFilterFlags nFlags = pFilter->GetFilterFlags(); 802cdf0e10cSrcweir if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetFilterName().CompareIgnoreCaseToAscii( aName ) == COMPARE_EQUAL ) 803cdf0e10cSrcweir return pFilter; 804cdf0e10cSrcweir } 805cdf0e10cSrcweir } 806cdf0e10cSrcweir 807cdf0e10cSrcweir SfxFilterContainer::ReadSingleFilter_Impl( rName, xTypeCFG, xFilterCFG, sal_False ); 808cdf0e10cSrcweir } 809cdf0e10cSrcweir } 810cdf0e10cSrcweir 811cdf0e10cSrcweir SfxFilterList_Impl* pList = pImpl->pList; 812cdf0e10cSrcweir if ( !pList ) 813cdf0e10cSrcweir pList = pFilterArr; 814cdf0e10cSrcweir 815cdf0e10cSrcweir sal_uInt16 nCount = ( sal_uInt16 ) pList->Count(); 816cdf0e10cSrcweir for( sal_uInt16 n = 0; n < nCount; n++ ) 817cdf0e10cSrcweir { 818cdf0e10cSrcweir const SfxFilter* pFilter = pList->GetObject( n ); 819cdf0e10cSrcweir SfxFilterFlags nFlags = pFilter->GetFilterFlags(); 820cdf0e10cSrcweir if ( (nFlags & nMust) == nMust && !(nFlags & nDont ) && pFilter->GetFilterName().CompareIgnoreCaseToAscii( aName ) == COMPARE_EQUAL ) 821cdf0e10cSrcweir return pFilter; 822cdf0e10cSrcweir } 823cdf0e10cSrcweir 824cdf0e10cSrcweir return NULL; 825cdf0e10cSrcweir } 826cdf0e10cSrcweir 827cdf0e10cSrcweir IMPL_STATIC_LINK( SfxFilterMatcher, MaybeFileHdl_Impl, String*, pString ) 828cdf0e10cSrcweir { 829cdf0e10cSrcweir const SfxFilter* pFilter = pThis->GetFilter4Extension( *pString, SFX_FILTER_IMPORT ); 830cdf0e10cSrcweir if( pFilter && !pFilter->GetWildcard().Matches( String() ) && 831cdf0e10cSrcweir pFilter->GetWildcard() != DEFINE_CONST_UNICODE("*.*") && pFilter->GetWildcard() != '*' ) 832cdf0e10cSrcweir return sal_True; 833cdf0e10cSrcweir return sal_False; 834cdf0e10cSrcweir } 835cdf0e10cSrcweir 836cdf0e10cSrcweir //---------------------------------------------------------------- 837cdf0e10cSrcweir 838cdf0e10cSrcweir SfxFilterMatcherIter::SfxFilterMatcherIter( 839cdf0e10cSrcweir const SfxFilterMatcher* pMatchP, 840cdf0e10cSrcweir SfxFilterFlags nOrMaskP, SfxFilterFlags nAndMaskP ) 841cdf0e10cSrcweir : nOrMask( nOrMaskP ), nAndMask( nAndMaskP ), 842cdf0e10cSrcweir nCurrent(0), pMatch( pMatchP->pImpl) 843cdf0e10cSrcweir { 844cdf0e10cSrcweir if( nOrMask == 0xffff ) //Wg. Fehlbuild auf s 845cdf0e10cSrcweir nOrMask = 0; 846cdf0e10cSrcweir pMatch->InitForIterating(); 847cdf0e10cSrcweir } 848cdf0e10cSrcweir 849cdf0e10cSrcweir //---------------------------------------------------------------- 850cdf0e10cSrcweir 851cdf0e10cSrcweir const SfxFilter* SfxFilterMatcherIter::Find_Impl() 852cdf0e10cSrcweir { 853cdf0e10cSrcweir const SfxFilter* pFilter = 0; 854cdf0e10cSrcweir while( nCurrent < pMatch->pList->Count() ) 855cdf0e10cSrcweir { 856cdf0e10cSrcweir pFilter = pMatch->pList->GetObject(nCurrent++); 857cdf0e10cSrcweir SfxFilterFlags nFlags = pFilter->GetFilterFlags(); 858cdf0e10cSrcweir if( ((nFlags & nOrMask) == nOrMask ) && !(nFlags & nAndMask ) ) 859cdf0e10cSrcweir break; 860cdf0e10cSrcweir pFilter = 0; 861cdf0e10cSrcweir } 862cdf0e10cSrcweir 863cdf0e10cSrcweir return pFilter; 864cdf0e10cSrcweir } 865cdf0e10cSrcweir 866cdf0e10cSrcweir const SfxFilter* SfxFilterMatcherIter::First() 867cdf0e10cSrcweir { 868cdf0e10cSrcweir nCurrent = 0; 869cdf0e10cSrcweir return Find_Impl(); 870cdf0e10cSrcweir } 871cdf0e10cSrcweir 872cdf0e10cSrcweir //---------------------------------------------------------------- 873cdf0e10cSrcweir 874cdf0e10cSrcweir const SfxFilter* SfxFilterMatcherIter::Next() 875cdf0e10cSrcweir { 876cdf0e10cSrcweir return Find_Impl(); 877cdf0e10cSrcweir } 878cdf0e10cSrcweir 879cdf0e10cSrcweir /*--------------------------------------------------------------- 880cdf0e10cSrcweir helper to build own formated string from given stringlist by 881cdf0e10cSrcweir using given seperator 882cdf0e10cSrcweir ---------------------------------------------------------------*/ 883cdf0e10cSrcweir ::rtl::OUString implc_convertStringlistToString( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& lList , 884cdf0e10cSrcweir const sal_Unicode& cSeperator, 885cdf0e10cSrcweir const ::rtl::OUString& sPrefix ) 886cdf0e10cSrcweir { 887cdf0e10cSrcweir ::rtl::OUStringBuffer sString ( 1000 ) ; 888cdf0e10cSrcweir sal_Int32 nCount = lList.getLength(); 889cdf0e10cSrcweir sal_Int32 nItem = 0 ; 890cdf0e10cSrcweir for( nItem=0; nItem<nCount; ++nItem ) 891cdf0e10cSrcweir { 892cdf0e10cSrcweir if( sPrefix.getLength() > 0 ) 893cdf0e10cSrcweir { 894cdf0e10cSrcweir sString.append( sPrefix ); 895cdf0e10cSrcweir } 896cdf0e10cSrcweir sString.append( lList[nItem] ); 897cdf0e10cSrcweir if( nItem+1<nCount ) 898cdf0e10cSrcweir { 899cdf0e10cSrcweir sString.append( cSeperator ); 900cdf0e10cSrcweir } 901cdf0e10cSrcweir } 902cdf0e10cSrcweir return sString.makeStringAndClear(); 903cdf0e10cSrcweir } 904cdf0e10cSrcweir 905cdf0e10cSrcweir 906cdf0e10cSrcweir void SfxFilterContainer::ReadSingleFilter_Impl( 907cdf0e10cSrcweir const ::rtl::OUString& rName, 908cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& xTypeCFG, 909cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& xFilterCFG, 910cdf0e10cSrcweir sal_Bool bUpdate 911cdf0e10cSrcweir ) 912cdf0e10cSrcweir { 913cdf0e10cSrcweir ::rtl::OUString sFilterName( rName ); 914cdf0e10cSrcweir SfxFilterList_Impl& rList = *pFilterArr; 915cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lFilterProperties ; 916cdf0e10cSrcweir ::com::sun::star::uno::Any aResult; 917cdf0e10cSrcweir try 918cdf0e10cSrcweir { 919cdf0e10cSrcweir aResult = xFilterCFG->getByName( sFilterName ); 920cdf0e10cSrcweir } 921cdf0e10cSrcweir catch( ::com::sun::star::container::NoSuchElementException& ) 922cdf0e10cSrcweir { 923cdf0e10cSrcweir aResult = ::com::sun::star::uno::Any(); 924cdf0e10cSrcweir } 925cdf0e10cSrcweir 926cdf0e10cSrcweir if( aResult >>= lFilterProperties ) 927cdf0e10cSrcweir { 928cdf0e10cSrcweir // collect informations to add filter to container 929cdf0e10cSrcweir // (attention: some informations aren't available on filter directly ... you must search for corresponding type too!) 930cdf0e10cSrcweir sal_Int32 nFlags = 0 ; 931cdf0e10cSrcweir sal_Int32 nClipboardId = 0 ; 932cdf0e10cSrcweir sal_Int32 nDocumentIconId = 0 ; 933cdf0e10cSrcweir sal_Int32 nFormatVersion = 0 ; 934cdf0e10cSrcweir ::rtl::OUString sMimeType ; 935cdf0e10cSrcweir ::rtl::OUString sType ; 936cdf0e10cSrcweir ::rtl::OUString sUIName ; 937cdf0e10cSrcweir ::rtl::OUString sHumanName ; 938cdf0e10cSrcweir ::rtl::OUString sDefaultTemplate ; 939cdf0e10cSrcweir ::rtl::OUString sUserData ; 940cdf0e10cSrcweir ::rtl::OUString sExtension ; 941cdf0e10cSrcweir ::rtl::OUString sPattern ; 942cdf0e10cSrcweir ::rtl::OUString sServiceName ; 943cdf0e10cSrcweir 944cdf0e10cSrcweir // first get directly available properties 945cdf0e10cSrcweir sal_Int32 nFilterPropertyCount = lFilterProperties.getLength(); 946cdf0e10cSrcweir sal_Int32 nFilterProperty = 0 ; 947cdf0e10cSrcweir for( nFilterProperty=0; nFilterProperty<nFilterPropertyCount; ++nFilterProperty ) 948cdf0e10cSrcweir { 949cdf0e10cSrcweir if( lFilterProperties[nFilterProperty].Name.compareToAscii( "FileFormatVersion" ) == 0 ) 950cdf0e10cSrcweir { 951cdf0e10cSrcweir lFilterProperties[nFilterProperty].Value >>= nFormatVersion; 952cdf0e10cSrcweir } 953cdf0e10cSrcweir else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "TemplateName" ) == 0 ) 954cdf0e10cSrcweir { 955cdf0e10cSrcweir lFilterProperties[nFilterProperty].Value >>= sDefaultTemplate; 956cdf0e10cSrcweir } 957cdf0e10cSrcweir else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "Flags" ) == 0 ) 958cdf0e10cSrcweir { 959cdf0e10cSrcweir lFilterProperties[nFilterProperty].Value >>= nFlags; 960cdf0e10cSrcweir } 961cdf0e10cSrcweir else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "UIName" ) == 0 ) 962cdf0e10cSrcweir { 963cdf0e10cSrcweir lFilterProperties[nFilterProperty].Value >>= sUIName; 964cdf0e10cSrcweir } 965cdf0e10cSrcweir else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "UserData" ) == 0 ) 966cdf0e10cSrcweir { 967cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > lUserData; 968cdf0e10cSrcweir lFilterProperties[nFilterProperty].Value >>= lUserData; 969cdf0e10cSrcweir sUserData = implc_convertStringlistToString( lUserData, ',', ::rtl::OUString() ); 970cdf0e10cSrcweir } 971cdf0e10cSrcweir else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "DocumentService" ) == 0 ) 972cdf0e10cSrcweir { 973cdf0e10cSrcweir lFilterProperties[nFilterProperty].Value >>= sServiceName; 974cdf0e10cSrcweir } 975cdf0e10cSrcweir else if( lFilterProperties[nFilterProperty].Name.compareToAscii( "Type" ) == 0 ) 976cdf0e10cSrcweir { 977cdf0e10cSrcweir lFilterProperties[nFilterProperty].Value >>= sType; 978cdf0e10cSrcweir // Try to get filter .. but look for any exceptions! 979cdf0e10cSrcweir // May be filter was deleted by another thread ... 980cdf0e10cSrcweir try 981cdf0e10cSrcweir { 982cdf0e10cSrcweir aResult = xTypeCFG->getByName( sType ); 983cdf0e10cSrcweir } 984cdf0e10cSrcweir catch( ::com::sun::star::container::NoSuchElementException& ) 985cdf0e10cSrcweir { 986cdf0e10cSrcweir aResult = ::com::sun::star::uno::Any(); 987cdf0e10cSrcweir } 988cdf0e10cSrcweir 989cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lTypeProperties; 990cdf0e10cSrcweir if( aResult >>= lTypeProperties ) 991cdf0e10cSrcweir { 992cdf0e10cSrcweir // get indirect available properties then (types) 993cdf0e10cSrcweir sal_Int32 nTypePropertyCount = lTypeProperties.getLength(); 994cdf0e10cSrcweir sal_Int32 nTypeProperty = 0 ; 995cdf0e10cSrcweir for( nTypeProperty=0; nTypeProperty<nTypePropertyCount; ++nTypeProperty ) 996cdf0e10cSrcweir { 997cdf0e10cSrcweir if( lTypeProperties[nTypeProperty].Name.compareToAscii( "ClipboardFormat" ) == 0 ) 998cdf0e10cSrcweir { 999cdf0e10cSrcweir lTypeProperties[nTypeProperty].Value >>= sHumanName; 1000cdf0e10cSrcweir } 1001cdf0e10cSrcweir else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "DocumentIconID" ) == 0 ) 1002cdf0e10cSrcweir { 1003cdf0e10cSrcweir lTypeProperties[nTypeProperty].Value >>= nDocumentIconId; 1004cdf0e10cSrcweir } 1005cdf0e10cSrcweir else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "MediaType" ) == 0 ) 1006cdf0e10cSrcweir { 1007cdf0e10cSrcweir lTypeProperties[nTypeProperty].Value >>= sMimeType; 1008cdf0e10cSrcweir } 1009cdf0e10cSrcweir else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "Extensions" ) == 0 ) 1010cdf0e10cSrcweir { 1011cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > lExtensions; 1012cdf0e10cSrcweir lTypeProperties[nTypeProperty].Value >>= lExtensions; 1013cdf0e10cSrcweir sExtension = implc_convertStringlistToString( lExtensions, ';', DEFINE_CONST_UNICODE("*.") ); 1014cdf0e10cSrcweir } 1015cdf0e10cSrcweir else if( lTypeProperties[nTypeProperty].Name.compareToAscii( "URLPattern" ) == 0 ) 1016cdf0e10cSrcweir { 1017cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > lPattern; 1018cdf0e10cSrcweir lTypeProperties[nTypeProperty].Value >>= lPattern; 1019cdf0e10cSrcweir sPattern = implc_convertStringlistToString( lPattern, ';', ::rtl::OUString() ); 1020cdf0e10cSrcweir } 1021cdf0e10cSrcweir } 1022cdf0e10cSrcweir } 1023cdf0e10cSrcweir } 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir if ( !sServiceName.getLength() ) 1027cdf0e10cSrcweir return; 1028cdf0e10cSrcweir 1029cdf0e10cSrcweir // old formats are found ... using HumanPresentableName! 1030cdf0e10cSrcweir if( sHumanName.getLength() ) 1031cdf0e10cSrcweir { 1032cdf0e10cSrcweir nClipboardId = SotExchange::RegisterFormatName( sHumanName ); 1033cdf0e10cSrcweir 1034cdf0e10cSrcweir // #100570# For external filters ignore clipboard IDs 1035cdf0e10cSrcweir if((nFlags & SFX_FILTER_STARONEFILTER) == SFX_FILTER_STARONEFILTER) 1036cdf0e10cSrcweir { 1037cdf0e10cSrcweir nClipboardId = 0; 1038cdf0e10cSrcweir } 1039cdf0e10cSrcweir } 1040cdf0e10cSrcweir // register SfxFilter 1041cdf0e10cSrcweir // first erase module name from old filter names! 1042cdf0e10cSrcweir // e.g: "scalc: DIF" => "DIF" 1043cdf0e10cSrcweir sal_Int32 nStartRealName = sFilterName.indexOf( DEFINE_CONST_UNICODE(": "), 0 ); 1044cdf0e10cSrcweir if( nStartRealName != -1 ) 1045cdf0e10cSrcweir { 1046cdf0e10cSrcweir DBG_ERROR("Old format, not supported!"); 1047cdf0e10cSrcweir sFilterName = sFilterName.copy( nStartRealName+2 ); 1048cdf0e10cSrcweir } 1049cdf0e10cSrcweir 1050cdf0e10cSrcweir SfxFilter* pFilter = bUpdate ? (SfxFilter*) SfxFilter::GetFilterByName( sFilterName ) : 0; 1051cdf0e10cSrcweir sal_Bool bNew = sal_False; 1052cdf0e10cSrcweir if (!pFilter) 1053cdf0e10cSrcweir { 1054cdf0e10cSrcweir bNew = sal_True; 1055cdf0e10cSrcweir pFilter = new SfxFilter( sFilterName , 1056cdf0e10cSrcweir sExtension , 1057cdf0e10cSrcweir nFlags , 1058cdf0e10cSrcweir nClipboardId , 1059cdf0e10cSrcweir sType , 1060cdf0e10cSrcweir (sal_uInt16)nDocumentIconId , 1061cdf0e10cSrcweir sMimeType , 1062cdf0e10cSrcweir sUserData , 1063cdf0e10cSrcweir sServiceName ); 1064cdf0e10cSrcweir } 1065cdf0e10cSrcweir else 1066cdf0e10cSrcweir { 1067cdf0e10cSrcweir pFilter->aFilterName = sFilterName; 1068cdf0e10cSrcweir pFilter->aWildCard = WildCard(sExtension, ';'); 1069cdf0e10cSrcweir pFilter->nFormatType = nFlags; 1070cdf0e10cSrcweir pFilter->lFormat = nClipboardId; 1071cdf0e10cSrcweir pFilter->aTypeName = sType; 1072cdf0e10cSrcweir pFilter->nDocIcon = (sal_uInt16)nDocumentIconId; 1073cdf0e10cSrcweir pFilter->aMimeType = sMimeType; 1074cdf0e10cSrcweir pFilter->aUserData = sUserData; 1075cdf0e10cSrcweir pFilter->aServiceName = sServiceName; 1076cdf0e10cSrcweir } 1077cdf0e10cSrcweir 1078cdf0e10cSrcweir // Don't forget to set right UIName! 1079cdf0e10cSrcweir // Otherwise internal name is used as fallback ... 1080cdf0e10cSrcweir pFilter->SetUIName( sUIName ); 1081cdf0e10cSrcweir pFilter->SetDefaultTemplate( sDefaultTemplate ); 1082cdf0e10cSrcweir if( nFormatVersion ) 1083cdf0e10cSrcweir { 1084cdf0e10cSrcweir pFilter->SetVersion( nFormatVersion ); 1085cdf0e10cSrcweir } 1086cdf0e10cSrcweir pFilter->SetURLPattern(sPattern); 1087cdf0e10cSrcweir 1088cdf0e10cSrcweir if (bNew) 1089cdf0e10cSrcweir rList.Insert( pFilter, USHRT_MAX ); 1090cdf0e10cSrcweir } 1091cdf0e10cSrcweir } 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir void SfxFilterContainer::ReadFilters_Impl( sal_Bool bUpdate ) 1094cdf0e10cSrcweir { 1095cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aMeasure, "sfx2 (as96863) ::SfxFilterContainer::ReadFilters" ); 1096cdf0e10cSrcweir if ( !pFilterArr ) 1097cdf0e10cSrcweir CreateFilterArr(); 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir bFirstRead = sal_False; 1100cdf0e10cSrcweir SfxFilterList_Impl& rList = *pFilterArr; 1101cdf0e10cSrcweir 1102cdf0e10cSrcweir try 1103cdf0e10cSrcweir { 1104cdf0e10cSrcweir // get the FilterFactory service to access the registered filters ... and types! 1105cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory(); 1106cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xFilterCFG ; 1107cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > xTypeCFG ; 1108cdf0e10cSrcweir if( xServiceManager.is() == sal_True ) 1109cdf0e10cSrcweir { 1110cdf0e10cSrcweir xFilterCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), ::com::sun::star::uno::UNO_QUERY ); 1111cdf0e10cSrcweir xTypeCFG = ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" ) ), ::com::sun::star::uno::UNO_QUERY ); 1112cdf0e10cSrcweir } 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir if( 1115cdf0e10cSrcweir ( xFilterCFG.is() == sal_True ) && 1116cdf0e10cSrcweir ( xTypeCFG.is() == sal_True ) 1117cdf0e10cSrcweir ) 1118cdf0e10cSrcweir { 1119cdf0e10cSrcweir // select right query to get right set of filters for search modul 1120cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > lFilterNames = xFilterCFG->getElementNames(); 1121cdf0e10cSrcweir if ( lFilterNames.getLength() ) 1122cdf0e10cSrcweir { 1123cdf0e10cSrcweir // If list of filters already exist ... 1124cdf0e10cSrcweir // ReadExternalFilters must work in update mode. 1125cdf0e10cSrcweir // Best way seams to mark all filters NOT_INSTALLED 1126cdf0e10cSrcweir // and change it back for all valid filters afterwards. 1127cdf0e10cSrcweir if( rList.Count() > 0 ) 1128cdf0e10cSrcweir { 1129cdf0e10cSrcweir bUpdate = sal_True; 1130cdf0e10cSrcweir sal_uInt16 nCount = (sal_uInt16)rList.Count(); 1131cdf0e10cSrcweir SfxFilter* pFilter; 1132cdf0e10cSrcweir for (sal_uInt16 f=0; f<nCount; ++f) 1133cdf0e10cSrcweir { 1134cdf0e10cSrcweir pFilter = NULL; 1135cdf0e10cSrcweir pFilter = rList.GetObject(f); 1136cdf0e10cSrcweir pFilter->nFormatType |= SFX_FILTER_NOTINSTALLED; 1137cdf0e10cSrcweir } 1138cdf0e10cSrcweir } 1139cdf0e10cSrcweir 1140cdf0e10cSrcweir // get all properties of filters ... put it into the filter container 1141cdf0e10cSrcweir sal_Int32 nFilterCount = lFilterNames.getLength(); 1142cdf0e10cSrcweir sal_Int32 nFilter=0; 1143cdf0e10cSrcweir for( nFilter=0; nFilter<nFilterCount; ++nFilter ) 1144cdf0e10cSrcweir { 1145cdf0e10cSrcweir // Try to get filter .. but look for any exceptions! 1146cdf0e10cSrcweir // May be filter was deleted by another thread ... 1147cdf0e10cSrcweir ::rtl::OUString sFilterName = lFilterNames[nFilter]; 1148cdf0e10cSrcweir 1149cdf0e10cSrcweir // This debug code can be used to break on inserting/updating 1150cdf0e10cSrcweir // special debug filters at runtime. 1151cdf0e10cSrcweir // Otherwise you have to check more then 300 filter names manually .-) 1152cdf0e10cSrcweir // And conditional breakpoints on unicode values seams not to be supported .-( 1153cdf0e10cSrcweir #ifdef DEBUG 1154cdf0e10cSrcweir bool bDBGStop = sal_False; 1155cdf0e10cSrcweir if (sFilterName.indexOf(::rtl::OUString::createFromAscii("DBG_"))>-1) 1156cdf0e10cSrcweir bDBGStop = sal_True; 1157cdf0e10cSrcweir #endif 1158cdf0e10cSrcweir 1159cdf0e10cSrcweir ReadSingleFilter_Impl( sFilterName, xTypeCFG, xFilterCFG, bUpdate ); 1160cdf0e10cSrcweir } 1161cdf0e10cSrcweir } 1162cdf0e10cSrcweir } 1163cdf0e10cSrcweir } 1164cdf0e10cSrcweir catch( ::com::sun::star::uno::Exception& ) 1165cdf0e10cSrcweir { 1166cdf0e10cSrcweir DBG_ASSERT( sal_False, "SfxFilterContainer::ReadFilter()\nException detected. Possible not all filters could be cached.\n" ); 1167cdf0e10cSrcweir } 1168cdf0e10cSrcweir 1169cdf0e10cSrcweir if ( pImplArr && bUpdate ) 1170cdf0e10cSrcweir { 1171cdf0e10cSrcweir // global filter arry was modified, factory specific ones might need an update too 1172cdf0e10cSrcweir for ( sal_uInt16 n=0; n<pImplArr->Count(); n++ ) 1173cdf0e10cSrcweir pImplArr->GetObject(n)->Update(); 1174cdf0e10cSrcweir } 1175cdf0e10cSrcweir } 1176