1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cacheitem.cxx,v $
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"
36 #include "constant.hxx"
38 //_______________________________________________
40 #include <com/sun/star/uno/Sequence.h>
42 #ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_Hpp_
43 #include <com/sun/star/beans/PropertyValue.hpp>
46 //_______________________________________________
52 namespace css
= ::com::sun::star
;
54 //_______________________________________________
57 /*-----------------------------------------------
59 -----------------------------------------------*/
60 CacheItem::CacheItem()
65 /*-----------------------------------------------
67 -----------------------------------------------*/
68 void CacheItem::update(const CacheItem
& rUpdateItem
)
70 for(const_iterator pItUpdate
= rUpdateItem
.begin();
71 pItUpdate
!= rUpdateItem
.end() ;
74 iterator pItThis
= this->find(pItUpdate
->first
);
75 if (pItThis
== this->end())
76 (*this)[pItUpdate
->first
] = pItUpdate
->second
; // add new prop
78 pItThis
->second
= pItUpdate
->second
; // change value of existing prop
82 /*-----------------------------------------------
84 -----------------------------------------------*/
85 void CacheItem::validateUINames(const ::rtl::OUString
& sActLocale
)
87 if (!sActLocale
.getLength())
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
;
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 /*-----------------------------------------------
119 -----------------------------------------------*/
120 css::uno::Sequence
< css::beans::PropertyValue
> CacheItem::getAsPackedPropertyValueList()
122 sal_Int32 c
= (sal_Int32
)size();
125 css::uno::Sequence
< css::beans::PropertyValue
> lList(c
);
126 css::beans::PropertyValue
* pList
= lList
.getArray();
128 for (const_iterator pProp
= begin();
132 const ::rtl::OUString
& rName
= pProp
->first
;
133 const css::uno::Any
& rValue
= pProp
->second
;
135 if (!rValue
.hasValue())
138 pList
[i
].Name
= rName
;
139 pList
[i
].Value
= rValue
;
147 /*-----------------------------------------------
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")
162 css::uno::TypeClass aTypeClass
= aT1
.getTypeClass();
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")
182 //---------------------------------------
183 case css::uno::TypeClass_STRING
:
193 sal_Bool bIs
= (v1
.equals(v2
));
194 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for string types => return %s\n", bIs
? "TRUE" : "FALSE")
200 //---------------------------------------
201 case css::uno::TypeClass_ANY
:
211 sal_Bool bIs
= (isSubSet(v1
, v2
));
212 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for packed any types => return %s\n", bIs
? "TRUE" : "FALSE")
218 //---------------------------------------
219 case css::uno::TypeClass_STRUCT
:
221 css::beans::PropertyValue p1
;
222 css::beans::PropertyValue p2
;
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")
237 css::beans::NamedValue n1
;
238 css::beans::NamedValue n2
;
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")
255 //---------------------------------------
256 case css::uno::TypeClass_SEQUENCE
:
258 css::uno::Sequence
< ::rtl::OUString
> uno_s1
;
259 css::uno::Sequence
< ::rtl::OUString
> uno_s2
;
262 (aSubSet
>>= uno_s1
) &&
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() ;
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
))
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")
284 css::uno::Sequence
< css::beans::PropertyValue
> uno_p1
;
285 css::uno::Sequence
< css::beans::PropertyValue
> uno_p2
;
288 (aSubSet
>>= uno_p1
) &&
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() ;
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
))
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
))
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")
316 css::uno::Sequence
< css::beans::NamedValue
> uno_n1
;
317 css::uno::Sequence
< css::beans::NamedValue
> uno_n2
;
320 (aSubSet
>>= uno_n1
) &&
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() ;
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
))
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
))
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")
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 :
372 OSL_ENSURE(sal_False
, "isSubSet() ... this point should not be reached!");
376 /*-----------------------------------------------
378 -----------------------------------------------*/
379 sal_Bool
CacheItem::haveProps(const CacheItem
& lProps
) const
381 for (const_iterator pIt
= lProps
.begin();
382 pIt
!= lProps
.end() ;
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
))
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
))
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")
408 /*-----------------------------------------------
410 -----------------------------------------------*/
411 sal_Bool
CacheItem::dontHaveProps(const CacheItem
& lProps
) const
413 for (const_iterator pIt
= lProps
.begin();
414 pIt
!= lProps
.end() ;
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
))
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
))
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")
445 } // namespace config
446 } // namespace filter