bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / core / DocumentSettingsContext.cxx
blobf963983e6041f20232ecd01a32b222ef14ca21db
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 <xmlenums.hxx>
49 using namespace com::sun::star;
50 using namespace ::xmloff::token;
52 class XMLMyList
54 std::list<beans::PropertyValue> aProps;
55 sal_uInt32 nCount;
57 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
59 public:
60 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)
69 : nCount(0),
70 m_xContext(rxContext)
72 DBG_ASSERT( rxContext.is(), "got no service manager" );
75 uno::Sequence<beans::PropertyValue> XMLMyList::GetSequence()
77 uno::Sequence<beans::PropertyValue> aSeq;
78 if(nCount)
80 DBG_ASSERT(nCount == aProps.size(), "wrong count of PropertyValue");
81 aSeq.realloc(nCount);
82 beans::PropertyValue* pProps = aSeq.getArray();
83 std::list<beans::PropertyValue>::iterator aItr = aProps.begin();
84 while (aItr != aProps.end())
86 *pProps = *aItr;
87 ++pProps;
88 ++aItr;
91 return aSeq;
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);
101 ++aItr;
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();
111 sal_uInt32 i(0);
112 while (aItr != aProps.end())
114 xIndexContainer->insertByIndex(i, aItr->Value);
115 ++aItr;
116 ++i;
119 return xIndexContainer;
122 //=============================================================================
124 class XMLConfigBaseContext : public SvXMLImportContext
126 protected:
127 XMLMyList maProps;
128 beans::PropertyValue maProp;
129 com::sun::star::uno::Any& mrAny;
130 XMLConfigBaseContext* mpBaseContext;
131 public:
132 XMLConfigBaseContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
133 com::sun::star::uno::Any& rAny,
134 XMLConfigBaseContext* pBaseContext);
135 virtual ~XMLConfigBaseContext();
137 void AddPropertyValue() { maProps.push_back(maProp); }
140 //=============================================================================
142 class XMLConfigItemContext : public SvXMLImportContext
144 OUString msType;
145 OUString msValue;
146 uno::Sequence<sal_Int8> maDecoded;
147 com::sun::star::uno::Any& mrAny;
148 const OUString mrItemName;
149 XMLConfigBaseContext* mpBaseContext;
151 public:
152 XMLConfigItemContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
153 const ::com::sun::star::uno::Reference<
154 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
155 com::sun::star::uno::Any& rAny,
156 const OUString& rItemName,
157 XMLConfigBaseContext* pBaseContext);
158 virtual ~XMLConfigItemContext();
160 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
161 const OUString& rLocalName,
162 const ::com::sun::star::uno::Reference<
163 ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
164 virtual void Characters( const OUString& rChars );
166 virtual void EndElement();
168 virtual void ManipulateConfigItem();
171 //=============================================================================
173 class XMLConfigItemSetContext : public XMLConfigBaseContext
175 public:
176 XMLConfigItemSetContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
177 const ::com::sun::star::uno::Reference<
178 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
179 com::sun::star::uno::Any& rAny,
180 XMLConfigBaseContext* pBaseContext);
181 virtual ~XMLConfigItemSetContext();
183 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
184 const OUString& rLocalName,
185 const ::com::sun::star::uno::Reference<
186 ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
188 virtual void EndElement();
191 //=============================================================================
193 class XMLConfigItemMapNamedContext : public XMLConfigBaseContext
195 public:
196 XMLConfigItemMapNamedContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
197 const ::com::sun::star::uno::Reference<
198 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
199 com::sun::star::uno::Any& rAny,
200 XMLConfigBaseContext* pBaseContext);
201 virtual ~XMLConfigItemMapNamedContext();
203 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
204 const OUString& rLocalName,
205 const ::com::sun::star::uno::Reference<
206 ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
208 virtual void EndElement();
211 //=============================================================================
213 class XMLConfigItemMapIndexedContext : public XMLConfigBaseContext
215 private:
216 OUString maConfigItemName;
218 public:
219 XMLConfigItemMapIndexedContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
220 const OUString& rLName,
221 const ::com::sun::star::uno::Reference<
222 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
223 com::sun::star::uno::Any& rAny,
224 const OUString& rConfigItemName,
225 XMLConfigBaseContext* pBaseContext);
226 virtual ~XMLConfigItemMapIndexedContext();
228 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
229 const OUString& rLocalName,
230 const ::com::sun::star::uno::Reference<
231 ::com::sun::star::xml::sax::XAttributeList>& xAttrList );
233 virtual void EndElement();
236 //=============================================================================
238 SvXMLImportContext *CreateSettingsContext(SvXMLImport& rImport, sal_uInt16 p_nPrefix,
239 const OUString& rLocalName,
240 const uno::Reference<xml::sax::XAttributeList>& xAttrList,
241 beans::PropertyValue& rProp, XMLConfigBaseContext* pBaseContext)
243 SvXMLImportContext *pContext = 0;
245 rProp.Name = OUString();
246 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
247 for( sal_Int16 i=0; i < nAttrCount; i++ )
249 OUString sAttrName = xAttrList->getNameByIndex( i );
250 OUString aLocalName;
251 sal_uInt16 nPrefix = rImport.GetNamespaceMap().GetKeyByAttrName(
252 sAttrName, &aLocalName );
253 OUString sValue = xAttrList->getValueByIndex( i );
255 if (nPrefix == XML_NAMESPACE_CONFIG)
257 if (IsXMLToken(aLocalName, XML_NAME))
258 rProp.Name = sValue;
262 if (p_nPrefix == XML_NAMESPACE_CONFIG)
264 if (IsXMLToken(rLocalName, XML_CONFIG_ITEM))
265 pContext = new XMLConfigItemContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, rProp.Name, pBaseContext);
266 else if((IsXMLToken(rLocalName, XML_CONFIG_ITEM_SET)) ||
267 (IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_ENTRY)) )
268 pContext = new XMLConfigItemSetContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, pBaseContext);
269 else if(IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_NAMED))
270 pContext = new XMLConfigItemMapNamedContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, pBaseContext);
271 else if(IsXMLToken(rLocalName, XML_CONFIG_ITEM_MAP_INDEXED))
272 pContext = new XMLConfigItemMapIndexedContext(rImport, p_nPrefix, rLocalName, xAttrList, rProp.Value, rProp.Name, pBaseContext);
275 if( !pContext )
276 pContext = new SvXMLImportContext( rImport, p_nPrefix, rLocalName );
278 return pContext;
281 //=============================================================================
282 namespace
284 struct SettingsGroup
286 OUString sGroupName;
287 uno::Any aSettings;
289 SettingsGroup()
290 :sGroupName()
291 ,aSettings()
295 SettingsGroup( const OUString& _rGroupName, const uno::Any& _rSettings )
296 :sGroupName( _rGroupName )
297 ,aSettings( _rSettings )
303 struct XMLDocumentSettingsContext_Data
305 com::sun::star::uno::Any aViewProps;
306 com::sun::star::uno::Any aConfigProps;
307 ::std::list< SettingsGroup > aDocSpecificSettings;
310 //=============================================================================
312 XMLDocumentSettingsContext::XMLDocumentSettingsContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
313 const uno::Reference<xml::sax::XAttributeList>& )
314 : SvXMLImportContext( rImport, nPrfx, rLName )
315 , m_pData( new XMLDocumentSettingsContext_Data )
317 // here are no attributes
320 XMLDocumentSettingsContext::~XMLDocumentSettingsContext()
324 SvXMLImportContext *XMLDocumentSettingsContext::CreateChildContext( sal_uInt16 p_nPrefix,
325 const OUString& rLocalName,
326 const ::com::sun::star::uno::Reference<
327 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
329 SvXMLImportContext *pContext = 0;
330 OUString sName;
332 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
333 for( sal_Int16 i=0; i < nAttrCount; i++ )
335 OUString sAttrName = xAttrList->getNameByIndex( i );
336 OUString aLocalName;
337 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
338 sAttrName, &aLocalName );
339 OUString sValue = xAttrList->getValueByIndex( i );
341 if (nPrefix == XML_NAMESPACE_CONFIG)
343 if (IsXMLToken(aLocalName, XML_NAME))
344 sName = sValue;
348 if (p_nPrefix == XML_NAMESPACE_CONFIG)
350 if (IsXMLToken(rLocalName, XML_CONFIG_ITEM_SET))
352 OUString aLocalConfigName;
353 sal_uInt16 nConfigPrefix =
354 GetImport().GetNamespaceMap().GetKeyByAttrName(
355 sName, &aLocalConfigName );
357 if( XML_NAMESPACE_OOO == nConfigPrefix )
359 if (IsXMLToken(aLocalConfigName, XML_VIEW_SETTINGS))
360 pContext = new XMLConfigItemSetContext(GetImport(),
361 p_nPrefix, rLocalName, xAttrList,
362 m_pData->aViewProps, NULL);
363 else if (IsXMLToken(aLocalConfigName,
364 XML_CONFIGURATION_SETTINGS))
365 pContext = new XMLConfigItemSetContext(GetImport(),
366 p_nPrefix, rLocalName, xAttrList,
367 m_pData->aConfigProps, NULL);
368 else
370 m_pData->aDocSpecificSettings.push_back( SettingsGroup( aLocalConfigName, uno::Any() ) );
372 ::std::list< SettingsGroup >::reverse_iterator settingsPos =
373 m_pData->aDocSpecificSettings.rbegin();
375 pContext = new XMLConfigItemSetContext(GetImport(),
376 p_nPrefix, rLocalName, xAttrList,
377 settingsPos->aSettings, NULL);
383 if( !pContext )
384 pContext = new SvXMLImportContext( GetImport(), p_nPrefix, rLocalName );
386 return pContext;
389 void XMLDocumentSettingsContext::EndElement()
391 uno::Sequence<beans::PropertyValue> aSeqViewProps;
392 if (m_pData->aViewProps >>= aSeqViewProps)
394 GetImport().SetViewSettings(aSeqViewProps);
395 sal_Int32 i(aSeqViewProps.getLength() - 1);
396 sal_Bool bFound(sal_False);
397 while((i >= 0) && !bFound)
399 if (aSeqViewProps[i].Name.compareToAscii("Views") == 0)
401 bFound = sal_True;
402 uno::Reference<container::XIndexAccess> xIndexAccess;
403 if (aSeqViewProps[i].Value >>= xIndexAccess)
405 uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetImport().GetModel(), uno::UNO_QUERY);
406 if (xViewDataSupplier.is())
407 xViewDataSupplier->setViewData(xIndexAccess);
410 else
411 i--;
415 uno::Sequence<beans::PropertyValue> aSeqConfigProps;
416 if ( m_pData->aConfigProps >>= aSeqConfigProps )
418 if (!officecfg::Office::Common::Save::Document::LoadPrinter::get())
420 sal_Int32 i = aSeqConfigProps.getLength() - 1;
421 int nFound = 0;
423 while ( ( i >= 0 ) && nFound < 2 )
425 OUString sProp( aSeqConfigProps[i].Name );
427 if ( sProp.compareToAscii("PrinterName") == 0 )
429 OUString sEmpty;
430 aSeqConfigProps[i].Value = uno::makeAny( sEmpty );
431 nFound++;
433 else if ( sProp.compareToAscii("PrinterSetup") == 0 )
435 uno::Sequence< sal_Int8 > aEmpty;
436 aSeqConfigProps[i].Value = uno::makeAny( aEmpty );
437 nFound++;
440 i--;
444 GetImport().SetConfigurationSettings( aSeqConfigProps );
447 for ( ::std::list< SettingsGroup >::const_iterator settings = m_pData->aDocSpecificSettings.begin();
448 settings != m_pData->aDocSpecificSettings.end();
449 ++settings
452 uno::Sequence< beans::PropertyValue > aDocSettings;
453 OSL_VERIFY( settings->aSettings >>= aDocSettings );
454 GetImport().SetDocumentSpecificSettings( settings->sGroupName, aDocSettings );
458 //=============================================================================
460 XMLConfigBaseContext::XMLConfigBaseContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
461 const OUString& rLName, com::sun::star::uno::Any& rTempAny,
462 XMLConfigBaseContext* pTempBaseContext)
463 : SvXMLImportContext( rImport, nPrfx, rLName ),
464 maProps( rImport.GetComponentContext() ),
465 maProp(),
466 mrAny(rTempAny),
467 mpBaseContext(pTempBaseContext)
471 XMLConfigBaseContext::~XMLConfigBaseContext()
475 //=============================================================================
477 XMLConfigItemSetContext::XMLConfigItemSetContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
478 const OUString& rLName,
479 const ::com::sun::star::uno::Reference<
480 ::com::sun::star::xml::sax::XAttributeList>&,
481 com::sun::star::uno::Any& rAny,
482 XMLConfigBaseContext* pBaseContext)
483 : XMLConfigBaseContext( rImport, nPrfx, rLName, rAny, pBaseContext )
485 // here are no attributes
488 XMLConfigItemSetContext::~XMLConfigItemSetContext()
492 SvXMLImportContext *XMLConfigItemSetContext::CreateChildContext( sal_uInt16 nPrefix,
493 const OUString& rLocalName,
494 const ::com::sun::star::uno::Reference<
495 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
497 return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
500 void XMLConfigItemSetContext::EndElement()
502 mrAny <<= maProps.GetSequence();
503 if (mpBaseContext)
504 mpBaseContext->AddPropertyValue();
507 //=============================================================================
509 XMLConfigItemContext::XMLConfigItemContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
510 const ::com::sun::star::uno::Reference<
511 ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
512 com::sun::star::uno::Any& rTempAny,
513 const OUString& rTempItemName,
514 XMLConfigBaseContext* pTempBaseContext)
515 : SvXMLImportContext(rImport, nPrfx, rLName),
516 mrAny(rTempAny),
517 mrItemName(rTempItemName),
518 mpBaseContext(pTempBaseContext)
520 sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
521 for( sal_Int16 i=0; i < nAttrCount; i++ )
523 OUString sAttrName = xAttrList->getNameByIndex( i );
524 OUString aLocalName;
525 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName(
526 sAttrName, &aLocalName );
527 OUString sValue = xAttrList->getValueByIndex( i );
529 if (nPrefix == XML_NAMESPACE_CONFIG)
531 if (IsXMLToken(aLocalName, XML_TYPE))
532 msType = sValue;
537 XMLConfigItemContext::~XMLConfigItemContext()
541 SvXMLImportContext *XMLConfigItemContext::CreateChildContext( sal_uInt16 nPrefix,
542 const OUString& rLocalName,
543 const ::com::sun::star::uno::Reference<
544 ::com::sun::star::xml::sax::XAttributeList>& )
546 SvXMLImportContext* pContext = new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
547 return pContext;
550 void XMLConfigItemContext::Characters( const OUString& rChars )
552 if (IsXMLToken(msType, XML_BASE64BINARY))
554 OUString sTrimmedChars( rChars.trim() );
555 if( !sTrimmedChars.isEmpty() )
557 OUString sChars;
558 if( !msValue.isEmpty() )
560 sChars = msValue;
561 sChars += sTrimmedChars;
562 msValue = OUString();
564 else
566 sChars = sTrimmedChars;
568 uno::Sequence<sal_Int8> aBuffer((sChars.getLength() / 4) * 3 );
569 sal_Int32 const nCharsDecoded =
570 ::sax::Converter::decodeBase64SomeChars( aBuffer, sChars );
571 sal_uInt32 nStartPos(maDecoded.getLength());
572 sal_uInt32 nCount(aBuffer.getLength());
573 maDecoded.realloc(nStartPos + nCount);
574 sal_Int8* pDecoded = maDecoded.getArray();
575 sal_Int8* pBuffer = aBuffer.getArray();
576 for (sal_uInt32 i = 0; i < nCount; i++, pBuffer++)
577 pDecoded[nStartPos + i] = *pBuffer;
578 if( nCharsDecoded != sChars.getLength() )
579 msValue = sChars.copy( nCharsDecoded );
582 else
583 msValue += rChars;
587 void XMLConfigItemContext::EndElement()
589 if (mpBaseContext)
591 if (IsXMLToken(msType, XML_BOOLEAN))
593 sal_Bool bValue(sal_False);
594 if (IsXMLToken(msValue, XML_TRUE))
595 bValue = sal_True;
596 mrAny <<= bValue;
598 else if (IsXMLToken(msType, XML_BYTE))
600 sal_Int32 nValue(0);
601 ::sax::Converter::convertNumber(nValue, msValue);
602 mrAny <<= static_cast<sal_Int8>(nValue);
604 else if (IsXMLToken(msType, XML_SHORT))
606 sal_Int32 nValue(0);
607 ::sax::Converter::convertNumber(nValue, msValue);
608 mrAny <<= static_cast<sal_Int16>(nValue);
610 else if (IsXMLToken(msType, XML_INT))
612 sal_Int32 nValue(0);
613 ::sax::Converter::convertNumber(nValue, msValue);
614 mrAny <<= nValue;
616 else if (IsXMLToken(msType, XML_LONG))
618 sal_Int64 nValue(msValue.toInt64());
619 mrAny <<= nValue;
621 else if (IsXMLToken(msType, XML_DOUBLE))
623 double fValue(0.0);
624 ::sax::Converter::convertDouble(fValue, msValue);
625 mrAny <<= fValue;
627 else if (IsXMLToken(msType, XML_STRING))
629 mrAny <<= msValue;
631 else if (IsXMLToken(msType, XML_DATETIME))
633 util::DateTime aDateTime;
634 ::sax::Converter::convertDateTime(aDateTime, msValue);
635 mrAny <<= aDateTime;
637 else if (IsXMLToken(msType, XML_BASE64BINARY))
639 mrAny <<= maDecoded;
641 else {
642 OSL_FAIL("wrong type");
645 ManipulateConfigItem();
647 mpBaseContext->AddPropertyValue();
649 else {
650 OSL_FAIL("no BaseContext");
654 /** There are some instances where there is a mismatch between API and
655 * XML mapping of a setting. In this case, this method allows us to
656 * manipulate the values accordingly. */
657 void XMLConfigItemContext::ManipulateConfigItem()
659 if( mrItemName == "PrinterIndependentLayout" )
661 OUString sValue;
662 mrAny >>= sValue;
664 sal_Int16 nTmp = document::PrinterIndependentLayout::HIGH_RESOLUTION;
666 if( sValue == "enabled" || sValue == "low-resolution" )
668 nTmp = document::PrinterIndependentLayout::LOW_RESOLUTION;
670 else if ( sValue == "disabled" )
672 nTmp = document::PrinterIndependentLayout::DISABLED;
674 // else: default to high_resolution
676 mrAny <<= nTmp;
678 else if( (mrItemName == "ColorTableURL") || (mrItemName == "LineEndTableURL") || (mrItemName == "HatchTableURL")
679 || (mrItemName == "DashTableURL") || (mrItemName == "GradientTableURL") || (mrItemName == "BitmapTableURL") )
683 uno::Reference< uno::XComponentContext > xContext( GetImport().GetComponentContext() );
684 uno::Reference< util::XStringSubstitution > xStringSubsitution( util::PathSubstitution::create(xContext) );
686 OUString aURL;
687 mrAny >>= aURL;
688 aURL = xStringSubsitution->substituteVariables( aURL, sal_False );
689 mrAny <<= aURL;
691 catch( uno::Exception& )
698 //=============================================================================
700 XMLConfigItemMapNamedContext::XMLConfigItemMapNamedContext(SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName,
701 const ::com::sun::star::uno::Reference<
702 ::com::sun::star::xml::sax::XAttributeList>&,
703 com::sun::star::uno::Any& rAny,
704 XMLConfigBaseContext* pBaseContext)
705 : XMLConfigBaseContext(rImport, nPrfx, rLName, rAny, pBaseContext)
709 XMLConfigItemMapNamedContext::~XMLConfigItemMapNamedContext()
713 SvXMLImportContext *XMLConfigItemMapNamedContext::CreateChildContext( sal_uInt16 nPrefix,
714 const OUString& rLocalName,
715 const ::com::sun::star::uno::Reference<
716 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
718 return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
721 void XMLConfigItemMapNamedContext::EndElement()
723 if (mpBaseContext)
725 mrAny <<= maProps.GetNameContainer();
726 mpBaseContext->AddPropertyValue();
728 else {
729 OSL_FAIL("no BaseContext");
733 //=============================================================================
735 XMLConfigItemMapIndexedContext::XMLConfigItemMapIndexedContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
736 const OUString& rLName,
737 const ::com::sun::star::uno::Reference<
738 ::com::sun::star::xml::sax::XAttributeList>&,
739 com::sun::star::uno::Any& rAny,
740 const OUString& rConfigItemName,
741 XMLConfigBaseContext* pBaseContext)
742 : XMLConfigBaseContext(rImport, nPrfx, rLName, rAny, pBaseContext),
743 maConfigItemName( rConfigItemName )
747 XMLConfigItemMapIndexedContext::~XMLConfigItemMapIndexedContext()
751 SvXMLImportContext *XMLConfigItemMapIndexedContext::CreateChildContext( sal_uInt16 nPrefix,
752 const OUString& rLocalName,
753 const ::com::sun::star::uno::Reference<
754 ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
756 return CreateSettingsContext(GetImport(), nPrefix, rLocalName, xAttrList, maProp, this);
759 void XMLConfigItemMapIndexedContext::EndElement()
761 if (mpBaseContext)
763 if ( maConfigItemName == "ForbiddenCharacters" )
765 uno::Reference< i18n::XForbiddenCharacters > xForbChars;
767 // get the forbidden characters from the document
768 uno::Reference< lang::XMultiServiceFactory > xFac( GetImport().GetModel(), uno::UNO_QUERY );
769 if( xFac.is() )
771 uno::Reference< beans::XPropertySet > xProps( xFac->createInstance( "com.sun.star.document.Settings" ), uno::UNO_QUERY );
772 if( xProps.is() && xProps->getPropertySetInfo()->hasPropertyByName( maConfigItemName ) )
774 xProps->getPropertyValue( maConfigItemName ) >>= xForbChars;
778 if( xForbChars.is() )
781 uno::Reference< container::XIndexAccess > xIndex( maProps.GetIndexContainer(), uno::UNO_QUERY );
783 const sal_Int32 nCount = xIndex->getCount();
784 uno::Sequence < beans::PropertyValue > aProps;
785 for (sal_Int32 i = 0; i < nCount; i++)
787 if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_FORBIDDEN_CHARACTER_MAX ) )
789 beans::PropertyValue *pForChar = aProps.getArray();
790 i18n::ForbiddenCharacters aForbid;
791 lang::Locale aLocale;
792 const OUString sLanguage ( "Language" );
793 const OUString sCountry ( "Country" );
794 const OUString sVariant ( "Variant" );
795 const OUString sBeginLine ( "BeginLine" );
796 const OUString sEndLine ( "EndLine" );
797 sal_Bool bHaveLanguage = sal_False, bHaveCountry = sal_False, bHaveVariant = sal_False,
798 bHaveBegin = sal_False, bHaveEnd = sal_False;
800 for ( sal_Int32 j = 0 ; j < XML_FORBIDDEN_CHARACTER_MAX ; j++ )
802 if (pForChar->Name.equals (sLanguage ) )
804 pForChar->Value >>= aLocale.Language;
805 bHaveLanguage = sal_True;
807 else if (pForChar->Name.equals (sCountry ) )
809 pForChar->Value >>= aLocale.Country;
810 bHaveCountry = sal_True;
812 else if (pForChar->Name.equals (sVariant ) )
814 pForChar->Value >>= aLocale.Variant;
815 bHaveVariant = sal_True;
817 else if (pForChar->Name.equals (sBeginLine ) )
819 pForChar->Value >>= aForbid.beginLine;
820 bHaveBegin = sal_True;
822 else if (pForChar->Name.equals (sEndLine ) )
824 pForChar->Value >>= aForbid.endLine;
825 bHaveEnd = sal_True;
827 pForChar++;
830 if ( bHaveLanguage && bHaveCountry && bHaveVariant && bHaveBegin && bHaveEnd )
834 xForbChars->setForbiddenCharacters( aLocale, aForbid );
836 catch( uno::Exception& )
838 OSL_FAIL( "Exception while importing forbidden characters" );
844 else
846 OSL_FAIL( "could not get the XForbiddenCharacters from document!" );
847 mrAny <<= maProps.GetIndexContainer();
850 else if ( maConfigItemName == "Symbols" )
852 uno::Reference< container::XIndexAccess > xIndex( maProps.GetIndexContainer(), uno::UNO_QUERY );
854 const sal_Int32 nCount = xIndex->getCount();
855 uno::Sequence < beans::PropertyValue > aProps;
856 uno::Sequence < formula::SymbolDescriptor > aSymbolList ( nCount );
858 formula::SymbolDescriptor *pDescriptor = aSymbolList.getArray();
860 const OUString sName ( "Name" );
861 const OUString sExportName ( "ExportName" );
862 const OUString sFontName ( "FontName" );
863 const OUString sSymbolSet ( "SymbolSet" );
864 const OUString sCharacter ( "Character" );
865 const OUString sCharSet ( "CharSet" );
866 const OUString sFamily ( "Family" );
867 const OUString sPitch ( "Pitch" );
868 const OUString sWeight ( "Weight" );
869 const OUString sItalic ( "Italic" );
870 sal_Int16 nNumFullEntries = 0;
872 for ( sal_Int32 i = 0; i < nCount; i++ )
874 if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_SYMBOL_DESCRIPTOR_MAX ) )
876 sal_Bool bHaveName = sal_False, bHaveExportName = sal_False, bHaveCharSet = sal_False,
877 bHaveFontName = sal_False, bHaveFamily = sal_False, bHavePitch = sal_False,
878 bHaveWeight = sal_False, bHaveItalic = sal_False, bHaveSymbolSet = sal_False,
879 bHaveCharacter = sal_False;
880 beans::PropertyValue *pSymbol = aProps.getArray();
882 for ( sal_Int32 j = 0 ; j < XML_SYMBOL_DESCRIPTOR_MAX ; j++ )
884 if (pSymbol->Name.equals ( sName ) )
886 pSymbol->Value >>= pDescriptor[nNumFullEntries].sName;
887 bHaveName = sal_True;
889 else if (pSymbol->Name.equals (sExportName ) )
891 pSymbol->Value >>= pDescriptor[nNumFullEntries].sExportName;
892 bHaveExportName = sal_True;
894 else if (pSymbol->Name.equals (sFontName ) )
896 pSymbol->Value >>= pDescriptor[nNumFullEntries].sFontName;
897 bHaveFontName = sal_True;
899 else if (pSymbol->Name.equals (sCharSet ) )
901 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharSet;
902 bHaveCharSet = sal_True;
904 else if (pSymbol->Name.equals (sFamily ) )
906 pSymbol->Value >>= pDescriptor[nNumFullEntries].nFamily;
907 bHaveFamily = sal_True;
909 else if (pSymbol->Name.equals (sPitch ) )
911 pSymbol->Value >>= pDescriptor[nNumFullEntries].nPitch;
912 bHavePitch = sal_True;
914 else if (pSymbol->Name.equals (sWeight ) )
916 pSymbol->Value >>= pDescriptor[nNumFullEntries].nWeight;
917 bHaveWeight = sal_True;
919 else if (pSymbol->Name.equals (sItalic ) )
921 pSymbol->Value >>= pDescriptor[nNumFullEntries].nItalic;
922 bHaveItalic = sal_True;
924 else if (pSymbol->Name.equals (sSymbolSet ) )
926 pSymbol->Value >>= pDescriptor[nNumFullEntries].sSymbolSet;
927 bHaveSymbolSet = sal_True;
929 else if (pSymbol->Name.equals (sCharacter ) )
931 pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharacter;
932 bHaveCharacter = sal_True;
934 pSymbol++;
936 if ( bHaveName && bHaveExportName && bHaveCharSet && bHaveFontName && bHaveCharacter
937 && bHaveFamily && bHavePitch && bHaveWeight && bHaveItalic && bHaveSymbolSet)
938 nNumFullEntries++;
941 aSymbolList.realloc (nNumFullEntries);
942 mrAny <<= aSymbolList;
944 else
946 mrAny <<= maProps.GetIndexContainer();
948 mpBaseContext->AddPropertyValue();
950 else {
951 OSL_FAIL("no BaseContext");
955 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */