LibreOffice Module xmloff (master)  1
DocumentSettingsContext.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <officecfg/Office/Common.hxx>
23 #include <sax/tools/converter.hxx>
24 
25 #include <com/sun/star/util/PathSubstitution.hpp>
26 #include <com/sun/star/util/XStringSubstitution.hpp>
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmltoken.hxx>
30 #include <xmloff/xmlnamespace.hxx>
31 #include <xmloff/namespacemap.hxx>
32 #include <comphelper/base64.hxx>
33 
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/frame/XModel.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 <com/sun/star/beans/XPropertySet.hpp>
46 #include <sal/log.hxx>
47 #include <osl/diagnose.h>
48 #include <tools/diagnose_ex.h>
49 #include <unotools/configmgr.hxx>
50 #include "xmlenums.hxx"
51 
52 using namespace com::sun::star;
53 using namespace ::xmloff::token;
54 
55 namespace {
56 
57 class XMLMyList
58 {
59  std::vector<beans::PropertyValue> aProps;
60  sal_uInt32 nCount;
61 
62  css::uno::Reference< css::uno::XComponentContext > m_xContext;
63 
64 public:
65  explicit XMLMyList(const uno::Reference<uno::XComponentContext>& rxContext);
66 
67  void push_back(beans::PropertyValue const & aProp) { aProps.push_back(aProp); nCount++; }
68  uno::Sequence<beans::PropertyValue> GetSequence();
69  uno::Reference<container::XNameContainer> GetNameContainer();
70  uno::Reference<container::XIndexContainer> GetIndexContainer();
71 };
72 
73 }
74 
75 XMLMyList::XMLMyList(const uno::Reference<uno::XComponentContext>& rxContext)
76 : nCount(0),
77  m_xContext(rxContext)
78 {
79  assert(m_xContext.is());
80 }
81 
82 uno::Sequence<beans::PropertyValue> XMLMyList::GetSequence()
83 {
84  uno::Sequence<beans::PropertyValue> aSeq;
85  if(nCount)
86  {
87  assert(nCount == aProps.size());
88  aSeq.realloc(nCount);
89  beans::PropertyValue* pProps = aSeq.getArray();
90  for (auto const& prop : aProps)
91  {
92  *pProps = prop;
93  ++pProps;
94  }
95  }
96  return aSeq;
97 }
98 
99 uno::Reference<container::XNameContainer> XMLMyList::GetNameContainer()
100 {
101  uno::Reference<container::XNameContainer> xNameContainer = document::NamedPropertyValues::create(m_xContext);
102  for (auto const& prop : aProps)
103  {
104  xNameContainer->insertByName(prop.Name, prop.Value);
105  }
106 
107  return xNameContainer;
108 }
109 
110 uno::Reference<container::XIndexContainer> XMLMyList::GetIndexContainer()
111 {
112  uno::Reference<container::XIndexContainer> xIndexContainer = document::IndexedPropertyValues::create(m_xContext);
113  sal_uInt32 i(0);
114  for (auto const& prop : aProps)
115  {
116  xIndexContainer->insertByIndex(i, prop.Value);
117  ++i;
118  }
119 
120  return xIndexContainer;
121 }
122 
123 namespace {
124 
125 class XMLConfigBaseContext : public SvXMLImportContext
126 {
127 protected:
128  XMLMyList maProps;
129  beans::PropertyValue maProp;
130  css::uno::Any& mrAny;
131  XMLConfigBaseContext* mpBaseContext;
132 public:
133  XMLConfigBaseContext(SvXMLImport& rImport,
134  css::uno::Any& rAny,
135  XMLConfigBaseContext* pBaseContext);
136 
137  void AddPropertyValue() { maProps.push_back(maProp); }
138 };
139 
140 class XMLConfigItemContext : public SvXMLImportContext
141 {
142  OUString msType;
143  css::uno::Any& mrAny;
144  const OUString mrItemName;
145  XMLConfigBaseContext* mpBaseContext;
146  OUStringBuffer maCharBuffer;
147 
148 public:
149  XMLConfigItemContext(SvXMLImport& rImport,
150  const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
151  css::uno::Any& rAny,
152  const OUString& rItemName,
153  XMLConfigBaseContext* pBaseContext);
154 
155  virtual void SAL_CALL characters( const OUString& rChars ) override;
156 
157  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
158 
159  void ManipulateConfigItem();
160 };
161 
162 class XMLConfigItemSetContext : public XMLConfigBaseContext
163 {
164 public:
165  XMLConfigItemSetContext(SvXMLImport& rImport,
166  css::uno::Any& rAny,
167  XMLConfigBaseContext* pBaseContext);
168 
169  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
170  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
171 
172  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
173 };
174 
175 class XMLConfigItemMapNamedContext : public XMLConfigBaseContext
176 {
177 public:
178  XMLConfigItemMapNamedContext(SvXMLImport& rImport,
179  css::uno::Any& rAny,
180  XMLConfigBaseContext* pBaseContext);
181 
182  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
183  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
184 
185  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
186 };
187 
188 class XMLConfigItemMapIndexedContext : public XMLConfigBaseContext
189 {
190 private:
191  OUString maConfigItemName;
192 
193 public:
194  XMLConfigItemMapIndexedContext(SvXMLImport& rImport,
195  css::uno::Any& rAny,
196  const OUString& rConfigItemName,
197  XMLConfigBaseContext* pBaseContext);
198 
199  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
200  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
201 
202  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
203 };
204 
205 }
206 
207 static SvXMLImportContext *CreateSettingsContext(SvXMLImport& rImport, sal_Int32 nElement,
208  const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
209  beans::PropertyValue& rProp, XMLConfigBaseContext* pBaseContext)
210 {
211  SvXMLImportContext *pContext = nullptr;
212 
213  rProp.Name.clear();
214  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
215  {
216  if (aIter.getToken() == XML_ELEMENT(CONFIG, XML_NAME))
217  rProp.Name = aIter.toString();
218  }
219 
220  if (nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM))
221  pContext = new XMLConfigItemContext(rImport, xAttrList, rProp.Value, rProp.Name, pBaseContext);
222  else if(nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_SET) ||
223  nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_MAP_ENTRY) )
224  pContext = new XMLConfigItemSetContext(rImport, rProp.Value, pBaseContext);
225  else if(nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_MAP_NAMED))
226  pContext = new XMLConfigItemMapNamedContext(rImport, rProp.Value, pBaseContext);
227  else if(nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_MAP_INDEXED))
228  pContext = new XMLConfigItemMapIndexedContext(rImport, rProp.Value, rProp.Name, pBaseContext);
229 
230  return pContext;
231 }
232 
234  : SvXMLImportContext( rImport )
235 {
236  // here are no attributes
237 }
238 
240 {
241 }
242 
243 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDocumentSettingsContext::createFastChildContext(
244  sal_Int32 nElement,
245  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
246 {
247  SvXMLImportContext *pContext = nullptr;
248  OUString sName;
249 
250  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
251  {
252  if (aIter.getToken() == XML_ELEMENT(CONFIG, XML_NAME))
253  sName = aIter.toString();
254  }
255 
256  if (nElement == XML_ELEMENT(CONFIG, XML_CONFIG_ITEM_SET))
257  {
258  OUString aLocalConfigName;
259  sal_uInt16 nConfigPrefix =
261  sName, &aLocalConfigName );
262 
263  if( XML_NAMESPACE_OOO == nConfigPrefix )
264  {
265  if (IsXMLToken(aLocalConfigName, XML_VIEW_SETTINGS))
266  pContext = new XMLConfigItemSetContext(GetImport(),
267  maViewProps, nullptr);
268  else if (IsXMLToken(aLocalConfigName,
270  pContext = new XMLConfigItemSetContext(GetImport(),
271  maConfigProps, nullptr);
272  else
273  {
274  maDocSpecificSettings.push_back( {aLocalConfigName, uno::Any()} );
275 
276  pContext = new XMLConfigItemSetContext(GetImport(),
277  maDocSpecificSettings.back().aSettings, nullptr);
278  }
279  }
280  }
281 
282  return pContext;
283 }
284 
286 {
287  uno::Sequence<beans::PropertyValue> aSeqViewProps;
288  if (maViewProps >>= aSeqViewProps)
289  {
290  GetImport().SetViewSettings(aSeqViewProps);
291  sal_Int32 i(aSeqViewProps.getLength() - 1);
292  bool bFound(false);
293  while((i >= 0) && !bFound)
294  {
295  if (aSeqViewProps[i].Name == "Views")
296  {
297  bFound = true;
298  uno::Reference<container::XIndexAccess> xIndexAccess;
299  if (aSeqViewProps[i].Value >>= xIndexAccess)
300  {
301  uno::Reference<document::XViewDataSupplier> xViewDataSupplier(GetImport().GetModel(), uno::UNO_QUERY);
302  if (xViewDataSupplier.is())
303  xViewDataSupplier->setViewData(xIndexAccess);
304  }
305  }
306  else
307  i--;
308  }
309  }
310 
311  uno::Sequence<beans::PropertyValue> aSeqConfigProps;
312  if ( maConfigProps >>= aSeqConfigProps )
313  {
314  if (!utl::ConfigManager::IsFuzzing() && !officecfg::Office::Common::Save::Document::LoadPrinter::get())
315  {
316  sal_Int32 i = aSeqConfigProps.getLength() - 1;
317  int nFound = 0;
318 
319  while ( ( i >= 0 ) && nFound < 2 )
320  {
321  OUString sProp( aSeqConfigProps[i].Name );
322 
323  if ( sProp == "PrinterName" )
324  {
325  aSeqConfigProps[i].Value <<= OUString();
326  nFound++;
327  }
328  else if ( sProp == "PrinterSetup" )
329  {
330  uno::Sequence< sal_Int8 > aEmpty;
331  aSeqConfigProps[i].Value <<= aEmpty;
332  nFound++;
333  }
334 
335  i--;
336  }
337  }
338 
339  GetImport().SetConfigurationSettings( aSeqConfigProps );
340  }
341 
342  for (auto const& settings : maDocSpecificSettings)
343  {
344  uno::Sequence< beans::PropertyValue > aDocSettings;
345  OSL_VERIFY( settings.aSettings >>= aDocSettings );
346  GetImport().SetDocumentSpecificSettings( settings.sGroupName, aDocSettings );
347  }
348 }
349 
350 XMLConfigBaseContext::XMLConfigBaseContext(SvXMLImport& rImport,
351  css::uno::Any& rTempAny,
352  XMLConfigBaseContext* pTempBaseContext)
353  : SvXMLImportContext( rImport ),
354  maProps( rImport.GetComponentContext() ),
355  mrAny(rTempAny),
356  mpBaseContext(pTempBaseContext)
357 {
358 }
359 
360 XMLConfigItemSetContext::XMLConfigItemSetContext(SvXMLImport& rImport,
361  css::uno::Any& rAny,
362  XMLConfigBaseContext* pBaseContext)
363  : XMLConfigBaseContext( rImport, rAny, pBaseContext )
364 {
365  // here are no attributes
366 }
367 
368 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemSetContext::createFastChildContext(
369  sal_Int32 nElement,
370  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
371 {
372  return CreateSettingsContext(GetImport(), nElement, xAttrList, maProp, this);
373 }
374 
375 void XMLConfigItemSetContext::endFastElement(sal_Int32 )
376 {
377  mrAny <<= maProps.GetSequence();
378  if (mpBaseContext)
379  mpBaseContext->AddPropertyValue();
380 }
381 
382 XMLConfigItemContext::XMLConfigItemContext(SvXMLImport& rImport,
383  const css::uno::Reference< css::xml::sax::XFastAttributeList>& xAttrList,
384  css::uno::Any& rTempAny,
385  const OUString& rTempItemName,
386  XMLConfigBaseContext* pTempBaseContext)
387  : SvXMLImportContext(rImport),
388  mrAny(rTempAny),
389  mrItemName(rTempItemName),
390  mpBaseContext(pTempBaseContext)
391 {
392  for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
393  {
394  if (aIter.getToken() == XML_ELEMENT(CONFIG, XML_TYPE))
395  msType = aIter.toString();
396  }
397 }
398 
399 void XMLConfigItemContext::characters( const OUString& rChars )
400 {
401  maCharBuffer.append(rChars);
402 }
403 
404 void XMLConfigItemContext::endFastElement(sal_Int32 )
405 {
406  OUString sValue;
407  uno::Sequence<sal_Int8> aDecoded;
408  if (IsXMLToken(msType, XML_BASE64BINARY))
409  {
410  OUString sChars = maCharBuffer.makeStringAndClear().trim();
411  if( !sChars.isEmpty() )
412  ::comphelper::Base64::decodeSomeChars( aDecoded, sChars );
413  }
414  else
415  sValue = maCharBuffer.makeStringAndClear();
416 
417  if (mpBaseContext)
418  {
419  if (IsXMLToken(msType, XML_BOOLEAN))
420  {
421  bool bValue(false);
422  if (IsXMLToken(sValue, XML_TRUE))
423  bValue = true;
424  mrAny <<= bValue;
425  }
426  else if (IsXMLToken(msType, XML_BYTE))
427  {
428  sal_Int32 nValue(0);
429  ::sax::Converter::convertNumber(nValue, sValue);
430  mrAny <<= static_cast<sal_Int8>(nValue);
431  }
432  else if (IsXMLToken(msType, XML_SHORT))
433  {
434  sal_Int32 nValue(0);
435  ::sax::Converter::convertNumber(nValue, sValue);
436  mrAny <<= static_cast<sal_Int16>(nValue);
437  }
438  else if (IsXMLToken(msType, XML_INT))
439  {
440  sal_Int32 nValue(0);
441  ::sax::Converter::convertNumber(nValue, sValue);
442  mrAny <<= nValue;
443  }
444  else if (IsXMLToken(msType, XML_LONG))
445  {
446  sal_Int64 nValue(sValue.toInt64());
447  mrAny <<= nValue;
448  }
449  else if (IsXMLToken(msType, XML_DOUBLE))
450  {
451  double fValue(0.0);
452  ::sax::Converter::convertDouble(fValue, sValue);
453  mrAny <<= fValue;
454  }
455  else if (IsXMLToken(msType, XML_STRING))
456  {
457  mrAny <<= sValue;
458  }
459  else if (IsXMLToken(msType, XML_DATETIME))
460  {
461  util::DateTime aDateTime;
462  ::sax::Converter::parseDateTime(aDateTime, sValue);
463  mrAny <<= aDateTime;
464  }
465  else if (IsXMLToken(msType, XML_BASE64BINARY))
466  {
467  mrAny <<= aDecoded;
468  }
469  else {
470  SAL_INFO("xmloff.core",
471  "XMLConfigItemContext: unknown type: " << msType);
472  }
473 
474  ManipulateConfigItem();
475 
476  mpBaseContext->AddPropertyValue();
477  }
478  else {
479  assert(false && "no BaseContext");
480  }
481 }
482 
486 void XMLConfigItemContext::ManipulateConfigItem()
487 {
488  if( mrItemName == "PrinterIndependentLayout" )
489  {
490  OUString sValue;
491  mrAny >>= sValue;
492 
493  sal_Int16 nTmp = document::PrinterIndependentLayout::HIGH_RESOLUTION;
494 
495  if( sValue == "enabled" || sValue == "low-resolution" )
496  {
497  nTmp = document::PrinterIndependentLayout::LOW_RESOLUTION;
498  }
499  else if ( sValue == "disabled" )
500  {
501  nTmp = document::PrinterIndependentLayout::DISABLED;
502  }
503  // else: default to high_resolution
504 
505  mrAny <<= nTmp;
506  }
507  else if( (mrItemName == "ColorTableURL") || (mrItemName == "LineEndTableURL") || (mrItemName == "HatchTableURL")
508  || (mrItemName == "DashTableURL") || (mrItemName == "GradientTableURL") || (mrItemName == "BitmapTableURL") )
509  {
510  try
511  {
512  uno::Reference< uno::XComponentContext > xContext( GetImport().GetComponentContext() );
513  uno::Reference< util::XStringSubstitution > xStringSubstitution( util::PathSubstitution::create(xContext) );
514 
515  OUString aURL;
516  mrAny >>= aURL;
517  aURL = xStringSubstitution->substituteVariables( aURL, false );
518  mrAny <<= aURL;
519  }
520  catch( uno::Exception& )
521  {
522  }
523  }
524 }
525 
526 XMLConfigItemMapNamedContext::XMLConfigItemMapNamedContext(SvXMLImport& rImport,
527  css::uno::Any& rAny,
528  XMLConfigBaseContext* pBaseContext)
529  : XMLConfigBaseContext(rImport, rAny, pBaseContext)
530 {
531 }
532 
533 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemMapNamedContext::createFastChildContext(
534  sal_Int32 nElement,
535  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
536 {
537  return CreateSettingsContext(GetImport(), nElement, xAttrList, maProp, this);
538 }
539 
540 void XMLConfigItemMapNamedContext::endFastElement(sal_Int32 )
541 {
542  if (mpBaseContext)
543  {
544  mrAny <<= maProps.GetNameContainer();
545  mpBaseContext->AddPropertyValue();
546  }
547  else {
548  assert(false && "no BaseContext");
549  }
550 }
551 
552 XMLConfigItemMapIndexedContext::XMLConfigItemMapIndexedContext(SvXMLImport& rImport,
553  css::uno::Any& rAny,
554  const OUString& rConfigItemName,
555  XMLConfigBaseContext* pBaseContext)
556  : XMLConfigBaseContext(rImport, rAny, pBaseContext),
557  maConfigItemName( rConfigItemName )
558 {
559 }
560 
561 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLConfigItemMapIndexedContext::createFastChildContext(
562  sal_Int32 nElement,
563  const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
564 {
565  return CreateSettingsContext(GetImport(), nElement, xAttrList, maProp, this);
566 }
567 
568 void XMLConfigItemMapIndexedContext::endFastElement(sal_Int32 )
569 {
570  if (mpBaseContext)
571  {
572  if ( maConfigItemName == "ForbiddenCharacters" )
573  {
574  uno::Reference< i18n::XForbiddenCharacters > xForbChars;
575 
576  // get the forbidden characters from the document
577  uno::Reference< lang::XMultiServiceFactory > xFac( GetImport().GetModel(), uno::UNO_QUERY );
578  if( xFac.is() )
579  {
580  uno::Reference< beans::XPropertySet > xProps( xFac->createInstance( "com.sun.star.document.Settings" ), uno::UNO_QUERY );
581  if( xProps.is() && xProps->getPropertySetInfo()->hasPropertyByName( maConfigItemName ) )
582  {
583  xProps->getPropertyValue( maConfigItemName ) >>= xForbChars;
584  }
585  }
586 
587  if( xForbChars.is() )
588  {
589 
590  uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
591 
592  const sal_Int32 nCount = xIndex->getCount();
593  uno::Sequence < beans::PropertyValue > aProps;
594  for (sal_Int32 i = 0; i < nCount; i++)
595  {
596  if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_FORBIDDEN_CHARACTER_MAX ) )
597  {
598  /* FIXME-BCP47: this stupid and counterpart in
599  * xmloff/source/core/SettingsExportHelper.cxx
600  * XMLSettingsExportHelper::exportForbiddenCharacters()
601  * */
602 
603  beans::PropertyValue *pForChar = aProps.getArray();
604  i18n::ForbiddenCharacters aForbid;
605  lang::Locale aLocale;
606  bool bHaveLanguage = false, bHaveCountry = false, bHaveVariant = false,
607  bHaveBegin = false, bHaveEnd = false;
608 
609  for ( sal_Int32 j = 0 ; j < XML_FORBIDDEN_CHARACTER_MAX ; j++ )
610  {
611  if (pForChar->Name == "Language")
612  {
613  pForChar->Value >>= aLocale.Language;
614  bHaveLanguage = true;
615  }
616  else if (pForChar->Name == "Country")
617  {
618  pForChar->Value >>= aLocale.Country;
619  bHaveCountry = true;
620  }
621  else if (pForChar->Name == "Variant")
622  {
623  pForChar->Value >>= aLocale.Variant;
624  bHaveVariant = true;
625  }
626  else if (pForChar->Name == "BeginLine")
627  {
628  pForChar->Value >>= aForbid.beginLine;
629  bHaveBegin = true;
630  }
631  else if (pForChar->Name == "EndLine")
632  {
633  pForChar->Value >>= aForbid.endLine;
634  bHaveEnd = true;
635  }
636  pForChar++;
637  }
638 
639  if ( bHaveLanguage && bHaveCountry && bHaveVariant && bHaveBegin && bHaveEnd )
640  {
641  try
642  {
643  xForbChars->setForbiddenCharacters( aLocale, aForbid );
644  }
645  catch (uno::Exception const&)
646  {
647  TOOLS_WARN_EXCEPTION("xmloff.core",
648  "Exception while importing forbidden characters");
649  }
650  }
651  }
652  }
653  }
654  else
655  {
656  SAL_WARN("xmloff.core", "could not get the XForbiddenCharacters from document!");
657  mrAny <<= maProps.GetIndexContainer();
658  }
659  }
660  else if ( maConfigItemName == "Symbols" )
661  {
662  uno::Reference< container::XIndexAccess > xIndex = maProps.GetIndexContainer();
663 
664  const sal_Int32 nCount = xIndex->getCount();
665  uno::Sequence < beans::PropertyValue > aProps;
666  uno::Sequence < formula::SymbolDescriptor > aSymbolList ( nCount );
667 
668  formula::SymbolDescriptor *pDescriptor = aSymbolList.getArray();
669 
670  sal_Int16 nNumFullEntries = 0;
671 
672  for ( sal_Int32 i = 0; i < nCount; i++ )
673  {
674  if ((xIndex->getByIndex( i ) >>= aProps) && (aProps.getLength() == XML_SYMBOL_DESCRIPTOR_MAX ) )
675  {
676  bool bHaveName = false, bHaveExportName = false, bHaveCharSet = false,
677  bHaveFontName = false, bHaveFamily = false, bHavePitch = false,
678  bHaveWeight = false, bHaveItalic = false, bHaveSymbolSet = false,
679  bHaveCharacter = false;
680  beans::PropertyValue *pSymbol = aProps.getArray();
681 
682  for ( sal_Int32 j = 0 ; j < XML_SYMBOL_DESCRIPTOR_MAX ; j++ )
683  {
684  if (pSymbol->Name == "Name")
685  {
686  pSymbol->Value >>= pDescriptor[nNumFullEntries].sName;
687  bHaveName = true;
688  }
689  else if (pSymbol->Name == "ExportName")
690  {
691  pSymbol->Value >>= pDescriptor[nNumFullEntries].sExportName;
692  bHaveExportName = true;
693  }
694  else if (pSymbol->Name == "FontName")
695  {
696  pSymbol->Value >>= pDescriptor[nNumFullEntries].sFontName;
697  bHaveFontName = true;
698  }
699  else if (pSymbol->Name == "CharSet")
700  {
701  pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharSet;
702  bHaveCharSet = true;
703  }
704  else if (pSymbol->Name == "Family")
705  {
706  pSymbol->Value >>= pDescriptor[nNumFullEntries].nFamily;
707  bHaveFamily = true;
708  }
709  else if (pSymbol->Name == "Pitch")
710  {
711  pSymbol->Value >>= pDescriptor[nNumFullEntries].nPitch;
712  bHavePitch = true;
713  }
714  else if (pSymbol->Name == "Weight")
715  {
716  pSymbol->Value >>= pDescriptor[nNumFullEntries].nWeight;
717  bHaveWeight = true;
718  }
719  else if (pSymbol->Name == "Italic")
720  {
721  pSymbol->Value >>= pDescriptor[nNumFullEntries].nItalic;
722  bHaveItalic = true;
723  }
724  else if (pSymbol->Name == "SymbolSet")
725  {
726  pSymbol->Value >>= pDescriptor[nNumFullEntries].sSymbolSet;
727  bHaveSymbolSet = true;
728  }
729  else if (pSymbol->Name == "Character")
730  {
731  pSymbol->Value >>= pDescriptor[nNumFullEntries].nCharacter;
732  bHaveCharacter = true;
733  }
734  pSymbol++;
735  }
736  if ( bHaveName && bHaveExportName && bHaveCharSet && bHaveFontName && bHaveCharacter
737  && bHaveFamily && bHavePitch && bHaveWeight && bHaveItalic && bHaveSymbolSet)
738  nNumFullEntries++;
739  }
740  }
741  aSymbolList.realloc (nNumFullEntries);
742  mrAny <<= aSymbolList;
743  }
744  else
745  {
746  mrAny <<= maProps.GetIndexContainer();
747  }
748  mpBaseContext->AddPropertyValue();
749  }
750  else {
751  assert(false && "no BaseContext");
752  }
753 }
754 
755 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SvXMLImportContext * CreateSettingsContext(SvXMLImport &rImport, sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > &xAttrList, beans::PropertyValue &rProp, XMLConfigBaseContext *pBaseContext)
URL aURL
SvXMLImport & GetImport()
Definition: xmlictxt.hxx:59
constexpr sal_uInt16 XML_NAMESPACE_OOO
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
SvXMLNamespaceMap & GetNamespaceMap()
Definition: xmlimp.hxx:398
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3508
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
static bool parseDateTime(css::util::DateTime &rDateTime, std::u16string_view rString)
OUString Name
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
Value
virtual void SetConfigurationSettings(const css::uno::Sequence< css::beans::PropertyValue > &aConfigProps)
Definition: xmlimp.cxx:1424
static bool IsFuzzing()
int nCount
sal_uInt16 GetKeyByAttrValueQName(const OUString &rAttrName, OUString *pLocalName) const
const char * sName
virtual void SetViewSettings(const css::uno::Sequence< css::beans::PropertyValue > &aViewProps)
Definition: xmlimp.cxx:1420
#define TOOLS_WARN_EXCEPTION(area, stream)
int i
::std::vector< SettingsGroup > maDocSpecificSettings
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
const uno::Reference< uno::XComponentContext > m_xContext
virtual ~XMLDocumentSettingsContext() override
This class deliberately does not support XWeak, to improve performance when loading large documents...
Definition: xmlictxt.hxx:44
virtual void SetDocumentSpecificSettings(const OUString &_rSettingsGroupName, const css::uno::Sequence< css::beans::PropertyValue > &_rSettings)
Definition: xmlimp.cxx:1428
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
Definition: xmlictxt.cxx:40
Handling of tokens in XML:
#define SAL_INFO(area, stream)
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
static sal_Int32 decodeSomeChars(css::uno::Sequence< sal_Int8 > &aPass, const OUString &sBuffer)
virtual void SAL_CALL characters(const OUString &aChars) override
This method is called for all characters that are contained in the current element.
Definition: xmlictxt.cxx:70
sal_Int16 nValue
XMLDocumentSettingsContext(SvXMLImport &rImport)
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)