1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26
27 #include "filterfactory.hxx"
28 #include "macros.hxx"
29 #include "constant.hxx"
30 #include "versions.hxx"
31
32 //_______________________________________________
33 // includes
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <comphelper/enumhelper.hxx>
36 #include <comphelper/configurationhelper.hxx>
37 #include <rtl/ustrbuf.hxx>
38
39 //_______________________________________________
40 // namespace
41
42 namespace filter{
43 namespace config{
44
45 namespace css = ::com::sun::star;
46
47 //_______________________________________________
48 // definitions
49
50 /** @short can be used to query for filters related to its application module.
51 */
52 #define BASE_QUERY_ALL "_query_all"
53 #define BASE_QUERY_WRITER "_query_Writer"
54 #define BASE_QUERY_WEB "_query_web"
55 #define BASE_QUERY_GLOBAL "_query_global"
56 #define BASE_QUERY_CHART "_query_chart"
57 #define BASE_QUERY_CALC "_query_calc"
58 #define BASE_QUERY_IMPRESS "_query_impress"
59 #define BASE_QUERY_DRAW "_query_draw"
60 #define BASE_QUERY_MATH "_query_math"
61
62 //_______________________________________________
63
64 /** @short define all possible parts of a filter query.
65
66 @descr syntax: "<query>[:<param>[=<value>]]"
67 e.g.: "_query_writer:default_first:use_order:sort_prop=uiname"
68
69 argument description default
70 -----------------------------------------------------------------------------------------------
71 iflags=<mask> include filters by given mask 0
72 eflags=<mask> exclude filters by given mask 0
73 sort_prop=<[name,uiname]> sort by internal name or uiname name
74 descending sort descending false
75 use_order use order flag of filters for sorting false
76 default_first set default filter on top of return list false
77 case_sensitive compare "sort_prop" case sensitive false
78 */
79 #define SEPERATOR_QUERYPARAM ((sal_Unicode)':')
80 #define SEPERATOR_QUERYPARAMVALUE ((sal_Unicode)'=')
81
82 #define QUERYPARAM_IFLAGS ::rtl::OUString::createFromAscii("iflags")
83 #define QUERYPARAM_EFLAGS ::rtl::OUString::createFromAscii("eflags")
84 #define QUERYPARAM_SORT_PROP ::rtl::OUString::createFromAscii("sort_prop")
85
86 #define QUERYPARAM_DESCENDING ::rtl::OUString::createFromAscii("descending")
87 #define QUERYPARAM_USE_ORDER ::rtl::OUString::createFromAscii("use_order")
88 #define QUERYPARAM_DEFAULT_FIRST ::rtl::OUString::createFromAscii("default_first")
89 #define QUERYPARAM_CASE_SENSITIVE ::rtl::OUString::createFromAscii("case_sensitive")
90
91 #define QUERYPARAMVALUE_SORT_PROP_NAME ::rtl::OUString::createFromAscii("name")
92 #define QUERYPARAMVALUE_SORT_PROP_UINAME ::rtl::OUString::createFromAscii("uiname")
93
94 /*-----------------------------------------------
95 09.07.2003 07:43
96 -----------------------------------------------*/
FilterFactory(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)97 FilterFactory::FilterFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
98 {
99 BaseContainer::init(xSMGR ,
100 FilterFactory::impl_getImplementationName() ,
101 FilterFactory::impl_getSupportedServiceNames(),
102 FilterCache::E_FILTER );
103 }
104
105 /*-----------------------------------------------
106 09.07.2003 07:43
107 -----------------------------------------------*/
~FilterFactory()108 FilterFactory::~FilterFactory()
109 {
110 }
111
112 /*-----------------------------------------------
113 16.07.2003 13:43
114 -----------------------------------------------*/
createInstance(const::rtl::OUString & sFilter)115 css::uno::Reference< css::uno::XInterface > SAL_CALL FilterFactory::createInstance(const ::rtl::OUString& sFilter)
116 {
117 return createInstanceWithArguments(sFilter, css::uno::Sequence< css::uno::Any >());
118 }
119
120 /*-----------------------------------------------
121 17.07.2003 08:56
122 -----------------------------------------------*/
createInstanceWithArguments(const::rtl::OUString & sFilter,const css::uno::Sequence<css::uno::Any> & lArguments)123 css::uno::Reference< css::uno::XInterface > SAL_CALL FilterFactory::createInstanceWithArguments(const ::rtl::OUString& sFilter ,
124 const css::uno::Sequence< css::uno::Any >& lArguments)
125 {
126 // SAFE ->
127 ::osl::ResettableMutexGuard aLock(m_aLock);
128
129 ::rtl::OUString sRealFilter = sFilter;
130
131 #ifdef _FILTER_CONFIG_MIGRATION_Q_
132
133 /* -> TODO - HACK
134 check if the given filter name really exists ...
135 Because our old implementation worked with an internal
136 type name instead of a filter name. For a small migration time
137 we must simulate this old feature :-( */
138
139 if (!m_rCache->hasItem(FilterCache::E_FILTER, sFilter) && m_rCache->hasItem(FilterCache::E_TYPE, sFilter))
140 {
141 OSL_ENSURE(sal_False, "Who use this deprecated functionality?");
142 _FILTER_CONFIG_LOG_("FilterFactory::createInstanceWithArguments() ... simulate old type search functionality!\n");
143
144 css::uno::Sequence< css::beans::NamedValue > lQuery(1);
145 lQuery[0].Name = PROPNAME_TYPE;
146 lQuery[0].Value <<= sFilter;
147
148 css::uno::Reference< css::container::XEnumeration > xSet = createSubSetEnumerationByProperties(lQuery);
149 while(xSet->hasMoreElements())
150 {
151 ::comphelper::SequenceAsHashMap lHandlerProps(xSet->nextElement());
152 if (!(lHandlerProps[PROPNAME_NAME] >>= sRealFilter))
153 continue;
154 }
155
156 // prevent outside code against NoSuchElementException!
157 // But don't implement such defensive strategy for our new create handling :-)
158 if (!m_rCache->hasItem(FilterCache::E_FILTER, sRealFilter))
159 return css::uno::Reference< css::uno::XInterface>();
160 }
161
162 /* <- HACK */
163
164 #endif // _FILTER_CONFIG_MIGRATION_Q_
165
166 // search filter on cache
167 CacheItem aFilter = m_rCache->getItem(FilterCache::E_FILTER, sRealFilter);
168 ::rtl::OUString sFilterService;
169 aFilter[PROPNAME_FILTERSERVICE] >>= sFilterService;
170
171 // create service instance
172 css::uno::Reference< css::uno::XInterface > xFilter;
173 if (sFilterService.getLength())
174 xFilter = m_xSMGR->createInstance(sFilterService);
175
176 // initialize filter
177 css::uno::Reference< css::lang::XInitialization > xInit(xFilter, css::uno::UNO_QUERY);
178 if (xInit.is())
179 {
180 // format: lInitData[0] = seq<PropertyValue>, which contains all configuration properties of this filter
181 // lInitData[1] = lArguments[0]
182 // ...
183 // lInitData[n] = lArguments[n-1]
184 css::uno::Sequence< css::beans::PropertyValue > lConfig;
185 aFilter >> lConfig;
186
187 ::comphelper::SequenceAsVector< css::uno::Any > stlArguments(lArguments);
188 stlArguments.insert(stlArguments.begin(), css::uno::makeAny(lConfig));
189
190 css::uno::Sequence< css::uno::Any > lInitData;
191 stlArguments >> lInitData;
192
193 xInit->initialize(lInitData);
194 }
195
196 return xFilter;
197 // <- SAFE
198 }
199
200 /*-----------------------------------------------
201 18.02.2004 14:21
202 -----------------------------------------------*/
getAvailableServiceNames()203 css::uno::Sequence< ::rtl::OUString > SAL_CALL FilterFactory::getAvailableServiceNames()
204 {
205 /* Attention: Instead of getElementNames() this method have to return only filter names,
206 which can be created as UNO Services really. That's why we search for filters,
207 which dont have a valid value for the property "FilterService".
208 Of course we can't check for corrupted service names here. We can check
209 for empty strings only ...
210 */
211 CacheItem lIProps;
212 CacheItem lEProps;
213 lEProps[PROPNAME_FILTERSERVICE] <<= ::rtl::OUString();
214
215 OUStringList lUNOFilters;
216 try
217 {
218 lUNOFilters = m_rCache->getMatchingItemsByProps(FilterCache::E_FILTER, lIProps, lEProps);
219 }
220 catch(const css::uno::RuntimeException&)
221 { throw; }
222 catch(const css::uno::Exception&)
223 { lUNOFilters.clear(); }
224
225 return lUNOFilters.getAsConstList();
226 }
227
228 /*-----------------------------------------------
229 11.03.2004 08:37
230 -----------------------------------------------*/
createSubSetEnumerationByQuery(const::rtl::OUString & sQuery)231 css::uno::Reference< css::container::XEnumeration > SAL_CALL FilterFactory::createSubSetEnumerationByQuery(const ::rtl::OUString& sQuery)
232 {
233 // reject old deprecated queries ...
234 if (sQuery.matchAsciiL("_filterquery_",13,0))
235 throw css::uno::RuntimeException(
236 _FILTER_CONFIG_FROM_ASCII_("Use of deprecated and now unsupported query!"),
237 static_cast< css::container::XContainerQuery* >(this));
238
239 // convert "_query_xxx:..." to "getByDocService=xxx:..."
240 ::rtl::OUString sNewQuery(sQuery);
241 sal_Int32 pos = sNewQuery.indexOf(::rtl::OUString::createFromAscii("_query_"),0);
242 if (pos != -1)
243 {
244 OSL_ENSURE(sal_False, "DEPRECATED!\nPlease use new query format: 'matchByDocumentService=...'");
245 ::rtl::OUStringBuffer sPatchedQuery(256);
246 sPatchedQuery.appendAscii("matchByDocumentService=");
247 sPatchedQuery.append (sNewQuery.copy(7) );
248 sNewQuery = sPatchedQuery.makeStringAndClear();
249 }
250
251 // analyze query and split it into its tokens
252 QueryTokenizer lTokens(sNewQuery);
253 QueryTokenizer::const_iterator pIt;
254 OUStringList lEnumSet;
255
256 // start query
257 // (see attention comment below!)
258 if (lTokens.valid())
259 {
260 // SAFE -> ----------------------
261 ::osl::ResettableMutexGuard aLock(m_aLock);
262 // May be not all filters was loaded ...
263 // But we need it now!
264 impl_loadOnDemand();
265 aLock.clear();
266 // <- SAFE ----------------------
267
268 if (lTokens.find(QUERY_IDENTIFIER_GETPREFERREDFILTERFORTYPE) != lTokens.end())
269 OSL_ENSURE(sal_False, "DEPRECATED!\nPlease use prop search at the TypeDetection container!");
270 // lEnumSet = impl_queryGetPreferredFilterForType(lTokens);
271 else
272 if (lTokens.find(QUERY_IDENTIFIER_MATCHBYDOCUMENTSERVICE) != lTokens.end())
273 lEnumSet = impl_queryMatchByDocumentService(lTokens);
274 else
275 if (lTokens.find(QUERY_IDENTIFIER_GET_SORTED_FILTERLIST) != lTokens.end())
276 lEnumSet = impl_getSortedFilterList(lTokens);
277 }
278
279 // pack list of item names as an enum list
280 // Attention: Do not return empty reference for empty list!
281 // The outside check "hasMoreElements()" should be enough, to detect this state :-)
282 // size_t c = lEnumSet.size();
283 css::uno::Sequence< ::rtl::OUString > lSet = lEnumSet.getAsConstList();
284 ::comphelper::OEnumerationByName* pEnum = new ::comphelper::OEnumerationByName(this, lSet);
285 return css::uno::Reference< css::container::XEnumeration >(static_cast< css::container::XEnumeration* >(pEnum), css::uno::UNO_QUERY);
286 }
287 /*
288 if (lEnumSet.empty())
289 {
290 //-------------------------------------------
291 // 1) getDefaultFilterForType=<internal_typename>
292
293 pIt = lTokens.find(::rtl::OUString::createFromAscii("getDefaultFilterForType"));
294 if (pIt != lTokens.end())
295 {
296 // SAFE ->
297 ::osl::ResettableMutexGuard aLock(m_aLock);
298
299 // might not all types was loaded till now!
300 impl_loadOnDemand();
301
302 ::rtl::OUString sType = pIt->second;
303 FilterCache* pCache = impl_getWorkingCache();
304 if (pCache->hasItem(FilterCache::E_TYPE, sType))
305 {
306 CacheItem aType = pCache->getItem(FilterCache::E_TYPE, sType);
307 ::rtl::OUString sPreferredFilter;
308 aType[PROPNAME_PREFERREDFILTER] >>= sPreferredFilter;
309
310 if (
311 (sPreferredFilter.getLength() ) &&
312 (pCache->hasItem(FilterCache::E_FILTER, sPreferredFilter))
313 )
314 {
315 lEnumSet.push_back(sPreferredFilter);
316 }
317 }
318
319 aLock.clear();
320 // <- SAFE
321 }
322 }
323 */
324
325 /*-----------------------------------------------
326 11.03.2004 08:33
327 -----------------------------------------------*/
impl_queryMatchByDocumentService(const QueryTokenizer & lTokens) const328 OUStringList FilterFactory::impl_queryMatchByDocumentService(const QueryTokenizer& lTokens) const
329 {
330 // analyze query
331 QueryTokenizer::const_iterator pIt;
332
333 ::rtl::OUString sDocumentService;
334 sal_Int32 nIFlags = 0;
335 sal_Int32 nEFlags = 0;
336
337 pIt = lTokens.find(QUERY_IDENTIFIER_MATCHBYDOCUMENTSERVICE);
338 if (pIt != lTokens.end())
339 sDocumentService = pIt->second;
340
341 #define COMP_HACK
342 #ifdef COMP_HACK
343 if (sDocumentService.equalsAscii("writer"))
344 {
345 OSL_ENSURE(sal_False, "DEPRECATED!\nPlease use right document service for filter query!");
346 sDocumentService = ::rtl::OUString::createFromAscii("com.sun.star.text.TextDocument");
347 }
348 else
349 if (sDocumentService.equalsAscii("web"))
350 {
351 OSL_ENSURE(sal_False, "DEPRECATED!\nPlease use right document service for filter query!");
352 sDocumentService = ::rtl::OUString::createFromAscii("com.sun.star.text.WebDocument");
353 }
354 else
355 if (sDocumentService.equalsAscii("global"))
356 {
357 OSL_ENSURE(sal_False, "DEPRECATED!\nPlease use right document service for filter query!");
358 sDocumentService = ::rtl::OUString::createFromAscii("com.sun.star.text.GlobalDocument");
359 }
360 else
361 if (sDocumentService.equalsAscii("calc"))
362 {
363 OSL_ENSURE(sal_False, "DEPRECATED!\nPlease use right document service for filter query!");
364 sDocumentService = ::rtl::OUString::createFromAscii("com.sun.star.sheet.SpreadsheetDocument");
365 }
366 else
367 if (sDocumentService.equalsAscii("draw"))
368 {
369 OSL_ENSURE(sal_False, "DEPRECATED!\nPlease use right document service for filter query!");
370 sDocumentService = ::rtl::OUString::createFromAscii("com.sun.star.drawing.DrawingDocument");
371 }
372 else
373 if (sDocumentService.equalsAscii("impress"))
374 {
375 OSL_ENSURE(sal_False, "DEPRECATED!\nPlease use right document service for filter query!");
376 sDocumentService = ::rtl::OUString::createFromAscii("com.sun.star.presentation.PresentationDocument");
377 }
378 else
379 if (sDocumentService.equalsAscii("math"))
380 {
381 OSL_ENSURE(sal_False, "DEPRECATED!\nPlease use right document service for filter query!");
382 sDocumentService = ::rtl::OUString::createFromAscii("com.sun.star.formula.FormulaProperties");
383 }
384 #endif
385
386 pIt = lTokens.find(QUERY_PARAM_IFLAGS);
387 if (pIt != lTokens.end())
388 nIFlags = ::rtl::OUString(pIt->second).toInt32();
389
390 pIt = lTokens.find(QUERY_PARAM_EFLAGS);
391 if (pIt != lTokens.end())
392 nEFlags = ::rtl::OUString(pIt->second).toInt32();
393
394 // SAFE -> ----------------------
395 ::osl::ResettableMutexGuard aLock(m_aLock);
396
397 // search suitable filters
398 FilterCache* pCache = impl_getWorkingCache();
399 OUStringList lFilterNames = pCache->getItemNames(FilterCache::E_FILTER);
400 OUStringList lResult ;
401
402 for (OUStringList::const_iterator pName = lFilterNames.begin();
403 pName != lFilterNames.end() ;
404 ++pName )
405 {
406 try
407 {
408 const ::rtl::OUString& sName = *pName;
409 const CacheItem aFilter = pCache->getItem(FilterCache::E_FILTER, sName);
410 CacheItem::const_iterator pProp ;
411
412 // "matchByDocumentService=" => any filter will be addressed here
413 // "matchByDocumentService=all" => any filter will be addressed here
414 // "matchByDocumentService=com.sun.star..." => only filter matching this document service will be addressed
415 ::rtl::OUString sCheckValue = aFilter.getUnpackedValueOrDefault(PROPNAME_DOCUMENTSERVICE, ::rtl::OUString());
416 if (
417 ( sDocumentService.getLength() ) &&
418 (!sDocumentService.equals(QUERY_CONSTVALUE_ALL)) &&
419 (!sCheckValue.equals(sDocumentService) )
420 )
421 {
422 continue; // ignore filter -> try next one!
423 }
424
425 // "iflags=" => not allowed
426 // "iflags=-1" => not allowed
427 // "iflags=0" => not useful
428 // "iflags=283648" => only filter, which has set these flag field will be addressed
429 sal_Int32 nCheckValue = aFilter.getUnpackedValueOrDefault(PROPNAME_FLAGS, (sal_Int32)0);
430 if (
431 (nIFlags > 0 ) &&
432 ((nCheckValue & nIFlags) != nIFlags)
433 )
434 {
435 continue; // ignore filter -> try next one!
436 }
437
438 // "eflags=" => not allowed
439 // "eflags=-1" => not allowed
440 // "eflags=0" => not useful
441 // "eflags=283648" => only filter, which has not set these flag field will be addressed
442 if (
443 (nEFlags > 0 ) &&
444 ((nCheckValue & nEFlags) == nEFlags)
445 )
446 {
447 continue; // ignore filter -> try next one!
448 }
449
450 // OK - this filter passed all checks.
451 // It match the query ...
452 lResult.push_back(sName);
453 }
454 catch(const css::uno::RuntimeException& exRun)
455 { throw exRun; }
456 catch(const css::uno::Exception&)
457 { continue; }
458 }
459
460 aLock.clear();
461 // <- SAFE ----------------------
462
463 return lResult;
464 }
465
466 /*-----------------------------------------------
467 21.01.2005 13:39
468 -----------------------------------------------*/
469 class stlcomp_removeIfMatchFlags
470 {
471 private:
472 FilterCache* m_pCache ;
473 sal_Int32 m_nFlags ;
474 sal_Bool m_bIFlags;
475
476 public:
stlcomp_removeIfMatchFlags(FilterCache * pCache,sal_Int32 nFlags,sal_Bool bIFlags)477 stlcomp_removeIfMatchFlags(FilterCache* pCache ,
478 sal_Int32 nFlags ,
479 sal_Bool bIFlags)
480 : m_pCache (pCache )
481 , m_nFlags (nFlags )
482 , m_bIFlags(bIFlags)
483 {}
484
operator ()(const::rtl::OUString & sFilter) const485 bool operator() (const ::rtl::OUString& sFilter) const
486 {
487 try
488 {
489 const CacheItem aFilter = m_pCache->getItem(FilterCache::E_FILTER, sFilter);
490 sal_Int32 nFlags = aFilter.getUnpackedValueOrDefault(PROPNAME_FLAGS, ((sal_Int32)0));
491
492 bool bMatch = false;
493 if (m_bIFlags)
494 // IFlags are interpeted as ALL_FLAGS_MUST_MATCH !
495 bMatch = ((nFlags & m_nFlags) == m_nFlags);
496 else
497 // EFlags are interpreted as ATE_LEAST_ONE_FLAG_MUST_MATCH !
498 bMatch = !(nFlags & m_nFlags);
499 // We are asked for bRemove ! And bMatch = !bRemove => so bRemove = !bMatch .-)
500 return !bMatch;
501 }
502 catch(css::container::NoSuchElementException)
503 {
504 return true;
505 }
506 }
507 };
508
509 /*-----------------------------------------------
510 21.01.2005 13:39
511 -----------------------------------------------*/
impl_getSortedFilterList(const QueryTokenizer & lTokens) const512 OUStringList FilterFactory::impl_getSortedFilterList(const QueryTokenizer& lTokens) const
513 {
514 // analyze the given query parameter
515 QueryTokenizer::const_iterator pIt1;
516
517 ::rtl::OUString sModule;
518 sal_Int32 nIFlags = -1;
519 sal_Int32 nEFlags = -1;
520
521 pIt1 = lTokens.find(QUERY_PARAM_MODULE);
522 if (pIt1 != lTokens.end())
523 sModule = pIt1->second;
524 pIt1 = lTokens.find(QUERY_PARAM_IFLAGS);
525 if (pIt1 != lTokens.end())
526 nIFlags = ::rtl::OUString(pIt1->second).toInt32();
527 pIt1 = lTokens.find(QUERY_PARAM_EFLAGS);
528 if (pIt1 != lTokens.end())
529 nEFlags = ::rtl::OUString(pIt1->second).toInt32();
530
531 // simple search for filters of one specific module.
532 OUStringList lFilterList;
533 if (sModule.getLength())
534 lFilterList = impl_getSortedFilterListForModule(sModule, nIFlags, nEFlags);
535 else
536 {
537 // more complex search for all filters
538 // We check first, which office modules are installed ...
539 OUStringList lModules = impl_getListOfInstalledModules();
540 OUStringList::const_iterator pIt2;
541 for ( pIt2 = lModules.begin();
542 pIt2 != lModules.end() ;
543 ++pIt2 )
544 {
545 sModule = *pIt2;
546 OUStringList lFilters4Module = impl_getSortedFilterListForModule(sModule, nIFlags, nEFlags);
547 OUStringList::const_iterator pIt3;
548 for ( pIt3 = lFilters4Module.begin();
549 pIt3 != lFilters4Module.end() ;
550 ++pIt3 )
551 {
552 const ::rtl::OUString& sFilter = *pIt3;
553 lFilterList.push_back(sFilter);
554 }
555 }
556 }
557
558 return lFilterList;
559 }
560
561 /*-----------------------------------------------
562 21.01.2005 10:19
563 -----------------------------------------------*/
impl_getListOfInstalledModules() const564 OUStringList FilterFactory::impl_getListOfInstalledModules() const
565 {
566 // SAFE -> ----------------------
567 ::osl::ResettableMutexGuard aLock(m_aLock);
568 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
569 aLock.clear();
570 // <- SAFE ----------------------
571
572 try
573 {
574 css::uno::Reference< css::container::XNameAccess > xModuleConfig(
575 ::comphelper::ConfigurationHelper::openConfig(xSMGR,
576 CFGPACKAGE_OOO_MODULES,
577 ::comphelper::ConfigurationHelper::E_READONLY),
578 css::uno::UNO_QUERY_THROW);
579 OUStringList lModules(xModuleConfig->getElementNames());
580 return lModules;
581 }
582 catch(const css::uno::RuntimeException& exRun)
583 { throw exRun; }
584 catch(const css::uno::Exception&)
585 {}
586
587 return OUStringList();
588 }
589
590 /*-----------------------------------------------
591 21.01.2005 10:19
592 -----------------------------------------------*/
impl_getSortedFilterListForModule(const::rtl::OUString & sModule,sal_Int32 nIFlags,sal_Int32 nEFlags) const593 OUStringList FilterFactory::impl_getSortedFilterListForModule(const ::rtl::OUString& sModule,
594 sal_Int32 nIFlags,
595 sal_Int32 nEFlags) const
596 {
597 OUStringList lSortedFilters = impl_readSortedFilterListFromConfig(sModule);
598
599 // get all filters for the requested module
600 CacheItem lIProps;
601 lIProps[PROPNAME_DOCUMENTSERVICE] <<= sModule;
602
603 // SAFE -> ----------------------
604 ::osl::ResettableMutexGuard aLock(m_aLock);
605 FilterCache* pCache = impl_getWorkingCache();
606 OUStringList lOtherFilters = pCache->getMatchingItemsByProps(FilterCache::E_FILTER, lIProps);
607 aLock.clear();
608 // <- SAFE ----------------------
609
610 // bring "other" filters in an alphabetical order
611 // It's needed below.
612 ::std::sort(lOtherFilters.begin(), lOtherFilters.end());
613
614 // merge both lists together
615 OUStringList lMergedFilters = lSortedFilters;
616 OUStringList::iterator pIt2;
617 OUStringList::iterator pIt3;
618 for ( pIt2 = lOtherFilters.begin();
619 pIt2 != lOtherFilters.end() ;
620 ++pIt2 )
621 {
622 const ::rtl::OUString& rFilter = *pIt2;
623 pIt3 = ::std::find(lSortedFilters.begin(), lSortedFilters.end(), rFilter);
624 if (pIt3 == lSortedFilters.end())
625 lMergedFilters.push_back(rFilter);
626 }
627
628 // remove all filters from this merged list, which does not fit the flag specification
629 if (nIFlags != -1)
630 {
631 pIt2 = ::std::remove_if(lMergedFilters.begin(), lMergedFilters.end(), stlcomp_removeIfMatchFlags(pCache, nIFlags, sal_True));
632 lMergedFilters.erase(pIt2, lMergedFilters.end());
633 }
634 if (nEFlags != -1)
635 {
636 pIt2 = ::std::remove_if(lMergedFilters.begin(), lMergedFilters.end(), stlcomp_removeIfMatchFlags(pCache, nEFlags, sal_False));
637 lMergedFilters.erase(pIt2, lMergedFilters.end());
638 }
639
640 // sort the default filter to the front of this list
641 // TODO
642
643 return lMergedFilters;
644 }
645
646 /*-----------------------------------------------
647 21.01.2005 10:19
648 -----------------------------------------------*/
impl_readSortedFilterListFromConfig(const::rtl::OUString & sModule) const649 OUStringList FilterFactory::impl_readSortedFilterListFromConfig(const ::rtl::OUString& sModule) const
650 {
651 // SAFE -> ----------------------
652 ::osl::ResettableMutexGuard aLock(m_aLock);
653 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
654 aLock.clear();
655 // <- SAFE ----------------------
656
657 try
658 {
659 css::uno::Reference< css::container::XNameAccess > xUISortConfig(
660 ::comphelper::ConfigurationHelper::openConfig(xSMGR,
661 CFGPACKAGE_TD_UISORT,
662 ::comphelper::ConfigurationHelper::E_READONLY),
663 css::uno::UNO_QUERY_THROW);
664
665 // dont ccheck the module name here. If it does not exists, an exception is thrown and catched below.
666 // We return an empty list as result then.
667 css::uno::Reference< css::container::XNameAccess > xModule;
668 xUISortConfig->getByName(sModule) >>= xModule;
669 if (xModule.is()) // only to be on the safe side of life if the exception was not thrown .-)
670 {
671 // Note: conversion of the returned Any to OUStringList throws
672 // an IllegalArgumentException if the type does not match ...
673 // but it resets the OUStringList to a length of 0 if the Any is empty!
674 OUStringList lSortedFilters(xModule->getByName(PROPNAME_SORTEDFILTERLIST));
675 return lSortedFilters;
676 }
677 }
678 catch(const css::uno::RuntimeException& exRun)
679 { throw exRun; }
680 catch(const css::uno::Exception&)
681 {}
682
683 return OUStringList();
684 }
685
686 /*-----------------------------------------------
687 09.07.2003 07:43
688 -----------------------------------------------*/
impl_getImplementationName()689 ::rtl::OUString FilterFactory::impl_getImplementationName()
690 {
691 return ::rtl::OUString::createFromAscii("com.sun.star.comp.filter.config.FilterFactory");
692 }
693
694 /*-----------------------------------------------
695 09.07.2003 07:43
696 -----------------------------------------------*/
impl_getSupportedServiceNames()697 css::uno::Sequence< ::rtl::OUString > FilterFactory::impl_getSupportedServiceNames()
698 {
699 css::uno::Sequence< ::rtl::OUString > lServiceNames(1);
700 lServiceNames[0] = ::rtl::OUString::createFromAscii("com.sun.star.document.FilterFactory");
701 return lServiceNames;
702 }
703
704 /*-----------------------------------------------
705 09.07.2003 07:43
706 -----------------------------------------------*/
impl_createInstance(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)707 css::uno::Reference< css::uno::XInterface > SAL_CALL FilterFactory::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
708 {
709 FilterFactory* pNew = new FilterFactory(xSMGR);
710 return css::uno::Reference< css::uno::XInterface >(static_cast< css::lang::XMultiServiceFactory* >(pNew), css::uno::UNO_QUERY);
711 }
712
713 } // namespace config
714 } // namespace filter
715