Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "cacheitem.hxx"
31 : : #include "macros.hxx"
32 : : #include "constant.hxx"
33 : :
34 : : #include <com/sun/star/uno/Sequence.h>
35 : :
36 : : #include <com/sun/star/beans/PropertyValue.hpp>
37 : :
38 : :
39 : : namespace filter{
40 : : namespace config{
41 : :
42 : : namespace css = ::com::sun::star;
43 : :
44 : :
45 : :
46 : :
47 : 168924 : CacheItem::CacheItem()
48 : 168924 : : SequenceAsHashMap()
49 : : {
50 : 168924 : }
51 : :
52 : :
53 : :
54 : 19603 : void CacheItem::update(const CacheItem& rUpdateItem)
55 : : {
56 [ + - ][ + + ]: 196030 : for(const_iterator pItUpdate = rUpdateItem.begin();
57 [ + - ]: 98015 : pItUpdate != rUpdateItem.end() ;
58 : : ++pItUpdate )
59 : : {
60 [ + - ][ + - ]: 78412 : iterator pItThis = this->find(pItUpdate->first);
61 [ + - ][ + + ]: 78412 : if (pItThis == this->end())
62 [ + - ][ + - ]: 58809 : (*this)[pItUpdate->first] = pItUpdate->second; // add new prop
[ + - ]
63 : : else
64 [ + - ][ + - ]: 19603 : pItThis->second = pItUpdate->second; // change value of existing prop
65 : : }
66 : 19603 : }
67 : :
68 : :
69 : :
70 : 2 : void CacheItem::validateUINames(const ::rtl::OUString& sActLocale)
71 : : {
72 [ + - ]: 2 : if (sActLocale.isEmpty())
73 : 2 : return;
74 : :
75 : : // 1) check UINames first
76 [ + - ]: 2 : const_iterator pUINames = find(PROPNAME_UINAMES);
77 [ + - ]: 2 : const_iterator pUIName = find(PROPNAME_UINAME );
78 : :
79 [ + - ]: 2 : ::comphelper::SequenceAsHashMap lUINames;
80 [ + - ][ + - ]: 2 : if (pUINames != end())
81 [ + - ][ + - ]: 2 : lUINames << pUINames->second;
82 : :
83 : 2 : ::rtl::OUString sUIName;
84 [ + - ][ + - ]: 2 : if (pUIName != end())
85 [ + - ]: 2 : pUIName->second >>= sUIName;
86 : :
87 [ + - ]: 2 : if (!sUIName.isEmpty())
88 : : {
89 : : // 1a) set UIName inside list of UINames for current locale
90 [ + - ][ + - ]: 2 : lUINames[sActLocale] <<= sUIName;
91 : : }
92 [ # # ]: 0 : else if (lUINames.size()>0)
93 : : {
94 : : // 1b) or get it from this list, if it not exist!
95 [ # # ]: 0 : lUINames[sActLocale] >>= sUIName;
96 : : }
97 : :
98 [ + - ][ + - ]: 2 : (*this)[PROPNAME_UINAMES] <<= lUINames.getAsConstPropertyValueList();
[ + - ][ + - ]
99 [ + - ][ + - ]: 2 : (*this)[PROPNAME_UINAME ] <<= sUIName;
[ + - ]
100 : : }
101 : :
102 : :
103 : :
104 : 27951 : css::uno::Sequence< css::beans::PropertyValue > CacheItem::getAsPackedPropertyValueList()
105 : : {
106 : 27951 : sal_Int32 c = (sal_Int32)size();
107 : 27951 : sal_Int32 i = 0;
108 : :
109 : 27951 : css::uno::Sequence< css::beans::PropertyValue > lList(c);
110 [ + - ]: 27951 : css::beans::PropertyValue* pList = lList.getArray();
111 : :
112 [ + - ][ + + ]: 745218 : for (const_iterator pProp = begin();
113 [ + - ]: 372609 : pProp != end() ;
114 : : ++pProp )
115 : : {
116 [ + - ]: 344658 : const ::rtl::OUString& rName = pProp->first;
117 [ + - ]: 344658 : const css::uno::Any& rValue = pProp->second;
118 : :
119 [ + + ]: 344658 : if (!rValue.hasValue())
120 : 14183 : continue;
121 : :
122 : 330475 : pList[i].Name = rName ;
123 : 330475 : pList[i].Value = rValue;
124 : 330475 : ++i;
125 : : }
126 [ + - ]: 27951 : lList.realloc(i);
127 : :
128 : 27951 : return lList;
129 : : }
130 : :
131 : :
132 : :
133 : 914979 : sal_Bool isSubSet(const css::uno::Any& aSubSet,
134 : : const css::uno::Any& aSet )
135 : : {
136 : 914979 : css::uno::Type aT1 = aSubSet.getValueType();
137 : 914979 : css::uno::Type aT2 = aSet.getValueType();
138 : :
139 [ - + ]: 914979 : if (!aT1.equals(aT2))
140 : : {
141 : : _FILTER_CONFIG_LOG_("isSubSet() ... types of any values are different => return FALSE\n")
142 : 0 : return sal_False;
143 : : }
144 : :
145 : 914979 : css::uno::TypeClass aTypeClass = aT1.getTypeClass();
146 [ + + - - : 914979 : switch(aTypeClass)
+ - ]
147 : : {
148 : : //---------------------------------------
149 : : case css::uno::TypeClass_BOOLEAN :
150 : : case css::uno::TypeClass_BYTE :
151 : : case css::uno::TypeClass_SHORT :
152 : : case css::uno::TypeClass_UNSIGNED_SHORT :
153 : : case css::uno::TypeClass_LONG :
154 : : case css::uno::TypeClass_UNSIGNED_LONG :
155 : : case css::uno::TypeClass_HYPER :
156 : : case css::uno::TypeClass_UNSIGNED_HYPER :
157 : : case css::uno::TypeClass_FLOAT :
158 : : case css::uno::TypeClass_DOUBLE :
159 : : {
160 : 206727 : sal_Bool bIs = (aSubSet == aSet);
161 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for atomic types => return %s\n", bIs ? "TRUE" : "FALSE")
162 : 206727 : return bIs;
163 : : }
164 : :
165 : : //---------------------------------------
166 : : case css::uno::TypeClass_STRING :
167 : : {
168 : 692995 : ::rtl::OUString v1;
169 : 692995 : ::rtl::OUString v2;
170 : :
171 [ + - ]: 1385990 : if (
[ + - + - ]
172 : 692995 : (aSubSet >>= v1) &&
173 : 692995 : (aSet >>= v2)
174 : : )
175 : : {
176 : 692995 : sal_Bool bIs = (v1.equals(v2));
177 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for string types => return %s\n", bIs ? "TRUE" : "FALSE")
178 : 692995 : return bIs;
179 [ + - ][ - + ]: 692995 : }
180 : : }
181 : 692995 : break;
182 : :
183 : : //---------------------------------------
184 : : case css::uno::TypeClass_ANY :
185 : : {
186 : 0 : css::uno::Any v1;
187 : 0 : css::uno::Any v2;
188 : :
189 [ # # ]: 0 : if (
[ # # # # ]
190 : 0 : (aSubSet >>= v1) &&
191 : 0 : (aSet >>= v2)
192 : : )
193 : : {
194 [ # # ]: 0 : sal_Bool bIs = (isSubSet(v1, v2));
195 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for packed any types => return %s\n", bIs ? "TRUE" : "FALSE")
196 : 0 : return bIs;
197 [ # # ][ # # ]: 0 : }
198 : : }
199 : 0 : break;
200 : :
201 : : //---------------------------------------
202 : : case css::uno::TypeClass_STRUCT :
203 : : {
204 : 0 : css::beans::PropertyValue p1;
205 : 0 : css::beans::PropertyValue p2;
206 : :
207 [ # # ][ # # ]: 0 : if (
[ # # ]
208 [ # # ]: 0 : (aSubSet >>= p1) &&
209 [ # # ]: 0 : (aSet >>= p2)
210 : : )
211 : : {
212 : : sal_Bool bIs = (
213 : 0 : (p1.Name.equals(p2.Name) ) &&
214 [ # # ]: 0 : (isSubSet(p1.Value, p2.Value))
215 [ # # ][ # # ]: 0 : );
216 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [PropertyValue] => return %s\n", bIs ? "TRUE" : "FALSE")
217 : 0 : return bIs;
218 : : }
219 : :
220 : 0 : css::beans::NamedValue n1;
221 : 0 : css::beans::NamedValue n2;
222 : :
223 [ # # ][ # # ]: 0 : if (
[ # # ]
224 [ # # ]: 0 : (aSubSet >>= n1) &&
225 [ # # ]: 0 : (aSet >>= n2)
226 : : )
227 : : {
228 : : sal_Bool bIs = (
229 : 0 : (n1.Name.equals(n2.Name) ) &&
230 [ # # ]: 0 : (isSubSet(n1.Value, n2.Value))
231 [ # # ][ # # ]: 0 : );
232 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [NamedValue] => return %s\n", bIs ? "TRUE" : "FALSE")
233 : 0 : return bIs;
234 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
235 : : }
236 : 0 : break;
237 : :
238 : : //---------------------------------------
239 : : case css::uno::TypeClass_SEQUENCE :
240 : : {
241 [ + - ]: 15257 : css::uno::Sequence< ::rtl::OUString > uno_s1;
242 [ + - ]: 15257 : css::uno::Sequence< ::rtl::OUString > uno_s2;
243 : :
244 [ + - ][ + - ]: 30514 : if (
[ + - ]
245 [ + - ]: 15257 : (aSubSet >>= uno_s1) &&
246 [ + - ]: 15257 : (aSet >>= uno_s2)
247 : : )
248 : : {
249 [ + - ]: 15257 : OUStringList stl_s1(uno_s1);
250 [ + - ]: 15257 : OUStringList stl_s2(uno_s2);
251 : :
252 [ + - ][ + - ]: 36002 : for (OUStringList::const_iterator it1 = stl_s1.begin();
[ + + ]
253 : 18001 : it1 != stl_s1.end() ;
254 : : ++it1 )
255 : : {
256 [ + - ][ + - ]: 15257 : if (::std::find(stl_s2.begin(), stl_s2.end(), *it1) == stl_s2.end())
[ + + ]
257 : : {
258 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(*it1))
259 : 12513 : return sal_False;
260 : : }
261 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... found \"%s\" => continue loop\n", _FILTER_CONFIG_TO_ASCII_(*it1))
262 : : }
263 : : _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [OUString] => return TRUE\n")
264 : 15257 : return sal_True;
265 : : }
266 : :
267 [ # # ]: 0 : css::uno::Sequence< css::beans::PropertyValue > uno_p1;
268 [ # # ]: 0 : css::uno::Sequence< css::beans::PropertyValue > uno_p2;
269 : :
270 [ # # ][ # # ]: 0 : if (
[ # # ]
271 [ # # ]: 0 : (aSubSet >>= uno_p1) &&
272 [ # # ]: 0 : (aSet >>= uno_p2)
273 : : )
274 : : {
275 [ # # ]: 0 : ::comphelper::SequenceAsHashMap stl_p1(uno_p1);
276 [ # # ]: 0 : ::comphelper::SequenceAsHashMap stl_p2(uno_p2);
277 : :
278 [ # # ][ # # ]: 0 : for (::comphelper::SequenceAsHashMap::const_iterator it1 = stl_p1.begin();
279 [ # # ]: 0 : it1 != stl_p1.end() ;
280 : : ++it1 )
281 : : {
282 [ # # ][ # # ]: 0 : ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_p2.find(it1->first);
283 [ # # ][ # # ]: 0 : if (it2 == stl_p2.end())
284 : : {
285 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
286 : 0 : return sal_False;
287 : : }
288 [ # # ][ # # ]: 0 : if (!isSubSet(it1->second, it2->second))
[ # # ][ # # ]
289 : : {
290 : : _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))
291 : 0 : return sal_False;
292 : : }
293 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
294 : : }
295 : : _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [PropertyValue] => return TRUE\n")
296 [ # # ][ # # ]: 0 : return sal_True;
297 : : }
298 : :
299 [ # # ]: 0 : css::uno::Sequence< css::beans::NamedValue > uno_n1;
300 [ # # ]: 0 : css::uno::Sequence< css::beans::NamedValue > uno_n2;
301 : :
302 [ # # ][ # # ]: 0 : if (
[ # # ]
303 [ # # ]: 0 : (aSubSet >>= uno_n1) &&
304 [ # # ]: 0 : (aSet >>= uno_n2)
305 : : )
306 : : {
307 [ # # ]: 0 : ::comphelper::SequenceAsHashMap stl_n1(uno_n1);
308 [ # # ]: 0 : ::comphelper::SequenceAsHashMap stl_n2(uno_n2);
309 : :
310 [ # # ][ # # ]: 0 : for (::comphelper::SequenceAsHashMap::const_iterator it1 = stl_n1.begin();
311 [ # # ]: 0 : it1 != stl_n1.end() ;
312 : : ++it1 )
313 : : {
314 [ # # ][ # # ]: 0 : ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_n2.find(it1->first);
315 [ # # ][ # # ]: 0 : if (it2 == stl_n2.end())
316 : : {
317 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
318 : 0 : return sal_False;
319 : : }
320 [ # # ][ # # ]: 0 : if (!isSubSet(it1->second, it2->second))
[ # # ][ # # ]
321 : : {
322 : : _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))
323 : 0 : return sal_False;
324 : : }
325 : : _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
326 : : }
327 : : _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [NamedValue] => return TRUE\n")
328 [ # # ][ # # ]: 0 : return sal_True;
329 [ # # ][ # # ]: 15257 : }
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ + - ][ + - ]
[ + - ][ - + ]
330 : : }
331 : 15257 : break;
332 : 0 : default: break;
333 : : }
334 : :
335 : : OSL_FAIL("isSubSet() ... this point should not be reached!");
336 : 914979 : return sal_False;
337 : : }
338 : :
339 : :
340 : :
341 : 898291 : sal_Bool CacheItem::haveProps(const CacheItem& lProps) const
342 : : {
343 [ + - ][ + + ]: 2737346 : for (const_iterator pIt = lProps.begin();
344 [ + - ]: 924076 : pIt != lProps.end() ;
345 : : ++pIt )
346 : : {
347 : : // i) one required property does not exist at this item => return false
348 [ + - ][ + - ]: 914979 : const_iterator pItThis = this->find(pIt->first);
349 [ + - ][ - + ]: 914979 : if (pItThis == this->end())
350 : : {
351 : : _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
352 : 0 : return sal_False;
353 : : }
354 : :
355 : : // ii) one item does not have the right value => return false
356 [ + - ][ + - ]: 914979 : if (!isSubSet(pIt->second, pItThis->second))
[ + - ][ + + ]
357 : : {
358 : : _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... item \"%s\" has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
359 : 889194 : return sal_False;
360 : : }
361 : : }
362 : :
363 : : // this method was not breaked before =>
364 : : // the given property set seems to match with our
365 : : // own properties in its minimum => return TRUE
366 : : _FILTER_CONFIG_LOG_("CacheItem::haveProps() ... => return TRUE\n")
367 : 898291 : return sal_True;
368 : : }
369 : :
370 : :
371 : :
372 : 9097 : sal_Bool CacheItem::dontHaveProps(const CacheItem& lProps) const
373 : : {
374 [ + - ][ - + ]: 18194 : for (const_iterator pIt = lProps.begin();
375 [ + - ]: 9097 : pIt != lProps.end() ;
376 : : ++pIt )
377 : : {
378 : : // i) one item does not exists in general
379 : : // => continue with next one, because
380 : : // "excluding" means ... "dont have it".
381 : : // And "not exists" match to "dont have it".
382 [ # # ][ # # ]: 0 : const_iterator pItThis = this->find(pIt->first);
383 [ # # ][ # # ]: 0 : if (pItThis == this->end())
384 : : {
385 : : _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... not found \"%s\" => continue loop!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
386 : 0 : continue;
387 : : }
388 : :
389 : : // ii) one item have the right value => return false
390 : : // because this item has the requested property ...
391 : : // But we checked for "dont have it" here.
392 [ # # ][ # # ]: 0 : if (isSubSet(pIt->second, pItThis->second))
[ # # ][ # # ]
393 : : {
394 : : _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... item \"%s\" has same value => return FALSE!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
395 : 0 : return sal_False;
396 : : }
397 : : }
398 : :
399 : : // this method was not breaked before =>
400 : : // That means: this item has no matching property
401 : : // of the given set. It "dont have" it ... => return true.
402 : : _FILTER_CONFIG_LOG_("CacheItem::dontHaveProps() ... => return TRUE\n")
403 : 9097 : return sal_True;
404 : : }
405 : :
406 : : } // namespace config
407 : : } // namespace filter
408 : :
409 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|