1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <comphelper/processfactory.hxx>
36 #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
37 #include <com/sun/star/container/XIndexContainer.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/formula/SymbolDescriptor.hpp>
40 #include <com/sun/star/util/DateTime.hpp>
41 #include <com/sun/star/document/XViewDataSupplier.hpp>
42 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
43 #include <com/sun/star/document/IndexedPropertyValues.hpp>
44 #include <com/sun/star/document/NamedPropertyValues.hpp>
45 #include <rtl/ustrbuf.hxx>
46 #include <osl/diagnose.h>
47 #include <xmlenums.hxx>
49 using namespace com::sun::star
;
50 using namespace ::xmloff::token
;
54 std::list
<beans::PropertyValue
> aProps
;
57 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
60 explicit XMLMyList(const uno::Reference
<uno::XComponentContext
>& rxContext
);
62 void push_back(beans::PropertyValue
& aProp
) { aProps
.push_back(aProp
); nCount
++; }
63 uno::Sequence
<beans::PropertyValue
> GetSequence();
64 uno::Reference
<container::XNameContainer
> GetNameContainer();
65 uno::Reference
<container::XIndexContainer
> GetIndexContainer();
68 XMLMyList::XMLMyList(const uno::Reference
<uno::XComponentContext
>& rxContext
)
72 assert(m_xContext
.is());
75 uno::Sequence
<beans::PropertyValue
> XMLMyList::GetSequence()
77 uno::Sequence
<beans::PropertyValue
> aSeq
;
80 assert(nCount
== aProps
.size());
82 beans::PropertyValue
* pProps
= aSeq
.getArray();
83 std::list
<beans::PropertyValue
>::iterator aItr
= aProps
.begin();
84 while (aItr
!= aProps
.end())
94 uno::Reference
<container::XNameContainer
> XMLMyList::GetNameContainer()
96 uno::Reference
<container::XNameContainer
> xNameContainer
= document::NamedPropertyValues::create(m_xContext
);
97 std::list
<beans::PropertyValue
>::iterator aItr
= aProps
.begin();
98 while (aItr
!= aProps
.end())
100 xNameContainer
->insertByName(aItr
->Name
, aItr
->Value
);
104 return xNameContainer
;
107 uno::Reference
<container::XIndexContainer
> XMLMyList::GetIndexContainer()
109 uno::Reference
<container::XIndexContainer
> xIndexContainer
= document::IndexedPropertyValues::create(m_xContext
);
110 std::list
<beans::PropertyValue
>::iterator aItr
= aProps
.begin();
112 while (aItr
!= aProps
.end())
114 xIndexContainer
->insertByIndex(i
, aItr
->Value
);
119 return xIndexContainer
;
122 class XMLConfigBaseContext
: public SvXMLImportContext
126 beans::PropertyValue maProp
;
127 css::uno::Any
& mrAny
;
128 XMLConfigBaseContext
* mpBaseContext
;
130 XMLConfigBaseContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
132 XMLConfigBaseContext
* pBaseContext
);
133 virtual ~XMLConfigBaseContext();
135 void AddPropertyValue() { maProps
.push_back(maProp
); }
138 class XMLConfigItemContext
: public SvXMLImportContext
142 uno::Sequence
<sal_Int8
> maDecoded
;
143 css::uno::Any
& mrAny
;
144 const OUString mrItemName
;
145 XMLConfigBaseContext
* mpBaseContext
;
148 XMLConfigItemContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
149 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
151 const OUString
& rItemName
,
152 XMLConfigBaseContext
* pBaseContext
);
153 virtual ~XMLConfigItemContext();
155 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
156 const OUString
& rLocalName
,
157 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
) override
;
158 virtual void Characters( const OUString
& rChars
) override
;
160 virtual void EndElement() override
;
162 void ManipulateConfigItem();
165 class XMLConfigItemSetContext
: public XMLConfigBaseContext
168 XMLConfigItemSetContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
169 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
171 XMLConfigBaseContext
* pBaseContext
);
172 virtual ~XMLConfigItemSetContext();
174 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
175 const OUString
& rLocalName
,
176 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
) override
;
178 virtual void EndElement() override
;
181 class XMLConfigItemMapNamedContext
: public XMLConfigBaseContext
184 XMLConfigItemMapNamedContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
185 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
187 XMLConfigBaseContext
* pBaseContext
);
188 virtual ~XMLConfigItemMapNamedContext();
190 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
191 const OUString
& rLocalName
,
192 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
) override
;
194 virtual void EndElement() override
;
197 class XMLConfigItemMapIndexedContext
: public XMLConfigBaseContext
200 OUString maConfigItemName
;
203 XMLConfigItemMapIndexedContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
204 const OUString
& rLName
,
205 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
207 const OUString
& rConfigItemName
,
208 XMLConfigBaseContext
* pBaseContext
);
209 virtual ~XMLConfigItemMapIndexedContext();
211 virtual SvXMLImportContext
*CreateChildContext( sal_uInt16 nPrefix
,
212 const OUString
& rLocalName
,
213 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
) override
;
215 virtual void EndElement() override
;
218 SvXMLImportContext
*CreateSettingsContext(SvXMLImport
& rImport
, sal_uInt16 p_nPrefix
,
219 const OUString
& rLocalName
,
220 const uno::Reference
<xml::sax::XAttributeList
>& xAttrList
,
221 beans::PropertyValue
& rProp
, XMLConfigBaseContext
* pBaseContext
)
223 SvXMLImportContext
*pContext
= nullptr;
226 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
227 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
229 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
231 sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().GetKeyByAttrName(
232 sAttrName
, &aLocalName
);
233 OUString sValue
= xAttrList
->getValueByIndex( i
);
235 if (nPrefix
== XML_NAMESPACE_CONFIG
)
237 if (IsXMLToken(aLocalName
, XML_NAME
))
242 if (p_nPrefix
== XML_NAMESPACE_CONFIG
)
244 if (IsXMLToken(rLocalName
, XML_CONFIG_ITEM
))
245 pContext
= new XMLConfigItemContext(rImport
, p_nPrefix
, rLocalName
, xAttrList
, rProp
.Value
, rProp
.Name
, pBaseContext
);
246 else if((IsXMLToken(rLocalName
, XML_CONFIG_ITEM_SET
)) ||
247 (IsXMLToken(rLocalName
, XML_CONFIG_ITEM_MAP_ENTRY
)) )
248 pContext
= new XMLConfigItemSetContext(rImport
, p_nPrefix
, rLocalName
, xAttrList
, rProp
.Value
, pBaseContext
);
249 else if(IsXMLToken(rLocalName
, XML_CONFIG_ITEM_MAP_NAMED
))
250 pContext
= new XMLConfigItemMapNamedContext(rImport
, p_nPrefix
, rLocalName
, xAttrList
, rProp
.Value
, pBaseContext
);
251 else if(IsXMLToken(rLocalName
, XML_CONFIG_ITEM_MAP_INDEXED
))
252 pContext
= new XMLConfigItemMapIndexedContext(rImport
, p_nPrefix
, rLocalName
, xAttrList
, rProp
.Value
, rProp
.Name
, pBaseContext
);
256 pContext
= new SvXMLImportContext( rImport
, p_nPrefix
, rLocalName
);
268 SettingsGroup( const OUString
& _rGroupName
, const uno::Any
& _rSettings
)
269 :sGroupName( _rGroupName
)
270 ,aSettings( _rSettings
)
276 struct XMLDocumentSettingsContext_Data
278 css::uno::Any aViewProps
;
279 css::uno::Any aConfigProps
;
280 ::std::list
< SettingsGroup
> aDocSpecificSettings
;
283 XMLDocumentSettingsContext::XMLDocumentSettingsContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
284 const uno::Reference
<xml::sax::XAttributeList
>& )
285 : SvXMLImportContext( rImport
, nPrfx
, rLName
)
286 , m_pData( new XMLDocumentSettingsContext_Data
)
288 // here are no attributes
291 XMLDocumentSettingsContext::~XMLDocumentSettingsContext()
295 SvXMLImportContext
*XMLDocumentSettingsContext::CreateChildContext( sal_uInt16 p_nPrefix
,
296 const OUString
& rLocalName
,
297 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
)
299 SvXMLImportContext
*pContext
= nullptr;
302 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
303 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
305 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
307 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName(
308 sAttrName
, &aLocalName
);
309 OUString sValue
= xAttrList
->getValueByIndex( i
);
311 if (nPrefix
== XML_NAMESPACE_CONFIG
)
313 if (IsXMLToken(aLocalName
, XML_NAME
))
318 if (p_nPrefix
== XML_NAMESPACE_CONFIG
)
320 if (IsXMLToken(rLocalName
, XML_CONFIG_ITEM_SET
))
322 OUString aLocalConfigName
;
323 sal_uInt16 nConfigPrefix
=
324 GetImport().GetNamespaceMap().GetKeyByAttrName(
325 sName
, &aLocalConfigName
);
327 if( XML_NAMESPACE_OOO
== nConfigPrefix
)
329 if (IsXMLToken(aLocalConfigName
, XML_VIEW_SETTINGS
))
330 pContext
= new XMLConfigItemSetContext(GetImport(),
331 p_nPrefix
, rLocalName
, xAttrList
,
332 m_pData
->aViewProps
, nullptr);
333 else if (IsXMLToken(aLocalConfigName
,
334 XML_CONFIGURATION_SETTINGS
))
335 pContext
= new XMLConfigItemSetContext(GetImport(),
336 p_nPrefix
, rLocalName
, xAttrList
,
337 m_pData
->aConfigProps
, nullptr);
340 m_pData
->aDocSpecificSettings
.push_back( SettingsGroup( aLocalConfigName
, uno::Any() ) );
342 ::std::list
< SettingsGroup
>::reverse_iterator settingsPos
=
343 m_pData
->aDocSpecificSettings
.rbegin();
345 pContext
= new XMLConfigItemSetContext(GetImport(),
346 p_nPrefix
, rLocalName
, xAttrList
,
347 settingsPos
->aSettings
, nullptr);
354 pContext
= new SvXMLImportContext( GetImport(), p_nPrefix
, rLocalName
);
359 void XMLDocumentSettingsContext::EndElement()
361 uno::Sequence
<beans::PropertyValue
> aSeqViewProps
;
362 if (m_pData
->aViewProps
>>= aSeqViewProps
)
364 GetImport().SetViewSettings(aSeqViewProps
);
365 sal_Int32
i(aSeqViewProps
.getLength() - 1);
367 while((i
>= 0) && !bFound
)
369 if (aSeqViewProps
[i
].Name
== "Views")
372 uno::Reference
<container::XIndexAccess
> xIndexAccess
;
373 if (aSeqViewProps
[i
].Value
>>= xIndexAccess
)
375 uno::Reference
<document::XViewDataSupplier
> xViewDataSupplier(GetImport().GetModel(), uno::UNO_QUERY
);
376 if (xViewDataSupplier
.is())
377 xViewDataSupplier
->setViewData(xIndexAccess
);
385 uno::Sequence
<beans::PropertyValue
> aSeqConfigProps
;
386 if ( m_pData
->aConfigProps
>>= aSeqConfigProps
)
388 if (!officecfg::Office::Common::Save::Document::LoadPrinter::get())
390 sal_Int32 i
= aSeqConfigProps
.getLength() - 1;
393 while ( ( i
>= 0 ) && nFound
< 2 )
395 OUString
sProp( aSeqConfigProps
[i
].Name
);
397 if ( sProp
== "PrinterName" )
399 aSeqConfigProps
[i
].Value
= uno::makeAny( OUString() );
402 else if ( sProp
== "PrinterSetup" )
404 uno::Sequence
< sal_Int8
> aEmpty
;
405 aSeqConfigProps
[i
].Value
= uno::makeAny( aEmpty
);
413 GetImport().SetConfigurationSettings( aSeqConfigProps
);
416 for ( ::std::list
< SettingsGroup
>::const_iterator settings
= m_pData
->aDocSpecificSettings
.begin();
417 settings
!= m_pData
->aDocSpecificSettings
.end();
421 uno::Sequence
< beans::PropertyValue
> aDocSettings
;
422 OSL_VERIFY( settings
->aSettings
>>= aDocSettings
);
423 GetImport().SetDocumentSpecificSettings( settings
->sGroupName
, aDocSettings
);
427 XMLConfigBaseContext::XMLConfigBaseContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
428 const OUString
& rLName
, css::uno::Any
& rTempAny
,
429 XMLConfigBaseContext
* pTempBaseContext
)
430 : SvXMLImportContext( rImport
, nPrfx
, rLName
),
431 maProps( rImport
.GetComponentContext() ),
434 mpBaseContext(pTempBaseContext
)
438 XMLConfigBaseContext::~XMLConfigBaseContext()
442 XMLConfigItemSetContext::XMLConfigItemSetContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
443 const OUString
& rLName
,
444 const css::uno::Reference
< css::xml::sax::XAttributeList
>&,
446 XMLConfigBaseContext
* pBaseContext
)
447 : XMLConfigBaseContext( rImport
, nPrfx
, rLName
, rAny
, pBaseContext
)
449 // here are no attributes
452 XMLConfigItemSetContext::~XMLConfigItemSetContext()
456 SvXMLImportContext
*XMLConfigItemSetContext::CreateChildContext( sal_uInt16 nPrefix
,
457 const OUString
& rLocalName
,
458 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
)
460 return CreateSettingsContext(GetImport(), nPrefix
, rLocalName
, xAttrList
, maProp
, this);
463 void XMLConfigItemSetContext::EndElement()
465 mrAny
<<= maProps
.GetSequence();
467 mpBaseContext
->AddPropertyValue();
470 XMLConfigItemContext::XMLConfigItemContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
471 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
,
472 css::uno::Any
& rTempAny
,
473 const OUString
& rTempItemName
,
474 XMLConfigBaseContext
* pTempBaseContext
)
475 : SvXMLImportContext(rImport
, nPrfx
, rLName
),
477 mrItemName(rTempItemName
),
478 mpBaseContext(pTempBaseContext
)
480 sal_Int16 nAttrCount
= xAttrList
.is() ? xAttrList
->getLength() : 0;
481 for( sal_Int16 i
=0; i
< nAttrCount
; i
++ )
483 OUString sAttrName
= xAttrList
->getNameByIndex( i
);
485 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().GetKeyByAttrName(
486 sAttrName
, &aLocalName
);
487 OUString sValue
= xAttrList
->getValueByIndex( i
);
489 if (nPrefix
== XML_NAMESPACE_CONFIG
)
491 if (IsXMLToken(aLocalName
, XML_TYPE
))
497 XMLConfigItemContext::~XMLConfigItemContext()
501 SvXMLImportContext
*XMLConfigItemContext::CreateChildContext( sal_uInt16 nPrefix
,
502 const OUString
& rLocalName
,
503 const css::uno::Reference
< css::xml::sax::XAttributeList
>& )
505 SvXMLImportContext
* pContext
= new SvXMLImportContext(GetImport(), nPrefix
, rLocalName
);
509 void XMLConfigItemContext::Characters( const OUString
& rChars
)
511 if (IsXMLToken(msType
, XML_BASE64BINARY
))
513 OUString
sTrimmedChars( rChars
.trim() );
514 if( !sTrimmedChars
.isEmpty() )
517 if( !msValue
.isEmpty() )
520 sChars
+= sTrimmedChars
;
525 sChars
= sTrimmedChars
;
527 uno::Sequence
<sal_Int8
> aBuffer((sChars
.getLength() / 4) * 3 );
528 sal_Int32
const nCharsDecoded
=
529 ::sax::Converter::decodeBase64SomeChars( aBuffer
, sChars
);
530 sal_uInt32
nStartPos(maDecoded
.getLength());
531 sal_uInt32
nCount(aBuffer
.getLength());
532 maDecoded
.realloc(nStartPos
+ nCount
);
533 sal_Int8
* pDecoded
= maDecoded
.getArray();
534 sal_Int8
* pBuffer
= aBuffer
.getArray();
535 for (sal_uInt32 i
= 0; i
< nCount
; i
++, pBuffer
++)
536 pDecoded
[nStartPos
+ i
] = *pBuffer
;
537 if( nCharsDecoded
!= sChars
.getLength() )
538 msValue
= sChars
.copy( nCharsDecoded
);
545 void XMLConfigItemContext::EndElement()
549 if (IsXMLToken(msType
, XML_BOOLEAN
))
552 if (IsXMLToken(msValue
, XML_TRUE
))
556 else if (IsXMLToken(msType
, XML_BYTE
))
559 ::sax::Converter::convertNumber(nValue
, msValue
);
560 mrAny
<<= static_cast<sal_Int8
>(nValue
);
562 else if (IsXMLToken(msType
, XML_SHORT
))
565 ::sax::Converter::convertNumber(nValue
, msValue
);
566 mrAny
<<= static_cast<sal_Int16
>(nValue
);
568 else if (IsXMLToken(msType
, XML_INT
))
571 ::sax::Converter::convertNumber(nValue
, msValue
);
574 else if (IsXMLToken(msType
, XML_LONG
))
576 sal_Int64
nValue(msValue
.toInt64());
579 else if (IsXMLToken(msType
, XML_DOUBLE
))
582 ::sax::Converter::convertDouble(fValue
, msValue
);
585 else if (IsXMLToken(msType
, XML_STRING
))
589 else if (IsXMLToken(msType
, XML_DATETIME
))
591 util::DateTime aDateTime
;
592 ::sax::Converter::parseDateTime(aDateTime
, nullptr, msValue
);
595 else if (IsXMLToken(msType
, XML_BASE64BINARY
))
600 SAL_INFO("xmloff.core",
601 "XMLConfigItemContext: unknown type: " << msType
);
604 ManipulateConfigItem();
606 mpBaseContext
->AddPropertyValue();
609 assert(false && "no BaseContext");
613 /** There are some instances where there is a mismatch between API and
614 * XML mapping of a setting. In this case, this method allows us to
615 * manipulate the values accordingly. */
616 void XMLConfigItemContext::ManipulateConfigItem()
618 if( mrItemName
== "PrinterIndependentLayout" )
623 sal_Int16 nTmp
= document::PrinterIndependentLayout::HIGH_RESOLUTION
;
625 if( sValue
== "enabled" || sValue
== "low-resolution" )
627 nTmp
= document::PrinterIndependentLayout::LOW_RESOLUTION
;
629 else if ( sValue
== "disabled" )
631 nTmp
= document::PrinterIndependentLayout::DISABLED
;
633 // else: default to high_resolution
637 else if( (mrItemName
== "ColorTableURL") || (mrItemName
== "LineEndTableURL") || (mrItemName
== "HatchTableURL")
638 || (mrItemName
== "DashTableURL") || (mrItemName
== "GradientTableURL") || (mrItemName
== "BitmapTableURL") )
642 uno::Reference
< uno::XComponentContext
> xContext( GetImport().GetComponentContext() );
643 uno::Reference
< util::XStringSubstitution
> xStringSubsitution( util::PathSubstitution::create(xContext
) );
647 aURL
= xStringSubsitution
->substituteVariables( aURL
, false );
650 catch( uno::Exception
& )
656 XMLConfigItemMapNamedContext::XMLConfigItemMapNamedContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& rLName
,
657 const css::uno::Reference
< css::xml::sax::XAttributeList
>&,
659 XMLConfigBaseContext
* pBaseContext
)
660 : XMLConfigBaseContext(rImport
, nPrfx
, rLName
, rAny
, pBaseContext
)
664 XMLConfigItemMapNamedContext::~XMLConfigItemMapNamedContext()
668 SvXMLImportContext
*XMLConfigItemMapNamedContext::CreateChildContext( sal_uInt16 nPrefix
,
669 const OUString
& rLocalName
,
670 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
)
672 return CreateSettingsContext(GetImport(), nPrefix
, rLocalName
, xAttrList
, maProp
, this);
675 void XMLConfigItemMapNamedContext::EndElement()
679 mrAny
<<= maProps
.GetNameContainer();
680 mpBaseContext
->AddPropertyValue();
683 assert(false && "no BaseContext");
687 XMLConfigItemMapIndexedContext::XMLConfigItemMapIndexedContext(SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
688 const OUString
& rLName
,
689 const css::uno::Reference
< css::xml::sax::XAttributeList
>&,
691 const OUString
& rConfigItemName
,
692 XMLConfigBaseContext
* pBaseContext
)
693 : XMLConfigBaseContext(rImport
, nPrfx
, rLName
, rAny
, pBaseContext
),
694 maConfigItemName( rConfigItemName
)
698 XMLConfigItemMapIndexedContext::~XMLConfigItemMapIndexedContext()
702 SvXMLImportContext
*XMLConfigItemMapIndexedContext::CreateChildContext( sal_uInt16 nPrefix
,
703 const OUString
& rLocalName
,
704 const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttrList
)
706 return CreateSettingsContext(GetImport(), nPrefix
, rLocalName
, xAttrList
, maProp
, this);
709 void XMLConfigItemMapIndexedContext::EndElement()
713 if ( maConfigItemName
== "ForbiddenCharacters" )
715 uno::Reference
< i18n::XForbiddenCharacters
> xForbChars
;
717 // get the forbidden characters from the document
718 uno::Reference
< lang::XMultiServiceFactory
> xFac( GetImport().GetModel(), uno::UNO_QUERY
);
721 uno::Reference
< beans::XPropertySet
> xProps( xFac
->createInstance( "com.sun.star.document.Settings" ), uno::UNO_QUERY
);
722 if( xProps
.is() && xProps
->getPropertySetInfo()->hasPropertyByName( maConfigItemName
) )
724 xProps
->getPropertyValue( maConfigItemName
) >>= xForbChars
;
728 if( xForbChars
.is() )
731 uno::Reference
< container::XIndexAccess
> xIndex( maProps
.GetIndexContainer(), uno::UNO_QUERY
);
733 const sal_Int32 nCount
= xIndex
->getCount();
734 uno::Sequence
< beans::PropertyValue
> aProps
;
735 for (sal_Int32 i
= 0; i
< nCount
; i
++)
737 if ((xIndex
->getByIndex( i
) >>= aProps
) && (aProps
.getLength() == XML_FORBIDDEN_CHARACTER_MAX
) )
739 /* FIXME-BCP47: this stupid and counterpart in
740 * xmloff/source/core/SettingsExportHelper.cxx
741 * XMLSettingsExportHelper::exportForbiddenCharacters()
744 beans::PropertyValue
*pForChar
= aProps
.getArray();
745 i18n::ForbiddenCharacters aForbid
;
746 lang::Locale aLocale
;
747 bool bHaveLanguage
= false, bHaveCountry
= false, bHaveVariant
= false,
748 bHaveBegin
= false, bHaveEnd
= false;
750 for ( sal_Int32 j
= 0 ; j
< XML_FORBIDDEN_CHARACTER_MAX
; j
++ )
752 if (pForChar
->Name
== "Language")
754 pForChar
->Value
>>= aLocale
.Language
;
755 bHaveLanguage
= true;
757 else if (pForChar
->Name
== "Country")
759 pForChar
->Value
>>= aLocale
.Country
;
762 else if (pForChar
->Name
== "Variant")
764 pForChar
->Value
>>= aLocale
.Variant
;
767 else if (pForChar
->Name
== "BeginLine")
769 pForChar
->Value
>>= aForbid
.beginLine
;
772 else if (pForChar
->Name
== "EndLine")
774 pForChar
->Value
>>= aForbid
.endLine
;
780 if ( bHaveLanguage
&& bHaveCountry
&& bHaveVariant
&& bHaveBegin
&& bHaveEnd
)
784 xForbChars
->setForbiddenCharacters( aLocale
, aForbid
);
786 catch (uno::Exception
const& e
)
788 SAL_WARN("xmloff.core",
789 "Exception while importing forbidden characters: " << e
.Message
);
797 SAL_WARN("xmloff.core", "could not get the XForbiddenCharacters from document!");
798 mrAny
<<= maProps
.GetIndexContainer();
801 else if ( maConfigItemName
== "Symbols" )
803 uno::Reference
< container::XIndexAccess
> xIndex( maProps
.GetIndexContainer(), uno::UNO_QUERY
);
805 const sal_Int32 nCount
= xIndex
->getCount();
806 uno::Sequence
< beans::PropertyValue
> aProps
;
807 uno::Sequence
< formula::SymbolDescriptor
> aSymbolList ( nCount
);
809 formula::SymbolDescriptor
*pDescriptor
= aSymbolList
.getArray();
811 sal_Int16 nNumFullEntries
= 0;
813 for ( sal_Int32 i
= 0; i
< nCount
; i
++ )
815 if ((xIndex
->getByIndex( i
) >>= aProps
) && (aProps
.getLength() == XML_SYMBOL_DESCRIPTOR_MAX
) )
817 bool bHaveName
= false, bHaveExportName
= false, bHaveCharSet
= false,
818 bHaveFontName
= false, bHaveFamily
= false, bHavePitch
= false,
819 bHaveWeight
= false, bHaveItalic
= false, bHaveSymbolSet
= false,
820 bHaveCharacter
= false;
821 beans::PropertyValue
*pSymbol
= aProps
.getArray();
823 for ( sal_Int32 j
= 0 ; j
< XML_SYMBOL_DESCRIPTOR_MAX
; j
++ )
825 if (pSymbol
->Name
== "Name")
827 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].sName
;
830 else if (pSymbol
->Name
== "ExportName")
832 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].sExportName
;
833 bHaveExportName
= true;
835 else if (pSymbol
->Name
== "FontName")
837 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].sFontName
;
838 bHaveFontName
= true;
840 else if (pSymbol
->Name
== "CharSet")
842 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].nCharSet
;
845 else if (pSymbol
->Name
== "Family")
847 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].nFamily
;
850 else if (pSymbol
->Name
== "Pitch")
852 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].nPitch
;
855 else if (pSymbol
->Name
== "Weight")
857 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].nWeight
;
860 else if (pSymbol
->Name
== "Italic")
862 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].nItalic
;
865 else if (pSymbol
->Name
== "SymbolSet")
867 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].sSymbolSet
;
868 bHaveSymbolSet
= true;
870 else if (pSymbol
->Name
== "Character")
872 pSymbol
->Value
>>= pDescriptor
[nNumFullEntries
].nCharacter
;
873 bHaveCharacter
= true;
877 if ( bHaveName
&& bHaveExportName
&& bHaveCharSet
&& bHaveFontName
&& bHaveCharacter
878 && bHaveFamily
&& bHavePitch
&& bHaveWeight
&& bHaveItalic
&& bHaveSymbolSet
)
882 aSymbolList
.realloc (nNumFullEntries
);
883 mrAny
<<= aSymbolList
;
887 mrAny
<<= maProps
.GetIndexContainer();
889 mpBaseContext
->AddPropertyValue();
892 assert(false && "no BaseContext");
896 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */