LCOV - code coverage report
Current view: top level - filter/source/config/cache - filterfactory.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 227 14.5 %
Date: 2015-06-13 12:38:46 Functions: 7 17 41.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11