update dev300-m58
[ooovba.git] / filter / source / config / cache / cacheitem.cxx
blobdbd17efe1b2a045884eec6e876fb83a2c248b713
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cacheitem.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_filter.hxx"
34 #include "cacheitem.hxx"
35 #include "macros.hxx"
36 #include "constant.hxx"
38 //_______________________________________________
39 // includes
40 #include <com/sun/star/uno/Sequence.h>
42 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_Hpp_
43 #include <com/sun/star/beans/PropertyValue.hpp>
44 #endif
46 //_______________________________________________
47 // namespace
49 namespace filter{
50 namespace config{
52 namespace css = ::com::sun::star;
54 //_______________________________________________
55 // definitions
57 /*-----------------------------------------------
58 04.11.2003 09:27
59 -----------------------------------------------*/
60 CacheItem::CacheItem()
61 : SequenceAsHashMap()
65 /*-----------------------------------------------
66 26.06.2003 11:37
67 -----------------------------------------------*/
68 void CacheItem::update(const CacheItem& rUpdateItem)
70 for(const_iterator pItUpdate = rUpdateItem.begin();
71 pItUpdate != rUpdateItem.end() ;
72 ++pItUpdate )
74 iterator pItThis = this->find(pItUpdate->first);
75 if (pItThis == this->end())
76 (*this)[pItUpdate->first] = pItUpdate->second; // add new prop
77 else
78 pItThis->second = pItUpdate->second; // change value of existing prop
82 /*-----------------------------------------------
83 26.11.2003 13:27
84 -----------------------------------------------*/
85 void CacheItem::validateUINames(const ::rtl::OUString& sActLocale)
87 if (!sActLocale.getLength())
88 return;
90 // 1) check UINames first
91 const_iterator pUINames = find(PROPNAME_UINAMES);
92 const_iterator pUIName = find(PROPNAME_UINAME );
94 ::comphelper::SequenceAsHashMap lUINames;
95 if (pUINames != end())
96 lUINames << pUINames->second;
98 ::rtl::OUString sUIName;
99 if (pUIName != end())
100 pUIName->second >>= sUIName;
102 if (sUIName.getLength())
104 // 1a) set UIName inside list of UINames for current locale
105 lUINames[sActLocale] <<= sUIName;
107 else if (lUINames.size()>0)
109 // 1b) or get it from this list, if it not exist!
110 lUINames[sActLocale] >>= sUIName;
113 (*this)[PROPNAME_UINAMES] <<= lUINames.getAsConstPropertyValueList();
114 (*this)[PROPNAME_UINAME ] <<= sUIName;
117 /*-----------------------------------------------
118 12.01.2004 13:32
119 -----------------------------------------------*/
120 css::uno::Sequence< css::beans::PropertyValue > CacheItem::getAsPackedPropertyValueList()
122 sal_Int32 c = (sal_Int32)size();
123 sal_Int32 i = 0;
125 css::uno::Sequence< css::beans::PropertyValue > lList(c);
126 css::beans::PropertyValue* pList = lList.getArray();
128 for (const_iterator pProp = begin();
129 pProp != end() ;
130 ++pProp )
132 const ::rtl::OUString& rName = pProp->first;
133 const css::uno::Any& rValue = pProp->second;
135 if (!rValue.hasValue())
136 continue;
138 pList[i].Name = rName ;
139 pList[i].Value = rValue;
140 ++i;
142 lList.realloc(i);
144 return lList;
147 /*-----------------------------------------------
148 17.07.2003 08:27
149 -----------------------------------------------*/
150 sal_Bool isSubSet(const css::uno::Any& aSubSet,
151 const css::uno::Any& aSet )
153 css::uno::Type aT1 = aSubSet.getValueType();
154 css::uno::Type aT2 = aSet.getValueType();
156 if (!aT1.equals(aT2))
158 _FILTER_CONFIG_LOG_("isSubSet() ... types of any values are different => return FALSE\n")
159 return sal_False;
162 css::uno::TypeClass aTypeClass = aT1.getTypeClass();
163 switch(aTypeClass)
165 //---------------------------------------
166 case css::uno::TypeClass_BOOLEAN :
167 case css::uno::TypeClass_BYTE :
168 case css::uno::TypeClass_SHORT :
169 case css::uno::TypeClass_UNSIGNED_SHORT :
170 case css::uno::TypeClass_LONG :
171 case css::uno::TypeClass_UNSIGNED_LONG :
172 case css::uno::TypeClass_HYPER :
173 case css::uno::TypeClass_UNSIGNED_HYPER :
174 case css::uno::TypeClass_FLOAT :
175 case css::uno::TypeClass_DOUBLE :
177 sal_Bool bIs = (aSubSet == aSet);
178 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for atomic types => return %s\n", bIs ? "TRUE" : "FALSE")
179 return bIs;
182 //---------------------------------------
183 case css::uno::TypeClass_STRING :
185 ::rtl::OUString v1;
186 ::rtl::OUString v2;
188 if (
189 (aSubSet >>= v1) &&
190 (aSet >>= v2)
193 sal_Bool bIs = (v1.equals(v2));
194 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for string types => return %s\n", bIs ? "TRUE" : "FALSE")
195 return bIs;
198 break;
200 //---------------------------------------
201 case css::uno::TypeClass_ANY :
203 css::uno::Any v1;
204 css::uno::Any v2;
206 if (
207 (aSubSet >>= v1) &&
208 (aSet >>= v2)
211 sal_Bool bIs = (isSubSet(v1, v2));
212 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for packed any types => return %s\n", bIs ? "TRUE" : "FALSE")
213 return bIs;
216 break;
218 //---------------------------------------
219 case css::uno::TypeClass_STRUCT :
221 css::beans::PropertyValue p1;
222 css::beans::PropertyValue p2;
224 if (
225 (aSubSet >>= p1) &&
226 (aSet >>= p2)
229 sal_Bool bIs = (
230 (p1.Name.equals(p2.Name) ) &&
231 (isSubSet(p1.Value, p2.Value))
233 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [PropertyValue] => return %s\n", bIs ? "TRUE" : "FALSE")
234 return bIs;
237 css::beans::NamedValue n1;
238 css::beans::NamedValue n2;
240 if (
241 (aSubSet >>= n1) &&
242 (aSet >>= n2)
245 sal_Bool bIs = (
246 (n1.Name.equals(n2.Name) ) &&
247 (isSubSet(n1.Value, n2.Value))
249 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [NamedValue] => return %s\n", bIs ? "TRUE" : "FALSE")
250 return bIs;
253 break;
255 //---------------------------------------
256 case css::uno::TypeClass_SEQUENCE :
258 css::uno::Sequence< ::rtl::OUString > uno_s1;
259 css::uno::Sequence< ::rtl::OUString > uno_s2;
261 if (
262 (aSubSet >>= uno_s1) &&
263 (aSet >>= uno_s2)
266 OUStringList stl_s1(uno_s1);
267 OUStringList stl_s2(uno_s2);
269 for (OUStringList::const_iterator it1 = stl_s1.begin();
270 it1 != stl_s1.end() ;
271 ++it1 )
273 if (::std::find(stl_s2.begin(), stl_s2.end(), *it1) == stl_s2.end())
275 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(*it1))
276 return sal_False;
278 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... found \"%s\" => continue loop\n", _FILTER_CONFIG_TO_ASCII_(*it1))
280 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [OUString] => return TRUE\n")
281 return sal_True;
284 css::uno::Sequence< css::beans::PropertyValue > uno_p1;
285 css::uno::Sequence< css::beans::PropertyValue > uno_p2;
287 if (
288 (aSubSet >>= uno_p1) &&
289 (aSet >>= uno_p2)
292 ::comphelper::SequenceAsHashMap stl_p1(uno_p1);
293 ::comphelper::SequenceAsHashMap stl_p2(uno_p2);
295 for (::comphelper::SequenceAsHashMap::const_iterator it1 = stl_p1.begin();
296 it1 != stl_p1.end() ;
297 ++it1 )
299 ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_p2.find(it1->first);
300 if (it2 == stl_p2.end())
302 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
303 return sal_False;
305 if (!isSubSet(it1->second, it2->second))
307 _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))
308 return sal_False;
310 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
312 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [PropertyValue] => return TRUE\n")
313 return sal_True;
316 css::uno::Sequence< css::beans::NamedValue > uno_n1;
317 css::uno::Sequence< css::beans::NamedValue > uno_n2;
319 if (
320 (aSubSet >>= uno_n1) &&
321 (aSet >>= uno_n2)
324 ::comphelper::SequenceAsHashMap stl_n1(uno_n1);
325 ::comphelper::SequenceAsHashMap stl_n2(uno_n2);
327 for (::comphelper::SequenceAsHashMap::const_iterator it1 = stl_n1.begin();
328 it1 != stl_n1.end() ;
329 ++it1 )
331 ::comphelper::SequenceAsHashMap::const_iterator it2 = stl_n2.find(it1->first);
332 if (it2 == stl_n2.end())
334 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
335 return sal_False;
337 if (!isSubSet(it1->second, it2->second))
339 _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))
340 return sal_False;
342 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... found \"%s\" with right value => continue loop\n", _FILTER_CONFIG_TO_ASCII_(it1->first))
344 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [NamedValue] => return TRUE\n")
345 return sal_True;
348 break;
350 case css::uno::TypeClass_CHAR :
351 case css::uno::TypeClass_VOID :
352 case css::uno::TypeClass_TYPE :
353 case css::uno::TypeClass_ENUM :
354 case css::uno::TypeClass_TYPEDEF :
355 case css::uno::TypeClass_UNION :
356 case css::uno::TypeClass_EXCEPTION :
357 case css::uno::TypeClass_ARRAY :
358 case css::uno::TypeClass_INTERFACE :
359 case css::uno::TypeClass_SERVICE :
360 case css::uno::TypeClass_MODULE :
361 case css::uno::TypeClass_INTERFACE_METHOD :
362 case css::uno::TypeClass_INTERFACE_ATTRIBUTE :
363 case css::uno::TypeClass_UNKNOWN :
364 case css::uno::TypeClass_PROPERTY :
365 case css::uno::TypeClass_CONSTANT :
366 case css::uno::TypeClass_CONSTANTS :
367 case css::uno::TypeClass_SINGLETON :
369 default: break;
372 OSL_ENSURE(sal_False, "isSubSet() ... this point should not be reached!");
373 return sal_False;
376 /*-----------------------------------------------
377 14.07.2003 10:24
378 -----------------------------------------------*/
379 sal_Bool CacheItem::haveProps(const CacheItem& lProps) const
381 for (const_iterator pIt = lProps.begin();
382 pIt != lProps.end() ;
383 ++pIt )
385 // i) one required property does not exist at this item => return false
386 const_iterator pItThis = this->find(pIt->first);
387 if (pItThis == this->end())
389 _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
390 return sal_False;
393 // ii) one item does not have the right value => return false
394 if (!isSubSet(pIt->second, pItThis->second))
396 _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... item \"%s\" has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
397 return sal_False;
401 // this method was not breaked before =>
402 // the given property set seems to match with our
403 // own properties in its minimum => return TRUE
404 _FILTER_CONFIG_LOG_("CacheItem::haveProps() ... => return TRUE\n")
405 return sal_True;
408 /*-----------------------------------------------
409 14.07.2003 10:43
410 -----------------------------------------------*/
411 sal_Bool CacheItem::dontHaveProps(const CacheItem& lProps) const
413 for (const_iterator pIt = lProps.begin();
414 pIt != lProps.end() ;
415 ++pIt )
417 // i) one item does not exists in general
418 // => continue with next one, because
419 // "excluding" means ... "dont have it".
420 // And "not exists" match to "dont have it".
421 const_iterator pItThis = this->find(pIt->first);
422 if (pItThis == this->end())
424 _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... not found \"%s\" => continue loop!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
425 continue;
428 // ii) one item have the right value => return false
429 // because this item has the requested property ...
430 // But we checked for "dont have it" here.
431 if (isSubSet(pIt->second, pItThis->second))
433 _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... item \"%s\" has same value => return FALSE!\n", _FILTER_CONFIG_TO_ASCII_(pIt->first))
434 return sal_False;
438 // this method was not breaked before =>
439 // That means: this item has no matching property
440 // of the given set. It "dont have" it ... => return true.
441 _FILTER_CONFIG_LOG_("CacheItem::dontHaveProps() ... => return TRUE\n")
442 return sal_True;
445 } // namespace config
446 } // namespace filter