1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "cacheitem.hxx"
22 #include "constant.hxx"
24 #include <com/sun/star/uno/Sequence.h>
26 #include <com/sun/star/beans/NamedValue.hpp>
27 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <osl/diagnose.h>
30 #include <comphelper/sequence.hxx>
33 namespace filter::config
{
35 CacheItem::CacheItem()
40 void CacheItem::update(const CacheItem
& rUpdateItem
)
42 for (auto const& elem
: rUpdateItem
)
43 (*this)[elem
.first
] = elem
.second
;
47 void CacheItem::validateUINames(const OUString
& sActLocale
)
49 if (sActLocale
.isEmpty())
52 // 1) check UINames first
53 const_iterator pUINames
= find(PROPNAME_UINAMES
);
54 const_iterator pUIName
= find(PROPNAME_UINAME
);
56 ::comphelper::SequenceAsHashMap lUINames
;
57 if (pUINames
!= end())
58 lUINames
<< pUINames
->second
;
62 pUIName
->second
>>= sUIName
;
64 if (!sUIName
.isEmpty())
66 // 1a) set UIName inside list of UINames for current locale
67 lUINames
[sActLocale
] <<= sUIName
;
69 else if (!lUINames
.empty())
71 // 1b) or get it from this list, if it not exist!
72 lUINames
[sActLocale
] >>= sUIName
;
75 (*this)[PROPNAME_UINAMES
] <<= lUINames
.getAsConstPropertyValueList();
76 (*this)[PROPNAME_UINAME
] <<= sUIName
;
80 css::uno::Sequence
< css::beans::PropertyValue
> CacheItem::getAsPackedPropertyValueList(bool bFinalized
, bool bMandatory
) const
82 sal_Int32 c
= static_cast<sal_Int32
>(size());
85 css::uno::Sequence
< css::beans::PropertyValue
> lList(c
+2);
86 css::beans::PropertyValue
* pList
= lList
.getArray();
88 for (const_iterator pProp
= begin();
92 const OUString
& rName
= pProp
->first
.maString
;
93 const css::uno::Any
& rValue
= pProp
->second
;
95 if (!rValue
.hasValue())
97 assert (rName
!= PROPNAME_FINALIZED
&& rName
!= PROPNAME_MANDATORY
);
99 pList
[i
].Name
= rName
;
100 pList
[i
].Value
= rValue
;
103 pList
[i
].Name
= PROPNAME_FINALIZED
;
104 pList
[i
].Value
<<= bFinalized
;
106 pList
[i
].Name
= PROPNAME_MANDATORY
;
107 pList
[i
].Value
<<= bMandatory
;
115 static bool isSubSet(const css::uno::Any
& aSubSet
,
116 const css::uno::Any
& aSet
)
118 const css::uno::Type
& aT1
= aSubSet
.getValueType();
119 const css::uno::Type
& aT2
= aSet
.getValueType();
121 if (!aT1
.equals(aT2
))
126 if (aSubSet
.hasValue() && aSet
.hasValue())
128 css::uno::TypeClass aTypeClass
= aT1
.getTypeClass();
132 case css::uno::TypeClass_BOOLEAN
:
133 case css::uno::TypeClass_BYTE
:
134 case css::uno::TypeClass_SHORT
:
135 case css::uno::TypeClass_UNSIGNED_SHORT
:
136 case css::uno::TypeClass_LONG
:
137 case css::uno::TypeClass_UNSIGNED_LONG
:
138 case css::uno::TypeClass_HYPER
:
139 case css::uno::TypeClass_UNSIGNED_HYPER
:
140 case css::uno::TypeClass_FLOAT
:
141 case css::uno::TypeClass_DOUBLE
:
143 bool bIs
= (aSubSet
== aSet
);
148 case css::uno::TypeClass_STRING
:
149 return aSubSet
== aSet
;
153 case css::uno::TypeClass_STRUCT
:
155 css::beans::PropertyValue p1
;
156 css::beans::PropertyValue p2
;
163 bool bIs
= (p1
.Name
== p2
.Name
) && isSubSet(p1
.Value
, p2
.Value
);
167 css::beans::NamedValue n1
;
168 css::beans::NamedValue n2
;
175 bool bIs
= (n1
.Name
== n2
.Name
) && isSubSet(n1
.Value
, n2
.Value
);
182 case css::uno::TypeClass_SEQUENCE
:
184 css::uno::Sequence
< OUString
> uno_s1
;
185 css::uno::Sequence
< OUString
> uno_s2
;
188 (aSubSet
>>= uno_s1
) &&
192 auto s2Begin
= uno_s2
.getConstArray();
193 auto s2End
= uno_s2
.getConstArray() + uno_s2
.getLength();
195 for (auto const& elem
: uno_s1
)
197 if (::std::find(s2Begin
, s2End
, elem
) == s2End
)
205 css::uno::Sequence
< css::beans::PropertyValue
> uno_p1
;
206 css::uno::Sequence
< css::beans::PropertyValue
> uno_p2
;
209 (aSubSet
>>= uno_p1
) &&
213 ::comphelper::SequenceAsHashMap
stl_p1(uno_p1
);
214 ::comphelper::SequenceAsHashMap
stl_p2(uno_p2
);
216 for (auto const& elem
: stl_p1
)
218 ::comphelper::SequenceAsHashMap::const_iterator it2
= stl_p2
.find(elem
.first
);
219 if (it2
== stl_p2
.end())
223 if (!isSubSet(elem
.second
, it2
->second
))
231 css::uno::Sequence
< css::beans::NamedValue
> uno_n1
;
232 css::uno::Sequence
< css::beans::NamedValue
> uno_n2
;
235 (aSubSet
>>= uno_n1
) &&
239 ::comphelper::SequenceAsHashMap
stl_n1(uno_n1
);
240 ::comphelper::SequenceAsHashMap
stl_n2(uno_n2
);
242 for (auto const& elem
: stl_n1
)
244 ::comphelper::SequenceAsHashMap::const_iterator it2
= stl_n2
.find(elem
.first
);
245 if (it2
== stl_n2
.end())
249 if (!isSubSet(elem
.second
, it2
->second
))
261 OSL_FAIL("isSubSet() ... this point should not be reached!");
266 bool CacheItem::haveProps(std::span
< const css::beans::NamedValue
> lProps
) const
268 for (auto const& prop
: lProps
)
270 // i) one required property does not exist at this item => return false
271 const_iterator pItThis
= find(prop
.Name
);
272 if (pItThis
== end())
277 // ii) one item does not have the right value => return false
278 if (!isSubSet(prop
.Value
, pItThis
->second
))
284 // this method was not broken before =>
285 // the given property set seems to match with our
286 // own properties in its minimum => return TRUE
291 bool CacheItem::dontHaveProps(std::span
< const css::beans::NamedValue
> lProps
) const
293 for (auto const& prop
: lProps
)
295 // i) one item does not exist in general
296 // => continue with next one, because
297 // "excluding" means... "don't have it".
298 // And "not exists" matches to "don't have it".
299 const_iterator pItThis
= find(prop
.Name
);
300 if (pItThis
== end())
305 // ii) one item have the right value => return false
306 // because this item has the requested property...
307 // But we checked for "don't have it" here.
308 if (isSubSet(prop
.Value
, pItThis
->second
))
314 // this method was not broken before =>
315 // That means: this item has no matching property
316 // of the given set. It "don't have" it ... => return true.
320 FlatDetectionInfo::FlatDetectionInfo() :
321 bMatchByExtension(false), bMatchByPattern(false), bPreselectedByDocumentService(false) {}
323 } // namespace filter::config
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */