bump product version to 4.1.6.2
[LibreOffice.git] / filter / source / config / cache / cacheitem.cxx
blob8f91437fce307a5945f67f46c14bc4d055f5e76a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 #include "macros.hxx"
23 #include "constant.hxx"
25 #include <com/sun/star/uno/Sequence.h>
27 #include <com/sun/star/beans/PropertyValue.hpp>
30 namespace filter{
31 namespace config{
33 CacheItem::CacheItem()
34 : SequenceAsHashMap()
40 void CacheItem::update(const CacheItem& rUpdateItem)
42 for(const_iterator pItUpdate = rUpdateItem.begin();
43 pItUpdate != rUpdateItem.end() ;
44 ++pItUpdate )
46 iterator pItThis = this->find(pItUpdate->first);
47 if (pItThis == this->end())
48 (*this)[pItUpdate->first] = pItUpdate->second; // add new prop
49 else
50 pItThis->second = pItUpdate->second; // change value of existing prop
56 void CacheItem::validateUINames(const OUString& sActLocale)
58 if (sActLocale.isEmpty())
59 return;
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;
69 OUString sUIName;
70 if (pUIName != end())
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();
93 sal_Int32 i = 0;
95 css::uno::Sequence< css::beans::PropertyValue > lList(c);
96 css::beans::PropertyValue* pList = lList.getArray();
98 for (const_iterator pProp = begin();
99 pProp != end() ;
100 ++pProp )
102 const OUString& rName = pProp->first;
103 const css::uno::Any& rValue = pProp->second;
105 if (!rValue.hasValue())
106 continue;
108 pList[i].Name = rName ;
109 pList[i].Value = rValue;
110 ++i;
112 lList.realloc(i);
114 return lList;
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")
128 return sal_False;
131 css::uno::TypeClass aTypeClass = aT1.getTypeClass();
132 switch(aTypeClass)
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")
148 return bIs;
151 //---------------------------------------
152 case css::uno::TypeClass_STRING :
154 OUString v1;
155 OUString v2;
157 if (
158 (aSubSet >>= v1) &&
159 (aSet >>= v2)
162 sal_Bool bIs = (v1.equals(v2));
163 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for string types => return %s\n", bIs ? "TRUE" : "FALSE")
164 return bIs;
167 break;
169 //---------------------------------------
170 case css::uno::TypeClass_ANY :
172 css::uno::Any v1;
173 css::uno::Any v2;
175 if (
176 (aSubSet >>= v1) &&
177 (aSet >>= v2)
180 sal_Bool bIs = (isSubSet(v1, v2));
181 _FILTER_CONFIG_LOG_1_("isSubSet() ... check for packed any types => return %s\n", bIs ? "TRUE" : "FALSE")
182 return bIs;
185 break;
187 //---------------------------------------
188 case css::uno::TypeClass_STRUCT :
190 css::beans::PropertyValue p1;
191 css::beans::PropertyValue p2;
193 if (
194 (aSubSet >>= p1) &&
195 (aSet >>= p2)
198 sal_Bool bIs = (
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")
203 return bIs;
206 css::beans::NamedValue n1;
207 css::beans::NamedValue n2;
209 if (
210 (aSubSet >>= n1) &&
211 (aSet >>= n2)
214 sal_Bool bIs = (
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")
219 return bIs;
222 break;
224 //---------------------------------------
225 case css::uno::TypeClass_SEQUENCE :
227 css::uno::Sequence< OUString > uno_s1;
228 css::uno::Sequence< OUString > uno_s2;
230 if (
231 (aSubSet >>= uno_s1) &&
232 (aSet >>= uno_s2)
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() ;
240 ++it1 )
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))
245 return sal_False;
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")
250 return sal_True;
253 css::uno::Sequence< css::beans::PropertyValue > uno_p1;
254 css::uno::Sequence< css::beans::PropertyValue > uno_p2;
256 if (
257 (aSubSet >>= uno_p1) &&
258 (aSet >>= uno_p2)
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() ;
266 ++it1 )
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))
272 return sal_False;
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))
277 return sal_False;
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")
282 return sal_True;
285 css::uno::Sequence< css::beans::NamedValue > uno_n1;
286 css::uno::Sequence< css::beans::NamedValue > uno_n2;
288 if (
289 (aSubSet >>= uno_n1) &&
290 (aSet >>= uno_n2)
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() ;
298 ++it1 )
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))
304 return sal_False;
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))
309 return sal_False;
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")
314 return sal_True;
317 break;
318 default: break;
321 OSL_FAIL("isSubSet() ... this point should not be reached!");
322 return sal_False;
327 sal_Bool CacheItem::haveProps(const CacheItem& lProps) const
329 for (const_iterator pIt = lProps.begin();
330 pIt != lProps.end() ;
331 ++pIt )
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))
338 return sal_False;
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))
345 return sal_False;
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 return sal_True;
358 sal_Bool CacheItem::dontHaveProps(const CacheItem& lProps) const
360 for (const_iterator pIt = lProps.begin();
361 pIt != lProps.end() ;
362 ++pIt )
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))
372 continue;
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))
381 return sal_False;
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 return sal_True;
392 FlatDetectionInfo::FlatDetectionInfo() :
393 bMatchByExtension(false), bMatchByPattern(false), bPreselectedByDocumentService(false) {}
395 } // namespace config
396 } // namespace filter
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */