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