LibreOffice Module filter (master) 1
cacheitem.cxx
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
21#include "cacheitem.hxx"
22#include "constant.hxx"
23
24#include <com/sun/star/uno/Sequence.h>
25
26#include <com/sun/star/beans/NamedValue.hpp>
27#include <com/sun/star/beans/PropertyValue.hpp>
28
29#include <osl/diagnose.h>
31
32
33namespace filter::config{
34
36{
37}
38
39
40void CacheItem::update(const CacheItem& rUpdateItem)
41{
42 for (auto const& elem : rUpdateItem)
43 (*this)[elem.first] = elem.second;
44}
45
46
47void CacheItem::validateUINames(const OUString& sActLocale)
48{
49 if (sActLocale.isEmpty())
50 return;
51
52 // 1) check UINames first
55
57 if (pUINames != end())
58 lUINames << pUINames->second;
59
60 OUString sUIName;
61 if (pUIName != end())
62 pUIName->second >>= sUIName;
63
64 if (!sUIName.isEmpty())
65 {
66 // 1a) set UIName inside list of UINames for current locale
67 lUINames[sActLocale] <<= sUIName;
68 }
69 else if (!lUINames.empty())
70 {
71 // 1b) or get it from this list, if it not exist!
72 lUINames[sActLocale] >>= sUIName;
73 }
74
75 (*this)[PROPNAME_UINAMES] <<= lUINames.getAsConstPropertyValueList();
76 (*this)[PROPNAME_UINAME ] <<= sUIName;
77}
78
79
80css::uno::Sequence< css::beans::PropertyValue > CacheItem::getAsPackedPropertyValueList(bool bFinalized, bool bMandatory) const
81{
82 sal_Int32 c = static_cast<sal_Int32>(size());
83 sal_Int32 i = 0;
84
85 css::uno::Sequence< css::beans::PropertyValue > lList(c+2);
86 css::beans::PropertyValue* pList = lList.getArray();
87
88 for (const_iterator pProp = begin();
89 pProp != end() ;
90 ++pProp )
91 {
92 const OUString& rName = pProp->first.maString;
93 const css::uno::Any& rValue = pProp->second;
94
95 if (!rValue.hasValue())
96 continue;
97 assert (rName != PROPNAME_FINALIZED && rName != PROPNAME_MANDATORY);
98
99 pList[i].Name = rName ;
100 pList[i].Value = rValue;
101 ++i;
102 }
103 pList[i].Name = PROPNAME_FINALIZED ;
104 pList[i].Value <<= bFinalized;
105 ++i;
106 pList[i].Name = PROPNAME_MANDATORY ;
107 pList[i].Value <<= bMandatory;
108 ++i;
109 lList.realloc(i);
110
111 return lList;
112}
113
114
115static bool isSubSet(const css::uno::Any& aSubSet,
116 const css::uno::Any& aSet )
117{
118 const css::uno::Type& aT1 = aSubSet.getValueType();
119 const css::uno::Type& aT2 = aSet.getValueType();
120
121 if (!aT1.equals(aT2))
122 {
123 return false;
124 }
125
126 if (aSubSet.hasValue() && aSet.hasValue())
127 {
128 css::uno::TypeClass aTypeClass = aT1.getTypeClass();
129 switch(aTypeClass)
130 {
131
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 :
142 {
143 bool bIs = (aSubSet == aSet);
144 return bIs;
145 }
146
147
148 case css::uno::TypeClass_STRING :
149 return aSubSet == aSet;
150 break;
151
152
153 case css::uno::TypeClass_STRUCT :
154 {
155 css::beans::PropertyValue p1;
156 css::beans::PropertyValue p2;
157
158 if (
159 (aSubSet >>= p1) &&
160 (aSet >>= p2)
161 )
162 {
163 bool bIs = (p1.Name == p2.Name) && isSubSet(p1.Value, p2.Value);
164 return bIs;
165 }
166
167 css::beans::NamedValue n1;
168 css::beans::NamedValue n2;
169
170 if (
171 (aSubSet >>= n1) &&
172 (aSet >>= n2)
173 )
174 {
175 bool bIs = (n1.Name == n2.Name) && isSubSet(n1.Value, n2.Value);
176 return bIs;
177 }
178 }
179 break;
180
181
182 case css::uno::TypeClass_SEQUENCE :
183 {
184 css::uno::Sequence< OUString > uno_s1;
185 css::uno::Sequence< OUString > uno_s2;
186
187 if (
188 (aSubSet >>= uno_s1) &&
189 (aSet >>= uno_s2)
190 )
191 {
192 auto s2Begin = uno_s2.getConstArray();
193 auto s2End = uno_s2.getConstArray() + uno_s2.getLength();
194
195 for (auto const& elem : uno_s1)
196 {
197 if (::std::find(s2Begin, s2End, elem) == s2End)
198 {
199 return false;
200 }
201 }
202 return true;
203 }
204
205 css::uno::Sequence< css::beans::PropertyValue > uno_p1;
206 css::uno::Sequence< css::beans::PropertyValue > uno_p2;
207
208 if (
209 (aSubSet >>= uno_p1) &&
210 (aSet >>= uno_p2)
211 )
212 {
213 ::comphelper::SequenceAsHashMap stl_p1(uno_p1);
214 ::comphelper::SequenceAsHashMap stl_p2(uno_p2);
215
216 for (auto const& elem : stl_p1)
217 {
219 if (it2 == stl_p2.end())
220 {
221 return false;
222 }
223 if (!isSubSet(elem.second, it2->second))
224 {
225 return false;
226 }
227 }
228 return true;
229 }
230
231 css::uno::Sequence< css::beans::NamedValue > uno_n1;
232 css::uno::Sequence< css::beans::NamedValue > uno_n2;
233
234 if (
235 (aSubSet >>= uno_n1) &&
236 (aSet >>= uno_n2)
237 )
238 {
239 ::comphelper::SequenceAsHashMap stl_n1(uno_n1);
240 ::comphelper::SequenceAsHashMap stl_n2(uno_n2);
241
242 for (auto const& elem : stl_n1)
243 {
245 if (it2 == stl_n2.end())
246 {
247 return false;
248 }
249 if (!isSubSet(elem.second, it2->second))
250 {
251 return false;
252 }
253 }
254 return true;
255 }
256 }
257 break;
258 default: break;
259 }
260 }
261 OSL_FAIL("isSubSet() ... this point should not be reached!");
262 return false;
263}
264
265
267{
268 for (auto const& prop : lProps)
269 {
270 // i) one required property does not exist at this item => return false
271 const_iterator pItThis = find(prop.Name);
272 if (pItThis == end())
273 {
274 return false;
275 }
276
277 // ii) one item does not have the right value => return false
278 if (!isSubSet(prop.Value, pItThis->second))
279 {
280 return false;
281 }
282 }
283
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
287 return true;
288}
289
290
292{
293 for (auto const& prop : lProps)
294 {
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())
301 {
302 continue;
303 }
304
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))
309 {
310 return false;
311 }
312 }
313
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.
317 return true;
318}
319
321 bMatchByExtension(false), bMatchByPattern(false), bPreselectedByDocumentService(false) {}
322
323} // namespace filter::config
324
325/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
iterator find(const OUString &rKey)
css::uno::Sequence< css::beans::PropertyValue > getAsConstPropertyValueList() const
SequenceAsHashMapBase::const_iterator const_iterator
represent an item of a FilterCache instance.
Definition: cacheitem.hxx:40
void update(const CacheItem &rUpdateItem)
update only properties, which are given by the specified rItem.
Definition: cacheitem.cxx:40
bool haveProps(o3tl::span< const css::beans::NamedValue > lProps) const
check, if the given properties exist at this item.
Definition: cacheitem.cxx:266
css::uno::Sequence< css::beans::PropertyValue > getAsPackedPropertyValueList(bool bFinalized, bool bMandatory) const
convert this structure to a seq< PropertyValue > and ignore all empty properties!
Definition: cacheitem.cxx:80
CacheItem()
creates an empty item.
Definition: cacheitem.cxx:35
void validateUINames(const OUString &sActLocale)
because we know two UIName properties (a list with all locales and the value for the current locale o...
Definition: cacheitem.cxx:47
bool dontHaveProps(o3tl::span< const css::beans::NamedValue > lProps) const
check, if the given properties don't exist at this item.
Definition: cacheitem.cxx:291
constexpr OUStringLiteral PROPNAME_UINAME
used to identify a type item property against the configuration API and can be used at all name conta...
Definition: constant.hxx:33
constexpr OUStringLiteral PROPNAME_MANDATORY
Definition: constant.hxx:72
constexpr OUStringLiteral PROPNAME_UINAMES
Definition: constant.hxx:34
constexpr OUStringLiteral PROPNAME_FINALIZED
implicit properties.
Definition: constant.hxx:71
int n2
int n1
static bool isSubSet(const css::uno::Any &aSubSet, const css::uno::Any &aSet)
Definition: cacheitem.cxx:115
int i
Definition: gentoken.py:48