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