LibreOffice Module filter (master) 1
filtercache.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <memory>
23#include <mutex>
24
25#include "cacheitem.hxx"
26#include <com/sun/star/beans/NamedValue.hpp>
27#include <com/sun/star/util/URL.hpp>
28#include <com/sun/star/uno/XInterface.hpp>
29#include <com/sun/star/container/XNameAccess.hpp>
30#include <com/sun/star/container/XNameReplace.hpp>
31#include <com/sun/star/uno/Reference.h>
32#include <com/sun/star/uno/Any.h>
35#include <rtl/ref.hxx>
36#include <rtl/ustring.hxx>
37
38
39namespace filter::config {
40
41class CacheUpdateListener;
42
43
61{
62
63 // public types
64
65 public:
66
67
74 {
79 };
80
81
96 {
103 };
104
105
106 // private types
107
108 private:
109
110
122 {
125 E_READ_ALL = 3
126 };
127
128
139 {
147 E_ITEM_ADDED = 3
148 };
149
150
153 {
158 };
159
160
161 // member
162
163 private:
164
165 mutable std::mutex m_aMutex;
166
169 mutable css::uno::Reference< css::uno::XInterface > m_xConfigTypes;
170
171
174 mutable css::uno::Reference< css::uno::XInterface > m_xConfigFilters;
175
176
180 mutable css::uno::Reference< css::uno::XInterface > m_xConfigOthers;
181
182
185
186
189
190
193
194
197
198
203
204
209
210
213 OUString m_sActLocale;
214
215
226
227
229 std::vector<OUString> m_lChangedTypes;
230 std::vector<OUString> m_lChangedFilters;
231 std::vector<OUString> m_lChangedFrameLoaders;
232 std::vector<OUString> m_lChangedContentHandlers;
233
235 css::uno::Sequence< OUString > m_aStandardProps[4];
236
238 css::uno::Sequence< OUString > m_aTypeProps[4];
239
241 css::uno::Reference< css::container::XNameAccess > m_xModuleCfg;
242
245
246
247 // interface
248
249 public:
250
251
252 // ctor/dtor
253
268 FilterCache();
269
270
273 ~FilterCache();
274
275
294 std::unique_ptr<FilterCache> clone() const;
295
296
299 void takeOver(const FilterCache& rClone);
300
301
317 void load(EFillState eRequired);
318
319
333 bool isFillState(EFillState eRequired) const;
334
335
367 std::vector<OUString> getMatchingItemsByProps( EItemType eType,
370
371
393 bool hasItems(EItemType eType) const;
394
395
416 std::vector<OUString> getItemNames(EItemType eType) const;
417
418
438 bool hasItem( EItemType eType,
439 const OUString& sItem);
440
441
467 const OUString& sItem);
468
469
474 void removeItem( EItemType eType,
475 const OUString& sItem);
476
477
482 void setItem( EItemType eType ,
483 const OUString& sItem ,
484 const CacheItem& aValue);
485
486
491 void refreshItem( EItemType eType,
492 const OUString& sItem);
493
494
530 css::uno::Any getItemWithStateProps( EItemType eType,
531 const OUString& sItem);
532
537 static void removeStatePropsFromItem(CacheItem& aValue);
538
539
549 void flush();
550
551
578 void detectFlatForURL(const css::util::URL& aURL ,
579 FlatDetection& rFlatTypes) const;
580
581
582 // private helper
583
584 private:
585
586 std::vector<OUString> getItemNames(std::unique_lock<std::mutex>& rGuard, EItemType eType) const;
587
601 const CacheItemList& impl_getItemList(std::unique_lock<std::mutex>& rGuard, EItemType eType) const;
602
603 CacheItemList& impl_getItemList(std::unique_lock<std::mutex>& rGuard, EItemType eType);
604
605 CacheItem& impl_getItem( std::unique_lock<std::mutex>& rGuard, EItemType eType, const OUString& sItem);
606
626 css::uno::Reference< css::uno::XInterface > impl_openConfig(std::unique_lock<std::mutex>& rGuard, EConfigProvider eProvide);
627
628
647 static css::uno::Reference< css::uno::XInterface > impl_createConfigAccess(std::unique_lock<std::mutex>& rGuard,
648 const OUString& sRoot ,
649 bool bReadOnly ,
650 bool bLocalesMode);
651
652
672 static css::uno::Any impl_getDirectCFGValue(std::unique_lock<std::mutex>& rGuard, std::u16string_view sDirectKey);
673
674
687 void impl_load(std::unique_lock<std::mutex>& rGuard, EFillState eRequiredState);
688
689
706 void impl_validateAndOptimize(std::unique_lock<std::mutex>& rGuard);
707
708 private:
709
710
736 void impl_loadSet(std::unique_lock<std::mutex>& rGuard,
737 const css::uno::Reference< css::container::XNameAccess >& xConfig,
738 EItemType eType ,
739 EReadOption eOption,
740 CacheItemList* pCache );
741
742
765 CacheItem impl_loadItem(std::unique_lock<std::mutex>& rGuard,
766 const css::uno::Reference< css::container::XNameAccess >& xSet ,
767 EItemType eType ,
768 const OUString& sItem ,
769 EReadOption eOption);
770
771
797 CacheItemList::iterator impl_loadItemOnDemand( std::unique_lock<std::mutex>& rGuard,
798 EItemType eType,
799 const OUString& sItem);
800
801
806 static void impl_saveItem(const css::uno::Reference< css::container::XNameReplace >& xSet ,
807 EItemType eType ,
808 const CacheItem & aValue);
809
810
816 const OUString& sItem);
817
818
823 static void impl_flushByList(const css::uno::Reference< css::container::XNameAccess >& xSet ,
824 EItemType eType ,
825 const CacheItemList& rCache,
826 const std::vector<OUString>& lItems);
827
828
856 static EItemFlushState impl_specifyFlushOperation(const css::uno::Reference< css::container::XNameAccess >& xSet ,
857 const CacheItemList& rList,
858 const OUString& sItem);
859
860
865 void impl_readPatchUINames(std::unique_lock<std::mutex>& rGuard,
866 const css::uno::Reference< css::container::XNameAccess >& xNode,
867 CacheItem& rItem);
868
869
874 static void impl_savePatchUINames(const css::uno::Reference< css::container::XNameReplace >& xNode,
875 const CacheItem& rItem);
876
878 void impl_readOldFormat(std::unique_lock<std::mutex>& rGuard);
879
884 CacheItem impl_readOldItem(std::unique_lock<std::mutex>& rGuard,
885 const css::uno::Reference< css::container::XNameAccess >& xSet ,
886 EItemType eType,
887 const OUString& sItem);
888
889
891 static void impl_interpretDataVal4Type(const OUString& sValue,
892 sal_Int32 nProp ,
893 CacheItem& rItem );
894
895
897 static void impl_interpretDataVal4Filter(const OUString& sValue,
898 sal_Int32 nProp ,
899 CacheItem& rItem );
900
901
903 static std::vector<OUString> impl_tokenizeString(std::u16string_view sData ,
904 sal_Unicode cSeparator);
905
906
907#if OSL_DEBUG_LEVEL > 0
909 OUString impl_searchFrameLoaderForType(const OUString& sType) const;
910 OUString impl_searchContentHandlerForType(const OUString& sType) const;
911#endif
912
913
921 bool impl_isModuleInstalled(std::unique_lock<std::mutex>& rGuard, const OUString& sModule);
922
923
931 static SfxFilterFlags impl_convertFlagNames2FlagField(const css::uno::Sequence< OUString >& lNames);
932
933
942 static css::uno::Sequence< OUString > impl_convertFlagField2FlagNames(SfxFilterFlags nFlags);
943};
944
945FilterCache& GetTheFilterCache();
946
947} // namespace filter::config
948
949/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
represent an item of a FilterCache instance.
Definition: cacheitem.hxx:40
implements a cache, which contains all elements of our filter and type detection configuration.
Definition: filtercache.hxx:61
std::unique_ptr< FilterCache > clone() const
creates a copy of this container.
static void impl_interpretDataVal4Filter(const OUString &sValue, sal_Int32 nProp, CacheItem &rItem)
TODO.
std::vector< OUString > m_lChangedContentHandlers
bool hasItems(EItemType eType) const
indicates if the requested sub container contains some items.
void impl_load(std::unique_lock< std::mutex > &rGuard, EFillState eRequiredState)
load the underlying configuration into this cache.
css::uno::Reference< css::uno::XInterface > m_xConfigTypes
holds the used configuration provider alive, which provides access to the list of types.
void impl_readPatchUINames(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< css::container::XNameAccess > &xNode, CacheItem &rItem)
TODO.
css::uno::Reference< css::container::XNameAccess > m_xModuleCfg
readonly access to the module configuration of OOo
OUString impl_searchFrameLoaderForType(const OUString &sType) const
TODO.
std::vector< OUString > getMatchingItemsByProps(EItemType eType, o3tl::span< const css::beans::NamedValue > lIProps, o3tl::span< const css::beans::NamedValue > lEProps={}) const
return a list of key names for items, which match the specified criteria.
static css::uno::Reference< css::uno::XInterface > impl_createConfigAccess(std::unique_lock< std::mutex > &rGuard, const OUString &sRoot, bool bReadOnly, bool bLocalesMode)
tries to open the requested configuration root using the specified modi.
static EItemFlushState impl_specifyFlushOperation(const css::uno::Reference< css::container::XNameAccess > &xSet, const CacheItemList &rList, const OUString &sItem)
specify, which save operation is necessary for the specified item.
css::uno::Reference< css::uno::XInterface > m_xConfigFilters
holds the used configuration provider alive, which provides access to the list of filters.
static css::uno::Any impl_getDirectCFGValue(std::unique_lock< std::mutex > &rGuard, std::u16string_view sDirectKey)
reads the specified configuration key and return its value.
EFillState
indicates, which items already exists inside this cache and which not.
Definition: filtercache.hxx:96
CacheItemRegistration m_lURLPattern2Types
optimize mapping of URL pattern to a type representation, by using patterns as key and a list of inte...
std::vector< OUString > m_lChangedFilters
static std::vector< OUString > impl_tokenizeString(std::u16string_view sData, sal_Unicode cSeparator)
TODO.
CacheItem & impl_getItem(std::unique_lock< std::mutex > &rGuard, EItemType eType, const OUString &sItem)
static css::uno::Sequence< OUString > impl_convertFlagField2FlagNames(SfxFilterFlags nFlags)
convert a flag field value to its list representation of flag names.
const CacheItemList & impl_getItemList(std::unique_lock< std::mutex > &rGuard, EItemType eType) const
return a reference to one of our internal sub container, which contains items of the requested type.
CacheItemRegistration m_lExtensions2Types
optimize mapping of URL extensions to a type representation, by using extensions as key and a list of...
OUString m_sActLocale
contains the current locale of the office and will be used to work with localized configuration value...
void flush()
force writing of all changes (which was made after last flush was called) back to the configuration.
std::vector< OUString > m_lChangedTypes
TODO document me ...
~FilterCache()
standard dtor.
static void impl_savePatchUINames(const css::uno::Reference< css::container::XNameReplace > &xNode, const CacheItem &rItem)
TODO.
css::uno::Reference< css::uno::XInterface > m_xConfigOthers
holds the used configuration provider alive, which provides access to the list of other values needed...
static void impl_flushByList(const css::uno::Reference< css::container::XNameAccess > &xSet, EItemType eType, const CacheItemList &rCache, const std::vector< OUString > &lItems)
TODO.
void impl_loadSet(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< css::container::XNameAccess > &xConfig, EItemType eType, EReadOption eOption, CacheItemList *pCache)
read the specified config set into the cache.
static void removeStatePropsFromItem(CacheItem &aValue)
TODO document me.
std::vector< OUString > getItemNames(EItemType eType) const
return a list of all key names, which represent an item inside the specified sub container.
static SfxFilterFlags impl_convertFlagNames2FlagField(const css::uno::Sequence< OUString > &lNames)
convert a list of flag names to its int representation.
bool isFillState(EFillState eRequired) const
return the current fill state of this cache.
bool hasItem(EItemType eType, const OUString &sItem)
check if the required item exist inside this container.
void load(EFillState eRequired)
force special fill state of this cache.
CacheItemList::iterator impl_loadItemOnDemand(std::unique_lock< std::mutex > &rGuard, EItemType eType, const OUString &sItem)
try to load the requested item on demand from the underlying configuration layer.
EConfigProvider
TODO document me.
void refreshItem(EItemType eType, const OUString &sItem)
TODO document me ...
css::uno::Reference< css::uno::XInterface > impl_openConfig(std::unique_lock< std::mutex > &rGuard, EConfigProvider eProvide)
return a valid configuration update access to the underlying configuration package,...
css::uno::Sequence< OUString > m_aStandardProps[4]
standard property names for filter config keyed by EReadOption
CacheItemList m_lFrameLoaders
contains all loaded frame loader with its properties.
EItemType
identify the type of a container item.
Definition: filtercache.hxx:74
css::uno::Any getItemWithStateProps(EItemType eType, const OUString &sItem)
add some implicit properties to the given cache item reference.
void detectFlatForURL(const css::util::URL &aURL, FlatDetection &rFlatTypes) const
supports a flat type detection for given URL.
rtl::Reference< CacheUpdateListener > m_xFiltersChgListener
EFillState m_eFillState
contains status, which cache items/properties was already loaded from the underlying configuration.
EItemFlushState
indicates the state of a configuration set item.
@ E_ITEM_UNCHANGED
indicates an unchanged item (can occur e.g. if an item was added and(!) removed before it was flushed...
@ E_ITEM_REMOVED
indicates an item, which exists inside config layer but not inside our own cache
@ E_ITEM_ADDED
indicates an item, which does not exists inside config layer but inside our own cache
@ E_ITEM_CHANGED
indicates an item, which exists inside config layer and inside our own cache
EReadOption
regulate, which properties of a configured item will be read.
static void impl_interpretDataVal4Type(const OUString &sValue, sal_Int32 nProp, CacheItem &rItem)
TODO.
rtl::Reference< CacheUpdateListener > m_xTypesChglisteners
void removeItem(EItemType eType, const OUString &sItem)
TODO document me ...
void takeOver(const FilterCache &rClone)
copy the cache content or rClone back to this instance.
void impl_validateAndOptimize(std::unique_lock< std::mutex > &rGuard)
validate the whole cache and create structures for optimized items access.
bool impl_isModuleInstalled(std::unique_lock< std::mutex > &rGuard, const OUString &sModule)
check if the specified OOo module is installed.
CacheItemList m_lFilters
contains all loaded filters with its properties.
CacheItem impl_loadItem(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< css::container::XNameAccess > &xSet, EItemType eType, const OUString &sItem, EReadOption eOption)
read the specified container item from the given configuration set.
void impl_addItem2FlushList(EItemType eType, const OUString &sItem)
TODO.
void setItem(EItemType eType, const OUString &sItem, const CacheItem &aValue)
TODO document me ...
CacheItem impl_readOldItem(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< css::container::XNameAccess > &xSet, EItemType eType, const OUString &sItem)
TODO.
void impl_readOldFormat(std::unique_lock< std::mutex > &rGuard)
TODO.
CacheItem getItem(EItemType eType, const OUString &sItem)
return an item, which match the specified type and name.
CacheItemList m_lTypes
contains all loaded types with its properties.
static void impl_saveItem(const css::uno::Reference< css::container::XNameReplace > &xSet, EItemType eType, const CacheItem &aValue)
TODO.
std::vector< OUString > m_lChangedFrameLoaders
css::uno::Sequence< OUString > m_aTypeProps[4]
type property names for filter config keyed by EReadOption
CacheItemList m_lContentHandlers
contains all loaded content handler with its properties.
OUString impl_searchContentHandlerForType(const OUString &sType) const
SfxFilterFlags
::std::vector< FlatDetectionInfo > FlatDetection
Definition: cacheitem.hxx:173
std::unordered_map< OUString, std::vector< OUString > > CacheItemRegistration
supports registration of multiple key to another string information.
Definition: cacheitem.hxx:145
std::unordered_map< OUString, CacheItem > CacheItemList
represent an item list of a FilterCache instance.
Definition: cacheitem.hxx:129
FilterCache & GetTheFilterCache()
sal_uInt16 sal_Unicode