Bump version to 6.4.0.12
[LibreOffice.git] / xmloff / source / core / DocumentSettingsContext.cxx
blob59c61614e6d8bdb62e8d5ff806084ac4e0764212
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 <comphelper/base64.hxx>
34 #include <vector>
35 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
36 #include <com/sun/star/container/XIndexContainer.hpp>
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #include <com/sun/star/formula/SymbolDescriptor.hpp>
39 #include <com/sun/star/util/DateTime.hpp>
40 #include <com/sun/star/document/XViewDataSupplier.hpp>
41 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
42 #include <com/sun/star/document/IndexedPropertyValues.hpp>
43 #include <com/sun/star/document/NamedPropertyValues.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <sal/log.hxx>
46 #include <osl/diagnose.h>
47 #include <tools/diagnose_ex.h>
48 #include <unotools/configmgr.hxx>
49 #include "xmlenums.hxx"
51 using namespace com::sun::star;
52 using namespace ::xmloff::token;
54 class XMLMyList
56 std::vector<beans::PropertyValue> aProps;
57 sal_uInt32 nCount;
59 css::uno::Reference< css::uno::XComponentContext > m_xContext;
61 public:
62 explicit XMLMyList(const uno::Reference<uno::XComponentContext>& rxContext);
64 void push_back(beans::PropertyValue const & aProp) { aProps.push_back(aProp); nCount++; }
65 uno::Sequence<beans::PropertyValue> GetSequence();
66 uno::Reference<container::XNameContainer> GetNameContainer();
67 uno::Reference<container::XIndexContainer> GetIndexContainer();
70 XMLMyList::XMLMyList(const uno::Reference<uno::XComponentContext>& rxContext)
71 : nCount(0),
72 m_xContext(rxContext)
74 assert(m_xContext.is());
77 uno::Sequence<beans::PropertyValue> XMLMyList::GetSequence()
79 uno::Sequence<beans::PropertyValue> aSeq;
80 if(nCount)
82 assert(nCount == aProps.size());
83 aSeq.realloc(nCount);
84 beans::PropertyValue* pProps = aSeq.getArray();
85 for (auto const& prop : aProps)
87 *pProps = prop;
88 ++pProps;
91 return aSeq;
94 uno::Reference<container::XNameContainer> XMLMyList::GetNameContainer()
96 uno::Reference<container::XNameContainer> xNameContainer = document::NamedPropertyValues::create(m_xContext);
97 for (auto const& prop : aProps)
99 xNameContainer->insertByName(prop.Name, prop.Value);
102 return xNameContainer;
105 uno::Reference<container::XIndexContainer> XMLMyList::GetIndexContainer()
107 uno::Reference<container::XIndexContainer> xIndexContainer = document::IndexedPropertyValues::create(m_xContext);
108 sal_uInt32 i(0);
109 for (auto const& prop : aProps)
111 xIndexContainer->insertByIndex(i, prop.Value);
112 ++i;
115 return xIndexContainer;
118 class XMLConfigBaseContext : public SvXMLImportContext
120 protected:
121 XMLMyList maProps;
122 beans::PropertyValue maProp;
123 css::uno::Any& mrAny;
124 XMLConfigBaseContext* mpBaseContext;
125 public:
126 XMLConfigBaseContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
127 css::uno::Any& rAny,
128 XMLConfigBaseContext* pBaseContext);
130 void AddPropertyValue() { maProps.push_back(maProp); }
133 class XMLConfigItemContext : public SvXMLImportContext
135 OUString msType;
136 OUString msValue;
137 uno::Sequence<sal_Int8> maDecoded;
138 css::uno::Any& mrAny;
139 const OUString mrItemName;
140 XMLConfigBaseContext* mpBaseContext;
142 public:
143 XMLConfigItemContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
144 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
145 css::uno::Any& rAny,
146 const OUString& rItemName,
147 XMLConfigBaseContext* pBaseContext);
149 virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
150 const OUString& rLocalName,
151 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override;
152 virtual void Characters( const OUString& rChars ) override;
154 virtual void EndElement() override;
156 void ManipulateConfigItem();
159 class XMLConfigItemSetContext : public XMLConfigBaseContext
161 public:
162 XMLConfigItemSetContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
163 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
164 css::uno::Any& rAny,
165 XMLConfigBaseContext* pBaseContext);
167 virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
168 const OUString& rLocalName,
169 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override;
171 virtual void EndElement() override;
174 class XMLConfigItemMapNamedContext : public XMLConfigBaseContext
176 public:
177 XMLConfigItemMapNamedContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
178 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
179 css::uno::Any& rAny,
180 XMLConfigBaseContext* pBaseContext);
182 virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
183 const OUString& rLocalName,
184 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override;
186 virtual void EndElement() override;
189 class XMLConfigItemMapIndexedContext : public XMLConfigBaseContext
191 private:
192 OUString const maConfigItemName;
194 public:
195 XMLConfigItemMapIndexedContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
196 const OUString& rLName,
197 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
198 css::uno::Any& rAny,
199 const OUString& rConfigItemName,
200 XMLConfigBaseContext* pBaseContext);
202 virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
203 const OUString& rLocalName,
204 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override;
206 virtual void EndElement() override;
209 static SvXMLImportContext *CreateSettingsContext(SvXMLImport& rImport, sal_uInt16 p_nPrefix,
210 const OUString& rLocalName,
211 const uno::Reference<xml::sax::XAttributeList>& xAttrList,
212 beans::PropertyValue& rProp, XMLConfigBaseContext* pBaseContext)
214 SvXMLImportContext *pContext = nullptr;
216 rProp.Name.clear();
217 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
218 for( sal_Int16 i=0; i < nAttrCount; i++ )
220 OUString sAttrName = xAttrList->getNameByIndex( i );
221 OUString aLocalName;
222 sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(
223 sAttrName, &aLocalName );
224 OUString sValue = xAttrList->getValueByIndex( i );
226 if (nPrefix == XML_NAMESPACE_CONFIG)
228 if (IsXMLToken(aLocalName, XML_NAME))
229 rProp.Name = sValue;
233 if (p_nPrefix == XML_NAMESPACE_CONFIG)
235 if (IsXMLToken(rLocalName, XML_CONFIG_ITEM))
236 pContext = new XMLConfigItemContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, rProp.Name, pBaseContext);
237 else if((IsXMLToken(rLocalName, XML_CONFIG_ITEM_SET)) ||
238 (IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_ENTRY)) )
239 pContext = new XMLConfigItemSetContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, pBaseContext);
240 else if(IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_NAMED))
241 pContext = new XMLConfigItemMapNamedContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, pBaseContext);
242 else if(IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_INDEXED))
243 pContext = new XMLConfigItemMapIndexedContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, rProp.Name, pBaseContext);
246 if( !pContext )
247 pContext = new SvXMLImportContext( rImport, p_nPrefix, rLocalName );
249 return pContext;
252 namespace
254 struct SettingsGroup
256 OUString const sGroupName;
257 uno::Any aSettings;
259 SettingsGroup( const OUString& _rGroupName, const uno::Any& _rSettings )
260 :sGroupName( _rGroupName )
261 ,aSettings( _rSettings )
267 struct XMLDocumentSettingsContext_Data
269 css::uno::Any aViewProps;
270 css::uno::Any aConfigProps;
271 ::std::vector< SettingsGroup > aDocSpecificSettings;
274 XMLDocumentSettingsContext::XMLDocumentSettingsContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
275 const uno::Reference<xml::sax::XAttributeList>& )
276 : SvXMLImportContext( rImport, nPrfx, rLName )
277 , m_pData( new XMLDocumentSettingsContext_Data )
279 // here are no attributes
282 XMLDocumentSettingsContext::~XMLDocumentSettingsContext()
286 SvXMLImportContextRef XMLDocumentSettingsContext::CreateChildContext( sal_uInt16 p_nPrefix,
287 const OUString& rLocalName,
288 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList )
290 SvXMLImportContext *pContext = nullptr;
291 OUString sName;
293 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
294 for( sal_Int16 i=0; i < nAttrCount; i++ )
296 OUString sAttrName = xAttrList->getNameByIndex( i );
297 OUString aLocalName;
298 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
299 sAttrName, &aLocalName );
300 OUString sValue = xAttrList->getValueByIndex( i );
302 if (nPrefix == XML_NAMESPACE_CONFIG)
304 if (IsXMLToken(aLocalName, XML_NAME))
305 sName = sValue;
309 if (p_nPrefix == XML_NAMESPACE_CONFIG)
311 if (IsXMLToken(rLocalName, XML_CONFIG_ITEM_SET))
313 OUString aLocalConfigName;
314 sal_uInt16 nConfigPrefix =
315 GetImport().GetNamespaceMap().GetKeyByAttrName(
316 sName, &aLocalConfigName );
318 if( XML_NAMESPACE_OOO == nConfigPrefix )
320 if (IsXMLToken(aLocalConfigName, XML_VIEW_SETTINGS))
321 pContext = new XMLConfigItemSetContext(GetImport(),
322 p_nPrefix, rLocalName, xAttrList,
323 m_pData->aViewProps, nullptr);
324 else if (IsXMLToken(aLocalConfigName,
325 XML_CONFIGURATION_SETTINGS))
326 pContext = new XMLConfigItemSetContext(GetImport(),
327 p_nPrefix, rLocalName, xAttrList,
328 m_pData->aConfigProps, nullptr);
329 else
331 m_pData->aDocSpecificSettings.emplace_back( aLocalConfigName, uno::Any() );
333 pContext = new XMLConfigItemSetContext(GetImport(),
334 p_nPrefix, rLocalName, xAttrList,
335 m_pData->aDocSpecificSettings.back().aSettings, nullptr);
341 if( !pContext )
342 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
344 return pContext;
347 void XMLDocumentSettingsContext::EndElement()
349 uno::Sequence<beans::PropertyValue> aSeqViewProps;
350 if (m_pData->aViewProps >>= aSeqViewProps)
352 GetImport().SetViewSettings(aSeqViewProps);
353 sal_Int32 i(aSeqViewProps.getLength() - 1);
354 bool bFound(false);
355 while((i >= 0) && !bFound)
357 if (aSeqViewProps[i].Name == "Views")
359 bFound = true;
360 uno::Reference<container::XIndexAccess> xIndexAccess;
361 if (aSeqViewProps[i].Value >>= xIndexAccess)
363 uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetImport().GetModel(), uno::UNO_QUERY);
364 if (xViewDataSupplier.is())
365 xViewDataSupplier->setViewData(xIndexAccess);
368 else
369 i--;
373 uno::Sequence<beans::PropertyValue> aSeqConfigProps;
374 if ( m_pData->aConfigProps >>= aSeqConfigProps )
376 if (!utl::ConfigManager::IsFuzzing() && !officecfg::Office::Common::Save::Document::LoadPrinter::get())
378 sal_Int32 i = aSeqConfigProps.getLength() - 1;
379 int nFound = 0;
381 while ( ( i >= 0 ) && nFound < 2 )
383 OUString sProp( aSeqConfigProps[i].Name );
385 if ( sProp == "PrinterName" )
387 aSeqConfigProps[i].Value <<= OUString();
388 nFound++;
390 else if ( sProp == "PrinterSetup" )
392 uno::Sequence< sal_Int8 > aEmpty;
393 aSeqConfigProps[i].Value <<= aEmpty;
394 nFound++;
397 i--;
401 GetImport().SetConfigurationSettings( aSeqConfigProps );
404 for (auto const& settings : m_pData->aDocSpecificSettings)
406 uno::Sequence< beans::PropertyValue > aDocSettings;
407 OSL_VERIFY( settings.aSettings >>= aDocSettings );
408 GetImport().SetDocumentSpecificSettings( settings.sGroupName, aDocSettings );
412 XMLConfigBaseContext::XMLConfigBaseContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
413 const OUString& rLName, css::uno::Any& rTempAny,
414 XMLConfigBaseContext* pTempBaseContext)
415 : SvXMLImportContext( rImport, nPrfx, rLName ),
416 maProps( rImport.GetComponentContext() ),
417 maProp(),
418 mrAny(rTempAny),
419 mpBaseContext(pTempBaseContext)
423 XMLConfigItemSetContext::XMLConfigItemSetContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
424 const OUString& rLName,
425 const css::uno::Reference< css::xml::sax::XAttributeList>&,
426 css::uno::Any& rAny,
427 XMLConfigBaseContext* pBaseContext)
428 : XMLConfigBaseContext( rImport, nPrfx, rLName, rAny, pBaseContext )
430 // here are no attributes
433 SvXMLImportContextRef XMLConfigItemSetContext::CreateChildContext( sal_uInt16 nPrefix,
434 const OUString& rLocalName,
435 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList )
437 return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
440 void XMLConfigItemSetContext::EndElement()
442 mrAny <<= maProps.GetSequence();
443 if (mpBaseContext)
444 mpBaseContext->AddPropertyValue();
447 XMLConfigItemContext::XMLConfigItemContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
448 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList,
449 css::uno::Any& rTempAny,
450 const OUString& rTempItemName,
451 XMLConfigBaseContext* pTempBaseContext)
452 : SvXMLImportContext(rImport, nPrfx, rLName),
453 mrAny(rTempAny),
454 mrItemName(rTempItemName),
455 mpBaseContext(pTempBaseContext)
457 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
458 for( sal_Int16 i=0; i < nAttrCount; i++ )
460 OUString sAttrName = xAttrList->getNameByIndex( i );
461 OUString aLocalName;
462 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
463 sAttrName, &aLocalName );
464 OUString sValue = xAttrList->getValueByIndex( i );
466 if (nPrefix == XML_NAMESPACE_CONFIG)
468 if (IsXMLToken(aLocalName, XML_TYPE))
469 msType = sValue;
474 SvXMLImportContextRef XMLConfigItemContext::CreateChildContext( sal_uInt16 nPrefix,
475 const OUString& rLocalName,
476 const css::uno::Reference< css::xml::sax::XAttributeList>& )
478 SvXMLImportContext* pContext = new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
479 return pContext;
482 void XMLConfigItemContext::Characters( const OUString& rChars )
484 if (IsXMLToken(msType, XML_BASE64BINARY))
486 OUString sTrimmedChars( rChars.trim() );
487 if( !sTrimmedChars.isEmpty() )
489 OUString sChars;
490 if( !msValue.isEmpty() )
492 sChars = msValue + sTrimmedChars;
493 msValue.clear();
495 else
497 sChars = sTrimmedChars;
499 uno::Sequence<sal_Int8> aBuffer((sChars.getLength() / 4) * 3 );
500 sal_Int32 const nCharsDecoded =
501 ::comphelper::Base64::decodeSomeChars( aBuffer, sChars );
502 sal_uInt32 nStartPos(maDecoded.getLength());
503 sal_uInt32 nCount(aBuffer.getLength());
504 maDecoded.realloc(nStartPos + nCount);
505 std::copy(aBuffer.begin(), aBuffer.end(), std::next(maDecoded.begin(), nStartPos));
506 if( nCharsDecoded != sChars.getLength() )
507 msValue = sChars.copy( nCharsDecoded );
510 else
511 msValue += rChars;
514 void XMLConfigItemContext::EndElement()
516 if (mpBaseContext)
518 if (IsXMLToken(msType, XML_BOOLEAN))
520 bool bValue(false);
521 if (IsXMLToken(msValue, XML_TRUE))
522 bValue = true;
523 mrAny <<= bValue;
525 else if (IsXMLToken(msType, XML_BYTE))
527 sal_Int32 nValue(0);
528 ::sax::Converter::convertNumber(nValue, msValue);
529 mrAny <<= static_cast<sal_Int8>(nValue);
531 else if (IsXMLToken(msType, XML_SHORT))
533 sal_Int32 nValue(0);
534 ::sax::Converter::convertNumber(nValue, msValue);
535 mrAny <<= static_cast<sal_Int16>(nValue);
537 else if (IsXMLToken(msType, XML_INT))
539 sal_Int32 nValue(0);
540 ::sax::Converter::convertNumber(nValue, msValue);
541 mrAny <<= nValue;
543 else if (IsXMLToken(msType, XML_LONG))
545 sal_Int64 nValue(msValue.toInt64());
546 mrAny <<= nValue;
548 else if (IsXMLToken(msType, XML_DOUBLE))
550 double fValue(0.0);
551 ::sax::Converter::convertDouble(fValue, msValue);
552 mrAny <<= fValue;
554 else if (IsXMLToken(msType, XML_STRING))
556 mrAny <<= msValue;
558 else if (IsXMLToken(msType, XML_DATETIME))
560 util::DateTime aDateTime;
561 ::sax::Converter::parseDateTime(aDateTime, msValue);
562 mrAny <<= aDateTime;
564 else if (IsXMLToken(msType, XML_BASE64BINARY))
566 mrAny <<= maDecoded;
568 else {
569 SAL_INFO("xmloff.core",
570 "XMLConfigItemContext: unknown type: " << msType);
573 ManipulateConfigItem();
575 mpBaseContext->AddPropertyValue();
577 else {
578 assert(false && "no BaseContext");
582 /** There are some instances where there is a mismatch between API and
583 * XML mapping of a setting. In this case, this method allows us to
584 * manipulate the values accordingly. */
585 void XMLConfigItemContext::ManipulateConfigItem()
587 if( mrItemName == "PrinterIndependentLayout" )
589 OUString sValue;
590 mrAny >>= sValue;
592 sal_Int16 nTmp = document::PrinterIndependentLayout::HIGH_RESOLUTION;
594 if( sValue == "enabled" || sValue == "low-resolution" )
596 nTmp = document::PrinterIndependentLayout::LOW_RESOLUTION;
598 else if ( sValue == "disabled" )
600 nTmp = document::PrinterIndependentLayout::DISABLED;
602 // else: default to high_resolution
604 mrAny <<= nTmp;
606 else if( (mrItemName == "ColorTableURL") || (mrItemName == "LineEndTableURL") || (mrItemName == "HatchTableURL")
607 || (mrItemName == "DashTableURL") || (mrItemName == "GradientTableURL") || (mrItemName == "BitmapTableURL") )
611 uno::Reference< uno::XComponentContext > xContext( GetImport().GetComponentContext() );
612 uno::Reference< util::XStringSubstitution > xStringSubsitution( util::PathSubstitution::create(xContext) );
614 OUString aURL;
615 mrAny >>= aURL;
616 aURL = xStringSubsitution->substituteVariables( aURL, false );
617 mrAny <<= aURL;
619 catch( uno::Exception& )
625 XMLConfigItemMapNamedContext::XMLConfigItemMapNamedContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
626 const css::uno::Reference< css::xml::sax::XAttributeList>&,
627 css::uno::Any& rAny,
628 XMLConfigBaseContext* pBaseContext)
629 : XMLConfigBaseContext(rImport, nPrfx, rLName, rAny, pBaseContext)
633 SvXMLImportContextRef XMLConfigItemMapNamedContext::CreateChildContext( sal_uInt16 nPrefix,
634 const OUString& rLocalName,
635 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList )
637 return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
640 void XMLConfigItemMapNamedContext::EndElement()
642 if (mpBaseContext)
644 mrAny <<= maProps.GetNameContainer();
645 mpBaseContext->AddPropertyValue();
647 else {
648 assert(false && "no BaseContext");
652 XMLConfigItemMapIndexedContext::XMLConfigItemMapIndexedContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
653 const OUString& rLName,
654 const css::uno::Reference< css::xml::sax::XAttributeList>&,
655 css::uno::Any& rAny,
656 const OUString& rConfigItemName,
657 XMLConfigBaseContext* pBaseContext)
658 : XMLConfigBaseContext(rImport, nPrfx, rLName, rAny, pBaseContext),
659 maConfigItemName( rConfigItemName )
663 SvXMLImportContextRef XMLConfigItemMapIndexedContext::CreateChildContext( sal_uInt16 nPrefix,
664 const OUString& rLocalName,
665 const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList )
667 return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
670 void XMLConfigItemMapIndexedContext::EndElement()
672 if (mpBaseContext)
674 if ( maConfigItemName == "ForbiddenCharacters" )
676 uno::Reference< i18n::XForbiddenCharacters > xForbChars;
678 // get the forbidden characters from the document
679 uno::Reference< lang::XMultiServiceFactory > xFac( GetImport().GetModel(), uno::UNO_QUERY );
680 if( xFac.is() )
682 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance( "com.sun.star.document.Settings" ), uno::UNO_QUERY );
683 if( xProps.is() && xProps->getPropertySetInfo()->hasPropertyByName( maConfigItemName ) )
685 xProps->getPropertyValue( maConfigItemName ) >>= xForbChars;
689 if( xForbChars.is() )
692 uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
694 const sal_Int32 nCount = xIndex->getCount();
695 uno::Sequence < beans::PropertyValue > aProps;
696 for (sal_Int32 i = 0; i < nCount; i++)
698 if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_FORBIDDEN_CHARACTER_MAX ) )
700 /* FIXME-BCP47: this stupid and counterpart in
701 * xmloff/source/core/SettingsExportHelper.cxx
702 * XMLSettingsExportHelper::exportForbiddenCharacters()
703 * */
705 beans::PropertyValue *pForChar = aProps.getArray();
706 i18n::ForbiddenCharacters aForbid;
707 lang::Locale aLocale;
708 bool bHaveLanguage = false, bHaveCountry = false, bHaveVariant = false,
709 bHaveBegin = false, bHaveEnd = false;
711 for ( sal_Int32 j = 0 ; j < XML_FORBIDDEN_CHARACTER_MAX ; j++ )
713 if (pForChar->Name == "Language")
715 pForChar->Value >>= aLocale.Language;
716 bHaveLanguage = true;
718 else if (pForChar->Name == "Country")
720 pForChar->Value >>= aLocale.Country;
721 bHaveCountry = true;
723 else if (pForChar->Name == "Variant")
725 pForChar->Value >>= aLocale.Variant;
726 bHaveVariant = true;
728 else if (pForChar->Name == "BeginLine")
730 pForChar->Value >>= aForbid.beginLine;
731 bHaveBegin = true;
733 else if (pForChar->Name == "EndLine")
735 pForChar->Value >>= aForbid.endLine;
736 bHaveEnd = true;
738 pForChar++;
741 if ( bHaveLanguage && bHaveCountry && bHaveVariant && bHaveBegin && bHaveEnd )
745 xForbChars->setForbiddenCharacters( aLocale, aForbid );
747 catch (uno::Exception const&)
749 TOOLS_WARN_EXCEPTION("xmloff.core",
750 "Exception while importing forbidden characters");
756 else
758 SAL_WARN("xmloff.core", "could not get the XForbiddenCharacters from document!");
759 mrAny <<= maProps.GetIndexContainer();
762 else if ( maConfigItemName == "Symbols" )
764 uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
766 const sal_Int32 nCount = xIndex->getCount();
767 uno::Sequence < beans::PropertyValue > aProps;
768 uno::Sequence < formula::SymbolDescriptor > aSymbolList ( nCount );
770 formula::SymbolDescriptor *pDescriptor = aSymbolList.getArray();
772 sal_Int16 nNumFullEntries = 0;
774 for ( sal_Int32 i = 0; i < nCount; i++ )
776 if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_SYMBOL_DESCRIPTOR_MAX ) )
778 bool bHaveName = false, bHaveExportName = false, bHaveCharSet = false,
779 bHaveFontName = false, bHaveFamily = false, bHavePitch = false,
780 bHaveWeight = false, bHaveItalic = false, bHaveSymbolSet = false,
781 bHaveCharacter = false;
782 beans::PropertyValue *pSymbol = aProps.getArray();
784 for ( sal_Int32 j = 0 ; j < XML_SYMBOL_DESCRIPTOR_MAX ; j++ )
786 if (pSymbol->Name == "Name")
788 pSymbol->Value >>= pDescriptor[nNumFullEntries].sName;
789 bHaveName = true;
791 else if (pSymbol->Name == "ExportName")
793 pSymbol->Value >>= pDescriptor[nNumFullEntries].sExportName;
794 bHaveExportName = true;
796 else if (pSymbol->Name == "FontName")
798 pSymbol->Value >>= pDescriptor[nNumFullEntries].sFontName;
799 bHaveFontName = true;
801 else if (pSymbol->Name == "CharSet")
803 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharSet;
804 bHaveCharSet = true;
806 else if (pSymbol->Name == "Family")
808 pSymbol->Value >>= pDescriptor[nNumFullEntries].nFamily;
809 bHaveFamily = true;
811 else if (pSymbol->Name == "Pitch")
813 pSymbol->Value >>= pDescriptor[nNumFullEntries].nPitch;
814 bHavePitch = true;
816 else if (pSymbol->Name == "Weight")
818 pSymbol->Value >>= pDescriptor[nNumFullEntries].nWeight;
819 bHaveWeight = true;
821 else if (pSymbol->Name == "Italic")
823 pSymbol->Value >>= pDescriptor[nNumFullEntries].nItalic;
824 bHaveItalic = true;
826 else if (pSymbol->Name == "SymbolSet")
828 pSymbol->Value >>= pDescriptor[nNumFullEntries].sSymbolSet;
829 bHaveSymbolSet = true;
831 else if (pSymbol->Name == "Character")
833 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharacter;
834 bHaveCharacter = true;
836 pSymbol++;
838 if ( bHaveName && bHaveExportName && bHaveCharSet && bHaveFontName && bHaveCharacter
839 && bHaveFamily && bHavePitch && bHaveWeight && bHaveItalic && bHaveSymbolSet)
840 nNumFullEntries++;
843 aSymbolList.realloc (nNumFullEntries);
844 mrAny <<= aSymbolList;
846 else
848 mrAny <<= maProps.GetIndexContainer();
850 mpBaseContext->AddPropertyValue();
852 else {
853 assert(false && "no BaseContext");
857 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */