1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FILTER_CONFIG_CACHEITEM_HXX_
25 #define __FILTER_CONFIG_CACHEITEM_HXX_
26 
27 //_______________________________________________
28 // includes
29 
30 #include <hash_map>
31 #include <deque>
32 #include <list>
33 #include <com/sun/star/uno/Any.h>
34 #include <com/sun/star/uno/Sequence.h>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/beans/NamedValue.hpp>
37 #include <comphelper/sequenceasvector.hxx>
38 #include <comphelper/sequenceashashmap.hxx>
39 #include <osl/mutex.hxx>
40 
41 //_______________________________________________
42 // namespace
43 
44 namespace filter{
45     namespace config{
46 
47 namespace css = ::com::sun::star;
48 
49 //_______________________________________________
50 // definitions
51 
52 /** @short  Must be used as first derived base class
53             to get a full initialized mutex member,
54             which can be used during the ctor runs too!
55  */
56 struct BaseLock
57 {
58     public:
59 
60         // must be mutable to be useable in const environments too!
61         mutable ::osl::Mutex m_aLock;
62 };
63 
64 
65 typedef ::comphelper::SequenceAsVector< ::rtl::OUString > OUStringList;
66 
67 //_______________________________________________
68 
69 /** @short  represent an item of a FilterCache
70             instance.
71 
72     @descr  This class is not threadsafe tp perform
73             operations, which use many instances of
74             this class! Synchronizations must be done outside.
75  */
76 class CacheItem : public ::comphelper::SequenceAsHashMap
77 {
78     //-------------------------------------------
79     public:
80 
81         //---------------------------------------
82         /** @short  creates an empty item.
83           */
84         CacheItem();
85 
86         //---------------------------------------
87 
88         /** @short  update only properties, which are given by the
89                     specified rItem.
90 
91             @descr  Update means: - add new properties
92                                   - change existing values
93 
94             @param  rUpdateItem
95                     another cache item, which contains some special
96                     properties, which should by used for updating
97                     this one.
98          */
99         void update(const CacheItem& rUpdateItem);
100 
101         //---------------------------------------
102 
103         /** @short  check, if the given properties exists
104                     at this item.
105 
106             @descr  All properties are compared in its minimum.
107                     E.g: string lists => only the requested items
108                     are checked. Additional existing items are ignored.
109 
110             @param  lProps
111                     contains all properties, which must exist at this item.
112 
113             @return sal_True if all given properties exist
114                     at this item; sal_False otherwise.
115          */
116         sal_Bool haveProps(const CacheItem& lProps) const;
117 
118         //---------------------------------------
119 
120         /** @short  check, if the given properties don't exist
121                     at this item.
122 
123             @descr  All properties are compared in its minimum.
124                     E.g: string lists => only the requested items
125                     are checked. Additional existing items are ignored.
126 
127             @param  lProps
128                     contains all properties, which should not exists at this item.
129 
130             @return sal_False if at least one property exists at this item(!);
131                     sal_True otherwise.
132          */
133         sal_Bool dontHaveProps(const CacheItem& lProps) const;
134 
135         //---------------------------------------
136 
137         /** @short  check, if the given properties don't exist
138                     at this item.
139 
140             @descr  All properties are compared in its minimum.
141                     E.g: string lists => only the specified items
142                     are checked. Additional existing items are ignored.
143 
144             @param  lProps
145                     contains all properties, which should be checked.
146 
147             @return sal_True if all given properties don't exist
148                     at this item; sal_False otherwise.
149          */
150         sal_Bool excludeProps(const CacheItem& lProps) const;
151 
152         //---------------------------------------
153 
154         /** @short  because we know two UIName properties
155                     (a list with all locales and the value
156                     for the current locale only), we must be sure
157                     that the correspond together.
158 
159             @param  sActLocale
160                     must specify the current office locale.
161                     Its needed to address the UIName property inside
162                     the list of possible ones.
163          */
164         void validateUINames(const ::rtl::OUString& sActLocale);
165 
166         //---------------------------------------
167 
168         /** @short  convert this structure to a seq< PropertyValue >
169                     and ignore all empty properties!
170 
171             @descr  Normally the converter routines of the base class
172                     SequenceAsHashMap done this job already.
173                     But it doesn't provide a "pack" mechanism to
174                     ignore properties with empty (means "void") values.
175 
176             @return css::uno::Sequence< css::beans::PropertyValue >
177                     as a list of all properties of this cacheitem,
178                     where empty properties was removed.
179          */
180         css::uno::Sequence< css::beans::PropertyValue > getAsPackedPropertyValueList();
181 };
182 
183 //_______________________________________________
184 
185 /** @short  represent an item list of a FilterCache
186             instance.
187  */
188 typedef ::std::hash_map< ::rtl::OUString                    ,
189                          CacheItem                          ,
190                          ::rtl::OUStringHash                ,
191                          ::std::equal_to< ::rtl::OUString > > CacheItemList;
192 
193 //_______________________________________________
194 
195 /** @short  supports registration of multiple key to
196             another string information.
197 
198     @descr  E.g. a list of internal type names can be registered
199             to an extension. Organization as an hash makes it
200             faster then searching inside vectors.
201 
202             On the other side e.g. URLPattern can't be really addressed
203             by a hash value ... because the use wildcards. But
204             there we need key-value pairs too, which can't be provided
205             by a pur vector!
206  */
207 typedef ::std::hash_map< ::rtl::OUString                    ,
208                          OUStringList                       ,
209                          ::rtl::OUStringHash                ,
210                          ::std::equal_to< ::rtl::OUString > > CacheItemRegistration;
211 
212 //_______________________________________________
213 
214 /** @short  is used to collect all matching types of an URL
215             during type detection.
216 
217     @descr  Every type in this list is combined with an information,
218             which property matched to the given URL. The user of this
219             structure can decide then, if a deep detection should be
220             suppressed e.g. if an URLPattern was used.
221  */
222 struct  FlatDetectionInfo
223 {
224     // the internal type name
225     ::rtl::OUString sType;
226 
227     // this type was found by a matching the URL extension
228     sal_Bool bMatchByExtension;
229 
230     // this type was found by a matching URL Pattern
231     sal_Bool bMatchByPattern;
232 
233     // the user selected this type explicitly
234     sal_Bool bPreselectedAsType;
235 
236     // the user selected this type implicit by selecting a corresponding filter
237     sal_Bool bPreselectedByFilter;
238 
239     // the user selected this type implicit by selecting a corresponding office module
240     sal_Bool bPreselectedByDocumentService;
241 
FlatDetectionInfofilter::config::FlatDetectionInfo242     FlatDetectionInfo()
243         : sType                        (::rtl::OUString())
244         , bMatchByExtension            (sal_False        )
245         , bMatchByPattern              (sal_False        )
246         , bPreselectedAsType           (sal_False        )
247         , bPreselectedByFilter         (sal_False        )
248         , bPreselectedByDocumentService(sal_False        )
249     {}
250 };
251 
252 typedef ::std::list< FlatDetectionInfo > FlatDetection;
253 
254     } // namespace config
255 } // namespace filter
256 
257 #endif // __FILTER_CONFIG_CACHEITEM_HXX_
258