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 "cacheitem.hxx"
22 : #include "macros.hxx"
23 : #include "constant.hxx"
24 :
25 : #include <com/sun/star/uno/Sequence.h>
26 :
27 : #include <com/sun/star/beans/PropertyValue.hpp>
28 :
29 :
30 : namespace filter{
31 : namespace config{
32 :
33 28369 : CacheItem::CacheItem()
34 28369 : : SequenceAsHashMap()
35 : {
36 28369 : }
37 :
38 :
39 :
40 1677 : void CacheItem::update(const CacheItem& rUpdateItem)
41 : {
42 25155 : for(const_iterator pItUpdate = rUpdateItem.begin();
43 16770 : pItUpdate != rUpdateItem.end() ;
44 : ++pItUpdate )
45 : {
46 6708 : iterator pItThis = this->find(pItUpdate->first);
47 6708 : if (pItThis == this->end())
48 5031 : (*this)[pItUpdate->first] = pItUpdate->second; // add new prop
49 : else
50 1677 : pItThis->second = pItUpdate->second; // change value of existing prop
51 : }
52 1677 : }
53 :
54 :
55 :
56 0 : void CacheItem::validateUINames(const ::rtl::OUString& sActLocale)
57 : {
58 0 : if (sActLocale.isEmpty())
59 0 : return;
60 :
61 : // 1) check UINames first
62 0 : const_iterator pUINames = find(PROPNAME_UINAMES);
63 0 : const_iterator pUIName = find(PROPNAME_UINAME );
64 :
65 0 : ::comphelper::SequenceAsHashMap lUINames;
66 0 : if (pUINames != end())
67 0 : lUINames << pUINames->second;
68 :
69 0 : ::rtl::OUString sUIName;
70 0 : if (pUIName != end())
71 0 : pUIName->second >>= sUIName;
72 :
73 0 : if (!sUIName.isEmpty())
74 : {
75 : // 1a) set UIName inside list of UINames for current locale
76 0 : lUINames[sActLocale] <<= sUIName;
77 : }
78 0 : else if (lUINames.size()>0)
79 : {
80 : // 1b) or get it from this list, if it not exist!
81 0 : lUINames[sActLocale] >>= sUIName;
82 : }
83 :
84 0 : (*this)[PROPNAME_UINAMES] <<= lUINames.getAsConstPropertyValueList();
85 0 : (*this)[PROPNAME_UINAME ] <<= sUIName;
86 : }
87 :
88 :
89 :
90 4436 : css::uno::Sequence< css::beans::PropertyValue > CacheItem::getAsPackedPropertyValueList()
91 : {
92 4436 : sal_Int32 c = (sal_Int32)size();
93 4436 : sal_Int32 i = 0;
94 :
95 4436 : css::uno::Sequence< css::beans::PropertyValue > lList(c);
96 4436 : css::beans::PropertyValue* pList = lList.getArray();
97 :
98 178344 : for (const_iterator pProp = begin();
99 118896 : pProp != end() ;
100 : ++pProp )
101 : {
102 55012 : const ::rtl::OUString& rName = pProp->first;
103 55012 : const css::uno::Any& rValue = pProp->second;
104 :
105 55012 : if (!rValue.hasValue())
106 2139 : continue;
107 :
108 52873 : pList[i].Name = rName ;
109 52873 : pList[i].Value = rValue;
110 52873 : ++i;
111 : }
112 4436 : lList.realloc(i);
113 :
114 4436 : return lList;
115 : }
116 :
117 :
118 :
119 245255 : sal_Bool isSubSet(const css::uno::Any& aSubSet,
120 : const css::uno::Any& aSet )
121 : {
122 245255 : css::uno::Type aT1 = aSubSet.getValueType();
123 245255 : css::uno::Type aT2 = aSet.getValueType();
124 :
125 245255 : if (!aT1.equals(aT2))
126 : {
127 : _FILTER_CONFIG_LOG_("isSubSet() ... types of any values are different => return FALSE\n")
128 0 : return sal_False;
129 : }
130 :
131 245255 : css::uno::TypeClass aTypeClass = aT1.getTypeClass();
132 245255 : switch(aTypeClass)
133 : {
134 : //---------------------------------------
135 : case css::uno::TypeClass_BOOLEAN :
136 : case css::uno::TypeClass_BYTE :
137 : case css::uno::TypeClass_SHORT :
138 : case css::uno::TypeClass_UNSIGNED_SHORT :
139 : case css::uno::TypeClass_LONG :
140 : case css::uno::TypeClass_UNSIGNED_LONG :
141 : case css::uno::TypeClass_HYPER :
142 : case css::uno::TypeClass_UNSIGNED_HYPER :
143 : case css::uno::TypeClass_FLOAT :
144 : case css::uno::TypeClass_DOUBLE :
145 : {
146 53196 : sal_Bool bIs = (aSubSet == aSet);
147 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for atomic types => return %s\n", bIs ? "TRUE" : "FALSE")
148 53196 : return bIs;
149 : }
150 :
151 : //---------------------------------------
152 : case css::uno::TypeClass_STRING :
153 : {
154 173064 : ::rtl::OUString v1;
155 173064 : ::rtl::OUString v2;
156 :
157 346128 : if (
158 173064 : (aSubSet >>= v1) &&
159 173064 : (aSet >>= v2)
160 : )
161 : {
162 173064 : sal_Bool bIs = (v1.equals(v2));
163 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for string types => return %s\n", bIs ? "TRUE" : "FALSE")
164 173064 : return bIs;
165 173064 : }
166 : }
167 0 : break;
168 :
169 : //---------------------------------------
170 : case css::uno::TypeClass_ANY :
171 : {
172 0 : css::uno::Any v1;
173 0 : css::uno::Any v2;
174 :
175 0 : if (
176 0 : (aSubSet >>= v1) &&
177 0 : (aSet >>= v2)
178 : )
179 : {
180 0 : sal_Bool bIs = (isSubSet(v1, v2));
181 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for packed any types => return %s\n", bIs ? "TRUE" : "FALSE")
182 0 : return bIs;
183 0 : }
184 : }
185 0 : break;
186 :
187 : //---------------------------------------
188 : case css::uno::TypeClass_STRUCT :
189 : {
190 0 : css::beans::PropertyValue p1;
191 0 : css::beans::PropertyValue p2;
192 :
193 0 : if (
194 0 : (aSubSet >>= p1) &&
195 0 : (aSet >>= p2)
196 : )
197 : {
198 : sal_Bool bIs = (
199 0 : (p1.Name.equals(p2.Name) ) &&
200 0 : (isSubSet(p1.Value, p2.Value))
201 0 : );
202 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [PropertyValue] => return %s\n", bIs ? "TRUE" : "FALSE")
203 0 : return bIs;
204 : }
205 :
206 0 : css::beans::NamedValue n1;
207 0 : css::beans::NamedValue n2;
208 :
209 0 : if (
210 0 : (aSubSet >>= n1) &&
211 0 : (aSet >>= n2)
212 : )
213 : {
214 : sal_Bool bIs = (
215 0 : (n1.Name.equals(n2.Name) ) &&
216 0 : (isSubSet(n1.Value, n2.Value))
217 0 : );
218 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [NamedValue] => return %s\n", bIs ? "TRUE" : "FALSE")
219 0 : return bIs;
220 0 : }
221 : }
222 0 : break;
223 :
224 : //---------------------------------------
225 : case css::uno::TypeClass_SEQUENCE :
226 : {
227 18995 : css::uno::Sequence< ::rtl::OUString > uno_s1;
228 18995 : css::uno::Sequence< ::rtl::OUString > uno_s2;
229 :
230 37990 : if (
231 18995 : (aSubSet >>= uno_s1) &&
232 18995 : (aSet >>= uno_s2)
233 : )
234 : {
235 18995 : OUStringList stl_s1(uno_s1);
236 18995 : OUStringList stl_s2(uno_s2);
237 :
238 58239 : for (OUStringList::const_iterator it1 = stl_s1.begin();
239 38826 : it1 != stl_s1.end() ;
240 : ++it1 )
241 : {
242 18995 : if (::std::find(stl_s2.begin(), stl_s2.end(), *it1) == stl_s2.end())
243 : {
244 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(*it1))
245 18577 : return sal_False;
246 : }
247 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... found \"%s\" => continue loop\n", _FILTER_CONFIG_TO_ASCII_(*it1))
248 : }
249 : _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [OUString] => return TRUE\n")
250 418 : return sal_True;
251 : }
252 :
253 0 : css::uno::Sequence< css::beans::PropertyValue > uno_p1;
254 0 : css::uno::Sequence< css::beans::PropertyValue > uno_p2;
255 :
256 0 : if (
257 0 : (aSubSet >>= uno_p1) &&
258 0 : (aSet >>= uno_p2)
259 : )
260 : {
261 0 : ::comphelper::SequenceAsHashMap stl_p1(uno_p1);
262 0 : ::comphelper::SequenceAsHashMap stl_p2(uno_p2);
263 :
264 0 : for (::comphelper::SequenceAsHashMap::const_iterator it1 = stl_p1.begin();
265 0 : it1 != stl_p1.end() ;
266 : ++it1 )
267 : {
268 0 : ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_p2.find(it1->first);
269 0 : if (it2 == stl_p2.end())
270 : {
271 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
272 0 : return sal_False;
273 : }
274 0 : if (!isSubSet(it1->second, it2->second))
275 : {
276 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... found \"%s\" but has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
277 0 : return sal_False;
278 : }
279 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
280 : }
281 : _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [PropertyValue] => return TRUE\n")
282 0 : return sal_True;
283 : }
284 :
285 0 : css::uno::Sequence< css::beans::NamedValue > uno_n1;
286 0 : css::uno::Sequence< css::beans::NamedValue > uno_n2;
287 :
288 0 : if (
289 0 : (aSubSet >>= uno_n1) &&
290 0 : (aSet >>= uno_n2)
291 : )
292 : {
293 0 : ::comphelper::SequenceAsHashMap stl_n1(uno_n1);
294 0 : ::comphelper::SequenceAsHashMap stl_n2(uno_n2);
295 :
296 0 : for (::comphelper::SequenceAsHashMap::const_iterator it1 = stl_n1.begin();
297 0 : it1 != stl_n1.end() ;
298 : ++it1 )
299 : {
300 0 : ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_n2.find(it1->first);
301 0 : if (it2 == stl_n2.end())
302 : {
303 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
304 0 : return sal_False;
305 : }
306 0 : if (!isSubSet(it1->second, it2->second))
307 : {
308 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... found \"%s\" but has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
309 0 : return sal_False;
310 : }
311 : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
312 : }
313 : _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [NamedValue] => return TRUE\n")
314 0 : return sal_True;
315 0 : }
316 : }
317 0 : break;
318 0 : default: break;
319 : }
320 :
321 : OSL_FAIL("isSubSet() ... this point should not be reached!");
322 0 : return sal_False;
323 : }
324 :
325 :
326 :
327 240965 : sal_Bool CacheItem::haveProps(const CacheItem& lProps) const
328 : {
329 741696 : for (const_iterator pIt = lProps.begin();
330 494464 : pIt != lProps.end() ;
331 : ++pIt )
332 : {
333 : // i) one required property does not exist at this item => return false
334 245255 : const_iterator pItThis = this->find(pIt->first);
335 245255 : if (pItThis == this->end())
336 : {
337 : _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
338 0 : return sal_False;
339 : }
340 :
341 : // ii) one item does not have the right value => return false
342 245255 : if (!isSubSet(pIt->second, pItThis->second))
343 : {
344 : _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... item \"%s\" has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
345 238988 : return sal_False;
346 : }
347 : }
348 :
349 : // this method was not breaked before =>
350 : // the given property set seems to match with our
351 : // own properties in its minimum => return TRUE
352 : _FILTER_CONFIG_LOG_("CacheItem::haveProps() ... => return TRUE\n")
353 1977 : return sal_True;
354 : }
355 :
356 :
357 :
358 1977 : sal_Bool CacheItem::dontHaveProps(const CacheItem& lProps) const
359 : {
360 5931 : for (const_iterator pIt = lProps.begin();
361 3954 : pIt != lProps.end() ;
362 : ++pIt )
363 : {
364 : // i) one item does not exists in general
365 : // => continue with next one, because
366 : // "excluding" means ... "dont have it".
367 : // And "not exists" match to "dont have it".
368 0 : const_iterator pItThis = this->find(pIt->first);
369 0 : if (pItThis == this->end())
370 : {
371 : _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... not found \"%s\" => continue loop!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
372 0 : continue;
373 : }
374 :
375 : // ii) one item have the right value => return false
376 : // because this item has the requested property ...
377 : // But we checked for "dont have it" here.
378 0 : if (isSubSet(pIt->second, pItThis->second))
379 : {
380 : _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... item \"%s\" has same value => return FALSE!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
381 0 : return sal_False;
382 : }
383 : }
384 :
385 : // this method was not breaked before =>
386 : // That means: this item has no matching property
387 : // of the given set. It "dont have" it ... => return true.
388 : _FILTER_CONFIG_LOG_("CacheItem::dontHaveProps() ... => return TRUE\n")
389 1977 : return sal_True;
390 : }
391 :
392 : } // namespace config
393 : } // namespace filter
394 :
395 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|