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