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