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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26
27 #include "filtercache.hxx"
28 #include "lateinitlistener.hxx"
29 #include "macros.hxx"
30 #include "constant.hxx"
31 #include "cacheupdatelistener.hxx"
32
33 /*TODO see using below ... */
34 #define AS_ENABLE_FILTER_UINAMES
35 #define WORKAROUND_EXCEPTION_PROBLEM
36
37 //_______________________________________________
38 // includes
39 #include <com/sun/star/util/XChangesBatch.hpp>
40 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
41 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/beans/XProperty.hpp>
44 #include <com/sun/star/beans/PropertyValue.hpp>
45 #include <com/sun/star/beans/Property.hpp>
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
47 #include <com/sun/star/document/CorruptedFilterConfigurationException.hpp>
48 #include <comphelper/sequenceasvector.hxx>
49 #include <comphelper/locale.hxx>
50 #include <unotools/processfactory.hxx>
51
52 #ifndef _UNOTOOLS_CONFIGPATHES_HXX_
53 #include <unotools/configpathes.hxx>
54 #endif
55 #include <rtl/ustrbuf.hxx>
56 #include <rtl/logfile.hxx>
57 #include <rtl/uri.hxx>
58 #include <tools/urlobj.hxx>
59 #include <tools/wldcrd.hxx>
60
61 #include <comphelper/configurationhelper.hxx>
62
63 //_______________________________________________
64 // namespace
65
66 namespace filter{
67 namespace config{
68
69 namespace css = ::com::sun::star;
70
71 //_______________________________________________
72 // definitions
73
74 // Error message in case filter config seems to be corrupted.
75 // Note: Don't tell user something about "setup -repair"!
76 // It's no longer supported by using native installers ...
77 static ::rtl::OUString MESSAGE_CORRUPTED_FILTERCONFIG = ::rtl::OUString::createFromAscii("The filter configuration appears to be defective. Please install the office suite again.");
78
79 /*-----------------------------------------------
80 15.03.2004 08:59
81 -----------------------------------------------*/
FilterCache()82 FilterCache::FilterCache()
83 : BaseLock ( )
84 , m_xSMGR (::comphelper::getProcessServiceFactory())
85 , m_eFillState(E_CONTAINS_NOTHING )
86 {
87 RTL_LOGFILE_TRACE("{ (as96863) FilterCache lifetime");
88 }
89
90 /*-----------------------------------------------
91 15.03.2004 08:59
92 -----------------------------------------------*/
~FilterCache()93 FilterCache::~FilterCache()
94 {
95 RTL_LOGFILE_TRACE("} (as96863) FilterCache lifetime");
96 }
97
98 /*-----------------------------------------------
99 03.03.2004 11:27
100 -----------------------------------------------*/
clone() const101 FilterCache* FilterCache::clone() const
102 {
103 // SAFE -> ----------------------------------
104 ::osl::ResettableMutexGuard aLock(m_aLock);
105
106 FilterCache* pClone = new FilterCache();
107
108 // Don't copy the configuration access points here.
109 // They will be created on demand inside the cloned instance,
110 // if they are needed.
111
112 pClone->m_xSMGR = m_xSMGR;
113
114 pClone->m_lTypes = m_lTypes;
115 pClone->m_lDetectServices = m_lDetectServices;
116 pClone->m_lFilters = m_lFilters;
117 pClone->m_lFrameLoaders = m_lFrameLoaders;
118 pClone->m_lContentHandlers = m_lContentHandlers;
119 pClone->m_lExtensions2Types = m_lExtensions2Types;
120 pClone->m_lURLPattern2Types = m_lURLPattern2Types;
121
122 pClone->m_sActLocale = m_sActLocale;
123 pClone->m_sProductName = m_sProductName;
124 pClone->m_sOOoXMLFormatName = m_sOOoXMLFormatName;
125 pClone->m_sOOoXMLFormatVersion = m_sOOoXMLFormatVersion;
126
127 pClone->m_eFillState = m_eFillState;
128
129 pClone->m_lChangedTypes = m_lChangedTypes;
130 pClone->m_lChangedFilters = m_lChangedFilters;
131 pClone->m_lChangedDetectServices = m_lChangedDetectServices;
132 pClone->m_lChangedFrameLoaders = m_lChangedFrameLoaders;
133 pClone->m_lChangedContentHandlers = m_lChangedContentHandlers;
134
135 return pClone;
136 // <- SAFE ----------------------------------
137 }
138
139 /*-----------------------------------------------
140 03.03.2004 14:39
141 -----------------------------------------------*/
takeOver(const FilterCache & rClone)142 void FilterCache::takeOver(const FilterCache& rClone)
143 {
144 // SAFE -> ----------------------------------
145 ::osl::ResettableMutexGuard aLock(m_aLock);
146
147 // a)
148 // Don't copy the configuration access points here!
149 // We must use our own ones ...
150
151 // b)
152 // Further we can ignore the uno service manager.
153 // We should already have a valid instance.
154
155 // c)
156 // Take over only changed items!
157 // Otherwise we risk the following scenario:
158 // c1) clone_1 contains changed filters
159 // c2) clone_2 container changed types
160 // c3) clone_1 take over changed filters and unchanged types
161 // c4) clone_2 take over unchanged filters(!) and changed types(!)
162 // c5) c4 overwrites c3!
163
164 if (rClone.m_lChangedTypes.size()>0)
165 m_lTypes = rClone.m_lTypes;
166 if (rClone.m_lChangedDetectServices.size()>0)
167 m_lDetectServices = rClone.m_lDetectServices;
168 if (rClone.m_lChangedFilters.size()>0)
169 m_lFilters = rClone.m_lFilters;
170 if (rClone.m_lChangedFrameLoaders.size()>0)
171 m_lFrameLoaders = rClone.m_lFrameLoaders;
172 if (rClone.m_lChangedContentHandlers.size()>0)
173 m_lContentHandlers = rClone.m_lContentHandlers;
174
175 m_lChangedTypes.clear();
176 m_lChangedDetectServices.clear();
177 m_lChangedFilters.clear();
178 m_lChangedFrameLoaders.clear();
179 m_lChangedContentHandlers.clear();
180
181 m_sActLocale = rClone.m_sActLocale;
182 m_sProductName = rClone.m_sProductName;
183 m_sOOoXMLFormatName = rClone.m_sOOoXMLFormatName;
184 m_sOOoXMLFormatVersion = rClone.m_sOOoXMLFormatVersion;
185
186 m_eFillState = rClone.m_eFillState;
187
188 // renew all dependencies and optimizations
189 // Because we can't be sure, that changed filters on one clone
190 // and changed types of another clone work together.
191 // But here we can check against the lates changes ...
192 impl_validateAndOptimize();
193 // <- SAFE ----------------------------------
194 }
195
196 /*-----------------------------------------------
197 28.10.2003 09:01
198 -----------------------------------------------*/
load(EFillState eRequired,sal_Bool bByThread)199 void FilterCache::load(EFillState eRequired,
200 #if OSL_DEBUG_LEVEL > 1
201 sal_Bool bByThread
202 #else
203 sal_Bool
204 #endif
205 )
206 {
207 // SAFE -> ----------------------------------
208 ::osl::ResettableMutexGuard aLock(m_aLock);
209
210 // check if required fill state is already reached ...
211 // There is nothing to do then.
212 if ((m_eFillState & eRequired) == eRequired)
213 return;
214
215 #if OSL_DEBUG_LEVEL > 1 && !defined(OS2)
216 if (
217 (!bByThread) &&
218 (
219 ((eRequired & E_CONTAINS_FILTERS) == E_CONTAINS_FILTERS) ||
220 ((eRequired & E_CONTAINS_ALL ) == E_CONTAINS_ALL )
221 )
222 )
223 {
224 OSL_TRACE("Who disturbs our \"fill cache on demand\" feature and force loading of ALL data during office startup? Please optimize your code, so a full filled filter cache is not really needed here!");
225 }
226 #endif
227
228 // Otherwise load the missing items.
229
230 // ------------------------------------------
231 // a) load some const values from configuration.
232 // These values are needed there for loading
233 // config items ...
234 // Further we load some std items from the
235 // configuration so we can try to load the first
236 // office document with a minimal set of values.
237 if (m_eFillState == E_CONTAINS_NOTHING)
238 {
239 impl_getDirectCFGValue(CFGDIRECTKEY_OFFICELOCALE) >>= m_sActLocale;
240 if (!m_sActLocale.getLength())
241 {
242 _FILTER_CONFIG_LOG_1_("FilterCache::ctor() ... could not specify office locale => use default \"%s\"\n", _FILTER_CONFIG_TO_ASCII_(DEFAULT_OFFICELOCALE));
243 m_sActLocale = DEFAULT_OFFICELOCALE;
244 }
245
246 impl_getDirectCFGValue(CFGDIRECTKEY_PRODUCTNAME) >>= m_sProductName;
247
248 impl_getDirectCFGValue(CFGDIRECTKEY_FORMATNAME) >>= m_sOOoXMLFormatName;
249 if (!m_sOOoXMLFormatName.getLength())
250 {
251 _FILTER_CONFIG_LOG_1_("FilterCache::ctor() ... could not specify format name => use default \"%s\"\n", _FILTER_CONFIG_TO_ASCII_(DEFAULT_FORMATNAME));
252 m_sOOoXMLFormatName = DEFAULT_FORMATNAME;
253 }
254
255 impl_getDirectCFGValue(CFGDIRECTKEY_FORMATVERSION) >>= m_sOOoXMLFormatVersion;
256 if (!m_sOOoXMLFormatVersion.getLength())
257 {
258 _FILTER_CONFIG_LOG_1_("FilterCache::ctor() ... could not specify format version => use default \"%s\"\n", _FILTER_CONFIG_TO_ASCII_(DEFAULT_FORMATVERSION));
259 m_sOOoXMLFormatVersion = DEFAULT_FORMATVERSION;
260 }
261
262 // Support the old configuration support. Read it only one time during office runtime!
263 impl_readOldFormat();
264
265 // enable "loadOnDemand" feature ...
266 // Create uno listener, which waits for finishing the office startup
267 // and starts a thread, which calls loadAll() at this filter cache.
268 // Note: It's not a leak to create this listener with new here.
269 // It kills itself after working!
270 /* LateInitListener* pLateInit = */ new LateInitListener(m_xSMGR);
271 }
272
273 // ------------------------------------------
274 // b) If the required fill state was not reached
275 // but std values was already loaded ...
276 // we must load some further missing items.
277 impl_load(eRequired);
278 // <- SAFE
279 }
280
281 /*-----------------------------------------------
282 28.10.2003 09:50
283 -----------------------------------------------*/
isFillState(FilterCache::EFillState eState) const284 sal_Bool FilterCache::isFillState(FilterCache::EFillState eState) const
285 {
286 // SAFE ->
287 ::osl::ResettableMutexGuard aLock(m_aLock);
288 return ((m_eFillState & eState) == eState);
289 // <- SAFE
290 }
291
292 /*-----------------------------------------------
293 14.07.2003 10:45
294 -----------------------------------------------*/
getMatchingItemsByProps(EItemType eType,const CacheItem & lIProps,const CacheItem & lEProps) const295 OUStringList FilterCache::getMatchingItemsByProps( EItemType eType ,
296 const CacheItem& lIProps,
297 const CacheItem& lEProps) const
298 {
299 // SAFE ->
300 ::osl::ResettableMutexGuard aLock(m_aLock);
301
302 // search for right list
303 // An exception is thrown if "eType" is unknown.
304 // => rList will be valid every time the next line is reached.
305 CacheItemList& rList = impl_getItemList(eType);
306
307 OUStringList lKeys;
308
309 // search items, which provides all needed properties of set "lIProps"
310 // but not of set "lEProps"!
311 for (CacheItemList::const_iterator pIt = rList.begin();
312 pIt != rList.end() ;
313 ++pIt )
314 {
315 _FILTER_CONFIG_LOG_1_("getMatchingProps for \"%s\" ...\n",
316 _FILTER_CONFIG_TO_ASCII_(pIt->first))
317 if (
318 (pIt->second.haveProps(lIProps) ) &&
319 (pIt->second.dontHaveProps(lEProps))
320 )
321 {
322 lKeys.push_back(pIt->first);
323 }
324 }
325
326 return lKeys;
327 // <- SAFE
328 }
329
330 /*-----------------------------------------------
331 02.07.2003 09:32
332 -----------------------------------------------*/
hasItems(EItemType eType) const333 sal_Bool FilterCache::hasItems(EItemType eType) const
334 {
335 // SAFE ->
336 ::osl::ResettableMutexGuard aLock(m_aLock);
337
338 // search for right list
339 // An exception is thrown if "eType" is unknown.
340 // => rList will be valid every time the next line is reached.
341 CacheItemList& rList = impl_getItemList(eType);
342
343 return (rList.size()>0);
344 // <- SAFE
345 }
346
347 /*-----------------------------------------------
348 02.07.2003 11:48
349 -----------------------------------------------*/
getItemNames(EItemType eType) const350 OUStringList FilterCache::getItemNames(EItemType eType) const
351 {
352 // SAFE ->
353 ::osl::ResettableMutexGuard aLock(m_aLock);
354
355 // search for right list
356 // An exception is thrown if "eType" is unknown.
357 // => rList will be valid every time the next line is reached.
358 CacheItemList& rList = impl_getItemList(eType);
359
360 OUStringList lKeys;
361 for (CacheItemList::const_iterator pIt = rList.begin();
362 pIt != rList.end() ;
363 ++pIt )
364 {
365 lKeys.push_back(pIt->first);
366 }
367 return lKeys;
368 // <- SAFE
369 }
370
371 /*-----------------------------------------------
372 27.10.2003 08:37
373 -----------------------------------------------*/
hasItem(EItemType eType,const::rtl::OUString & sItem)374 sal_Bool FilterCache::hasItem( EItemType eType,
375 const ::rtl::OUString& sItem)
376 {
377 // SAFE ->
378 ::osl::ResettableMutexGuard aLock(m_aLock);
379
380 // search for right list
381 // An exception is thrown if "eType" is unknown.
382 // => rList will be valid every time the next line is reached.
383 CacheItemList& rList = impl_getItemList(eType);
384
385 // if item could not be found - check if it can be loaded
386 // from the underlying configuration layer. Might it was not already
387 // loaded into this FilterCache object before.
388 CacheItemList::const_iterator pIt = rList.find(sItem);
389 if (pIt != rList.end())
390 return sal_True;
391
392 try
393 {
394 impl_loadItemOnDemand(eType, sItem);
395 // no exception => item could be loaded!
396 return sal_True;
397 }
398 catch(const css::container::NoSuchElementException&)
399 {}
400
401 return sal_False;
402 // <- SAFE
403 }
404
405 /*-----------------------------------------------
406 17.07.2006 09:15
407 -----------------------------------------------*/
getItem(EItemType eType,const::rtl::OUString & sItem)408 CacheItem FilterCache::getItem( EItemType eType,
409 const ::rtl::OUString& sItem)
410 {
411 // SAFE ->
412 ::osl::ResettableMutexGuard aLock(m_aLock);
413
414 // search for right list
415 // An exception is thrown if "eType" is unknown.
416 // => rList will be valid every time the next line is reached.
417 CacheItemList& rList = impl_getItemList(eType);
418
419 // check if item exists ...
420 CacheItemList::iterator pIt = rList.find(sItem);
421 if (pIt == rList.end())
422 {
423 // ... or load it on demand from the
424 // underlying configuration layer.
425 // Note: NoSuchElementException is thrown automatically here if
426 // item could not be loaded!
427 pIt = impl_loadItemOnDemand(eType, sItem);
428 }
429
430 /* Workaround for #137955#
431 Draw types and filters are installed ... but draw was disabled during setup.
432 We must suppress accessing these filters. Otherwise the office can crash.
433 Solution for the next major release: do not install those filters !
434 */
435 if (eType == E_FILTER)
436 {
437 CacheItem& rFilter = pIt->second;
438 ::rtl::OUString sDocService;
439 rFilter[PROPNAME_DOCUMENTSERVICE] >>= sDocService;
440
441 // --> PB 2006-10-18 #142498#
442 // In Standalone-Impress the module WriterWeb is not installed
443 // but it is there to load help pages
444 sal_Bool bIsHelpFilter = sItem.equalsAscii( "writer_web_HTML_help" );
445
446 if ( !bIsHelpFilter && !impl_isModuleInstalled(sDocService) )
447 // <--
448 {
449 ::rtl::OUStringBuffer sMsg(256);
450 sMsg.appendAscii("The requested filter '" );
451 sMsg.append (sItem );
452 sMsg.appendAscii("' exists ... but it shouldn't; because the corresponding AOO module was not installed.");
453 throw css::container::NoSuchElementException(sMsg.makeStringAndClear(), css::uno::Reference< css::uno::XInterface >());
454 }
455 }
456
457 return pIt->second;
458 // <- SAFE
459 }
460
461 /*-----------------------------------------------
462 03.03.2004 11:28
463 -----------------------------------------------*/
removeItem(EItemType eType,const::rtl::OUString & sItem)464 void FilterCache::removeItem( EItemType eType,
465 const ::rtl::OUString& sItem)
466 {
467 // SAFE ->
468 ::osl::ResettableMutexGuard aLock(m_aLock);
469
470 // search for right list
471 // An exception is thrown if "eType" is unknown.
472 // => rList will be valid every time the next line is reached.
473 CacheItemList& rList = impl_getItemList(eType);
474
475 CacheItemList::iterator pItem = rList.find(sItem);
476 if (pItem == rList.end())
477 pItem = impl_loadItemOnDemand(eType, sItem); // throws NoSuchELementException!
478 rList.erase(pItem);
479
480 impl_addItem2FlushList(eType, sItem);
481 }
482
483 /*-----------------------------------------------
484 26.11.2003 13:28
485 -----------------------------------------------*/
setItem(EItemType eType,const::rtl::OUString & sItem,const CacheItem & aValue)486 void FilterCache::setItem( EItemType eType ,
487 const ::rtl::OUString& sItem ,
488 const CacheItem& aValue)
489 {
490 // SAFE ->
491 ::osl::ResettableMutexGuard aLock(m_aLock);
492
493 // search for right list
494 // An exception is thrown if "eType" is unknown.
495 // => rList will be valid every time the next line is reached.
496 CacheItemList& rList = impl_getItemList(eType);
497
498 // name must be part of the property set too ... otherwise our
499 // container query can't work correctly
500 CacheItem aItem = aValue;
501 aItem[PROPNAME_NAME] <<= sItem;
502 aItem.validateUINames(m_sActLocale);
503
504 // remove implicit properties as e.g. FINALIZED or MANDATORY
505 // They can't be saved here and must be read on demand later, if they are needed.
506 removeStatePropsFromItem(aItem);
507
508 rList[sItem] = aItem;
509
510 impl_addItem2FlushList(eType, sItem);
511 }
512
513 //-----------------------------------------------
refreshItem(EItemType eType,const::rtl::OUString & sItem)514 void FilterCache::refreshItem( EItemType eType,
515 const ::rtl::OUString& sItem)
516 {
517 // SAFE ->
518 ::osl::ResettableMutexGuard aLock(m_aLock);
519 impl_loadItemOnDemand(eType, sItem);
520 }
521
522 /*-----------------------------------------------
523 27.10.2003 08:14
524 -----------------------------------------------*/
addStatePropsToItem(EItemType eType,const::rtl::OUString & sItem,CacheItem & rItem)525 void FilterCache::addStatePropsToItem( EItemType eType,
526 const ::rtl::OUString& sItem,
527 CacheItem& rItem)
528 {
529 // SAFE ->
530 ::osl::ResettableMutexGuard aLock(m_aLock);
531
532 // Note: Opening of the configuration layer throws some exceptions
533 // if it failed. So we don't have to check any reference here ...
534 css::uno::Reference< css::container::XNameAccess > xPackage;
535 css::uno::Reference< css::container::XNameAccess > xSet;
536 switch(eType)
537 {
538 case E_TYPE :
539 {
540 xPackage = css::uno::Reference< css::container::XNameAccess >(impl_openConfig(E_PROVIDER_TYPES), css::uno::UNO_QUERY);
541 xPackage->getByName(CFGSET_TYPES) >>= xSet;
542 }
543 break;
544
545 case E_FILTER :
546 {
547 xPackage = css::uno::Reference< css::container::XNameAccess >(impl_openConfig(E_PROVIDER_FILTERS), css::uno::UNO_QUERY);
548 xPackage->getByName(CFGSET_FILTERS) >>= xSet;
549 }
550 break;
551
552 case E_FRAMELOADER :
553 {
554 /* TODO
555 Hack -->
556 The default frame loader can't be located inside the normal set of frame loaders.
557 It's an atomic property inside the misc cfg package. So we can't retrieve the information
558 about FINALIZED and MANDATORY very easy ... :-(
559 => set it to readonly/required every time :-)
560 */
561 css::uno::Any aDirectValue = impl_getDirectCFGValue(CFGDIRECTKEY_DEFAULTFRAMELOADER);
562 ::rtl::OUString sDefaultFrameLoader;
563 if (
564 (aDirectValue >>= sDefaultFrameLoader) &&
565 (sDefaultFrameLoader.getLength() ) &&
566 (sItem.equals(sDefaultFrameLoader) )
567 )
568 {
569 rItem[PROPNAME_FINALIZED] <<= sal_True;
570 rItem[PROPNAME_MANDATORY] <<= sal_True;
571 return;
572 }
573 /* <-- HACK */
574
575 xPackage = css::uno::Reference< css::container::XNameAccess >(impl_openConfig(E_PROVIDER_OTHERS), css::uno::UNO_QUERY);
576 xPackage->getByName(CFGSET_FRAMELOADERS) >>= xSet;
577 }
578 break;
579
580 case E_CONTENTHANDLER :
581 {
582 xPackage = css::uno::Reference< css::container::XNameAccess >(impl_openConfig(E_PROVIDER_OTHERS), css::uno::UNO_QUERY);
583 xPackage->getByName(CFGSET_CONTENTHANDLERS) >>= xSet;
584 }
585 break;
586 default: break;
587 }
588
589 try
590 {
591 css::uno::Reference< css::beans::XProperty > xItem;
592 xSet->getByName(sItem) >>= xItem;
593 css::beans::Property aDescription = xItem->getAsProperty();
594
595 sal_Bool bFinalized = ((aDescription.Attributes & css::beans::PropertyAttribute::READONLY ) == css::beans::PropertyAttribute::READONLY );
596 sal_Bool bMandatory = ((aDescription.Attributes & css::beans::PropertyAttribute::REMOVEABLE) != css::beans::PropertyAttribute::REMOVEABLE);
597
598 rItem[PROPNAME_FINALIZED] <<= bFinalized;
599 rItem[PROPNAME_MANDATORY] <<= bMandatory;
600 }
601 catch(const css::container::NoSuchElementException&)
602 {
603 /* Ignore exceptions for missing elements inside configuration.
604 Maybe the following reason exists:
605 - The item does not exists inside the new configuration package org.openoffice.TypeDetection - but
606 we got it from the old package org.openoffice.Office/TypeDetection. We don't migrate such items
607 automatically to the new format. Because it will disturb e.g. the deinstallation of an external filter
608 package. Because such external filter can remove the old file - but not the automatically created new one ...
609
610 => mark item as FINALIZED / MANDATORY, we don't support writing to the old format
611 */
612 rItem[PROPNAME_FINALIZED] <<= sal_True;
613 rItem[PROPNAME_MANDATORY] <<= sal_True;
614 }
615
616 // <- SAFE
617 }
618
619 /*-----------------------------------------------
620 05.03.2004 10:36
621 -----------------------------------------------*/
removeStatePropsFromItem(CacheItem & rItem)622 void FilterCache::removeStatePropsFromItem(CacheItem& rItem)
623 {
624 CacheItem::iterator pIt;
625 pIt = rItem.find(PROPNAME_FINALIZED);
626 if (pIt != rItem.end())
627 rItem.erase(pIt);
628 pIt = rItem.find(PROPNAME_MANDATORY);
629 if (pIt != rItem.end())
630 rItem.erase(pIt);
631 }
632
633 /*-----------------------------------------------
634 02.07.2003 09:17
635 -----------------------------------------------*/
flush()636 void FilterCache::flush()
637 {
638 // SAFE ->
639 ::osl::ResettableMutexGuard aLock(m_aLock);
640
641 // renew all dependencies and optimizations
642 impl_validateAndOptimize();
643
644 if (m_lChangedTypes.size() > 0)
645 {
646 css::uno::Reference< css::container::XNameAccess > xConfig(impl_openConfig(E_PROVIDER_TYPES), css::uno::UNO_QUERY);
647 css::uno::Reference< css::container::XNameAccess > xSet ;
648
649 xConfig->getByName(CFGSET_TYPES) >>= xSet;
650 impl_flushByList(xSet, E_TYPE, m_lTypes, m_lChangedTypes);
651
652 css::uno::Reference< css::util::XChangesBatch > xFlush(xConfig, css::uno::UNO_QUERY);
653 xFlush->commitChanges();
654 }
655
656 if (m_lChangedFilters.size() > 0)
657 {
658 css::uno::Reference< css::container::XNameAccess > xConfig(impl_openConfig(E_PROVIDER_FILTERS), css::uno::UNO_QUERY);
659 css::uno::Reference< css::container::XNameAccess > xSet ;
660
661 xConfig->getByName(CFGSET_FILTERS) >>= xSet;
662 impl_flushByList(xSet, E_FILTER, m_lFilters, m_lChangedFilters);
663
664 css::uno::Reference< css::util::XChangesBatch > xFlush(xConfig, css::uno::UNO_QUERY);
665 xFlush->commitChanges();
666 }
667
668 /*TODO FrameLoader/ContentHandler must be flushed here too ... */
669 }
670
671 /*-----------------------------------------------
672 20.10.2003 09:22
673 -----------------------------------------------*/
impl_flushByList(const css::uno::Reference<css::container::XNameAccess> & xSet,EItemType eType,const CacheItemList & rCache,const OUStringList & lItems)674 void FilterCache::impl_flushByList(const css::uno::Reference< css::container::XNameAccess >& xSet ,
675 EItemType eType ,
676 const CacheItemList& rCache,
677 const OUStringList& lItems)
678 {
679 css::uno::Reference< css::container::XNameContainer > xAddRemoveSet = css::uno::Reference< css::container::XNameContainer > (xSet, css::uno::UNO_QUERY);
680 css::uno::Reference< css::container::XNameReplace > xReplaceeSet = css::uno::Reference< css::container::XNameReplace > (xSet, css::uno::UNO_QUERY);
681 css::uno::Reference< css::lang::XSingleServiceFactory > xFactory = css::uno::Reference< css::lang::XSingleServiceFactory >(xSet, css::uno::UNO_QUERY);
682
683 for (OUStringList::const_iterator pIt = lItems.begin();
684 pIt != lItems.end() ;
685 ++pIt )
686 {
687 const ::rtl::OUString& sItem = *pIt;
688 EItemFlushState eState = impl_specifyFlushOperation(xSet, rCache, sItem);
689 switch(eState)
690 {
691 case E_ITEM_REMOVED :
692 {
693 xAddRemoveSet->removeByName(sItem);
694 }
695 break;
696
697 case E_ITEM_ADDED :
698 {
699 css::uno::Reference< css::container::XNameReplace > xItem (xFactory->createInstance(), css::uno::UNO_QUERY);
700
701 // special case. no exception - but not a valid item => set must be finalized or mandatory!
702 // Reject flush operation by throwing an exception. At least one item couldn't be flushed.
703 if (!xItem.is())
704 throw css::uno::Exception(::rtl::OUString::createFromAscii("Can't add item. Set is finalized or mandatory!"),
705 css::uno::Reference< css::uno::XInterface >() );
706
707 CacheItemList::const_iterator pItem = rCache.find(sItem);
708 impl_saveItem(xItem, eType, pItem->second);
709 xAddRemoveSet->insertByName(sItem, css::uno::makeAny(xItem));
710 }
711 break;
712
713 case E_ITEM_CHANGED :
714 {
715 css::uno::Reference< css::container::XNameReplace > xItem;
716 xSet->getByName(sItem) >>= xItem;
717
718 // special case. no exception - but not a valid item => it must be finalized or mandatory!
719 // Reject flush operation by throwing an exception. At least one item couldn't be flushed.
720 if (!xItem.is())
721 throw css::uno::Exception(::rtl::OUString::createFromAscii("Can't change item. It's finalized or mandatory!"),
722 css::uno::Reference< css::uno::XInterface >() );
723
724 CacheItemList::const_iterator pItem = rCache.find(sItem);
725 impl_saveItem(xItem, eType, pItem->second);
726 }
727 break;
728 default: break;
729 }
730 }
731 }
732
733 /*-----------------------------------------------
734 03.11.2003 08:38
735 -----------------------------------------------*/
detectFlatForURL(const css::util::URL & aURL,FlatDetection & rFlatTypes) const736 void FilterCache::detectFlatForURL(const css::util::URL& aURL ,
737 FlatDetection& rFlatTypes) const
738 {
739 // extract extension from URL, so it can be used directly as key into our hash map!
740 // Note further: It must be converted to lower case, because the optimize hash
741 // (which maps extensions to types) work with lower case key strings!
742 INetURLObject aParser (aURL.Main);
743 ::rtl::OUString sExtension = aParser.getExtension(INetURLObject::LAST_SEGMENT ,
744 sal_True ,
745 INetURLObject::DECODE_WITH_CHARSET);
746 sExtension = sExtension.toAsciiLowerCase();
747
748 // SAFE -> ----------------------------------
749 ::osl::ResettableMutexGuard aLock(m_aLock);
750
751 //*******************************************
752 // i) Step over all well known URL pattern
753 // and add registered types to the return list too
754 // Do it as first one - because: if a type match by a
755 // pattern a following deep detection can be suppressed!
756 // Further we can stop after first match ...
757 for (CacheItemRegistration::const_iterator pPattReg = m_lURLPattern2Types.begin();
758 pPattReg != m_lURLPattern2Types.end() ;
759 ++pPattReg )
760 {
761 WildCard aPatternCheck(pPattReg->first);
762 if (aPatternCheck.Matches(aURL.Main))
763 {
764 const OUStringList& rTypesForPattern = pPattReg->second;
765
766 FlatDetectionInfo aInfo;
767 aInfo.sType = *(rTypesForPattern.begin());
768 aInfo.bMatchByPattern = sal_True;
769
770 rFlatTypes.push_back(aInfo);
771 // return;
772 }
773 }
774
775 //*******************************************
776 // ii) search types matching to the given extension.
777 // Copy every matching type without changing its order!
778 // Because preferred type was added as first one during
779 // loading configuration.
780 CacheItemRegistration::const_iterator pExtReg = m_lExtensions2Types.find(sExtension);
781 if (pExtReg != m_lExtensions2Types.end())
782 {
783 const OUStringList& rTypesForExtension = pExtReg->second;
784 for (OUStringList::const_iterator pIt = rTypesForExtension.begin();
785 pIt != rTypesForExtension.end() ;
786 ++pIt )
787 {
788 FlatDetectionInfo aInfo;
789 aInfo.sType = *pIt;
790 aInfo.bMatchByExtension = sal_True;
791
792 rFlatTypes.push_back(aInfo);
793 }
794 }
795
796 aLock.clear();
797 // <- SAFE ----------------------------------
798 }
799
800 /*-----------------------------------------------
801 03.11.2003 08:38
802 -----------------------------------------------*/
impl_getItemList(EItemType eType) const803 CacheItemList& FilterCache::impl_getItemList(EItemType eType) const
804 {
805 // SAFE -> ----------------------------------
806 ::osl::ResettableMutexGuard aLock(m_aLock);
807
808 switch(eType)
809 {
810 case E_TYPE : return m_lTypes ;
811 case E_FILTER : return m_lFilters ;
812 case E_FRAMELOADER : return m_lFrameLoaders ;
813 case E_CONTENTHANDLER : return m_lContentHandlers;
814 case E_DETECTSERVICE : return m_lDetectServices ;
815
816 default : throw css::uno::Exception(::rtl::OUString::createFromAscii("unknown sub container requested."),
817 css::uno::Reference< css::uno::XInterface >() );
818 }
819
820 // <- SAFE ----------------------------------
821 }
822
823 /*-----------------------------------------------
824 21.10.2003 13:20
825 -----------------------------------------------*/
impl_openConfig(EConfigProvider eProvider)826 css::uno::Reference< css::uno::XInterface > FilterCache::impl_openConfig(EConfigProvider eProvider)
827 {
828 // SAFE ->
829 ::osl::ResettableMutexGuard aLock(m_aLock);
830
831 ::rtl::OUString sPath ;
832 css::uno::Reference< css::uno::XInterface >* pConfig = 0;
833 css::uno::Reference< css::uno::XInterface > xOld ;
834 ::rtl::OString sRtlLog ;
835 FilterCache::EItemType eItemType( FilterCache::E_TYPE ) ;
836 sal_Bool bStartListening = sal_False;
837
838 switch(eProvider)
839 {
840 case E_PROVIDER_TYPES :
841 {
842 if (m_xConfigTypes.is())
843 return m_xConfigTypes;
844 sPath = CFGPACKAGE_TD_TYPES;
845 pConfig = &m_xConfigTypes;
846 eItemType = FilterCache::E_TYPE;
847 bStartListening = sal_True;
848 sRtlLog = ::rtl::OString("framework (as96863) ::FilterCache::impl_openconfig(E_PROVIDER_TYPES)");
849 }
850 break;
851
852 case E_PROVIDER_FILTERS :
853 {
854 if (m_xConfigFilters.is())
855 return m_xConfigFilters;
856 sPath = CFGPACKAGE_TD_FILTERS;
857 pConfig = &m_xConfigFilters;
858 eItemType = FilterCache::E_FILTER;
859 bStartListening = sal_True;
860 sRtlLog = ::rtl::OString("framework (as96863) ::FilterCache::impl_openconfig(E_PROVIDER_FILTERS)");
861 }
862 break;
863
864 case E_PROVIDER_OTHERS :
865 {
866 if (m_xConfigOthers.is())
867 return m_xConfigOthers;
868 sPath = CFGPACKAGE_TD_OTHERS;
869 pConfig = &m_xConfigOthers;
870 eItemType = FilterCache::E_TYPE;
871 sRtlLog = ::rtl::OString("framework (as96863) ::FilterCache::impl_openconfig(E_PROVIDER_OTHERS)");
872 }
873 break;
874
875 case E_PROVIDER_OLD :
876 {
877 // This special provider is used to work with
878 // the old configuration format only. It's not cached!
879 sPath = CFGPACKAGE_TD_OLD;
880 pConfig = &xOld;
881 sRtlLog = ::rtl::OString("framework (as96863) ::FilterCache::impl_openconfig(E_PROVIDER_OLD)");
882 }
883 break;
884
885 default : throw css::uno::Exception(::rtl::OUString::createFromAscii("These configuration node isn't supported here for open!"), 0);
886 }
887
888 {
889 RTL_LOGFILE_CONTEXT(aLog, sRtlLog.getStr());
890 *pConfig = impl_createConfigAccess(sPath ,
891 sal_False, // bReadOnly
892 sal_True ); // bLocalesMode
893 }
894
895 // Start listening for changes on that configuration access.
896 // We must not control the lifetime of this listener. Itself
897 // checks, when it's time to die :-)
898 if (bStartListening)
899 {
900 CacheUpdateListener* pListener = new CacheUpdateListener(m_xSMGR, *pConfig, eItemType);
901 pListener->startListening();
902 }
903
904 return *pConfig;
905 // <- SAFE
906 }
907
908 /*-----------------------------------------------
909 17.07.2003 10:10
910 -----------------------------------------------*/
impl_getDirectCFGValue(const::rtl::OUString & sDirectKey)911 css::uno::Any FilterCache::impl_getDirectCFGValue(const ::rtl::OUString& sDirectKey)
912 {
913 ::rtl::OUString sRoot;
914 ::rtl::OUString sKey ;
915
916 if (
917 (!::utl::splitLastFromConfigurationPath(sDirectKey, sRoot, sKey)) ||
918 (!sRoot.getLength() ) ||
919 (!sKey.getLength() )
920 )
921 return css::uno::Any();
922
923 css::uno::Reference< css::uno::XInterface > xCfg = impl_createConfigAccess(sRoot ,
924 sal_True , // bReadOnly
925 sal_False); // bLocalesMode
926 if (!xCfg.is())
927 return css::uno::Any();
928
929 css::uno::Reference< css::container::XNameAccess > xAccess(xCfg, css::uno::UNO_QUERY);
930 if (!xAccess.is())
931 return css::uno::Any();
932
933 css::uno::Any aValue;
934 try
935 {
936 aValue = xAccess->getByName(sKey);
937 }
938 catch(const css::uno::RuntimeException& exRun)
939 { throw exRun; }
940 #if OSL_DEBUG_LEVEL>0
941 catch(const css::uno::Exception& ex)
942 #else
943 catch(const css::uno::Exception&)
944 #endif
945 {
946 #if OSL_DEBUG_LEVEL > 0
947 OSL_ENSURE(sal_False, ::rtl::OUStringToOString(ex.Message, RTL_TEXTENCODING_UTF8).getStr());
948 #endif
949 aValue.clear();
950 }
951
952 return aValue;
953 }
954
955 /*-----------------------------------------------
956 17.07.2003 09:49
957 -----------------------------------------------*/
impl_createConfigAccess(const::rtl::OUString & sRoot,sal_Bool bReadOnly,sal_Bool bLocalesMode)958 css::uno::Reference< css::uno::XInterface > FilterCache::impl_createConfigAccess(const ::rtl::OUString& sRoot ,
959 sal_Bool bReadOnly ,
960 sal_Bool bLocalesMode)
961 {
962 // SAFE ->
963 ::osl::ResettableMutexGuard aLock(m_aLock);
964
965 css::uno::Reference< css::uno::XInterface > xCfg;
966
967 try
968 {
969 css::uno::Reference< css::lang::XMultiServiceFactory > xConfigProvider(
970 m_xSMGR->createInstance(SERVICE_CONFIGURATIONPROVIDER), css::uno::UNO_QUERY);
971
972 if (!xConfigProvider.is())
973 return css::uno::Reference< css::uno::XInterface >();
974
975 ::comphelper::SequenceAsVector< css::uno::Any > lParams;
976 css::beans::PropertyValue aParam ;
977
978 // set root path
979 aParam.Name = _FILTER_CONFIG_FROM_ASCII_("nodepath");
980 aParam.Value <<= sRoot;
981 lParams.push_back(css::uno::makeAny(aParam));
982
983 // enable "all locales mode" ... if required
984 if (bLocalesMode)
985 {
986 aParam.Name = _FILTER_CONFIG_FROM_ASCII_("locale");
987 aParam.Value <<= _FILTER_CONFIG_FROM_ASCII_("*" );
988 lParams.push_back(css::uno::makeAny(aParam));
989 }
990
991 // open it
992 if (bReadOnly)
993 xCfg = xConfigProvider->createInstanceWithArguments(SERVICE_CONFIGURATIONACCESS, lParams.getAsConstList());
994 else
995 xCfg = xConfigProvider->createInstanceWithArguments(SERVICE_CONFIGURATIONUPDATEACCESS, lParams.getAsConstList());
996
997 // If configuration could not be opened ... but factory method does not throw an exception
998 // trigger throwing of our own CorruptedFilterConfigurationException.
999 // Let message empty. The normal exception text show enough informations to the user.
1000 if (! xCfg.is())
1001 throw css::uno::Exception(
1002 _FILTER_CONFIG_FROM_ASCII_("Got NULL reference on opening configuration file ... but no exception."),
1003 css::uno::Reference< css::uno::XInterface >());
1004 }
1005 catch(const css::uno::Exception& ex)
1006 {
1007 throw css::document::CorruptedFilterConfigurationException(
1008 MESSAGE_CORRUPTED_FILTERCONFIG,
1009 css::uno::Reference< css::uno::XInterface >(),
1010 ex.Message);
1011 }
1012
1013 return xCfg;
1014 // <- SAFE
1015 }
1016
1017 /*-----------------------------------------------
1018 24.10.2003 10:03
1019 -----------------------------------------------*/
impl_validateAndOptimize()1020 void FilterCache::impl_validateAndOptimize()
1021 {
1022 // SAFE ->
1023 ::osl::ResettableMutexGuard aLock(m_aLock);
1024
1025 RTL_LOGFILE_CONTEXT( aLog, "framework (as96863) ::FilterCache::impl_validateAndOptimize");
1026
1027 // First check if any filter or type could be read
1028 // from the underlying configuration!
1029 sal_Bool bSomeTypesShouldExist = ((m_eFillState & E_CONTAINS_STANDARD ) == E_CONTAINS_STANDARD );
1030 sal_Bool bAllFiltersShouldExist = ((m_eFillState & E_CONTAINS_FILTERS ) == E_CONTAINS_FILTERS );
1031
1032 #if OSL_DEBUG_LEVEL > 0
1033
1034 sal_Int32 nWarnings = 0;
1035
1036 // sal_Bool bAllTypesShouldExist = ((m_eFillState & E_CONTAINS_TYPES ) == E_CONTAINS_TYPES );
1037 sal_Bool bAllLoadersShouldExist = ((m_eFillState & E_CONTAINS_FRAMELOADERS ) == E_CONTAINS_FRAMELOADERS );
1038 sal_Bool bAllHandlersShouldExist = ((m_eFillState & E_CONTAINS_CONTENTHANDLERS) == E_CONTAINS_CONTENTHANDLERS);
1039 #endif
1040
1041 if (
1042 (
1043 (bSomeTypesShouldExist) &&
1044 (m_lTypes.size() < 1 )
1045 ) ||
1046 (
1047 (bAllFiltersShouldExist) &&
1048 (m_lFilters.size() < 1 )
1049 )
1050 )
1051 {
1052 throw css::document::CorruptedFilterConfigurationException(
1053 MESSAGE_CORRUPTED_FILTERCONFIG,
1054 css::uno::Reference< css::uno::XInterface >(),
1055 ::rtl::OUString::createFromAscii("The list of types or filters is empty."));
1056 }
1057
1058 // Create a log for all detected problems, which
1059 // occur in the next few lines.
1060 // If there are some real errors throw a RuntimException!
1061 // If there are some warnings only, show an assertion.
1062 sal_Int32 nErrors = 0;
1063 ::rtl::OUStringBuffer sLog(256);
1064
1065 CacheItemList::iterator pIt;
1066
1067 for (pIt = m_lTypes.begin(); pIt != m_lTypes.end(); ++pIt)
1068 {
1069 ::rtl::OUString sType = pIt->first;
1070 CacheItem aType = pIt->second;
1071
1072 // create list of all known detect services / frame loader / content handler on demand
1073 // Because these informations are available as type properties!
1074 ::rtl::OUString sDetectService;
1075 aType[PROPNAME_DETECTSERVICE ] >>= sDetectService;
1076 if (sDetectService.getLength())
1077 impl_resolveItem4TypeRegistration(&m_lDetectServices, sDetectService, sType);
1078
1079 // get its registration for file Extensions AND(!) URLPattern ...
1080 // It doesn't matter if these items exists or if our
1081 // used index access create some default ones ...
1082 // only in case there is no filled set of Extensions AND
1083 // no filled set of URLPattern -> we must try to remove this invalid item
1084 // from this cache!
1085 css::uno::Sequence< ::rtl::OUString > lExtensions;
1086 css::uno::Sequence< ::rtl::OUString > lURLPattern;
1087 aType[PROPNAME_EXTENSIONS] >>= lExtensions;
1088 aType[PROPNAME_URLPATTERN] >>= lURLPattern;
1089 sal_Int32 ce = lExtensions.getLength();
1090 sal_Int32 cu = lURLPattern.getLength();
1091
1092 #if OSL_DEBUG_LEVEL > 0
1093
1094 ::rtl::OUString sInternalTypeNameCheck;
1095 aType[PROPNAME_NAME] >>= sInternalTypeNameCheck;
1096 if (!sInternalTypeNameCheck.equals(sType))
1097 {
1098 sLog.appendAscii("Warning\t:\t");
1099 sLog.appendAscii("The type \"" );
1100 sLog.append (sType );
1101 sLog.appendAscii("\" does support the property \"Name\" correctly.\n");
1102 ++nWarnings;
1103 }
1104
1105 if (!ce && !cu)
1106 {
1107 sLog.appendAscii("Warning\t:\t");
1108 sLog.appendAscii("The type \"" );
1109 sLog.append (sType );
1110 sLog.appendAscii("\" does not contain any URL pattern nor any extensions.\n");
1111 ++nWarnings;
1112 }
1113 #endif
1114
1115 // create an optimized registration for this type to
1116 // its set list of extensions/url pattern. If it's a "normal" type
1117 // set it at the end of this optimized list. But if it's
1118 // a "Preferred" one - set it to the front of this list.
1119 // Of course multiple "Preferred" registrations can occur
1120 // (they shouldn't - but they can!) ... Ignore it. The last
1121 // preferred type is usable in the same manner then every
1122 // other type!
1123 sal_Bool bPreferred = sal_False;
1124 aType[PROPNAME_PREFERRED] >>= bPreferred;
1125
1126 const ::rtl::OUString* pExtensions = lExtensions.getConstArray();
1127 for (sal_Int32 e=0; e<ce; ++e)
1128 {
1129 // Note: We must be sure that address the right hash entry
1130 // does not depend from any upper/lower case problems ...
1131 ::rtl::OUString sNormalizedExtension = pExtensions[e].toAsciiLowerCase();
1132
1133 OUStringList& lTypesForExtension = m_lExtensions2Types[sNormalizedExtension];
1134 if (::std::find(lTypesForExtension.begin(), lTypesForExtension.end(), sType) != lTypesForExtension.end())
1135 continue;
1136
1137 if (bPreferred)
1138 lTypesForExtension.insert(lTypesForExtension.begin(), sType);
1139 else
1140 lTypesForExtension.push_back(sType);
1141 }
1142
1143 const ::rtl::OUString* pURLPattern = lURLPattern.getConstArray();
1144 for (sal_Int32 u=0; u<cu; ++u)
1145 {
1146 OUStringList& lTypesForURLPattern = m_lURLPattern2Types[pURLPattern[u]];
1147 if (::std::find(lTypesForURLPattern.begin(), lTypesForURLPattern.end(), sType) != lTypesForURLPattern.end())
1148 continue;
1149
1150 if (bPreferred)
1151 lTypesForURLPattern.insert(lTypesForURLPattern.begin(), sType);
1152 else
1153 lTypesForURLPattern.push_back(sType);
1154 }
1155
1156 #if OSL_DEBUG_LEVEL > 0
1157
1158 // Don't check cross references between types and filters, if
1159 // not all filters read from disk!
1160 // OK - this cache can read single filters on demand too ...
1161 // but then the fill state of this cache shouldn't be set to E_CONTAINS_FILTERS!
1162 if (!bAllFiltersShouldExist)
1163 continue;
1164
1165 ::rtl::OUString sPrefFilter;
1166 aType[PROPNAME_PREFERREDFILTER] >>= sPrefFilter;
1167 if (!sPrefFilter.getLength())
1168 {
1169 // OK - there is no filter for this type. But that's not an error.
1170 // Maybe it can be handled by a ContentHandler ...
1171 // But at this time it's not guaranteed that there is any ContentHandler
1172 // or FrameLoader inside this cache ... but on disk ...
1173 sal_Bool bReferencedByLoader = sal_True;
1174 sal_Bool bReferencedByHandler = sal_True;
1175 if (bAllLoadersShouldExist)
1176 bReferencedByLoader = (impl_searchFrameLoaderForType(sType).getLength()!=0);
1177
1178 if (bAllHandlersShouldExist)
1179 bReferencedByHandler = (impl_searchContentHandlerForType(sType).getLength()!=0);
1180
1181 if (
1182 (!bReferencedByLoader ) &&
1183 (!bReferencedByHandler)
1184 )
1185 {
1186 sLog.appendAscii("Warning\t:\t" );
1187 sLog.appendAscii("The type \"" );
1188 sLog.append (sType );
1189 sLog.appendAscii("\" isn't used by any filter, loader or content handler.\n");
1190 ++nWarnings;
1191 }
1192 }
1193
1194 if (sPrefFilter.getLength())
1195 {
1196 CacheItemList::const_iterator pIt2 = m_lFilters.find(sPrefFilter);
1197 if (pIt2 == m_lFilters.end())
1198 {
1199 if (bAllFiltersShouldExist)
1200 {
1201 ++nWarnings; // preferred filters can point to a non-installed office module ! no error ... it's a warning only .-(
1202 sLog.appendAscii("error\t:\t");
1203 }
1204 else
1205 {
1206 ++nWarnings;
1207 sLog.appendAscii("warning\t:\t");
1208 }
1209
1210 sLog.appendAscii("The type \"" );
1211 sLog.append (sType );
1212 sLog.appendAscii("\" points to an invalid filter \"");
1213 sLog.append (sPrefFilter );
1214 sLog.appendAscii("\".\n" );
1215
1216 continue;
1217 }
1218
1219 CacheItem aPrefFilter = pIt2->second;
1220 ::rtl::OUString sFilterTypeReg;
1221 aPrefFilter[PROPNAME_TYPE] >>= sFilterTypeReg;
1222 if (sFilterTypeReg != sType)
1223 {
1224 sLog.appendAscii("error\t:\t" );
1225 sLog.appendAscii("The preferred filter \"" );
1226 sLog.append (sPrefFilter );
1227 sLog.appendAscii("\" of type \"" );
1228 sLog.append (sType );
1229 sLog.appendAscii("is registered for another type \"");
1230 sLog.append (sFilterTypeReg );
1231 sLog.appendAscii("\".\n" );
1232 ++nErrors;
1233 }
1234
1235 sal_Int32 nFlags = 0;
1236 aPrefFilter[PROPNAME_FLAGS] >>= nFlags;
1237 if ((nFlags & FLAGVAL_IMPORT) != FLAGVAL_IMPORT)
1238 {
1239 sLog.appendAscii("error\t:\t" );
1240 sLog.appendAscii("The preferred filter \"" );
1241 sLog.append (sPrefFilter );
1242 sLog.appendAscii("\" of type \"" );
1243 sLog.append (sType );
1244 sLog.appendAscii("\" is not an IMPORT filter!\n");
1245 ++nErrors;
1246 }
1247
1248 ::rtl::OUString sInternalFilterNameCheck;
1249 aPrefFilter[PROPNAME_NAME] >>= sInternalFilterNameCheck;
1250 if (!sInternalFilterNameCheck.equals(sPrefFilter))
1251 {
1252 sLog.appendAscii("Warning\t:\t" );
1253 sLog.appendAscii("The filter \"" );
1254 sLog.append (sPrefFilter );
1255 sLog.appendAscii("\" does support the property \"Name\" correctly.\n");
1256 ++nWarnings;
1257 }
1258 }
1259 #endif
1260 }
1261
1262 // create dependencies between the global default frame loader
1263 // and all types (and of course if registered filters), which
1264 // does not registered for any other loader.
1265 css::uno::Any aDirectValue = impl_getDirectCFGValue(CFGDIRECTKEY_DEFAULTFRAMELOADER);
1266 ::rtl::OUString sDefaultFrameLoader;
1267
1268 if (
1269 (!(aDirectValue >>= sDefaultFrameLoader)) ||
1270 (!sDefaultFrameLoader.getLength() )
1271 )
1272 {
1273 sLog.appendAscii("error\t:\t" );
1274 sLog.appendAscii("There is no valid default frame loader!?\n");
1275 ++nErrors;
1276 }
1277
1278 // a) get list of all well known types
1279 // b) step over all well known frame loader services
1280 // and remove all types from list a), which already
1281 // referenced by a loader b)
1282 OUStringList lTypes = getItemNames(E_TYPE);
1283 for ( pIt = m_lFrameLoaders.begin();
1284 pIt != m_lFrameLoaders.end() ;
1285 ++pIt )
1286 {
1287 // Note: of course the default loader must be ignored here.
1288 // Because we replace its registration later completely with all
1289 // types, which are not referenced by any other loader.
1290 // So we can avoid our code against the complexity of a diff!
1291 ::rtl::OUString sLoader = pIt->first;
1292 if (sLoader.equals(sDefaultFrameLoader))
1293 continue;
1294
1295 CacheItem& rLoader = pIt->second;
1296 css::uno::Any& rTypesReg = rLoader[PROPNAME_TYPES];
1297 OUStringList lTypesReg (rTypesReg);
1298
1299 for (OUStringList::const_iterator pTypesReg = lTypesReg.begin();
1300 pTypesReg != lTypesReg.end() ;
1301 ++pTypesReg )
1302 {
1303 OUStringList::iterator pTypeCheck = ::std::find(lTypes.begin(), lTypes.end(), *pTypesReg);
1304 if (pTypeCheck != lTypes.end())
1305 lTypes.erase(pTypeCheck);
1306 }
1307 }
1308
1309 CacheItem& rDefaultLoader = m_lFrameLoaders[sDefaultFrameLoader];
1310 rDefaultLoader[PROPNAME_NAME ] <<= sDefaultFrameLoader;
1311 rDefaultLoader[PROPNAME_TYPES] <<= lTypes.getAsConstList();
1312
1313 ::rtl::OUString sLogOut = sLog.makeStringAndClear();
1314 OSL_ENSURE(!nErrors, ::rtl::OUStringToOString(sLogOut,RTL_TEXTENCODING_UTF8).getStr());
1315 if (nErrors>0)
1316 throw css::document::CorruptedFilterConfigurationException(
1317 MESSAGE_CORRUPTED_FILTERCONFIG,
1318 css::uno::Reference< css::uno::XInterface >(),
1319 sLogOut);
1320 OSL_ENSURE(!nWarnings, ::rtl::OUStringToOString(sLogOut,RTL_TEXTENCODING_UTF8).getStr());
1321
1322 // <- SAFE
1323 }
1324
1325 /*-----------------------------------------------
1326 20.10.2003 08:15
1327 -----------------------------------------------*/
impl_addItem2FlushList(EItemType eType,const::rtl::OUString & sItem)1328 void FilterCache::impl_addItem2FlushList( EItemType eType,
1329 const ::rtl::OUString& sItem)
1330 {
1331 OUStringList* pList = 0;
1332 switch(eType)
1333 {
1334 case E_TYPE :
1335 pList = &m_lChangedTypes;
1336 break;
1337
1338 case E_FILTER :
1339 pList = &m_lChangedFilters;
1340 break;
1341
1342 case E_FRAMELOADER :
1343 pList = &m_lChangedFrameLoaders;
1344 break;
1345
1346 case E_CONTENTHANDLER :
1347 pList = &m_lChangedContentHandlers;
1348 break;
1349
1350 case E_DETECTSERVICE :
1351 pList = &m_lChangedDetectServices;
1352 break;
1353
1354 default : throw css::uno::Exception(::rtl::OUString::createFromAscii("unsupported item type"), 0);
1355 }
1356
1357 OUStringList::const_iterator pItem = ::std::find(pList->begin(), pList->end(), sItem);
1358 if (pItem == pList->end())
1359 pList->push_back(sItem);
1360 }
1361
1362 /*-----------------------------------------------
1363 20.10.2003 08:49
1364 -----------------------------------------------*/
impl_specifyFlushOperation(const css::uno::Reference<css::container::XNameAccess> & xSet,const CacheItemList & rList,const::rtl::OUString & sItem)1365 FilterCache::EItemFlushState FilterCache::impl_specifyFlushOperation(const css::uno::Reference< css::container::XNameAccess >& xSet ,
1366 const CacheItemList& rList,
1367 const ::rtl::OUString& sItem)
1368 {
1369 sal_Bool bExistsInConfigLayer = xSet->hasByName(sItem);
1370 sal_Bool bExistsInMemory = (rList.find(sItem) != rList.end());
1371
1372 EItemFlushState eState( E_ITEM_UNCHANGED );
1373
1374 // !? ... such a situation can occur, if an item was added and(!) removed before it was flushed :-)
1375 if (!bExistsInConfigLayer && !bExistsInMemory)
1376 eState = E_ITEM_UNCHANGED;
1377 else
1378 if (!bExistsInConfigLayer && bExistsInMemory)
1379 eState = E_ITEM_ADDED;
1380 else
1381 if (bExistsInConfigLayer && bExistsInMemory)
1382 eState = E_ITEM_CHANGED;
1383 else
1384 if (bExistsInConfigLayer && !bExistsInMemory)
1385 eState = E_ITEM_REMOVED;
1386
1387 return eState;
1388 }
1389
1390 /*-----------------------------------------------
1391 14.10.2003 09:26
1392 -----------------------------------------------*/
impl_resolveItem4TypeRegistration(CacheItemList * pList,const::rtl::OUString & sItem,const::rtl::OUString & sType)1393 void FilterCache::impl_resolveItem4TypeRegistration( CacheItemList* pList,
1394 const ::rtl::OUString& sItem,
1395 const ::rtl::OUString& sType)
1396 {
1397 CacheItem& rItem = (*pList)[sItem];
1398 // In case it's a new created entry (automatically done by the unordered_map index operator!)
1399 // we must be sure, that this entry has its own name as property available.
1400 // It's needed later at our container interface!
1401 rItem[PROPNAME_NAME] <<= sItem;
1402
1403 OUStringList lTypeRegs(rItem[PROPNAME_TYPES]);
1404 if (::std::find(lTypeRegs.begin(), lTypeRegs.end(), sType) == lTypeRegs.end())
1405 {
1406 lTypeRegs.push_back(sType);
1407 rItem[PROPNAME_TYPES] <<= lTypeRegs.getAsConstList();
1408 }
1409 }
1410
1411 /*-----------------------------------------------
1412 28.10.2003 09:18
1413 -----------------------------------------------*/
impl_load(EFillState eRequiredState)1414 void FilterCache::impl_load(EFillState eRequiredState)
1415 {
1416 // SAFE ->
1417 ::osl::ResettableMutexGuard aLock(m_aLock);
1418
1419 // Attention: Detect services are part of the standard set!
1420 // So there is no need to handle it separately.
1421
1422 // ------------------------------------------
1423 // a) The standard set of config value is needed.
1424 if (
1425 ((eRequiredState & E_CONTAINS_STANDARD) == E_CONTAINS_STANDARD) &&
1426 ((m_eFillState & E_CONTAINS_STANDARD) != E_CONTAINS_STANDARD)
1427 )
1428 {
1429 // Attention! If config couldn't be opened successfully
1430 // and exception os thrown automatically and must be forwarded
1431 // to our calli ...
1432 css::uno::Reference< css::container::XNameAccess > xTypes(impl_openConfig(E_PROVIDER_TYPES), css::uno::UNO_QUERY);
1433 {
1434 RTL_LOGFILE_CONTEXT( aLog, "framework (as96863) ::FilterCache::load std");
1435 impl_loadSet(xTypes, E_TYPE, E_READ_STANDARD, &m_lTypes);
1436 }
1437 }
1438
1439 // ------------------------------------------
1440 // b) We need all type informations ...
1441 if (
1442 ((eRequiredState & E_CONTAINS_TYPES) == E_CONTAINS_TYPES) &&
1443 ((m_eFillState & E_CONTAINS_TYPES) != E_CONTAINS_TYPES)
1444 )
1445 {
1446 // Attention! If config couldn't be opened successfully
1447 // and exception os thrown automatically and must be forwarded
1448 // to our calli ...
1449 css::uno::Reference< css::container::XNameAccess > xTypes(impl_openConfig(E_PROVIDER_TYPES), css::uno::UNO_QUERY);
1450 {
1451 RTL_LOGFILE_CONTEXT( aLog, "framework (as96863) ::FilterCache::load all types");
1452 impl_loadSet(xTypes, E_TYPE, E_READ_UPDATE, &m_lTypes);
1453 }
1454 }
1455
1456 // ------------------------------------------
1457 // c) We need all filter informations ...
1458 if (
1459 ((eRequiredState & E_CONTAINS_FILTERS) == E_CONTAINS_FILTERS) &&
1460 ((m_eFillState & E_CONTAINS_FILTERS) != E_CONTAINS_FILTERS)
1461 )
1462 {
1463 // Attention! If config couldn't be opened successfully
1464 // and exception os thrown automatically and must be forwarded
1465 // to our calli ...
1466 css::uno::Reference< css::container::XNameAccess > xFilters(impl_openConfig(E_PROVIDER_FILTERS), css::uno::UNO_QUERY);
1467 {
1468 RTL_LOGFILE_CONTEXT( aLog, "framework (as96863) ::FilterCache::load all filters");
1469 impl_loadSet(xFilters, E_FILTER, E_READ_ALL, &m_lFilters);
1470 }
1471 }
1472
1473 // ------------------------------------------
1474 // c) We need all frame loader informations ...
1475 if (
1476 ((eRequiredState & E_CONTAINS_FRAMELOADERS) == E_CONTAINS_FRAMELOADERS) &&
1477 ((m_eFillState & E_CONTAINS_FRAMELOADERS) != E_CONTAINS_FRAMELOADERS)
1478 )
1479 {
1480 // Attention! If config couldn't be opened successfully
1481 // and exception os thrown automatically and must be forwarded
1482 // to our calli ...
1483 css::uno::Reference< css::container::XNameAccess > xLoaders(impl_openConfig(E_PROVIDER_OTHERS), css::uno::UNO_QUERY);
1484 {
1485 RTL_LOGFILE_CONTEXT( aLog, "framework (as96863) ::FilterCache::load all frame loader");
1486 impl_loadSet(xLoaders, E_FRAMELOADER, E_READ_ALL, &m_lFrameLoaders);
1487 }
1488 }
1489
1490 // ------------------------------------------
1491 // d) We need all content handler informations ...
1492 if (
1493 ((eRequiredState & E_CONTAINS_CONTENTHANDLERS) == E_CONTAINS_CONTENTHANDLERS) &&
1494 ((m_eFillState & E_CONTAINS_CONTENTHANDLERS) != E_CONTAINS_CONTENTHANDLERS)
1495 )
1496 {
1497 // Attention! If config couldn't be opened successfully
1498 // and exception os thrown automatically and must be forwarded
1499 // to our calli ...
1500 css::uno::Reference< css::container::XNameAccess > xHandlers(impl_openConfig(E_PROVIDER_OTHERS), css::uno::UNO_QUERY);
1501 {
1502 RTL_LOGFILE_CONTEXT( aLog, "framework (as96863) ::FilterCache::load all content handler");
1503 impl_loadSet(xHandlers, E_CONTENTHANDLER, E_READ_ALL, &m_lContentHandlers);
1504 }
1505 }
1506
1507 // update fill state. Note: it's a bit field, which combines different parts.
1508 m_eFillState = (EFillState) ((sal_Int32)m_eFillState | (sal_Int32)eRequiredState);
1509
1510 // any data read?
1511 // yes! => validate it and update optimized structures.
1512 impl_validateAndOptimize();
1513
1514 // <- SAFE
1515 }
1516
1517 /*-----------------------------------------------
1518 22.09.2003 14:27
1519 -----------------------------------------------*/
impl_loadSet(const css::uno::Reference<css::container::XNameAccess> & xConfig,EItemType eType,EReadOption eOption,CacheItemList * pCache)1520 void FilterCache::impl_loadSet(const css::uno::Reference< css::container::XNameAccess >& xConfig,
1521 EItemType eType ,
1522 EReadOption eOption,
1523 CacheItemList* pCache )
1524 {
1525 // get access to the right configuration set
1526 ::rtl::OUString sSetName;
1527 switch(eType)
1528 {
1529 case E_TYPE :
1530 sSetName = CFGSET_TYPES;
1531 break;
1532
1533 case E_FILTER :
1534 sSetName = CFGSET_FILTERS;
1535 break;
1536
1537 case E_FRAMELOADER :
1538 sSetName = CFGSET_FRAMELOADERS;
1539 break;
1540
1541 case E_CONTENTHANDLER :
1542 sSetName = CFGSET_CONTENTHANDLERS;
1543 break;
1544 default: break;
1545 }
1546
1547 css::uno::Reference< css::container::XNameAccess > xSet;
1548 css::uno::Sequence< ::rtl::OUString > lItems;
1549
1550 try
1551 {
1552 css::uno::Any aVal = xConfig->getByName(sSetName);
1553 if (!(aVal >>= xSet) || !xSet.is())
1554 {
1555 ::rtl::OUStringBuffer sMsg(256);
1556 sMsg.appendAscii("Could not open configuration set \"");
1557 sMsg.append (sSetName );
1558 sMsg.appendAscii("\"." );
1559 throw css::uno::Exception(
1560 sMsg.makeStringAndClear(),
1561 css::uno::Reference< css::uno::XInterface >());
1562 }
1563 lItems = xSet->getElementNames();
1564 }
1565 catch(const css::uno::Exception& ex)
1566 {
1567 throw css::document::CorruptedFilterConfigurationException(
1568 MESSAGE_CORRUPTED_FILTERCONFIG,
1569 css::uno::Reference< css::uno::XInterface >(),
1570 ex.Message);
1571 }
1572
1573 // get names of all existing sub items of this set
1574 // step over it and fill internal cache structures.
1575
1576 // But don't update optimized structures like e.g. hash
1577 // for mapping extensions to its types!
1578
1579 const ::rtl::OUString* pItems = lItems.getConstArray();
1580 sal_Int32 c = lItems.getLength();
1581 for (sal_Int32 i=0; i<c; ++i)
1582 {
1583 CacheItemList::iterator pItem = pCache->find(pItems[i]);
1584 switch(eOption)
1585 {
1586 // a) read a standard set of properties only or read all
1587 case E_READ_STANDARD :
1588 case E_READ_ALL :
1589 {
1590 try
1591 {
1592 (*pCache)[pItems[i]] = impl_loadItem(xSet, eType, pItems[i], eOption);
1593 }
1594 catch(const css::uno::Exception& ex)
1595 {
1596 throw css::document::CorruptedFilterConfigurationException(
1597 MESSAGE_CORRUPTED_FILTERCONFIG,
1598 css::uno::Reference< css::uno::XInterface >(),
1599 ex.Message);
1600 }
1601 }
1602 break;
1603
1604 // b) read optional properties only!
1605 // All items must already exist inside our cache.
1606 // But they must be updated.
1607 case E_READ_UPDATE :
1608 {
1609 if (pItem == pCache->end())
1610 {
1611 ::rtl::OUStringBuffer sMsg(256);
1612 sMsg.appendAscii("item \"" );
1613 sMsg.append (pItems[i] );
1614 sMsg.appendAscii("\" not found for update!");
1615 throw css::uno::Exception(sMsg.makeStringAndClear() ,
1616 css::uno::Reference< css::uno::XInterface >());
1617 }
1618 try
1619 {
1620 CacheItem aItem = impl_loadItem(xSet, eType, pItems[i], eOption);
1621 pItem->second.update(aItem);
1622 }
1623 catch(const css::uno::Exception& ex)
1624 {
1625 throw css::document::CorruptedFilterConfigurationException(
1626 MESSAGE_CORRUPTED_FILTERCONFIG,
1627 css::uno::Reference< css::uno::XInterface >(),
1628 ex.Message);
1629 }
1630 }
1631 break;
1632 default: break;
1633 }
1634 }
1635 }
1636
1637 /*-----------------------------------------------
1638 26.11.2003 12:49
1639 -----------------------------------------------*/
impl_readPatchUINames(const css::uno::Reference<css::container::XNameAccess> & xNode,CacheItem & rItem)1640 void FilterCache::impl_readPatchUINames(const css::uno::Reference< css::container::XNameAccess >& xNode,
1641 CacheItem& rItem)
1642 {
1643 static ::rtl::OUString PRODUCTNAME_VAR = ::rtl::OUString::createFromAscii("%productname%");
1644 static ::rtl::OUString FORMATNAME_VAR = ::rtl::OUString::createFromAscii("%oooxmlformatname%" );
1645 static ::rtl::OUString FORMATVERSION_VAR = ::rtl::OUString::createFromAscii("%oooxmlformatversion%");
1646
1647 // SAFE -> ----------------------------------
1648 ::osl::ResettableMutexGuard aLock(m_aLock);
1649 ::rtl::OUString sProductName = m_sProductName;
1650 ::rtl::OUString sFormatName = m_sOOoXMLFormatName;
1651 ::rtl::OUString sFormatVersion = m_sOOoXMLFormatVersion;
1652 ::rtl::OUString sActLocale = m_sActLocale ;
1653 aLock.clear();
1654 // <- SAFE ----------------------------------
1655
1656 css::uno::Any aVal = xNode->getByName(PROPNAME_UINAME);
1657 css::uno::Reference< css::container::XNameAccess > xUIName;
1658 if (!(aVal >>= xUIName) && !xUIName.is())
1659 return;
1660
1661 const ::comphelper::SequenceAsVector< ::rtl::OUString > lLocales(xUIName->getElementNames());
1662 ::comphelper::SequenceAsVector< ::rtl::OUString >::const_iterator pLocale ;
1663 ::comphelper::SequenceAsHashMap lUINames;
1664
1665 // patch %productname%, %oooxmlformatname% and %oooxmlformatversion%
1666 for ( pLocale = lLocales.begin();
1667 pLocale != lLocales.end() ;
1668 ++pLocale )
1669 {
1670 const ::rtl::OUString& sLocale = *pLocale;
1671
1672 ::rtl::OUString sValue;
1673 xUIName->getByName(sLocale) >>= sValue;
1674
1675 // replace %productname%
1676 sal_Int32 nIndex = sValue.indexOf(PRODUCTNAME_VAR);
1677 while(nIndex != -1)
1678 {
1679 sValue = sValue.replaceAt(nIndex, PRODUCTNAME_VAR.getLength(), sProductName);
1680 nIndex = sValue.indexOf(PRODUCTNAME_VAR, nIndex);
1681 }
1682 // replace %oooxmlformatname%
1683 nIndex = sValue.indexOf(FORMATNAME_VAR);
1684 while(nIndex != -1)
1685 {
1686 sValue = sValue.replaceAt(nIndex, FORMATNAME_VAR.getLength(), sFormatName);
1687 nIndex = sValue.indexOf(FORMATNAME_VAR, nIndex);
1688 }
1689 // replace %oooxmlformatversion%
1690 nIndex = sValue.indexOf(FORMATVERSION_VAR);
1691 while(nIndex != -1)
1692 {
1693 sValue = sValue.replaceAt(nIndex, FORMATVERSION_VAR.getLength(), sFormatVersion);
1694 nIndex = sValue.indexOf(FORMATVERSION_VAR, nIndex);
1695 }
1696
1697 lUINames[sLocale] <<= sValue;
1698 }
1699
1700 aVal <<= lUINames.getAsConstPropertyValueList();
1701 rItem[PROPNAME_UINAMES] = aVal;
1702
1703 // find right UIName for current office locale
1704 // Use fallbacks too!
1705 pLocale = ::comphelper::Locale::getFallback(lLocales, sActLocale);
1706 if (pLocale == lLocales.end())
1707 {
1708 #if OSL_DEBUG_LEVEL > 0
1709 ::rtl::OUString sName = rItem.getUnpackedValueOrDefault(PROPNAME_NAME, ::rtl::OUString());
1710
1711 ::rtl::OUStringBuffer sMsg(256);
1712 sMsg.appendAscii("Fallback scenario for filter or type '" );
1713 sMsg.append (sName );
1714 sMsg.appendAscii("' and locale '" );
1715 sMsg.append (sActLocale );
1716 sMsg.appendAscii("' failed. Please check your filter configuration.");
1717
1718 OSL_ENSURE(sal_False, _FILTER_CONFIG_TO_ASCII_(sMsg.makeStringAndClear()));
1719 #endif
1720 return;
1721 }
1722
1723 const ::rtl::OUString& sLocale = *pLocale;
1724 ::comphelper::SequenceAsHashMap::const_iterator pUIName = lUINames.find(sLocale);
1725 if (pUIName != lUINames.end())
1726 rItem[PROPNAME_UINAME] = pUIName->second;
1727 }
1728
1729 /*-----------------------------------------------
1730 26.11.2003 12:56
1731 -----------------------------------------------*/
impl_savePatchUINames(const css::uno::Reference<css::container::XNameReplace> & xNode,const CacheItem & rItem)1732 void FilterCache::impl_savePatchUINames(const css::uno::Reference< css::container::XNameReplace >& xNode,
1733 const CacheItem& rItem)
1734 {
1735 css::uno::Reference< css::container::XNameContainer > xAdd (xNode, css::uno::UNO_QUERY);
1736 css::uno::Reference< css::container::XNameAccess > xCheck(xNode, css::uno::UNO_QUERY);
1737
1738 css::uno::Sequence< css::beans::PropertyValue > lUINames = rItem.getUnpackedValueOrDefault(PROPNAME_UINAMES, css::uno::Sequence< css::beans::PropertyValue >());
1739 sal_Int32 c = lUINames.getLength();
1740 const css::beans::PropertyValue* pUINames = lUINames.getConstArray();
1741
1742 for (sal_Int32 i=0; i<c; ++i)
1743 {
1744 if (xCheck->hasByName(pUINames[i].Name))
1745 xNode->replaceByName(pUINames[i].Name, pUINames[i].Value);
1746 else
1747 xAdd->insertByName(pUINames[i].Name, pUINames[i].Value);
1748 }
1749 }
1750
1751 /*-----------------------------------------------
1752 29.10.2003 13:17
1753 TODO
1754 clarify, how the real problem behind the
1755 wrong constructed CacheItem instance (which
1756 will force a crash during destruction)
1757 can be solved ...
1758 -----------------------------------------------*/
impl_loadItem(const css::uno::Reference<css::container::XNameAccess> & xSet,EItemType eType,const::rtl::OUString & sItem,EReadOption eOption)1759 CacheItem FilterCache::impl_loadItem(const css::uno::Reference< css::container::XNameAccess >& xSet ,
1760 EItemType eType ,
1761 const ::rtl::OUString& sItem ,
1762 EReadOption eOption)
1763 {
1764 // try to get an API object, which points directly to the
1765 // requested item. If it fail an exception should occur and
1766 // break this operation. Of course returned API object must be
1767 // checked too.
1768 css::uno::Reference< css::container::XNameAccess > xItem;
1769 #ifdef WORKAROUND_EXCEPTION_PROBLEM
1770 try
1771 {
1772 #endif
1773 css::uno::Any aVal = xSet->getByName(sItem);
1774 if (!(aVal >>= xItem) || !xItem.is())
1775 {
1776 ::rtl::OUStringBuffer sMsg(256);
1777 sMsg.appendAscii("found corrupted item \"");
1778 sMsg.append (sItem );
1779 sMsg.appendAscii("\"." );
1780 throw css::uno::Exception(sMsg.makeStringAndClear() ,
1781 css::uno::Reference< css::uno::XInterface >());
1782 }
1783 #ifdef WORKAROUND_EXCEPTION_PROBLEM
1784 }
1785 catch(const css::container::NoSuchElementException&)
1786 {
1787 throw;
1788 }
1789 #endif
1790
1791 // The internal name of an item must(!) be part of the property
1792 // set too. Of course it's already used as key into the e.g. outside
1793 // used hash map ... but some of our API methods provide
1794 // this property set as result only. But the user of this CacheItem
1795 // should know, which value the key names has :-) IT'S IMPORTANT!
1796 CacheItem aItem;
1797 aItem[PROPNAME_NAME] = css::uno::makeAny(sItem);
1798 switch(eType)
1799 {
1800 //---------------------------------------
1801 case E_TYPE :
1802 {
1803 // read standard properties of a type
1804 if (
1805 (eOption == E_READ_STANDARD) ||
1806 (eOption == E_READ_ALL )
1807 )
1808 {
1809 aItem[PROPNAME_PREFERREDFILTER] = xItem->getByName(PROPNAME_PREFERREDFILTER);
1810 aItem[PROPNAME_DETECTSERVICE ] = xItem->getByName(PROPNAME_DETECTSERVICE );
1811 aItem[PROPNAME_URLPATTERN ] = xItem->getByName(PROPNAME_URLPATTERN );
1812 aItem[PROPNAME_EXTENSIONS ] = xItem->getByName(PROPNAME_EXTENSIONS );
1813 aItem[PROPNAME_PREFERRED ] = xItem->getByName(PROPNAME_PREFERRED );
1814 aItem[PROPNAME_CLIPBOARDFORMAT] = xItem->getByName(PROPNAME_CLIPBOARDFORMAT);
1815 }
1816 // read optional properties of a type
1817 // no else here! Is an additional switch ...
1818 if (
1819 (eOption == E_READ_UPDATE) ||
1820 (eOption == E_READ_ALL )
1821 )
1822 {
1823 aItem[PROPNAME_MEDIATYPE ] = xItem->getByName(PROPNAME_MEDIATYPE );
1824 impl_readPatchUINames(xItem, aItem);
1825 }
1826 }
1827 break;
1828
1829 //---------------------------------------
1830 case E_FILTER :
1831 {
1832 // read standard properties of a filter
1833 if (
1834 (eOption == E_READ_STANDARD) ||
1835 (eOption == E_READ_ALL )
1836 )
1837 {
1838 aItem[PROPNAME_TYPE ] = xItem->getByName(PROPNAME_TYPE );
1839 aItem[PROPNAME_FILEFORMATVERSION] = xItem->getByName(PROPNAME_FILEFORMATVERSION);
1840 aItem[PROPNAME_UICOMPONENT ] = xItem->getByName(PROPNAME_UICOMPONENT );
1841 aItem[PROPNAME_FILTERSERVICE ] = xItem->getByName(PROPNAME_FILTERSERVICE );
1842 aItem[PROPNAME_DOCUMENTSERVICE ] = xItem->getByName(PROPNAME_DOCUMENTSERVICE );
1843
1844 // special handling for flags! Convert it from a list of names to its
1845 // int representation ...
1846 css::uno::Sequence< ::rtl::OUString > lFlagNames;
1847 if (xItem->getByName(PROPNAME_FLAGS) >>= lFlagNames)
1848 aItem[PROPNAME_FLAGS] <<= FilterCache::impl_convertFlagNames2FlagField(lFlagNames);
1849 }
1850 // read optional properties of a filter
1851 // no else here! It's an additional switch ...
1852 if (
1853 (eOption == E_READ_UPDATE) ||
1854 (eOption == E_READ_ALL )
1855 )
1856 {
1857 aItem[PROPNAME_USERDATA ] = xItem->getByName(PROPNAME_USERDATA );
1858 aItem[PROPNAME_TEMPLATENAME] = xItem->getByName(PROPNAME_TEMPLATENAME);
1859 //TODO remove it if moving of filter uinames to type uinames
1860 // will be finished really
1861 #ifdef AS_ENABLE_FILTER_UINAMES
1862 impl_readPatchUINames(xItem, aItem);
1863 #endif // AS_ENABLE_FILTER_UINAMES
1864 }
1865 }
1866 break;
1867
1868 //---------------------------------------
1869 case E_FRAMELOADER :
1870 case E_CONTENTHANDLER :
1871 {
1872 aItem[PROPNAME_TYPES] = xItem->getByName(PROPNAME_TYPES);
1873 }
1874 break;
1875 default: break;
1876 }
1877
1878 return aItem;
1879 }
1880
1881 /*-----------------------------------------------
1882 27.10.2003 08:47
1883 -----------------------------------------------*/
impl_loadItemOnDemand(EItemType eType,const::rtl::OUString & sItem)1884 CacheItemList::iterator FilterCache::impl_loadItemOnDemand( EItemType eType,
1885 const ::rtl::OUString& sItem)
1886 {
1887 CacheItemList* pList = 0;
1888 css::uno::Reference< css::uno::XInterface > xConfig ;
1889 ::rtl::OUString sSet ;
1890
1891 switch(eType)
1892 {
1893 case E_TYPE :
1894 {
1895 pList = &m_lTypes;
1896 xConfig = impl_openConfig(E_PROVIDER_TYPES);
1897 sSet = CFGSET_TYPES;
1898 }
1899 break;
1900
1901 case E_FILTER :
1902 {
1903 pList = &m_lFilters;
1904 xConfig = impl_openConfig(E_PROVIDER_FILTERS);
1905 sSet = CFGSET_FILTERS;
1906 }
1907 break;
1908
1909 case E_FRAMELOADER :
1910 {
1911 pList = &m_lFrameLoaders;
1912 xConfig = impl_openConfig(E_PROVIDER_OTHERS);
1913 sSet = CFGSET_FRAMELOADERS;
1914 }
1915 break;
1916
1917 case E_CONTENTHANDLER :
1918 {
1919 pList = &m_lContentHandlers;
1920 xConfig = impl_openConfig(E_PROVIDER_OTHERS);
1921 sSet = CFGSET_CONTENTHANDLERS;
1922 }
1923 break;
1924
1925 case E_DETECTSERVICE :
1926 {
1927 OSL_ENSURE(sal_False, "Can't load detect services on demand. Who uses this unsupported feature?");
1928 }
1929 break;
1930 }
1931
1932 css::uno::Reference< css::container::XNameAccess > xRoot(xConfig, css::uno::UNO_QUERY_THROW);
1933 css::uno::Reference< css::container::XNameAccess > xSet ;
1934 xRoot->getByName(sSet) >>= xSet;
1935
1936 CacheItemList::iterator pItemInCache = pList->find(sItem);
1937 sal_Bool bItemInConfig = xSet->hasByName(sItem);
1938
1939 if (bItemInConfig)
1940 {
1941 CacheItem aItem;
1942 CacheItem::iterator pDbgTest = aItem.find(PROPNAME_NAME);
1943 aItem = impl_loadItem(xSet, eType, sItem, E_READ_ALL);
1944 (*pList)[sItem] = aItem;
1945 _FILTER_CONFIG_LOG_2_("impl_loadItemOnDemand(%d, \"%s\") ... OK", (int)eType, _FILTER_CONFIG_TO_ASCII_(sItem).getStr())
1946 }
1947 else
1948 {
1949 if (pItemInCache != pList->end())
1950 pList->erase(pItemInCache);
1951 // OK - this item does not exist inside configuration.
1952 // And we already updated our internal cache.
1953 // But the outside code needs this NoSuchElementException
1954 // to know, that this item does not exist.
1955 // Nobody checks the iterator!
1956 throw css::container::NoSuchElementException();
1957 }
1958
1959 return pList->find(sItem);
1960 }
1961
1962 /*-----------------------------------------------
1963 20.10.2003 09:38
1964 -----------------------------------------------*/
impl_saveItem(const css::uno::Reference<css::container::XNameReplace> & xItem,EItemType eType,const CacheItem & aItem)1965 void FilterCache::impl_saveItem(const css::uno::Reference< css::container::XNameReplace >& xItem,
1966 EItemType eType,
1967 const CacheItem& aItem)
1968 {
1969 CacheItem::const_iterator pIt;
1970 switch(eType)
1971 {
1972 //---------------------------------------
1973 case E_TYPE :
1974 {
1975 pIt = aItem.find(PROPNAME_PREFERREDFILTER);
1976 if (pIt != aItem.end())
1977 xItem->replaceByName(PROPNAME_PREFERREDFILTER, pIt->second);
1978 pIt = aItem.find(PROPNAME_DETECTSERVICE);
1979 if (pIt != aItem.end())
1980 xItem->replaceByName(PROPNAME_DETECTSERVICE, pIt->second);
1981 pIt = aItem.find(PROPNAME_URLPATTERN);
1982 if (pIt != aItem.end())
1983 xItem->replaceByName(PROPNAME_URLPATTERN, pIt->second);
1984 pIt = aItem.find(PROPNAME_EXTENSIONS);
1985 if (pIt != aItem.end())
1986 xItem->replaceByName(PROPNAME_EXTENSIONS, pIt->second);
1987 pIt = aItem.find(PROPNAME_PREFERRED);
1988 if (pIt != aItem.end())
1989 xItem->replaceByName(PROPNAME_PREFERRED, pIt->second);
1990 pIt = aItem.find(PROPNAME_MEDIATYPE);
1991 if (pIt != aItem.end())
1992 xItem->replaceByName(PROPNAME_MEDIATYPE, pIt->second);
1993 pIt = aItem.find(PROPNAME_CLIPBOARDFORMAT);
1994 if (pIt != aItem.end())
1995 xItem->replaceByName(PROPNAME_CLIPBOARDFORMAT, pIt->second);
1996
1997 css::uno::Reference< css::container::XNameReplace > xUIName;
1998 xItem->getByName(PROPNAME_UINAME) >>= xUIName;
1999 impl_savePatchUINames(xUIName, aItem);
2000 }
2001 break;
2002
2003 //---------------------------------------
2004 case E_FILTER :
2005 {
2006 pIt = aItem.find(PROPNAME_TYPE);
2007 if (pIt != aItem.end())
2008 xItem->replaceByName(PROPNAME_TYPE, pIt->second);
2009 pIt = aItem.find(PROPNAME_FILEFORMATVERSION);
2010 if (pIt != aItem.end())
2011 xItem->replaceByName(PROPNAME_FILEFORMATVERSION, pIt->second);
2012 pIt = aItem.find(PROPNAME_UICOMPONENT);
2013 if (pIt != aItem.end())
2014 xItem->replaceByName(PROPNAME_UICOMPONENT, pIt->second);
2015 pIt = aItem.find(PROPNAME_FILTERSERVICE);
2016 if (pIt != aItem.end())
2017 xItem->replaceByName(PROPNAME_FILTERSERVICE, pIt->second);
2018 pIt = aItem.find(PROPNAME_DOCUMENTSERVICE);
2019 if (pIt != aItem.end())
2020 xItem->replaceByName(PROPNAME_DOCUMENTSERVICE, pIt->second);
2021 pIt = aItem.find(PROPNAME_USERDATA);
2022 if (pIt != aItem.end())
2023 xItem->replaceByName(PROPNAME_USERDATA, pIt->second);
2024 pIt = aItem.find(PROPNAME_TEMPLATENAME);
2025 if (pIt != aItem.end())
2026 xItem->replaceByName(PROPNAME_TEMPLATENAME, pIt->second);
2027
2028 // special handling for flags! Convert it from an integer flag field back
2029 // to a list of names ...
2030 // But note: because we work directly on a reference to the cache item,
2031 // it's not allowed to change the value here. We must work on a copy!
2032 sal_Int32 nFlags = 0;
2033 pIt = aItem.find(PROPNAME_FLAGS);
2034 if (pIt != aItem.end())
2035 {
2036 pIt->second >>= nFlags;
2037 css::uno::Any aFlagNameList;
2038 aFlagNameList <<= FilterCache::impl_convertFlagField2FlagNames(nFlags);
2039 xItem->replaceByName(PROPNAME_FLAGS, aFlagNameList);
2040 }
2041
2042 //TODO remove it if moving of filter uinames to type uinames
2043 // will be finished really
2044 #ifdef AS_ENABLE_FILTER_UINAMES
2045 css::uno::Reference< css::container::XNameReplace > xUIName;
2046 xItem->getByName(PROPNAME_UINAME) >>= xUIName;
2047 impl_savePatchUINames(xUIName, aItem);
2048 #endif // AS_ENABLE_FILTER_UINAMES
2049 }
2050 break;
2051
2052 //---------------------------------------
2053 case E_FRAMELOADER :
2054 case E_CONTENTHANDLER :
2055 {
2056 pIt = aItem.find(PROPNAME_TYPES);
2057 if (pIt != aItem.end())
2058 xItem->replaceByName(PROPNAME_TYPES, pIt->second);
2059 }
2060 break;
2061 default: break;
2062 }
2063 }
2064
2065 /*-----------------------------------------------
2066 20.10.2003 09:45
2067 static! => no locks necessary
2068 -----------------------------------------------*/
impl_convertFlagField2FlagNames(sal_Int32 nFlags)2069 css::uno::Sequence< ::rtl::OUString > FilterCache::impl_convertFlagField2FlagNames(sal_Int32 nFlags)
2070 {
2071 OUStringList lFlagNames;
2072
2073 if ((nFlags & FLAGVAL_3RDPARTYFILTER ) == FLAGVAL_3RDPARTYFILTER ) lFlagNames.push_back(FLAGNAME_3RDPARTYFILTER );
2074 if ((nFlags & FLAGVAL_ALIEN ) == FLAGVAL_ALIEN ) lFlagNames.push_back(FLAGNAME_ALIEN );
2075 if ((nFlags & FLAGVAL_ASYNCHRON ) == FLAGVAL_ASYNCHRON ) lFlagNames.push_back(FLAGNAME_ASYNCHRON );
2076 if ((nFlags & FLAGVAL_BROWSERPREFERRED ) == FLAGVAL_BROWSERPREFERRED ) lFlagNames.push_back(FLAGNAME_BROWSERPREFERRED );
2077 if ((nFlags & FLAGVAL_CONSULTSERVICE ) == FLAGVAL_CONSULTSERVICE ) lFlagNames.push_back(FLAGNAME_CONSULTSERVICE );
2078 if ((nFlags & FLAGVAL_DEFAULT ) == FLAGVAL_DEFAULT ) lFlagNames.push_back(FLAGNAME_DEFAULT );
2079 if ((nFlags & FLAGVAL_ENCRYPTION ) == FLAGVAL_ENCRYPTION ) lFlagNames.push_back(FLAGNAME_ENCRYPTION );
2080 if ((nFlags & FLAGVAL_EXPORT ) == FLAGVAL_EXPORT ) lFlagNames.push_back(FLAGNAME_EXPORT );
2081 if ((nFlags & FLAGVAL_IMPORT ) == FLAGVAL_IMPORT ) lFlagNames.push_back(FLAGNAME_IMPORT );
2082 if ((nFlags & FLAGVAL_INTERNAL ) == FLAGVAL_INTERNAL ) lFlagNames.push_back(FLAGNAME_INTERNAL );
2083 if ((nFlags & FLAGVAL_NOTINCHOOSER ) == FLAGVAL_NOTINCHOOSER ) lFlagNames.push_back(FLAGNAME_NOTINCHOOSER );
2084 if ((nFlags & FLAGVAL_NOTINFILEDIALOG ) == FLAGVAL_NOTINFILEDIALOG ) lFlagNames.push_back(FLAGNAME_NOTINFILEDIALOG );
2085 if ((nFlags & FLAGVAL_NOTINSTALLED ) == FLAGVAL_NOTINSTALLED ) lFlagNames.push_back(FLAGNAME_NOTINSTALLED );
2086 if ((nFlags & FLAGVAL_OWN ) == FLAGVAL_OWN ) lFlagNames.push_back(FLAGNAME_OWN );
2087 if ((nFlags & FLAGVAL_PACKED ) == FLAGVAL_PACKED ) lFlagNames.push_back(FLAGNAME_PACKED );
2088 if ((nFlags & FLAGVAL_PASSWORDTOMODIFY ) == FLAGVAL_PASSWORDTOMODIFY ) lFlagNames.push_back(FLAGNAME_PASSWORDTOMODIFY );
2089 if ((nFlags & FLAGVAL_PREFERRED ) == FLAGVAL_PREFERRED ) lFlagNames.push_back(FLAGNAME_PREFERRED );
2090 if ((nFlags & FLAGVAL_READONLY ) == FLAGVAL_READONLY ) lFlagNames.push_back(FLAGNAME_READONLY );
2091 if ((nFlags & FLAGVAL_SUPPORTSSELECTION) == FLAGVAL_SUPPORTSSELECTION) lFlagNames.push_back(FLAGNAME_SUPPORTSSELECTION);
2092 if ((nFlags & FLAGVAL_TEMPLATE ) == FLAGVAL_TEMPLATE ) lFlagNames.push_back(FLAGNAME_TEMPLATE );
2093 if ((nFlags & FLAGVAL_TEMPLATEPATH ) == FLAGVAL_TEMPLATEPATH ) lFlagNames.push_back(FLAGNAME_TEMPLATEPATH );
2094 if ((nFlags & FLAGVAL_USESOPTIONS ) == FLAGVAL_USESOPTIONS ) lFlagNames.push_back(FLAGNAME_USESOPTIONS );
2095 if ((nFlags & FLAGVAL_COMBINED ) == FLAGVAL_COMBINED ) lFlagNames.push_back(FLAGNAME_COMBINED );
2096
2097 return lFlagNames.getAsConstList();
2098 }
2099
2100 /*-----------------------------------------------
2101 27.06.2003 09:26
2102 static! => no locks necessary
2103 -----------------------------------------------*/
impl_convertFlagNames2FlagField(const css::uno::Sequence<::rtl::OUString> & lNames)2104 sal_Int32 FilterCache::impl_convertFlagNames2FlagField(const css::uno::Sequence< ::rtl::OUString >& lNames)
2105 {
2106 sal_Int32 nField = 0;
2107
2108 const ::rtl::OUString* pNames = lNames.getConstArray();
2109 sal_Int32 c = lNames.getLength();
2110 for (sal_Int32 i=0; i<c; ++i)
2111 {
2112 if (pNames[i].equals(FLAGNAME_3RDPARTYFILTER))
2113 {
2114 nField |= FLAGVAL_3RDPARTYFILTER;
2115 continue;
2116 }
2117 if (pNames[i].equals(FLAGNAME_ALIEN))
2118 {
2119 nField |= FLAGVAL_ALIEN;
2120 continue;
2121 }
2122 if (pNames[i].equals(FLAGNAME_ASYNCHRON))
2123 {
2124 nField |= FLAGVAL_ASYNCHRON;
2125 continue;
2126 }
2127 if (pNames[i].equals(FLAGNAME_BROWSERPREFERRED))
2128 {
2129 nField |= FLAGVAL_BROWSERPREFERRED;
2130 continue;
2131 }
2132 if (pNames[i].equals(FLAGNAME_CONSULTSERVICE))
2133 {
2134 nField |= FLAGVAL_CONSULTSERVICE;
2135 continue;
2136 }
2137 if (pNames[i].equals(FLAGNAME_DEFAULT))
2138 {
2139 nField |= FLAGVAL_DEFAULT;
2140 continue;
2141 }
2142 if (pNames[i].equals(FLAGNAME_ENCRYPTION))
2143 {
2144 nField |= FLAGVAL_ENCRYPTION;
2145 continue;
2146 }
2147 if (pNames[i].equals(FLAGNAME_EXPORT))
2148 {
2149 nField |= FLAGVAL_EXPORT;
2150 continue;
2151 }
2152 if (pNames[i].equals(FLAGNAME_IMPORT))
2153 {
2154 nField |= FLAGVAL_IMPORT;
2155 continue;
2156 }
2157 if (pNames[i].equals(FLAGNAME_INTERNAL))
2158 {
2159 nField |= FLAGVAL_INTERNAL;
2160 continue;
2161 }
2162 if (pNames[i].equals(FLAGNAME_NOTINCHOOSER))
2163 {
2164 nField |= FLAGVAL_NOTINCHOOSER;
2165 continue;
2166 }
2167 if (pNames[i].equals(FLAGNAME_NOTINFILEDIALOG))
2168 {
2169 nField |= FLAGVAL_NOTINFILEDIALOG;
2170 continue;
2171 }
2172 if (pNames[i].equals(FLAGNAME_NOTINSTALLED))
2173 {
2174 nField |= FLAGVAL_NOTINSTALLED;
2175 continue;
2176 }
2177 if (pNames[i].equals(FLAGNAME_OWN))
2178 {
2179 nField |= FLAGVAL_OWN;
2180 continue;
2181 }
2182 if (pNames[i].equals(FLAGNAME_PACKED))
2183 {
2184 nField |= FLAGVAL_PACKED;
2185 continue;
2186 }
2187 if (pNames[i].equals(FLAGNAME_PASSWORDTOMODIFY))
2188 {
2189 nField |= FLAGVAL_PASSWORDTOMODIFY;
2190 continue;
2191 }
2192 if (pNames[i].equals(FLAGNAME_PREFERRED))
2193 {
2194 nField |= FLAGVAL_PREFERRED;
2195 continue;
2196 }
2197 if (pNames[i].equals(FLAGNAME_READONLY))
2198 {
2199 nField |= FLAGVAL_READONLY;
2200 continue;
2201 }
2202 if (pNames[i].equals(FLAGNAME_SUPPORTSSELECTION))
2203 {
2204 nField |= FLAGVAL_SUPPORTSSELECTION;
2205 continue;
2206 }
2207 if (pNames[i].equals(FLAGNAME_TEMPLATE))
2208 {
2209 nField |= FLAGVAL_TEMPLATE;
2210 continue;
2211 }
2212 if (pNames[i].equals(FLAGNAME_TEMPLATEPATH))
2213 {
2214 nField |= FLAGVAL_TEMPLATEPATH;
2215 continue;
2216 }
2217 if (pNames[i].equals(FLAGNAME_USESOPTIONS))
2218 {
2219 nField |= FLAGVAL_USESOPTIONS;
2220 continue;
2221 }
2222 if (pNames[i].equals(FLAGNAME_COMBINED))
2223 {
2224 nField |= FLAGVAL_COMBINED;
2225 continue;
2226 }
2227 }
2228
2229 return nField;
2230 }
2231
2232 /*-----------------------------------------------
2233 12.02.2004 08:40
2234 -----------------------------------------------*/
impl_interpretDataVal4Type(const::rtl::OUString & sValue,sal_Int32 nProp,CacheItem & rItem)2235 void FilterCache::impl_interpretDataVal4Type(const ::rtl::OUString& sValue,
2236 sal_Int32 nProp ,
2237 CacheItem& rItem )
2238 {
2239 switch(nProp)
2240 {
2241 // Preferred
2242 case 0: {
2243 if (sValue.toInt32() == 1)
2244 rItem[PROPNAME_PREFERRED] = css::uno::makeAny(sal_True);
2245 else
2246 rItem[PROPNAME_PREFERRED] = css::uno::makeAny(sal_False);
2247 }
2248 break;
2249 // MediaType
2250 case 1: rItem[PROPNAME_MEDIATYPE] <<= ::rtl::Uri::decode(sValue, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8);
2251 break;
2252 // ClipboardFormat
2253 case 2: rItem[PROPNAME_CLIPBOARDFORMAT] <<= ::rtl::Uri::decode(sValue, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8);
2254 break;
2255 // URLPattern
2256 case 3: rItem[PROPNAME_URLPATTERN] <<= impl_tokenizeString(sValue, (sal_Unicode)';').getAsConstList();
2257 break;
2258 // Extensions
2259 case 4: rItem[PROPNAME_EXTENSIONS] <<= impl_tokenizeString(sValue, (sal_Unicode)';').getAsConstList();
2260 break;
2261 }
2262 }
2263
2264 /*-----------------------------------------------
2265 12.02.2004 08:50
2266 -----------------------------------------------*/
impl_interpretDataVal4Filter(const::rtl::OUString & sValue,sal_Int32 nProp,CacheItem & rItem)2267 void FilterCache::impl_interpretDataVal4Filter(const ::rtl::OUString& sValue,
2268 sal_Int32 nProp ,
2269 CacheItem& rItem )
2270 {
2271 switch(nProp)
2272 {
2273 // Order
2274 case 0: {
2275 sal_Int32 nOrder = sValue.toInt32();
2276 if (nOrder > 0)
2277 {
2278 OSL_ENSURE(sal_False, "FilterCache::impl_interpretDataVal4Filter()\nCant move Order value from filter to type on demand!\n");
2279 _FILTER_CONFIG_LOG_2_("impl_interpretDataVal4Filter(%d, \"%s\") ... OK", (int)eType, _FILTER_CONFIG_TO_ASCII_(rItem).getStr())
2280 }
2281 }
2282 break;
2283 // Type
2284 case 1: rItem[PROPNAME_TYPE] <<= ::rtl::Uri::decode(sValue, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8);
2285 break;
2286 // DocumentService
2287 case 2: rItem[PROPNAME_DOCUMENTSERVICE] <<= ::rtl::Uri::decode(sValue, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8);
2288 break;
2289 // FilterService
2290 case 3: rItem[PROPNAME_FILTERSERVICE] <<= ::rtl::Uri::decode(sValue, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8);
2291 break;
2292 // Flags
2293 case 4: rItem[PROPNAME_FLAGS] <<= sValue.toInt32();
2294 break;
2295 // UserData
2296 case 5: rItem[PROPNAME_USERDATA] <<= impl_tokenizeString(sValue, (sal_Unicode)';').getAsConstList();
2297 break;
2298 // FileFormatVersion
2299 case 6: rItem[PROPNAME_FILEFORMATVERSION] <<= sValue.toInt32();
2300 break;
2301 // TemplateName
2302 case 7: rItem[PROPNAME_TEMPLATENAME] <<= ::rtl::Uri::decode(sValue, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8);
2303 break;
2304 // [optional!] UIComponent
2305 case 8: rItem[PROPNAME_UICOMPONENT] <<= ::rtl::Uri::decode(sValue, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8);
2306 break;
2307 }
2308 }
2309
2310 /*-----------------------------------------------
2311 12.02.2004 08:30
2312 TODO work on a cache copy first, which can be flushed afterwards
2313 That would be usefully to guarantee a consistent cache.
2314 -----------------------------------------------*/
impl_readOldFormat()2315 void FilterCache::impl_readOldFormat()
2316 {
2317 static ::rtl::OUString TYPES_SET = ::rtl::OUString::createFromAscii("Types" );
2318 static ::rtl::OUString FILTER_SET = ::rtl::OUString::createFromAscii("Filters");
2319
2320 // Attention: Opening/Reading of this old configuration format has to be handled gracefully.
2321 // It's optional and shouldn't disturb our normal work!
2322 // E.g. we must check, if the package exists ...
2323
2324 css::uno::Reference< css::container::XNameAccess > xCfg;
2325 try
2326 {
2327 css::uno::Reference< css::uno::XInterface > xInt = impl_openConfig(E_PROVIDER_OLD);
2328 xCfg = css::uno::Reference< css::container::XNameAccess >(xInt, css::uno::UNO_QUERY_THROW);
2329 }
2330 /* corrupt filter addon ? because it's external (optional) code .. we can ignore it. Addon won't work then ...
2331 but that seems to be acceptable.
2332 see #139088# for further informations
2333 */
2334 catch(const css::uno::Exception&)
2335 { return; }
2336
2337 // Maybe there is no type set ...
2338 if (xCfg->hasByName(TYPES_SET))
2339 {
2340 css::uno::Reference< css::container::XNameAccess > xSet;
2341 xCfg->getByName(TYPES_SET) >>= xSet;
2342 const css::uno::Sequence< ::rtl::OUString > lItems = xSet->getElementNames();
2343 const ::rtl::OUString* pItems = lItems.getConstArray();
2344 for (sal_Int32 i=0; i<lItems.getLength(); ++i)
2345 m_lTypes[pItems[i]] = impl_readOldItem(xSet, E_TYPE, pItems[i]);
2346 }
2347
2348 // Maybe there is no filter set ...
2349 if (xCfg->hasByName(FILTER_SET))
2350 {
2351 css::uno::Reference< css::container::XNameAccess > xSet;
2352 xCfg->getByName(FILTER_SET) >>= xSet;
2353 const css::uno::Sequence< ::rtl::OUString > lItems = xSet->getElementNames();
2354 const ::rtl::OUString* pItems = lItems.getConstArray();
2355 for (sal_Int32 i=0; i<lItems.getLength(); ++i)
2356 m_lFilters[pItems[i]] = impl_readOldItem(xSet, E_FILTER, pItems[i]);
2357 }
2358 }
2359
2360 /*-----------------------------------------------
2361 12.02.2004 08:30
2362 -----------------------------------------------*/
impl_readOldItem(const css::uno::Reference<css::container::XNameAccess> & xSet,EItemType eType,const::rtl::OUString & sItem)2363 CacheItem FilterCache::impl_readOldItem(const css::uno::Reference< css::container::XNameAccess >& xSet ,
2364 EItemType eType,
2365 const ::rtl::OUString& sItem)
2366 {
2367 css::uno::Reference< css::container::XNameAccess > xItem;
2368 xSet->getByName(sItem) >>= xItem;
2369 if (!xItem.is())
2370 throw css::uno::Exception(
2371 ::rtl::OUString::createFromAscii("Can't read old item."),
2372 css::uno::Reference< css::uno::XInterface >());
2373
2374 CacheItem aItem;
2375 aItem[PROPNAME_NAME] <<= sItem;
2376
2377 // Installed flag ...
2378 // Isn't used any longer!
2379
2380 // UIName
2381 impl_readPatchUINames(xItem, aItem);
2382
2383 // Data
2384 ::rtl::OUString sData;
2385 OUStringList lData;
2386 xItem->getByName(::rtl::OUString::createFromAscii("Data")) >>= sData;
2387 lData = impl_tokenizeString(sData, (sal_Unicode)',');
2388 if (
2389 (!sData.getLength()) ||
2390 (lData.size()<1 )
2391 )
2392 {
2393 throw css::uno::Exception(
2394 ::rtl::OUString::createFromAscii("Can't read old item property DATA."),
2395 css::uno::Reference< css::uno::XInterface >());
2396 }
2397
2398 sal_Int32 nProp = 0;
2399 for (OUStringList::const_iterator pProp = lData.begin();
2400 pProp != lData.end() ;
2401 ++pProp )
2402 {
2403 const ::rtl::OUString& sProp = *pProp;
2404 switch(eType)
2405 {
2406 case E_TYPE :
2407 impl_interpretDataVal4Type(sProp, nProp, aItem);
2408 break;
2409
2410 case E_FILTER :
2411 impl_interpretDataVal4Filter(sProp, nProp, aItem);
2412 break;
2413 default: break;
2414 }
2415 ++nProp;
2416 }
2417
2418 return aItem;
2419 }
2420
2421 /*-----------------------------------------------
2422 12.02.2004 08:15
2423 -----------------------------------------------*/
impl_tokenizeString(const::rtl::OUString & sData,sal_Unicode cSeperator)2424 OUStringList FilterCache::impl_tokenizeString(const ::rtl::OUString& sData ,
2425 sal_Unicode cSeperator)
2426 {
2427 OUStringList lData ;
2428 sal_Int32 nToken = 0;
2429 do
2430 {
2431 ::rtl::OUString sToken = sData.getToken(0, cSeperator, nToken);
2432 lData.push_back(sToken);
2433 }
2434 while(nToken >= 0);
2435 return lData;
2436 }
2437
2438 #if OSL_DEBUG_LEVEL > 0
2439 /*-----------------------------------------------*/
impl_searchFrameLoaderForType(const::rtl::OUString & sType) const2440 ::rtl::OUString FilterCache::impl_searchFrameLoaderForType(const ::rtl::OUString& sType) const
2441 {
2442 CacheItemList::const_iterator pIt;
2443 for ( pIt = m_lFrameLoaders.begin();
2444 pIt != m_lFrameLoaders.end() ;
2445 ++pIt )
2446 {
2447 const ::rtl::OUString& sItem = pIt->first;
2448 ::comphelper::SequenceAsHashMap lProps(pIt->second);
2449 OUStringList lTypes(lProps[PROPNAME_TYPES]);
2450
2451 if (::std::find(lTypes.begin(), lTypes.end(), sType) != lTypes.end())
2452 return sItem;
2453 }
2454
2455 return ::rtl::OUString();
2456 }
2457
2458 /*-----------------------------------------------*/
impl_searchContentHandlerForType(const::rtl::OUString & sType) const2459 ::rtl::OUString FilterCache::impl_searchContentHandlerForType(const ::rtl::OUString& sType) const
2460 {
2461 CacheItemList::const_iterator pIt;
2462 for ( pIt = m_lContentHandlers.begin();
2463 pIt != m_lContentHandlers.end() ;
2464 ++pIt )
2465 {
2466 const ::rtl::OUString& sItem = pIt->first;
2467 ::comphelper::SequenceAsHashMap lProps(pIt->second);
2468 OUStringList lTypes(lProps[PROPNAME_TYPES]);
2469
2470 if (::std::find(lTypes.begin(), lTypes.end(), sType) != lTypes.end())
2471 return sItem;
2472 }
2473
2474 return ::rtl::OUString();
2475 }
2476 #endif
2477
2478 /*-----------------------------------------------*/
impl_isModuleInstalled(const::rtl::OUString & sModule)2479 sal_Bool FilterCache::impl_isModuleInstalled(const ::rtl::OUString& sModule)
2480 {
2481 css::uno::Reference< css::container::XNameAccess > xCfg;
2482
2483 // SAFE ->
2484 ::osl::ResettableMutexGuard aLock(m_aLock);
2485 if (! m_xModuleCfg.is())
2486 {
2487 m_xModuleCfg = css::uno::Reference< css::container::XNameAccess >(
2488 ::comphelper::ConfigurationHelper::openConfig(
2489 m_xSMGR,
2490 ::rtl::OUString::createFromAscii("org.openoffice.Setup/Office/Factories"),
2491 ::comphelper::ConfigurationHelper::E_READONLY),
2492 css::uno::UNO_QUERY_THROW);
2493 }
2494
2495 xCfg = m_xModuleCfg;
2496 aLock.clear();
2497 // <- SAFE
2498
2499 if (xCfg.is())
2500 return xCfg->hasByName(sModule);
2501
2502 return sal_False;
2503 }
2504
2505 } // namespace config
2506 } // namespace filter
2507