1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "cacheitem.hxx"
23 #include "constant.hxx"
25 #include <com/sun/star/uno/Sequence.h>
27 #include <com/sun/star/beans/PropertyValue.hpp>
33 CacheItem::CacheItem()
40 void CacheItem::update(const CacheItem
& rUpdateItem
)
42 for(const_iterator pItUpdate
= rUpdateItem
.begin();
43 pItUpdate
!= rUpdateItem
.end() ;
46 iterator pItThis
= this->find(pItUpdate
->first
);
47 if (pItThis
== this->end())
48 (*this)[pItUpdate
->first
] = pItUpdate
->second
; // add new prop
50 pItThis
->second
= pItUpdate
->second
; // change value of existing prop
56 void CacheItem::validateUINames(const OUString
& sActLocale
)
58 if (sActLocale
.isEmpty())
61 // 1) check UINames first
62 const_iterator pUINames
= find(PROPNAME_UINAMES
);
63 const_iterator pUIName
= find(PROPNAME_UINAME
);
65 ::comphelper::SequenceAsHashMap lUINames
;
66 if (pUINames
!= end())
67 lUINames
<< pUINames
->second
;
71 pUIName
->second
>>= sUIName
;
73 if (!sUIName
.isEmpty())
75 // 1a) set UIName inside list of UINames for current locale
76 lUINames
[sActLocale
] <<= sUIName
;
78 else if (lUINames
.size()>0)
80 // 1b) or get it from this list, if it not exist!
81 lUINames
[sActLocale
] >>= sUIName
;
84 (*this)[PROPNAME_UINAMES
] <<= lUINames
.getAsConstPropertyValueList();
85 (*this)[PROPNAME_UINAME
] <<= sUIName
;
90 css::uno::Sequence
< css::beans::PropertyValue
> CacheItem::getAsPackedPropertyValueList()
92 sal_Int32 c
= (sal_Int32
)size();
95 css::uno::Sequence
< css::beans::PropertyValue
> lList(c
);
96 css::beans::PropertyValue
* pList
= lList
.getArray();
98 for (const_iterator pProp
= begin();
102 const OUString
& rName
= pProp
->first
;
103 const css::uno::Any
& rValue
= pProp
->second
;
105 if (!rValue
.hasValue())
108 pList
[i
].Name
= rName
;
109 pList
[i
].Value
= rValue
;
119 sal_Bool
isSubSet(const css::uno::Any
& aSubSet
,
120 const css::uno::Any
& aSet
)
122 css::uno::Type aT1
= aSubSet
.getValueType();
123 css::uno::Type aT2
= aSet
.getValueType();
125 if (!aT1
.equals(aT2
))
127 _FILTER_CONFIG_LOG_("isSubSet() ... types of any values are different => return FALSE\n")
131 css::uno::TypeClass aTypeClass
= aT1
.getTypeClass();
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
:
146 sal_Bool bIs
= (aSubSet
== aSet
);
147 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for atomic types => return %s\n", bIs
? "TRUE" : "FALSE")
151 //---------------------------------------
152 case css::uno::TypeClass_STRING
:
162 sal_Bool bIs
= (v1
.equals(v2
));
163 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for string types => return %s\n", bIs
? "TRUE" : "FALSE")
169 //---------------------------------------
170 case css::uno::TypeClass_ANY
:
180 sal_Bool bIs
= (isSubSet(v1
, v2
));
181 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for packed any types => return %s\n", bIs
? "TRUE" : "FALSE")
187 //---------------------------------------
188 case css::uno::TypeClass_STRUCT
:
190 css::beans::PropertyValue p1
;
191 css::beans::PropertyValue p2
;
199 (p1
.Name
.equals(p2
.Name
) ) &&
200 (isSubSet(p1
.Value
, p2
.Value
))
202 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [PropertyValue] => return %s\n", bIs
? "TRUE" : "FALSE")
206 css::beans::NamedValue n1
;
207 css::beans::NamedValue n2
;
215 (n1
.Name
.equals(n2
.Name
) ) &&
216 (isSubSet(n1
.Value
, n2
.Value
))
218 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for structured types [NamedValue] => return %s\n", bIs
? "TRUE" : "FALSE")
224 //---------------------------------------
225 case css::uno::TypeClass_SEQUENCE
:
227 css::uno::Sequence
< OUString
> uno_s1
;
228 css::uno::Sequence
< OUString
> uno_s2
;
231 (aSubSet
>>= uno_s1
) &&
235 OUStringList
stl_s1(uno_s1
);
236 OUStringList
stl_s2(uno_s2
);
238 for (OUStringList::const_iterator it1
= stl_s1
.begin();
239 it1
!= stl_s1
.end() ;
242 if (::std::find(stl_s2
.begin(), stl_s2
.end(), *it1
) == stl_s2
.end())
244 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(*it1
))
247 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [OUString] ... found \"%s\" => continue loop\n", _FILTER_CONFIG_TO_ASCII_(*it1
))
249 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [OUString] => return TRUE\n")
253 css::uno::Sequence
< css::beans::PropertyValue
> uno_p1
;
254 css::uno::Sequence
< css::beans::PropertyValue
> uno_p2
;
257 (aSubSet
>>= uno_p1
) &&
261 ::comphelper::SequenceAsHashMap
stl_p1(uno_p1
);
262 ::comphelper::SequenceAsHashMap
stl_p2(uno_p2
);
264 for (::comphelper::SequenceAsHashMap::const_iterator it1
= stl_p1
.begin();
265 it1
!= stl_p1
.end() ;
268 ::comphelper::SequenceAsHashMap::const_iterator it2
= stl_p2
.find(it1
->first
);
269 if (it2
== stl_p2
.end())
271 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [PropertyValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1
->first
))
274 if (!isSubSet(it1
->second
, it2
->second
))
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
))
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
))
281 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [PropertyValue] => return TRUE\n")
285 css::uno::Sequence
< css::beans::NamedValue
> uno_n1
;
286 css::uno::Sequence
< css::beans::NamedValue
> uno_n2
;
289 (aSubSet
>>= uno_n1
) &&
293 ::comphelper::SequenceAsHashMap
stl_n1(uno_n1
);
294 ::comphelper::SequenceAsHashMap
stl_n2(uno_n2
);
296 for (::comphelper::SequenceAsHashMap::const_iterator it1
= stl_n1
.begin();
297 it1
!= stl_n1
.end() ;
300 ::comphelper::SequenceAsHashMap::const_iterator it2
= stl_n2
.find(it1
->first
);
301 if (it2
== stl_n2
.end())
303 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for list types [NamedValue] ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(it1
->first
))
306 if (!isSubSet(it1
->second
, it2
->second
))
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
))
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
))
313 _FILTER_CONFIG_LOG_("isSubSet() ... check for list types [NamedValue] => return TRUE\n")
321 OSL_FAIL("isSubSet() ... this point should not be reached!");
327 sal_Bool
CacheItem::haveProps(const CacheItem
& lProps
) const
329 for (const_iterator pIt
= lProps
.begin();
330 pIt
!= lProps
.end() ;
333 // i) one required property does not exist at this item => return false
334 const_iterator pItThis
= this->find(pIt
->first
);
335 if (pItThis
== this->end())
337 _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... dont found \"%s\" => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt
->first
))
341 // ii) one item does not have the right value => return false
342 if (!isSubSet(pIt
->second
, pItThis
->second
))
344 _FILTER_CONFIG_LOG_1_("CacheItem::haveProps() ... item \"%s\" has different value => return FALSE\n", _FILTER_CONFIG_TO_ASCII_(pIt
->first
))
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")
358 sal_Bool
CacheItem::dontHaveProps(const CacheItem
& lProps
) const
360 for (const_iterator pIt
= lProps
.begin();
361 pIt
!= lProps
.end() ;
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 const_iterator pItThis
= this->find(pIt
->first
);
369 if (pItThis
== this->end())
371 _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... not found \"%s\" => continue loop!\n", _FILTER_CONFIG_TO_ASCII_(pIt
->first
))
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 if (isSubSet(pIt
->second
, pItThis
->second
))
380 _FILTER_CONFIG_LOG_1_("CacheItem::dontHaveProps() ... item \"%s\" has same value => return FALSE!\n", _FILTER_CONFIG_TO_ASCII_(pIt
->first
))
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")
392 FlatDetectionInfo::FlatDetectionInfo() :
393 bMatchByExtension(false), bMatchByPattern(false), bPreselectedByDocumentService(false) {}
395 } // namespace config
396 } // namespace filter
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */