bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / core / DocumentSettingsContext.cxx
blob15e94ec5b4cb847f41845f0edb9c26f610edced7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <officecfg/Office/Common.hxx>
23 #include <sax/tools/converter.hxx>
25 #include <com/sun/star/util/PathSubstitution.hpp>
26 #include <com/sun/star/util/XStringSubstitution.hpp>
27 #include <xmloff/DocumentSettingsContext.hxx>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlnmspe.hxx>
31 #include <xmloff/nmspmap.hxx>
32 #include <xmloff/xmluconv.hxx>
33 #include <tools/debug.hxx>
34 #include <comphelper/processfactory.hxx>
36 #include <list>
37 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
38 #include <com/sun/star/container/XIndexContainer.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/formula/SymbolDescriptor.hpp>
41 #include <com/sun/star/util/DateTime.hpp>
42 #include <com/sun/star/document/XViewDataSupplier.hpp>
43 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
44 #include <com/sun/star/document/IndexedPropertyValues.hpp>
45 #include <com/sun/star/document/NamedPropertyValues.hpp>
46 #include <rtl/ustrbuf.hxx>
47 #include <osl/diagnose.h>
48 #include <xmlenums.hxx>
50 using namespace com::sun::star;
51 using namespace ::xmloff::token;
53 class XMLMyList
55 std::list<beans::PropertyValue> aProps;
56 sal_uInt32 nCount;
58 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
60 public:
61 XMLMyList(const uno::Reference<uno::XComponentContext>& rxContext);
63 void push_back(beans::PropertyValue& aProp) { aProps.push_back(aProp); nCount++; }
64 uno::Sequence<beans::PropertyValue> GetSequence();
65 uno::Reference<container::XNameContainer> GetNameContainer();
66 uno::Reference<container::XIndexContainer> GetIndexContainer();
69 XMLMyList::XMLMyList(const uno::Reference<uno::XComponentContext>& rxContext)
70 : nCount(0),
71 m_xContext(rxContext)
73 DBG_ASSERT( rxContext.is(), "got no service manager" );
76 uno::Sequence<beans::PropertyValue> XMLMyList::GetSequence()
78 uno::Sequence<beans::PropertyValue> aSeq;
79 if(nCount)
81 DBG_ASSERT(nCount == aProps.size(), "wrong count of PropertyValue");
82 aSeq.realloc(nCount);
83 beans::PropertyValue* pProps = aSeq.getArray();
84 std::list<beans::PropertyValue>::iterator aItr = aProps.begin();
85 while (aItr != aProps.end())
87 *pProps = *aItr;
88 ++pProps;
89 ++aItr;
92 return aSeq;
95 uno::Reference<container::XNameContainer> XMLMyList::GetNameContainer()
97 uno::Reference<container::XNameContainer> xNameContainer = document::NamedPropertyValues::create(m_xContext);
98 std::list<beans::PropertyValue>::iterator aItr = aProps.begin();
99 while (aItr != aProps.end())
101 xNameContainer->insertByName(aItr->Name, aItr->Value);
102 ++aItr;
105 return xNameContainer;
108 uno::Reference<container::XIndexContainer> XMLMyList::GetIndexContainer()
110 uno::Reference<container::XIndexContainer> xIndexContainer = document::IndexedPropertyValues::create(m_xContext);
111 std::list<beans::PropertyValue>::iterator aItr = aProps.begin();
112 sal_uInt32 i(0);
113 while (aItr != aProps.end())
115 xIndexContainer->insertByIndex(i, aItr->Value);
116 ++aItr;
117 ++i;
120 return xIndexContainer;
123 class XMLConfigBaseContext : public SvXMLImportContext
125 protected:
126 XMLMyList maProps;
127 beans::PropertyValue maProp;
128 com::sun::star::uno::Any& mrAny;
129 XMLConfigBaseContext* mpBaseContext;
130 public:
131 XMLConfigBaseContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
132 com::sun::star::uno::Any& rAny,
133 XMLConfigBaseContext* pBaseContext);
134 virtual ~XMLConfigBaseContext();
136 void AddPropertyValue() { maProps.push_back(maProp); }
139 class XMLConfigItemContext : public SvXMLImportContext
141 OUString msType;
142 OUString msValue;
143 uno::Sequence<sal_Int8> maDecoded;
144 com::sun::star::uno::Any& mrAny;
145 const OUString mrItemName;
146 XMLConfigBaseContext* mpBaseContext;
148 public:
149 XMLConfigItemContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
150 const ::com::sun::star::uno::Reference<
151 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
152 com::sun::star::uno::Any& rAny,
153 const OUString& rItemName,
154 XMLConfigBaseContext* pBaseContext);
155 virtual ~XMLConfigItemContext();
157 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
158 const OUString& rLocalName,
159 const ::com::sun::star::uno::Reference<
160 ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
161 virtual void Characters( const OUString& rChars ) SAL_OVERRIDE;
163 virtual void EndElement() SAL_OVERRIDE;
165 void ManipulateConfigItem();
168 class XMLConfigItemSetContext : public XMLConfigBaseContext
170 public:
171 XMLConfigItemSetContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
172 const ::com::sun::star::uno::Reference<
173 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
174 com::sun::star::uno::Any& rAny,
175 XMLConfigBaseContext* pBaseContext);
176 virtual ~XMLConfigItemSetContext();
178 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
179 const OUString& rLocalName,
180 const ::com::sun::star::uno::Reference<
181 ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
183 virtual void EndElement() SAL_OVERRIDE;
186 class XMLConfigItemMapNamedContext : public XMLConfigBaseContext
188 public:
189 XMLConfigItemMapNamedContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
190 const ::com::sun::star::uno::Reference<
191 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
192 com::sun::star::uno::Any& rAny,
193 XMLConfigBaseContext* pBaseContext);
194 virtual ~XMLConfigItemMapNamedContext();
196 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
197 const OUString& rLocalName,
198 const ::com::sun::star::uno::Reference<
199 ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
201 virtual void EndElement() SAL_OVERRIDE;
204 class XMLConfigItemMapIndexedContext : public XMLConfigBaseContext
206 private:
207 OUString maConfigItemName;
209 public:
210 XMLConfigItemMapIndexedContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
211 const OUString& rLName,
212 const ::com::sun::star::uno::Reference<
213 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
214 com::sun::star::uno::Any& rAny,
215 const OUString& rConfigItemName,
216 XMLConfigBaseContext* pBaseContext);
217 virtual ~XMLConfigItemMapIndexedContext();
219 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
220 const OUString& rLocalName,
221 const ::com::sun::star::uno::Reference<
222 ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) SAL_OVERRIDE;
224 virtual void EndElement() SAL_OVERRIDE;
227 SvXMLImportContext *CreateSettingsContext(SvXMLImport& rImport, sal_uInt16 p_nPrefix,
228 const OUString& rLocalName,
229 const uno::Reference<xml::sax::XAttributeList>& xAttrList,
230 beans::PropertyValue& rProp, XMLConfigBaseContext* pBaseContext)
232 SvXMLImportContext *pContext = 0;
234 rProp.Name.clear();
235 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
236 for( sal_Int16 i=0; i < nAttrCount; i++ )
238 OUString sAttrName = xAttrList->getNameByIndex( i );
239 OUString aLocalName;
240 sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(
241 sAttrName, &aLocalName );
242 OUString sValue = xAttrList->getValueByIndex( i );
244 if (nPrefix == XML_NAMESPACE_CONFIG)
246 if (IsXMLToken(aLocalName, XML_NAME))
247 rProp.Name = sValue;
251 if (p_nPrefix == XML_NAMESPACE_CONFIG)
253 if (IsXMLToken(rLocalName, XML_CONFIG_ITEM))
254 pContext = new XMLConfigItemContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, rProp.Name, pBaseContext);
255 else if((IsXMLToken(rLocalName, XML_CONFIG_ITEM_SET)) ||
256 (IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_ENTRY)) )
257 pContext = new XMLConfigItemSetContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, pBaseContext);
258 else if(IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_NAMED))
259 pContext = new XMLConfigItemMapNamedContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, pBaseContext);
260 else if(IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_INDEXED))
261 pContext = new XMLConfigItemMapIndexedContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, rProp.Name, pBaseContext);
264 if( !pContext )
265 pContext = new SvXMLImportContext( rImport, p_nPrefix, rLocalName );
267 return pContext;
270 namespace
272 struct SettingsGroup
274 OUString sGroupName;
275 uno::Any aSettings;
277 SettingsGroup( const OUString& _rGroupName, const uno::Any& _rSettings )
278 :sGroupName( _rGroupName )
279 ,aSettings( _rSettings )
285 struct XMLDocumentSettingsContext_Data
287 com::sun::star::uno::Any aViewProps;
288 com::sun::star::uno::Any aConfigProps;
289 ::std::list< SettingsGroup > aDocSpecificSettings;
292 XMLDocumentSettingsContext::XMLDocumentSettingsContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
293 const uno::Reference<xml::sax::XAttributeList>& )
294 : SvXMLImportContext( rImport, nPrfx, rLName )
295 , m_pData( new XMLDocumentSettingsContext_Data )
297 // here are no attributes
300 XMLDocumentSettingsContext::~XMLDocumentSettingsContext()
304 SvXMLImportContext *XMLDocumentSettingsContext::CreateChildContext( sal_uInt16 p_nPrefix,
305 const OUString& rLocalName,
306 const ::com::sun::star::uno::Reference<
307 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
309 SvXMLImportContext *pContext = 0;
310 OUString sName;
312 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
313 for( sal_Int16 i=0; i < nAttrCount; i++ )
315 OUString sAttrName = xAttrList->getNameByIndex( i );
316 OUString aLocalName;
317 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
318 sAttrName, &aLocalName );
319 OUString sValue = xAttrList->getValueByIndex( i );
321 if (nPrefix == XML_NAMESPACE_CONFIG)
323 if (IsXMLToken(aLocalName, XML_NAME))
324 sName = sValue;
328 if (p_nPrefix == XML_NAMESPACE_CONFIG)
330 if (IsXMLToken(rLocalName, XML_CONFIG_ITEM_SET))
332 OUString aLocalConfigName;
333 sal_uInt16 nConfigPrefix =
334 GetImport().GetNamespaceMap().GetKeyByAttrName(
335 sName, &aLocalConfigName );
337 if( XML_NAMESPACE_OOO == nConfigPrefix )
339 if (IsXMLToken(aLocalConfigName, XML_VIEW_SETTINGS))
340 pContext = new XMLConfigItemSetContext(GetImport(),
341 p_nPrefix, rLocalName, xAttrList,
342 m_pData->aViewProps, NULL);
343 else if (IsXMLToken(aLocalConfigName,
344 XML_CONFIGURATION_SETTINGS))
345 pContext = new XMLConfigItemSetContext(GetImport(),
346 p_nPrefix, rLocalName, xAttrList,
347 m_pData->aConfigProps, NULL);
348 else
350 m_pData->aDocSpecificSettings.push_back( SettingsGroup( aLocalConfigName, uno::Any() ) );
352 ::std::list< SettingsGroup >::reverse_iterator settingsPos =
353 m_pData->aDocSpecificSettings.rbegin();
355 pContext = new XMLConfigItemSetContext(GetImport(),
356 p_nPrefix, rLocalName, xAttrList,
357 settingsPos->aSettings, NULL);
363 if( !pContext )
364 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
366 return pContext;
369 void XMLDocumentSettingsContext::EndElement()
371 uno::Sequence<beans::PropertyValue> aSeqViewProps;
372 if (m_pData->aViewProps >>= aSeqViewProps)
374 GetImport().SetViewSettings(aSeqViewProps);
375 sal_Int32 i(aSeqViewProps.getLength() - 1);
376 bool bFound(false);
377 while((i >= 0) && !bFound)
379 if (aSeqViewProps[i].Name == "Views")
381 bFound = true;
382 uno::Reference<container::XIndexAccess> xIndexAccess;
383 if (aSeqViewProps[i].Value >>= xIndexAccess)
385 uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetImport().GetModel(), uno::UNO_QUERY);
386 if (xViewDataSupplier.is())
387 xViewDataSupplier->setViewData(xIndexAccess);
390 else
391 i--;
395 uno::Sequence<beans::PropertyValue> aSeqConfigProps;
396 if ( m_pData->aConfigProps >>= aSeqConfigProps )
398 if (!officecfg::Office::Common::Save::Document::LoadPrinter::get())
400 sal_Int32 i = aSeqConfigProps.getLength() - 1;
401 int nFound = 0;
403 while ( ( i >= 0 ) && nFound < 2 )
405 OUString sProp( aSeqConfigProps[i].Name );
407 if ( sProp == "PrinterName" )
409 OUString sEmpty;
410 aSeqConfigProps[i].Value = uno::makeAny( sEmpty );
411 nFound++;
413 else if ( sProp == "PrinterSetup" )
415 uno::Sequence< sal_Int8 > aEmpty;
416 aSeqConfigProps[i].Value = uno::makeAny( aEmpty );
417 nFound++;
420 i--;
424 GetImport().SetConfigurationSettings( aSeqConfigProps );
427 for ( ::std::list< SettingsGroup >::const_iterator settings = m_pData->aDocSpecificSettings.begin();
428 settings != m_pData->aDocSpecificSettings.end();
429 ++settings
432 uno::Sequence< beans::PropertyValue > aDocSettings;
433 OSL_VERIFY( settings->aSettings >>= aDocSettings );
434 GetImport().SetDocumentSpecificSettings( settings->sGroupName, aDocSettings );
438 XMLConfigBaseContext::XMLConfigBaseContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
439 const OUString& rLName, com::sun::star::uno::Any& rTempAny,
440 XMLConfigBaseContext* pTempBaseContext)
441 : SvXMLImportContext( rImport, nPrfx, rLName ),
442 maProps( rImport.GetComponentContext() ),
443 maProp(),
444 mrAny(rTempAny),
445 mpBaseContext(pTempBaseContext)
449 XMLConfigBaseContext::~XMLConfigBaseContext()
453 XMLConfigItemSetContext::XMLConfigItemSetContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
454 const OUString& rLName,
455 const ::com::sun::star::uno::Reference<
456 ::com::sun::star::xml::sax::XAttributeList>&,
457 com::sun::star::uno::Any& rAny,
458 XMLConfigBaseContext* pBaseContext)
459 : XMLConfigBaseContext( rImport, nPrfx, rLName, rAny, pBaseContext )
461 // here are no attributes
464 XMLConfigItemSetContext::~XMLConfigItemSetContext()
468 SvXMLImportContext *XMLConfigItemSetContext::CreateChildContext( sal_uInt16 nPrefix,
469 const OUString& rLocalName,
470 const ::com::sun::star::uno::Reference<
471 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
473 return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
476 void XMLConfigItemSetContext::EndElement()
478 mrAny <<= maProps.GetSequence();
479 if (mpBaseContext)
480 mpBaseContext->AddPropertyValue();
483 XMLConfigItemContext::XMLConfigItemContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
484 const ::com::sun::star::uno::Reference<
485 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
486 com::sun::star::uno::Any& rTempAny,
487 const OUString& rTempItemName,
488 XMLConfigBaseContext* pTempBaseContext)
489 : SvXMLImportContext(rImport, nPrfx, rLName),
490 mrAny(rTempAny),
491 mrItemName(rTempItemName),
492 mpBaseContext(pTempBaseContext)
494 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
495 for( sal_Int16 i=0; i < nAttrCount; i++ )
497 OUString sAttrName = xAttrList->getNameByIndex( i );
498 OUString aLocalName;
499 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
500 sAttrName, &aLocalName );
501 OUString sValue = xAttrList->getValueByIndex( i );
503 if (nPrefix == XML_NAMESPACE_CONFIG)
505 if (IsXMLToken(aLocalName, XML_TYPE))
506 msType = sValue;
511 XMLConfigItemContext::~XMLConfigItemContext()
515 SvXMLImportContext *XMLConfigItemContext::CreateChildContext( sal_uInt16 nPrefix,
516 const OUString& rLocalName,
517 const ::com::sun::star::uno::Reference<
518 ::com::sun::star::xml::sax::XAttributeList>& )
520 SvXMLImportContext* pContext = new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
521 return pContext;
524 void XMLConfigItemContext::Characters( const OUString& rChars )
526 if (IsXMLToken(msType, XML_BASE64BINARY))
528 OUString sTrimmedChars( rChars.trim() );
529 if( !sTrimmedChars.isEmpty() )
531 OUString sChars;
532 if( !msValue.isEmpty() )
534 sChars = msValue;
535 sChars += sTrimmedChars;
536 msValue.clear();
538 else
540 sChars = sTrimmedChars;
542 uno::Sequence<sal_Int8> aBuffer((sChars.getLength() / 4) * 3 );
543 sal_Int32 const nCharsDecoded =
544 ::sax::Converter::decodeBase64SomeChars( aBuffer, sChars );
545 sal_uInt32 nStartPos(maDecoded.getLength());
546 sal_uInt32 nCount(aBuffer.getLength());
547 maDecoded.realloc(nStartPos + nCount);
548 sal_Int8* pDecoded = maDecoded.getArray();
549 sal_Int8* pBuffer = aBuffer.getArray();
550 for (sal_uInt32 i = 0; i < nCount; i++, pBuffer++)
551 pDecoded[nStartPos + i] = *pBuffer;
552 if( nCharsDecoded != sChars.getLength() )
553 msValue = sChars.copy( nCharsDecoded );
556 else
557 msValue += rChars;
560 void XMLConfigItemContext::EndElement()
562 if (mpBaseContext)
564 if (IsXMLToken(msType, XML_BOOLEAN))
566 bool bValue(false);
567 if (IsXMLToken(msValue, XML_TRUE))
568 bValue = true;
569 mrAny <<= bValue;
571 else if (IsXMLToken(msType, XML_BYTE))
573 sal_Int32 nValue(0);
574 ::sax::Converter::convertNumber(nValue, msValue);
575 mrAny <<= static_cast<sal_Int8>(nValue);
577 else if (IsXMLToken(msType, XML_SHORT))
579 sal_Int32 nValue(0);
580 ::sax::Converter::convertNumber(nValue, msValue);
581 mrAny <<= static_cast<sal_Int16>(nValue);
583 else if (IsXMLToken(msType, XML_INT))
585 sal_Int32 nValue(0);
586 ::sax::Converter::convertNumber(nValue, msValue);
587 mrAny <<= nValue;
589 else if (IsXMLToken(msType, XML_LONG))
591 sal_Int64 nValue(msValue.toInt64());
592 mrAny <<= nValue;
594 else if (IsXMLToken(msType, XML_DOUBLE))
596 double fValue(0.0);
597 ::sax::Converter::convertDouble(fValue, msValue);
598 mrAny <<= fValue;
600 else if (IsXMLToken(msType, XML_STRING))
602 mrAny <<= msValue;
604 else if (IsXMLToken(msType, XML_DATETIME))
606 util::DateTime aDateTime;
607 ::sax::Converter::parseDateTime(aDateTime, 0, msValue);
608 mrAny <<= aDateTime;
610 else if (IsXMLToken(msType, XML_BASE64BINARY))
612 mrAny <<= maDecoded;
614 else {
615 OSL_FAIL("wrong type");
618 ManipulateConfigItem();
620 mpBaseContext->AddPropertyValue();
622 else {
623 OSL_FAIL("no BaseContext");
627 /** There are some instances where there is a mismatch between API and
628 * XML mapping of a setting. In this case, this method allows us to
629 * manipulate the values accordingly. */
630 void XMLConfigItemContext::ManipulateConfigItem()
632 if( mrItemName == "PrinterIndependentLayout" )
634 OUString sValue;
635 mrAny >>= sValue;
637 sal_Int16 nTmp = document::PrinterIndependentLayout::HIGH_RESOLUTION;
639 if( sValue == "enabled" || sValue == "low-resolution" )
641 nTmp = document::PrinterIndependentLayout::LOW_RESOLUTION;
643 else if ( sValue == "disabled" )
645 nTmp = document::PrinterIndependentLayout::DISABLED;
647 // else: default to high_resolution
649 mrAny <<= nTmp;
651 else if( (mrItemName == "ColorTableURL") || (mrItemName == "LineEndTableURL") || (mrItemName == "HatchTableURL")
652 || (mrItemName == "DashTableURL") || (mrItemName == "GradientTableURL") || (mrItemName == "BitmapTableURL") )
656 uno::Reference< uno::XComponentContext > xContext( GetImport().GetComponentContext() );
657 uno::Reference< util::XStringSubstitution > xStringSubsitution( util::PathSubstitution::create(xContext) );
659 OUString aURL;
660 mrAny >>= aURL;
661 aURL = xStringSubsitution->substituteVariables( aURL, sal_False );
662 mrAny <<= aURL;
664 catch( uno::Exception& )
670 XMLConfigItemMapNamedContext::XMLConfigItemMapNamedContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
671 const ::com::sun::star::uno::Reference<
672 ::com::sun::star::xml::sax::XAttributeList>&,
673 com::sun::star::uno::Any& rAny,
674 XMLConfigBaseContext* pBaseContext)
675 : XMLConfigBaseContext(rImport, nPrfx, rLName, rAny, pBaseContext)
679 XMLConfigItemMapNamedContext::~XMLConfigItemMapNamedContext()
683 SvXMLImportContext *XMLConfigItemMapNamedContext::CreateChildContext( sal_uInt16 nPrefix,
684 const OUString& rLocalName,
685 const ::com::sun::star::uno::Reference<
686 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
688 return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
691 void XMLConfigItemMapNamedContext::EndElement()
693 if (mpBaseContext)
695 mrAny <<= maProps.GetNameContainer();
696 mpBaseContext->AddPropertyValue();
698 else {
699 OSL_FAIL("no BaseContext");
703 XMLConfigItemMapIndexedContext::XMLConfigItemMapIndexedContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
704 const OUString& rLName,
705 const ::com::sun::star::uno::Reference<
706 ::com::sun::star::xml::sax::XAttributeList>&,
707 com::sun::star::uno::Any& rAny,
708 const OUString& rConfigItemName,
709 XMLConfigBaseContext* pBaseContext)
710 : XMLConfigBaseContext(rImport, nPrfx, rLName, rAny, pBaseContext),
711 maConfigItemName( rConfigItemName )
715 XMLConfigItemMapIndexedContext::~XMLConfigItemMapIndexedContext()
719 SvXMLImportContext *XMLConfigItemMapIndexedContext::CreateChildContext( sal_uInt16 nPrefix,
720 const OUString& rLocalName,
721 const ::com::sun::star::uno::Reference<
722 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
724 return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
727 void XMLConfigItemMapIndexedContext::EndElement()
729 if (mpBaseContext)
731 if ( maConfigItemName == "ForbiddenCharacters" )
733 uno::Reference< i18n::XForbiddenCharacters > xForbChars;
735 // get the forbidden characters from the document
736 uno::Reference< lang::XMultiServiceFactory > xFac( GetImport().GetModel(), uno::UNO_QUERY );
737 if( xFac.is() )
739 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance( "com.sun.star.document.Settings" ), uno::UNO_QUERY );
740 if( xProps.is() && xProps->getPropertySetInfo()->hasPropertyByName( maConfigItemName ) )
742 xProps->getPropertyValue( maConfigItemName ) >>= xForbChars;
746 if( xForbChars.is() )
749 uno::Reference< container::XIndexAccess > xIndex( maProps.GetIndexContainer(), uno::UNO_QUERY );
751 const sal_Int32 nCount = xIndex->getCount();
752 uno::Sequence < beans::PropertyValue > aProps;
753 for (sal_Int32 i = 0; i < nCount; i++)
755 if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_FORBIDDEN_CHARACTER_MAX ) )
757 /* FIXME-BCP47: this stupid and counterpart in
758 * xmloff/source/core/SettingsExportHelper.cxx
759 * XMLSettingsExportHelper::exportForbiddenCharacters()
760 * */
762 beans::PropertyValue *pForChar = aProps.getArray();
763 i18n::ForbiddenCharacters aForbid;
764 lang::Locale aLocale;
765 bool bHaveLanguage = false, bHaveCountry = false, bHaveVariant = false,
766 bHaveBegin = false, bHaveEnd = false;
768 for ( sal_Int32 j = 0 ; j < XML_FORBIDDEN_CHARACTER_MAX ; j++ )
770 if (pForChar->Name == "Language")
772 pForChar->Value >>= aLocale.Language;
773 bHaveLanguage = true;
775 else if (pForChar->Name == "Country")
777 pForChar->Value >>= aLocale.Country;
778 bHaveCountry = true;
780 else if (pForChar->Name == "Variant")
782 pForChar->Value >>= aLocale.Variant;
783 bHaveVariant = true;
785 else if (pForChar->Name == "BeginLine")
787 pForChar->Value >>= aForbid.beginLine;
788 bHaveBegin = true;
790 else if (pForChar->Name == "EndLine")
792 pForChar->Value >>= aForbid.endLine;
793 bHaveEnd = true;
795 pForChar++;
798 if ( bHaveLanguage && bHaveCountry && bHaveVariant && bHaveBegin && bHaveEnd )
802 xForbChars->setForbiddenCharacters( aLocale, aForbid );
804 catch( uno::Exception& )
806 OSL_FAIL( "Exception while importing forbidden characters" );
812 else
814 OSL_FAIL( "could not get the XForbiddenCharacters from document!" );
815 mrAny <<= maProps.GetIndexContainer();
818 else if ( maConfigItemName == "Symbols" )
820 uno::Reference< container::XIndexAccess > xIndex( maProps.GetIndexContainer(), uno::UNO_QUERY );
822 const sal_Int32 nCount = xIndex->getCount();
823 uno::Sequence < beans::PropertyValue > aProps;
824 uno::Sequence < formula::SymbolDescriptor > aSymbolList ( nCount );
826 formula::SymbolDescriptor *pDescriptor = aSymbolList.getArray();
828 sal_Int16 nNumFullEntries = 0;
830 for ( sal_Int32 i = 0; i < nCount; i++ )
832 if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_SYMBOL_DESCRIPTOR_MAX ) )
834 bool bHaveName = false, bHaveExportName = false, bHaveCharSet = false,
835 bHaveFontName = false, bHaveFamily = false, bHavePitch = false,
836 bHaveWeight = false, bHaveItalic = false, bHaveSymbolSet = false,
837 bHaveCharacter = false;
838 beans::PropertyValue *pSymbol = aProps.getArray();
840 for ( sal_Int32 j = 0 ; j < XML_SYMBOL_DESCRIPTOR_MAX ; j++ )
842 if (pSymbol->Name == "Name")
844 pSymbol->Value >>= pDescriptor[nNumFullEntries].sName;
845 bHaveName = true;
847 else if (pSymbol->Name == "ExportName")
849 pSymbol->Value >>= pDescriptor[nNumFullEntries].sExportName;
850 bHaveExportName = true;
852 else if (pSymbol->Name == "FontName")
854 pSymbol->Value >>= pDescriptor[nNumFullEntries].sFontName;
855 bHaveFontName = true;
857 else if (pSymbol->Name == "CharSet")
859 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharSet;
860 bHaveCharSet = true;
862 else if (pSymbol->Name == "Family")
864 pSymbol->Value >>= pDescriptor[nNumFullEntries].nFamily;
865 bHaveFamily = true;
867 else if (pSymbol->Name == "Pitch")
869 pSymbol->Value >>= pDescriptor[nNumFullEntries].nPitch;
870 bHavePitch = true;
872 else if (pSymbol->Name == "Weight")
874 pSymbol->Value >>= pDescriptor[nNumFullEntries].nWeight;
875 bHaveWeight = true;
877 else if (pSymbol->Name == "Italic")
879 pSymbol->Value >>= pDescriptor[nNumFullEntries].nItalic;
880 bHaveItalic = true;
882 else if (pSymbol->Name == "SymbolSet")
884 pSymbol->Value >>= pDescriptor[nNumFullEntries].sSymbolSet;
885 bHaveSymbolSet = true;
887 else if (pSymbol->Name == "Character")
889 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharacter;
890 bHaveCharacter = true;
892 pSymbol++;
894 if ( bHaveName && bHaveExportName && bHaveCharSet && bHaveFontName && bHaveCharacter
895 && bHaveFamily && bHavePitch && bHaveWeight && bHaveItalic && bHaveSymbolSet)
896 nNumFullEntries++;
899 aSymbolList.realloc (nNumFullEntries);
900 mrAny <<= aSymbolList;
902 else
904 mrAny <<= maProps.GetIndexContainer();
906 mpBaseContext->AddPropertyValue();
908 else {
909 OSL_FAIL("no BaseContext");
913 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */